Wiselib
wiselib.testing/algorithms/routing/dymo/dymo_route_discovery_msg.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_DYMO_ROUTE_DISCOVERY_MSG_H__
00020 #define __ALGORITHMS_ROUTING_DYMO_ROUTE_DISCOVERY_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 Path_P>
00030    class DYMORouteDiscoveryMessage
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 Path_P Path;
00037       // -----------------------------------------------------------------------
00038       DYMORouteDiscoveryMessage() {};
00039       // -----------------------------------------------------------------------
00040       inline DYMORouteDiscoveryMessage(
00041               uint8_t msg_type,
00042               uint8_t bcast_id,
00043               uint8_t hop_cnt,
00044               uint16_t source_seq_nr,
00045               uint16_t destination_seq_nr,
00046               uint16_t source,
00047               uint16_t destination,
00048               uint8_t  next_hop );
00049 
00050       // --------------------------------------------------------------------
00051       inline uint8_t msg_type()
00052       {return read<OsModel, block_data_t, uint8_t>( buffer ); };
00053       // --------------------------------------------------------------------
00054       inline void set_msg_type( uint8_t type )
00055       {write<OsModel, block_data_t, uint8_t>( buffer, type ); };
00056       // --------------------------------------------------------------------
00057       inline uint8_t bcast_id()
00058       { return read<OsModel, block_data_t, uint8_t>( buffer + BCAST_ID_POS ); };
00059       // --------------------------------------------------------------------
00060       inline void set_bcast_id( uint8_t bcast_id )
00061       { write<OsModel, block_data_t, uint8_t>( buffer + BCAST_ID_POS, bcast_id ); }
00062       // --------------------------------------------------------------------
00063       inline uint8_t hop_cnt()
00064       { return read<OsModel, block_data_t, uint8_t>(buffer + HOPS_POS); }
00065       // --------------------------------------------------------------------
00066       inline void set_hop_cnt( uint8_t hop_cnt )
00067       { write<OsModel, block_data_t, uint8_t>(buffer + HOPS_POS, hop_cnt); }
00068       // --------------------------------------------------------------------
00069       inline uint16_t source_sequence_nr()
00070       { return read<OsModel, block_data_t, uint16_t>(buffer + SRC_SEQ_POS); }
00071       // --------------------------------------------------------------------
00072       inline void set_source_sequence_nr( uint16_t src_seq )
00073       { write<OsModel, block_data_t, uint16_t>(buffer + SRC_SEQ_POS, src_seq); }
00074       // --------------------------------------------------------------------
00075       inline uint16_t destination_sequence_nr()
00076       { return read<OsModel, block_data_t, uint16_t>(buffer + DES_SEQ_POS); }
00077       // --------------------------------------------------------------------
00078       inline void set_destination_sequence_nr( uint16_t des_seq )
00079       { write<OsModel, block_data_t, uint16_t>(buffer + DES_SEQ_POS, des_seq); }
00080       // --------------------------------------------------------------------
00081       inline uint16_t source()
00082       { return read<OsModel, block_data_t, uint16_t>(buffer + SOURCE_POS); }
00083       // --------------------------------------------------------------------
00084       inline void set_source( uint16_t src )
00085       { write<OsModel, block_data_t, uint16_t>(buffer + SOURCE_POS, src); }
00086       // --------------------------------------------------------------------
00087       inline uint16_t destination()
00088       { return read<OsModel, block_data_t, uint16_t>(buffer + DEST_POS); }
00089       // --------------------------------------------------------------------
00090       inline void set_destination( uint16_t dest )
00091       { write<OsModel, block_data_t, uint16_t>(buffer + DEST_POS, dest); }
00092       // --------------------------------------------------------------------
00093       inline uint8_t next_hop()
00094       { return read<OsModel, block_data_t, uint8_t>(buffer + NHOP_POS); }
00095       // --------------------------------------------------------------------
00096       inline void set_next_hop( uint8_t next_hop )
00097       { write<OsModel, block_data_t, uint8_t>(buffer + NHOP_POS, next_hop); }
00098       // -----------------------------------------------------------------------
00099 
00100       inline uint8_t payload_size()
00101       { return read<OsModel, block_data_t, uint8_t>(buffer + PAYLOAD_POS); }
00102       // -----------------------------------------------------------------------
00103       inline void set_payload( uint8_t len, block_data_t* data )
00104       { memcpy( buffer + PAYLOAD_POS + 1, data, len ); }
00105       // -----------------------------------------------------------------------
00106       inline block_data_t* payload( void )
00107       { return buffer + PAYLOAD_POS + 1; }
00108       // --------------------------------------------------------------------
00109       inline size_t buffer_size()
00110       { return PAYLOAD_POS + 1 + payload_size(); }
00111 
00112    
00113       enum data_positions
00114       {
00115          MSG_TYPE_POS   = 0,
00116          BCAST_ID_POS   = 1,
00117          HOPS_POS       = 2,
00118          SRC_SEQ_POS    = 3,
00119          DES_SEQ_POS    = 5,
00120          SOURCE_POS     = 7,
00121          DEST_POS       = 9,
00122          NHOP_POS       = 11,
00123          PAYLOAD_POS   = 12
00124       };
00125 private:
00126       block_data_t buffer[Radio::MAX_MESSAGE_LENGTH];
00127    };
00128    // -----------------------------------------------------------------------
00129    template <typename OsModel_P,
00130              typename Radio_P,
00131              typename Path_P>
00132    DYMORouteDiscoveryMessage<OsModel_P, Radio_P, Path_P>::
00133    DYMORouteDiscoveryMessage(
00134               uint8_t msg_type,
00135               uint8_t bcast_id,
00136               uint8_t hop_cnt,
00137               uint16_t source_seq_nr,
00138               uint16_t destination_seq_nr,
00139               uint16_t source,
00140               uint16_t destination,
00141               uint8_t  next_hop  )
00142    {
00143       set_msg_type( msg_type);
00144       set_bcast_id( bcast_id );
00145       set_hop_cnt( hop_cnt );
00146       set_source_sequence_nr( source_seq_nr );
00147       set_destination_sequence_nr( destination_seq_nr);
00148       set_source( source );
00149       set_destination( destination );
00150       set_next_hop( next_hop );
00151    };
00152 
00153 }
00154 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines