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