Wiselib
|
00001 /* 00002 * File: join_message.h 00003 * Author: Amaxilatis 00004 * 00005 */ 00006 00007 #ifndef JOINCLUSTERMSG_H 00008 #define JOINCLUSTERMSG_H 00009 00010 namespace wiselib { 00011 00012 template<typename OsModel_P, typename Radio_P> 00013 class JoinClusterMsg { 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 CLUSTER_ID_POS = sizeof(message_id_t), 00027 HOPS_POS = sizeof(message_id_t) + sizeof(cluster_id_t) 00028 }; 00029 00030 // -------------------------------------------------------------------- 00031 00032 JoinClusterMsg() { 00033 set_msg_id(JOIN); 00034 set_cluster_id(0); 00035 set_hops(0); 00036 } 00037 // -------------------------------------------------------------------- 00038 00039 ~JoinClusterMsg() { 00040 } 00041 00042 // get the message id 00043 inline message_id_t msg_id() { 00044 return read<OsModel, block_data_t, uint8_t> (buffer + MSG_ID_POS); 00045 } 00046 // -------------------------------------------------------------------- 00047 00048 // set the message id 00049 inline void set_msg_id(message_id_t id) { 00050 write<OsModel, block_data_t, uint8_t> (buffer + MSG_ID_POS, id); 00051 } 00052 00053 inline cluster_id_t cluster_id() { 00054 return read<OsModel, block_data_t, cluster_id_t> (buffer 00055 + CLUSTER_ID_POS); 00056 } 00057 00058 inline void set_cluster_id(cluster_id_t cluster_id) { 00059 write<OsModel, block_data_t, cluster_id_t> (buffer + CLUSTER_ID_POS, 00060 cluster_id); 00061 } 00062 00063 inline int hops() { 00064 return read<OsModel, block_data_t, int> (buffer + HOPS_POS); 00065 } 00066 00067 inline void set_hops(int hops) { 00068 write<OsModel, block_data_t, int> (buffer + HOPS_POS, hops); 00069 } 00070 00071 inline size_t length() { 00072 return sizeof(uint8_t) + sizeof(cluster_id_t) + sizeof(int); 00073 } 00074 00075 private: 00076 block_data_t buffer[Radio::MAX_MESSAGE_LENGTH]; // buffer for the message data 00077 }; 00078 } 00079 #endif /* JOINCLUSTERMSG_H */ 00080