Wiselib
wiselib.testing/algorithms/synchronization/lts/lts_synchronization_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_SYNCHRONIZATION_LTS_SYNCHRONIZATION_MESSAGE_H
00020 #define __ALGORITHMS_SYNCHRONIZATION_LTS_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 time_t_P>
00030    class LtsSynchronizationMessage
00031    {
00032    public:
00033       typedef OsModel_P OsModel;
00034       typedef Radio_P Radio;
00035       typedef typename time_t_P time_t;
00036 
00037       typedef typename Radio::block_data_t block_data_t;
00038       typedef typename Radio::node_id_t node_id_t;
00039 
00040       static const uint8_t TIME_SIZE = sizeof( time_t );
00041       // --------------------------------------------------------------------
00042       inline uint8_t msg_id()
00043       { return read<OsModel, block_data_t, uint8_t>( buffer ); }
00044       // --------------------------------------------------------------------
00045       inline void set_msg_id( uint8_t id )
00046       { write<OsModel, block_data_t, uint8_t>( buffer, id ); }
00047       // --------------------------------------------------------------------
00048       inline time_t t1()
00049       {
00050          time_t t1;
00051          memcpy( &t1, buffer + TIME_POS, TIME_SIZE );
00052          return t1;
00053       }
00054       // --------------------------------------------------------------------
00055       inline time_t t2()
00056       {
00057          time_t t2;
00058          memcpy( &t2, buffer + TIME_POS + TIME_SIZE, TIME_SIZE );
00059          return t2;
00060       }
00061       // --------------------------------------------------------------------
00062       inline time_t t3()
00063       {
00064          time_t t3;
00065          memcpy( &t3, buffer + TIME_POS + 2*TIME_SIZE, TIME_SIZE );
00066          return t3;
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 void set_t3( time_t t3 )
00076       { memcpy( buffer + TIME_POS + 2*TIME_SIZE, &t3, TIME_SIZE ); }
00077       // --------------------------------------------------------------------
00078 
00079    private:
00080 
00081       enum data_positions
00082       {
00083          MSG_ID_POS  = 0,
00084          TIME_POS = 1,
00085       };
00086 
00087       uint8_t buffer[1 + TIME_SIZE*3];
00088    };
00089 }
00090 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines