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_SYNCHRONIZATION_TPSN_SYNCHRONIZATION_MESSAGE_H 00020 #define __ALGORITHMS_SYNCHRONIZATION_TPSN_SYNCHRONIZATION_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 typename Clock_P> 00030 class TpsnSynchronizationMessage 00031 { 00032 public: 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 typedef Clock_P Clock; 00038 typedef typename Clock::time_t time_t; 00039 00040 static const uint8_t NODE_ID_SIZE = sizeof( node_id_t ); 00041 static const uint8_t TIME_SIZE = sizeof( time_t ); 00042 // -------------------------------------------------------------------- 00043 inline uint8_t msg_id() 00044 { return read<OsModel, block_data_t, uint8_t>( buffer ); } 00045 // -------------------------------------------------------------------- 00046 inline void set_msg_id( uint8_t id ) 00047 { write<OsModel, block_data_t, uint8_t>( buffer, id ); } 00048 // -------------------------------------------------------------------- 00049 inline uint8_t level() 00050 { return read<OsModel, block_data_t, uint8_t>( buffer+1 ); } 00051 // -------------------------------------------------------------------- 00052 inline void set_level( uint8_t level ) 00053 { write<OsModel, block_data_t, uint8_t>( buffer+1, level ); } 00054 // -------------------------------------------------------------------- 00055 inline time_t t1() 00056 { 00057 time_t t1; 00058 memcpy( &t1, buffer + TIME_POS, TIME_SIZE ); 00059 return t1; 00060 } 00061 // -------------------------------------------------------------------- 00062 inline time_t t2() 00063 { 00064 time_t t2; 00065 memcpy( &t2, buffer + TIME_POS + TIME_SIZE, TIME_SIZE ); 00066 return t2; 00067 } 00068 // -------------------------------------------------------------------- 00069 inline void set_t1( time_t t1 ) 00070 { memcpy( buffer + TIME_POS, &t1, TIME_SIZE ); } 00071 // -------------------------------------------------------------------- 00072 inline void set_t2( time_t t2 ) 00073 { memcpy( buffer + TIME_POS + TIME_SIZE, &t2, TIME_SIZE ); } 00074 // -------------------------------------------------------------------- 00075 inline node_id_t receiver() 00076 { 00077 node_id_t receiver; 00078 memcpy( &receiver, buffer + RECEIVER_POS, NODE_ID_SIZE ); 00079 return receiver; 00080 } 00081 // -------------------------------------------------------------------- 00082 inline void set_receiver( node_id_t receiver ) 00083 { memcpy( buffer + RECEIVER_POS, &receiver, NODE_ID_SIZE ); } 00084 // -------------------------------------------------------------------- 00085 00086 private: 00087 00088 enum data_positions 00089 { 00090 MSG_ID_POS = 0, 00091 TIME_POS = 2, 00092 RECEIVER_POS = 1 + TIME_SIZE 00093 }; 00094 00095 uint8_t buffer[1 + TIME_SIZE*2 + NODE_ID_SIZE]; 00096 }; 00097 } 00098 #endif