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 time_t t1() 00050 { 00051 time_t t1; 00052 memcpy( &t1, buffer + TIME_POS, TIME_SIZE ); 00053 return t1; 00054 } 00055 // -------------------------------------------------------------------- 00056 inline time_t t2() 00057 { 00058 time_t t2; 00059 memcpy( &t2, buffer + TIME_POS + TIME_SIZE, TIME_SIZE ); 00060 return t2; 00061 } 00062 // -------------------------------------------------------------------- 00063 inline time_t t3() 00064 { 00065 time_t t3; 00066 memcpy( &t3, buffer + TIME_POS + 2*TIME_SIZE, TIME_SIZE ); 00067 return t3; 00068 } 00069 // -------------------------------------------------------------------- 00070 inline void set_t1( time_t t1 ) 00071 { memcpy( buffer + TIME_POS, &t1, TIME_SIZE ); } 00072 // -------------------------------------------------------------------- 00073 inline void set_t2( time_t t2 ) 00074 { memcpy( buffer + TIME_POS + TIME_SIZE, &t2, TIME_SIZE ); } 00075 // -------------------------------------------------------------------- 00076 inline void set_t3( time_t t3 ) 00077 { memcpy( buffer + TIME_POS + 2*TIME_SIZE, &t3, TIME_SIZE ); } 00078 // -------------------------------------------------------------------- 00079 inline node_id_t receiver() 00080 { 00081 node_id_t receiver; 00082 memcpy( &receiver, buffer + RECEIVER_POS, NODE_ID_SIZE ); 00083 return receiver; 00084 } 00085 // -------------------------------------------------------------------- 00086 inline void set_receiver( node_id_t receiver ) 00087 { memcpy( buffer + RECEIVER_POS, &receiver, NODE_ID_SIZE ); } 00088 // -------------------------------------------------------------------- 00089 00090 private: 00091 00092 enum data_positions 00093 { 00094 MSG_ID_POS = 0, 00095 TIME_POS = 1, 00096 RECEIVER_POS = 1 + TIME_SIZE 00097 }; 00098 00099 uint8_t buffer[1 + TIME_SIZE*3 + NODE_ID_SIZE]; 00100 }; 00101 } 00102 #endif