Wiselib
wiselib.testing/algorithms/localization/distance_based/modules/distance/localization_sum_dist_messages.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  ** This file is part of the generic algorithm library Wiselib.           **
00003  ** Copyright (C) 2008,2009 by the Wisebed (www.wisebed.eu) project.      **
00004  **                                                                       **
00005  ** The Wiselib is free software: you can redistribute it and/or modify   **
00006  ** it under the terms of the GNU Lesser General Public License as        **
00007  ** published by the Free Software Foundation, either version 3 of the    **
00008  ** License, or (at your option) any later version.                       **
00009  **                                                                       **
00010  ** The Wiselib is distributed in the hope that it will be useful,        **
00011  ** but WITHOUT ANY WARRANTY; without even the implied warranty of        **
00012  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         **
00013  ** GNU Lesser General Public License for more details.                   **
00014  **                                                                       **
00015  ** You should have received a copy of the GNU Lesser General Public      **
00016  ** License along with the Wiselib.                                       **
00017  ** If not, see <http://www.gnu.org/licenses/>.                           **
00018  ***************************************************************************/
00019 #ifndef __ALGORITHMS_LOCALIZATION_DISTANCE_BASED_LOCALIZATION_SUM_DIST_MESSAGES_H
00020 #define __ALGORITHMS_LOCALIZATION_DISTANCE_BASED_LOCALIZATION_SUM_DIST_MESSAGES_H
00021 
00022 #include "util/serialization/simple_types.h"
00023 #include "util/serialization/math_vec.h"
00024 #include "algorithms/localization/distance_based/util/localization_defutils.h"
00025 
00026 namespace wiselib
00027 {
00028 
00029    template<typename OsModel_P,
00030             typename Radio_P,
00031             typename Arithmatic_P>
00032    class LocalizationSumDistMessage
00033    {
00034    public:
00035       typedef OsModel_P OsModel;
00036       typedef Radio_P Radio;
00037       typedef Arithmatic_P Arithmatic;
00038       typedef typename Radio::node_id_t node_id_t;
00039       typedef typename Radio::block_data_t block_data_t;
00040       typedef typename Radio::size_t size_t;
00041       typedef typename Radio::message_id_t message_id_t;
00042       // --------------------------------------------------------------------
00043       inline LocalizationSumDistMessage();
00044       // --------------------------------------------------------------------
00045       inline message_id_t msg_id()
00046       { return read<OsModel, block_data_t, message_id_t>( buffer ); };
00047       // --------------------------------------------------------------------
00048       inline void set_msg_id( message_id_t id )
00049       { write<OsModel, block_data_t, message_id_t>( buffer, id ); }
00050       // --------------------------------------------------------------------
00051       inline node_id_t anchor()
00052       { return read<OsModel, block_data_t, node_id_t>(buffer + ANCHOR_POS); }
00053       // --------------------------------------------------------------------
00054       inline void set_anchor( node_id_t anchor )
00055       { write<OsModel, block_data_t, node_id_t>(buffer + ANCHOR_POS, anchor); }
00056       // --------------------------------------------------------------------
00057       inline Arithmatic path_length()
00058       { return read<OsModel, block_data_t, Arithmatic>(buffer + PATH_LEN_POS); }
00059       // --------------------------------------------------------------------
00060       inline void set_path_length( Arithmatic path_length )
00061       { write<OsModel, block_data_t, Arithmatic>(buffer + PATH_LEN_POS, path_length); }
00062       // --------------------------------------------------------------------
00063       inline Vec<Arithmatic> anchor_position()
00064       { return read<OsModel, block_data_t, Vec<Arithmatic> >(buffer + ANCHOR_POSITION_POS); }
00065       // --------------------------------------------------------------------
00066       inline void set_anchor_position( Vec<Arithmatic> pos )
00067       { write<OsModel, block_data_t, Vec<Arithmatic> >(buffer + ANCHOR_POSITION_POS, pos); }
00068       // --------------------------------------------------------------------
00069       inline size_t buffer_size()
00070       { return MSGEND_POS; }
00071 
00072    private:
00073       enum data_positions
00074       {
00075          ANCHOR_POS = sizeof(message_id_t),
00076          PATH_LEN_POS = ANCHOR_POS + sizeof(node_id_t),
00077          ANCHOR_POSITION_POS = PATH_LEN_POS + sizeof(Arithmatic),
00078          MSGEND_POS = ANCHOR_POSITION_POS + 3 * sizeof(Arithmatic)
00079       };
00080 
00081       block_data_t buffer[MSGEND_POS];
00082    };
00083    // -----------------------------------------------------------------------
00084    template<typename OsModel_P,
00085             typename Radio_P,
00086             typename Arithmatic_P>
00087    LocalizationSumDistMessage<OsModel_P, Radio_P, Arithmatic_P>::
00088    LocalizationSumDistMessage()
00089    {
00090       set_msg_id( 0 );
00091       set_anchor( 0 );
00092       set_path_length( 0.0 );
00093       set_anchor_position( UNKNOWN_POSITION );
00094    }
00095 
00096 }// namespace wiselib
00097 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines