Wiselib
|
00001 #ifndef __ALGORITHMS_COLORING_JUDGED_MSG_H__ 00002 #define __ALGORITHMS_COLORING_JUDGED_MSG_H__ 00003 00004 00005 #include "util/serialization/simple_types.h" 00006 00007 namespace wiselib 00008 { 00009 00010 enum message_types 00011 { 00012 JUDGE_START = 0, 00013 NODE_START = 1, 00014 BROAD_JUDGE = 2, 00015 REQUEST_COLOR = 3, 00016 ASSIGN_COLOR = 4, 00017 COLOR_ASSIGNED = 5, 00018 REASSIGN_COLOR = 6, 00019 ASK_PERMISSION =7, 00020 GIVE_PERMISSION = 8, 00021 DECL_PERMISSION = 10, 00022 COLOR_NOT_ASSIGNED = 9, 00023 TAKE_TURN = 11, 00024 ASK_JUDGE = 12, 00025 ASK_COLOR = 13, 00026 REPLY_COLOR = 14, 00027 FINAL_CHECK = 15, 00028 CHECK_OK = 16, 00029 CHECK_NOT_OK = 17, 00030 CENT_END = 18, 00031 ALL_END = 19 00032 }; 00033 00034 template<typename OsModel_P, 00035 typename Radio_P> 00036 class JudgedColoringMessage 00037 { 00038 public: 00039 typedef OsModel_P OsModel; 00040 typedef Radio_P Radio; 00041 typedef typename Radio::block_data_t block_data_t; 00042 // -------------------------------------------------------------------- 00043 inline JudgedColoringMessage(); 00044 // -------------------------------------------------------------------- 00045 inline uint8_t msg_id() 00046 { return read<OsModel, block_data_t, uint8_t>( buffer ); }; 00047 // -------------------------------------------------------------------- 00048 inline void set_msg_id( uint8_t id ) 00049 { write<OsModel, block_data_t, uint8_t>( buffer, id ); } 00050 // -------------------------------------------------------------------- 00051 inline uint16_t source() 00052 { return read<OsModel, block_data_t, uint16_t>(buffer + SOURCE_POS); } 00053 // -------------------------------------------------------------------- 00054 inline void set_source( uint16_t src ) 00055 { write<OsModel, block_data_t, uint16_t>(buffer + SOURCE_POS, src); } 00056 // -------------------------------------------------------------------- 00057 inline uint16_t destination() 00058 { return read<OsModel, block_data_t, uint16_t>(buffer + DEST_POS); } 00059 // -------------------------------------------------------------------- 00060 inline void set_destination( uint16_t dest ) 00061 { write<OsModel, block_data_t, uint16_t>(buffer + DEST_POS, dest); } 00062 // -------------------------------------------------------------------- 00063 inline uint8_t payload_size() 00064 { return read<OsModel, block_data_t, uint8_t>(buffer + PAYLOAD_POS); } 00065 // -------------------------------------------------------------------- 00066 inline uint8_t* payload() 00067 { return buffer + PAYLOAD_POS + 1; } 00068 // -------------------------------------------------------------------- 00069 inline void set_payload( uint8_t len, uint8_t *buf ) 00070 { 00071 write<OsModel, block_data_t, uint8_t>(buffer + PAYLOAD_POS, len); 00072 memcpy( buffer + PAYLOAD_POS + 1, buf, len); 00073 } 00074 // -------------------------------------------------------------------- 00075 inline size_t buffer_size() 00076 { return PAYLOAD_POS + 1 + payload_size(); } 00077 00078 private: 00079 inline void set_payload_size( uint8_t len ) 00080 { write<OsModel, block_data_t, uint8_t>(buffer + PAYLOAD_POS, len); } 00081 00082 enum data_positions 00083 { 00084 MSG_ID_POS = 0, 00085 SOURCE_POS = 1, 00086 DEST_POS = 3, 00087 PAYLOAD_POS = 5 00088 }; 00089 00090 uint8_t buffer[Radio::MAX_MESSAGE_LENGTH]; 00091 }; 00092 // ----------------------------------------------------------------------- 00093 template<typename OsModel_P, 00094 typename Radio_P> 00095 JudgedColoringMessage<OsModel_P, Radio_P>:: 00096 JudgedColoringMessage() 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 } 00103 00104 } 00105 #endif