Wiselib
wiselib.testing/algorithms/routing/tora/tora_broadcast_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_ROUTING_TORA_BROADCAST_MSG_H__
00020 #define __ALGORITHMS_ROUTING_TORA_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             typename RoutingTableEntry_P,
00030             int ENTRY_CNT>
00031    class ToraBroadcastMessage
00032    {
00033    public:
00034       typedef OsModel_P OsModel;
00035       typedef Radio_P Radio;
00036       typedef RoutingTableEntry_P RoutingTableEntry;
00037       typedef typename Radio::block_data_t block_data_t;
00038       // --------------------------------------------------------------------
00039       inline ToraBroadcastMessage();
00040       // --------------------------------------------------------------------
00041       inline uint8_t msg_id()
00042       { return read<OsModel, block_data_t, uint8_t>( buffer ); };
00043       // --------------------------------------------------------------------
00044       inline void set_msg_id( uint8_t id )
00045       { write<OsModel, block_data_t, uint8_t>( buffer, id ); }
00046       // --------------------------------------------------------------------
00047       inline uint8_t entry_cnt()
00048       { return read<OsModel, block_data_t, uint8_t>(buffer + ENTRY_CNT_POS); }
00049       // --------------------------------------------------------------------
00050       inline void set_entry_cnt( uint8_t cnt )
00051       { write<OsModel, block_data_t, uint8_t>(buffer + ENTRY_CNT_POS, cnt); }
00052       // --------------------------------------------------------------------
00053       inline void set_entry( uint8_t idx, RoutingTableEntry& entry )
00054       {
00055          int offset = DATA_POS + idx * sizeof(RoutingTableEntry);
00056          write<OsModel, block_data_t, RoutingTableEntry>( buffer + offset, entry );
00057       };
00058       // --------------------------------------------------------------------
00059       inline bool entry( uint8_t idx, RoutingTableEntry& entry )
00060       {
00061          if (idx >= ENTRY_CNT)
00062             return false;
00063 
00064          int offset = DATA_POS + idx * sizeof(RoutingTableEntry);
00065          read<OsModel, block_data_t, RoutingTableEntry>( buffer + offset, entry );
00066          return true;
00067       };
00068       // --------------------------------------------------------------------
00069       inline size_t buffer_size()
00070       { return DATA_POS + entry_cnt() * sizeof(RoutingTableEntry); }
00071 
00072    private:
00073       enum data_positions
00074       {
00075          MSG_ID_POS    = 0,
00076          ENTRY_CNT_POS = 1,
00077          DATA_POS      = 2
00078       };
00079 
00080       uint8_t buffer[DATA_POS + ENTRY_CNT * sizeof(RoutingTableEntry)];
00081    };
00082    // -----------------------------------------------------------------------
00083    template<typename OsModel_P,
00084             typename Radio_P,
00085             typename RoutingTableEntry_P,
00086             int ENTRY_CNT>
00087    ToraBroadcastMessage<OsModel_P, Radio_P, RoutingTableEntry_P, ENTRY_CNT>::
00088    ToraBroadcastMessage()
00089    {
00090       set_msg_id( 0 );
00091       set_entry_cnt( 0 );
00092    }
00093 
00094 }
00095 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines