Wiselib
wiselib.testing/algorithms/coloring/two_hops/two_hops_message_types.h
Go to the documentation of this file.
00001 #ifndef __ALGORITHMS_COLORING_TWO_HOPS_MSG_H__
00002 #define __ALGORITHMS_COLORING_TWO_HOPS_MSG_H__
00003 
00004 
00005 #include "util/serialization/simple_types.h"
00006 
00007 namespace wiselib
00008 {
00009 
00010     enum ms_types
00011       {
00012          NODE_STARTED = 20,
00013          REP_CHANGE = 21,
00014          REP_SAT = 22,
00015          REP_FBID= 23,
00016          REQ_COLOR = 24,
00017          REP_COLOR = 25
00018       };
00019 
00020    template<typename OsModel_P,
00021             typename Radio_P>
00022    class TwoHopsMessage
00023    {
00024    public:
00025       typedef OsModel_P OsModel;
00026       typedef Radio_P Radio;
00027       typedef typename Radio::block_data_t block_data_t;
00028       // --------------------------------------------------------------------
00029       inline TwoHopsMessage();
00030      // --------------------------------------------------------------------
00031       inline uint8_t msg_id()
00032       { return read<OsModel, block_data_t, uint8_t>( buffer ); };
00033       // --------------------------------------------------------------------
00034       inline void set_msg_id( uint8_t id )
00035       { write<OsModel, block_data_t, uint8_t>( buffer, id ); }
00036       // --------------------------------------------------------------------
00037       inline uint16_t source()
00038       { return read<OsModel, block_data_t, uint16_t>(buffer + SOURCE_POS); }
00039       // --------------------------------------------------------------------
00040       inline void set_source( uint16_t src )
00041       { write<OsModel, block_data_t, uint16_t>(buffer + SOURCE_POS, src); }
00042       // --------------------------------------------------------------------
00043       inline uint16_t destination()
00044       { return read<OsModel, block_data_t, uint16_t>(buffer + DEST_POS); }
00045       // --------------------------------------------------------------------
00046       inline void set_destination( uint16_t dest )
00047       { write<OsModel, block_data_t, uint16_t>(buffer + DEST_POS, dest); }
00048       // --------------------------------------------------------------------
00049       inline uint16_t hops()
00050       { return read<OsModel, block_data_t, uint16_t>(buffer + HOPS_POS); }
00051       // --------------------------------------------------------------------
00052       inline void set_hops( uint16_t hops)
00053       { write<OsModel, block_data_t, uint16_t>(buffer + HOPS_POS, hops); }
00054       // --------------------------------------------------------------------
00055       inline uint16_t id_num()
00056       { return read<OsModel, block_data_t, uint16_t>(buffer + ID_NUM_POS); }
00057       // --------------------------------------------------------------------
00058       inline void set_id_num( uint16_t hops)
00059       { write<OsModel, block_data_t, uint16_t>(buffer + ID_NUM_POS, hops); }
00060       // --------------------------------------------------------------------
00061       inline uint8_t payload_size()
00062       { return read<OsModel, block_data_t, uint8_t>(buffer + PAYLOAD_POS); }
00063       // --------------------------------------------------------------------
00064       inline uint8_t* payload()
00065       { return buffer + PAYLOAD_POS + 1; }
00066       // --------------------------------------------------------------------
00067       inline void set_payload( uint8_t len, uint8_t *buf )
00068       {
00069          write<OsModel, block_data_t, uint8_t>(buffer + PAYLOAD_POS, len);
00070          memcpy( buffer + PAYLOAD_POS + 1, buf, len);
00071       }
00072       // --------------------------------------------------------------------
00073       inline size_t buffer_size()
00074       { return PAYLOAD_POS + 1 + payload_size(); }
00075 
00076    private:
00077       inline void set_payload_size( uint8_t len )
00078       { write<OsModel, block_data_t, uint8_t>(buffer + PAYLOAD_POS, len); }
00079 
00080       enum data_positions
00081       {
00082          MSG_ID_POS  = 0,
00083          SOURCE_POS  = 1,
00084          DEST_POS    = 3,
00085          HOPS_POS    = 5,
00086          ID_NUM_POS  = 7,
00087          PAYLOAD_POS = 11
00088       };
00089 
00090       uint8_t buffer[Radio::MAX_MESSAGE_LENGTH];
00091    };
00092    // -----------------------------------------------------------------------
00093    template<typename OsModel_P,
00094             typename Radio_P>
00095    TwoHopsMessage<OsModel_P, Radio_P>::
00096    TwoHopsMessage()
00097    {
00098       set_msg_id( 0 );
00099       set_source( Radio::NULL_NODE_ID );
00100       set_destination( Radio::NULL_NODE_ID );
00101       set_payload_size( 0 );
00102       set_hops(0);
00103    }
00104 
00105 }
00106 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines