Wiselib
wiselib.testing/algorithms/aggregation/aggregationmsg.h
Go to the documentation of this file.
00001 /* 
00002  * File:   aggregationmsg.h
00003  * Author: Koninis
00004  *
00005  * Created on January 22, 2011, 1:16 PM
00006  */
00007 
00008 #ifndef AGGREGATIONMSG_H
00009 #define  AGGREGATIONMSG_H
00010 
00011 #include "aggregate.h"
00012 
00013 
00014 namespace wiselib {
00015 
00020     template
00021     <typename OsModel_P, typename Radio_P>
00022     class AggregateMsg {
00023     public:
00024         typedef OsModel_P OsModel;
00025         typedef Radio_P Radio;
00026 
00027         typedef typename Radio::node_id_t node_id_t;
00028         typedef typename Radio::size_t size_t;
00029         typedef typename Radio::block_data_t block_data_t;
00030         typedef typename Radio::message_id_t message_id_t;
00031         // message ids
00032 
00033         enum {
00034             AGG_MESSAGE_TYPE = 143
00035         };
00036 
00037         enum data_positions {
00038          MSG_ID_POS  = 0, // message id position inside the message [uint8]
00039          AGG_LEVEL_POS  = 1, // aggregation level
00040          PAYLOAD_POS = 2   // position of the payload length
00041                            // (the payload starts at +1)
00042         };
00043 
00044         enum aggregation_level {
00045          IN_CLUSTER  = 0,
00046          IN_TREE = 1
00047         };
00048         // --------------------------------------------------------------------
00049 
00050         AggregateMsg() {
00051          set_msg_id(AGG_MESSAGE_TYPE);
00052          set_payload_size(0);
00053                 set_level(IN_CLUSTER);
00054         };
00055         // --------------------------------------------------------------------
00056 
00057         ~AggregateMsg() {
00058         };
00059 
00060         // get the message id
00061 
00062         inline message_id_t msg_id() {
00063             return read<OsModel, block_data_t, uint8_t > (buffer + MSG_ID_POS);
00064         };
00065         // --------------------------------------------------------------------
00066 
00067         // set the message id
00068 
00069         inline void set_msg_id(message_id_t id) {
00070             write<OsModel, block_data_t, uint8_t > (buffer + MSG_ID_POS, id);
00071         };
00072 
00073         inline uint8_t level() {
00074             return read<OsModel, block_data_t, uint8_t > (buffer + AGG_LEVEL_POS);
00075         }
00076 
00077         inline void set_level(uint8_t level) {
00078             write<OsModel, block_data_t, uint8_t > (buffer + AGG_LEVEL_POS, level);
00079         }
00080 
00081         inline block_data_t * payload() {
00082             return buffer + PAYLOAD_POS + 1 ;
00083         };
00084 
00085         inline uint8_t payload_size() {
00086             return read<OsModel, block_data_t, uint8_t > (buffer + PAYLOAD_POS);
00087         }
00088 
00089         inline uint8_t buffer_size() {
00090             return PAYLOAD_POS + 1 + payload_size();
00091         }
00092 
00093         inline block_data_t* data() {
00094             return buffer;
00095         }
00096 
00097 //        inline add_aggregate(aggregate_t value) {
00098 //            write<OsModel, block_data_t, aggregate_t::value_t>( data() + buffer_size(), value.get() );
00099 //        }
00100 
00101         inline void set_payload_size(uint8_t payload_size ) {
00102             write<OsModel, block_data_t, uint8_t>( data() + PAYLOAD_POS, payload_size );
00103         }
00104 
00105     private:
00106         block_data_t buffer[Radio::MAX_MESSAGE_LENGTH]; // buffer for the message data
00107     };
00108 
00109 }
00110 
00111 #endif   /* AGGREGATEMSG_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines