Wiselib
|
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_LMST_TOPOLOGY_MESSAGE_H__ 00020 #define __ALGORITHMS_TOPOLOGY_LMST_TOPOLOGY_MESSAGE_H__ 00021 00022 #include "internal_interface/position/position.h" 00023 #include "util/serialization/simple_types.h" 00024 00025 namespace wiselib 00026 { 00027 00028 template<typename OsModel_P, 00029 typename Radio_P, 00030 typename Float = float> 00031 class LmstTopologyMessage 00032 { 00033 public: 00034 typedef OsModel_P OsModel; 00035 typedef Radio_P Radio; 00036 typedef typename Radio::block_data_t block_data_t; 00037 typedef Float float_t; 00038 00039 typedef PositionType<float_t> Position; 00040 static const uint8_t POSITION_SIZE = sizeof( Position ); 00041 // -------------------------------------------------------------------- 00042 inline LmstTopologyMessage( uint8_t id ); 00043 inline LmstTopologyMessage( uint8_t id, Position pos ); 00044 // -------------------------------------------------------------------- 00045 inline uint8_t msg_id() 00046 { return read<OsModel, block_data_t, uint8_t>( buffer ); } 00047 // -------------------------------------------------------------------- 00048 inline void set_msg_id( uint8_t id ) 00049 { write<OsModel, block_data_t, uint8_t>( buffer, id ); } 00050 // -------------------------------------------------------------------- 00051 inline Position position() 00052 { 00053 Position p; 00054 memcpy( &p.x, buffer + POS_POS, POSITION_SIZE ); 00055 return p; 00056 } 00057 // -------------------------------------------------------------------- 00058 inline void set_position( Position pos ) 00059 { 00060 memcpy( buffer + POS_POS, &pos.x, POSITION_SIZE ); 00061 } 00062 00063 private: 00064 00065 enum data_positions 00066 { 00067 MSG_ID_POS = 0, 00068 POS_POS = 1, 00069 }; 00070 00071 uint8_t buffer[1 + POSITION_SIZE]; 00072 }; 00073 // ----------------------------------------------------------------------- 00074 // ----------------------------------------------------------------------- 00075 // ----------------------------------------------------------------------- 00076 template<typename OsModel_P, 00077 typename Radio_P, 00078 typename Float> 00079 LmstTopologyMessage<OsModel_P, Radio_P, Float>:: 00080 LmstTopologyMessage( uint8_t id ) 00081 { 00082 set_msg_id( id ); 00083 } 00084 // ----------------------------------------------------------------------- 00085 template<typename OsModel_P, 00086 typename Radio_P, 00087 typename Float> 00088 LmstTopologyMessage<OsModel_P, Radio_P, Float>:: 00089 LmstTopologyMessage( uint8_t id, Position pos ) 00090 { 00091 set_msg_id( id ); 00092 set_position( pos ); 00093 } 00094 00095 } 00096 #endif