Wiselib
wiselib.testing/algorithms/synchronization/rbs/rbs_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_RBS_SYNCHRONIZATION_MESSAGE_H
00020 #define  __ALGORITHMS_RBS_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 rbsReceiverLocalTimeMessage
00031    {
00032    public:
00033       typedef OsModel_P OsModel;
00034       typedef Radio_P Radio;
00035       typedef Clock_P Clock;
00036 
00037       typedef typename Radio::block_data_t block_data_t;
00038       typedef typename Radio::node_id_t node_id_t;
00039       typedef typename Clock::time_t time_t;
00040 
00041       inline rbsReceiverLocalTimeMessage(uint8_t);
00042       
00043       // --------------------------------------------------------------------
00044       inline uint8_t msg_id()
00045       { return read<OsModel, block_data_t, uint8_t>( buffer + MSG_ID_POS); }
00046       // --------------------------------------------------------------------
00047       inline void set_msg_id( uint8_t id )
00048       { write<OsModel, block_data_t, uint8_t>( buffer + MSG_ID_POS, id ); }
00049       // --------------------------------------------------------------------
00050       inline uint16_t receiver()
00051       { return read<OsModel, block_data_t, uint16_t>(buffer + RECEIVER_POS); }
00052       // --------------------------------------------------------------------
00053       inline void set_receiver( uint16_t receiver_id )
00054       { write<OsModel, block_data_t, uint16_t>(buffer + RECEIVER_POS, receiver_id); }
00055       // --------------------------------------------------------------------
00056       inline time_t time()
00057       { return read<OsModel, block_data_t, time_t>(buffer + TIME_POS); }
00058       // --------------------------------------------------------------------
00059       inline void set_time( time_t time )
00060       { write<OsModel, block_data_t, time_t>(buffer + TIME_POS, time); }
00061       // --------------------------------------------------------------------
00062       inline size_t buffer_size()
00063       { return MESSAGE_SIZE; }
00064       // --------------------------------------------------------------------
00065       
00066 
00067    private:
00068 
00069       enum data_positions
00070       {
00071          MSG_ID_POS   = 0,
00072          TIME_POS     = MSG_ID_POS   + 1,
00073          RECEIVER_POS = TIME_POS     + sizeof( time_t ),
00074          MESSAGE_SIZE = RECEIVER_POS + sizeof( node_id_t )
00075       };
00076 
00077       uint8_t buffer[MESSAGE_SIZE];
00078    };
00079 
00080    template <typename OsModel_P,
00081              typename Radio_P,
00082              typename Clock_P>
00083    rbsReceiverLocalTimeMessage<OsModel_P, Radio_P, Clock_P>::
00084    rbsReceiverLocalTimeMessage(uint8_t msg_id)
00085    {
00086        set_msg_id(msg_id);
00087    }
00088    
00089 }
00090 #endif   /* _RBS_SYNCHRONIZATION_MESSAGE_H */
00091 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines