Wiselib
wiselib.testing/algorithms/cluster/attribute_message.h
Go to the documentation of this file.
00001 /*
00002  * File:   attribute_message.h
00003  * Author: Amaxilatis
00004  *
00005  */
00006 
00007 #ifndef ATTRIBUTECLUSTERMSG_H
00008 #define  ATTRIBUTECLUSTERMSG_H
00009 
00010 namespace wiselib {
00011 
00012 template<typename OsModel_P, typename Radio_P>
00013 class AttributeClusterMsg {
00014 public:
00015    typedef OsModel_P OsModel;
00016    typedef Radio_P Radio;
00017 
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    typedef typename Radio::message_id_t message_id_t;
00022    typedef node_id_t cluster_id_t;
00023 
00024    enum data_positions {
00025       MSG_ID_POS = 0, // message id position inside the message [uint8]
00026       ATTRIBUTE_POS = sizeof(message_id_t)
00027    };
00028 
00029    // --------------------------------------------------------------------
00030 
00031    AttributeClusterMsg() {
00032       set_msg_id(ATTRIBUTE);
00033       set_attribute(0);
00034    }
00035    // --------------------------------------------------------------------
00036 
00037    ~AttributeClusterMsg() {
00038    }
00039 
00040    // get the message id
00041    inline message_id_t msg_id() {
00042       return read<OsModel, block_data_t, message_id_t> (buffer + MSG_ID_POS);
00043    }
00044    // --------------------------------------------------------------------
00045 
00046    // set the message id
00047    inline void set_msg_id(message_id_t id) {
00048       write<OsModel, block_data_t, message_id_t> (buffer + MSG_ID_POS, id);
00049    }
00050 
00051    inline node_id_t attribute() {
00052       return read<OsModel, block_data_t, node_id_t> (buffer + ATTRIBUTE_POS);
00053    }
00054 
00055    inline void set_attribute(node_id_t attr) {
00056       write<OsModel, block_data_t, node_id_t> (buffer + ATTRIBUTE_POS, attr);
00057    }
00058 
00059    inline size_t length() {
00060       return sizeof(message_id_t) + sizeof(node_id_t);
00061    }
00062 
00063 private:
00064    block_data_t buffer[Radio::MAX_MESSAGE_LENGTH]; // buffer for the message data
00065 };
00066 }
00067 #endif   /* ATTRIBUTECLUSTERMSG_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines