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_ROUTING_TREE_BROADCAST_MSG_H__ 00020 #define __ALGORITHMS_ROUTING_TREE_BROADCAST_MSG_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 TreeBroadcastMessage 00030 { 00031 public: 00032 typedef OsModel_P OsModel; 00033 typedef Radio_P Radio; 00034 typedef typename Radio::block_data_t block_data_t; 00035 // -------------------------------------------------------------------- 00036 inline TreeBroadcastMessage(); 00037 inline TreeBroadcastMessage( uint8_t msg, uint8_t hops, uint16_t id ); 00038 // -------------------------------------------------------------------- 00039 inline uint8_t msg_id() 00040 { return read<OsModel, block_data_t, uint8_t>( buffer ); }; 00041 // -------------------------------------------------------------------- 00042 inline void set_msg_id( uint8_t id ) 00043 { write<OsModel, block_data_t, uint8_t>( buffer, id ); } 00044 // -------------------------------------------------------------------- 00045 inline uint8_t hops() 00046 { return read<OsModel, block_data_t, uint8_t>(buffer + HOPS_POS); } 00047 // -------------------------------------------------------------------- 00048 inline void set_hops( uint8_t hops ) 00049 { write<OsModel, block_data_t, uint8_t>(buffer + HOPS_POS, hops); } 00050 // -------------------------------------------------------------------- 00051 inline uint16_t gate_id() 00052 { return read<OsModel, block_data_t, uint16_t>(buffer + GATEID_POS); } 00053 // -------------------------------------------------------------------- 00054 inline void set_gate_id( uint16_t id ) 00055 { write<OsModel, block_data_t, uint16_t>(buffer + GATEID_POS, id); } 00056 // -------------------------------------------------------------------- 00057 inline size_t buffer_size() 00058 { return MSG_END; }; 00059 00060 private: 00061 enum data_positions 00062 { 00063 MSG_ID_POS = 0, 00064 HOPS_POS = 1, 00065 GATEID_POS = 2, 00066 MSG_END = 4 00067 }; 00068 00069 block_data_t buffer[MSG_END]; 00070 }; 00071 // ----------------------------------------------------------------------- 00072 template<typename OsModel_P, 00073 typename Radio_P> 00074 TreeBroadcastMessage<OsModel_P, Radio_P>:: 00075 TreeBroadcastMessage() 00076 { 00077 set_msg_id( 0 ); 00078 set_hops( 0 ); 00079 set_gate_id( Radio::NULL_NODE_ID ); 00080 } 00081 // ----------------------------------------------------------------------- 00082 template<typename OsModel_P, 00083 typename Radio_P> 00084 TreeBroadcastMessage<OsModel_P, Radio_P>:: 00085 TreeBroadcastMessage( uint8_t msg, uint8_t hops, uint16_t id ) 00086 { 00087 set_msg_id( msg ); 00088 set_hops( hops ); 00089 set_gate_id( id ); 00090 } 00091 00092 } 00093 #endif