Wiselib
wiselib.testing/algorithms/topology/cbtc/cbtc_topology_message.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_TOPOLOGY_CBTC_TOPOLOGY_MESSAGE_H__
00020 #define __ALGORITHMS_TOPOLOGY_CBTC_TOPOLOGY_MESSAGE_H__
00021 
00022 #include "util/serialization/simple_types.h"
00023 
00024 namespace wiselib
00025 {
00026 
00027    template<typename OsModel_P,
00028          typename Radio_P>
00029    class CbtcTopologyMessage
00030    {
00031       public:
00032       
00033       typedef OsModel_P OsModel;
00034       typedef Radio_P Radio;
00035       typedef typename Radio::block_data_t block_data_t;
00036       typedef typename Radio::node_id_t node_id_t;
00037       
00038       uint8_t const static HELLO_SIZE = sizeof(uint8_t) + sizeof(int) + sizeof(double) * 2;
00039       uint8_t const static ACK_SIZE = sizeof(uint8_t) + sizeof(int) + sizeof(double) * 2;
00040       uint8_t const static ASYMMETRIC_SIZE = sizeof(uint8_t);
00041       uint8_t const static NDP_SIZE = sizeof(uint8_t) + sizeof(int) + sizeof(double) * 2;
00042 
00043       // --------------------------------------------------------------------
00044       inline CbtcTopologyMessage( uint8_t id );
00045 
00046       // --------------------------------------------------------------------
00047       inline uint8_t msg_id()
00048       { return read<OsModel, block_data_t, uint8_t>( buffer ); }
00049 
00050       // --------------------------------------------------------------------
00051       inline void set_msg_id( uint8_t id )
00052       { write<OsModel, block_data_t, uint8_t>( buffer, id ); }
00053       
00054       // --------------------------------------------------------------------
00055       inline int power()
00056       { return (int)read<OsModel, block_data_t, int>( buffer + POWER_POS); }
00057       
00058       // --------------------------------------------------------------------
00059       inline void set_power( int power )
00060       { write<OsModel, block_data_t, int>(buffer + POWER_POS, power); }
00061       
00062       // --------------------------------------------------------------------
00063       inline double position_x()
00064       { return read<OsModel, block_data_t, double>(buffer + POSITIONX_POS);}
00065       
00066       // --------------------------------------------------------------------
00067       inline double position_y()
00068       { return read<OsModel, block_data_t, double>(buffer + POSITIONY_POS);}
00069       
00070       // --------------------------------------------------------------------
00071       inline void set_position( double x, double y )
00072       { 
00073          write<OsModel, block_data_t, double>(buffer + POSITIONX_POS, x);
00074          write<OsModel, block_data_t, double>(buffer + POSITIONY_POS, y);
00075       }
00076 
00077       private:
00078 
00079       enum data_positions
00080       {
00081          MSG_ID_POS  = 0,
00082          POWER_POS = MSG_ID_POS + sizeof(uint8_t),
00083          POSITIONX_POS = (POWER_POS + sizeof(int)),
00084          POSITIONY_POS = (POSITIONX_POS + sizeof(double))
00085       };
00086 
00087       uint8_t buffer[sizeof(uint8_t) + sizeof(int) + sizeof(double) * 2];
00088    };
00089    
00090    // -----------------------------------------------------------------------
00091    // -----------------------------------------------------------------------
00092    // -----------------------------------------------------------------------
00093    template<typename OsModel_P, typename Radio_P>
00094    CbtcTopologyMessage<OsModel_P, Radio_P>::
00095 	CbtcTopologyMessage( uint8_t id )
00096    {
00097       set_msg_id( id );
00098    }
00099 }
00100 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines