Wiselib
|
00001 #ifndef __ROOMBA_MOVEMENT_MESSAGE_H__ 00002 #define __ROOMBA_MOVEMENT_MESSAGE_H__ 00003 00004 #include <stdint.h> 00005 00006 #include "util/serialization/serialization.h" 00007 #include "external_interface/external_interface.h" 00008 00009 00010 template<typename OsModel_P, typename Radio_P> 00011 class RoombaMovementMessage 00012 { 00013 public: 00014 typedef OsModel_P OsModel; 00015 typedef Radio_P Radio; 00016 00017 typedef typename Radio::node_id_t node_id_t; 00018 typedef typename Radio::block_data_t block_data_t; 00019 typedef typename Radio::message_id_t message_id_t; 00020 00021 typedef RoombaMovementMessage<OsModel, Radio> self_type; 00022 typedef RoombaMovementMessage<OsModel, Radio>* self_pointer_t; 00023 00024 typedef uint8_t message_type_t; 00025 00026 enum RoombaMovementSpecialNodeIds 00027 { 00028 BROADCAST_ADDRESS = Radio::BROADCAST_ADDRESS 00029 }; 00030 00031 enum RoombaMovementMessageType 00032 { 00033 STOP_MOVEMENT = 0x00, START_MOVEMENT 00034 }; 00035 00036 enum MessageIds 00037 { 00038 ROOMBA_MOVEMENT_MESSAGE_ID = 0x17 //23 00039 }; 00040 00041 enum 00042 { 00043 MAX_MESSAGE_LENGTH = sizeof(message_id_t) + sizeof( message_type_t ) 00044 }; 00045 00046 RoombaMovementMessage(); 00047 00048 inline uint8_t msg_id() 00049 { 00050 return ROOMBA_MOVEMENT_MESSAGE_ID; 00051 } 00052 // -------------------------------------------------------------------- 00053 inline void set_msg_id( uint8_t id ) 00054 { 00055 // Changing the msg_id is not allowed! 00056 } 00057 // -------------------------------------------------------------------- 00058 inline uint8_t set_msg_type( RoombaMovementMessageType mt ) 00059 { 00060 return wiselib::write<OsModel, block_data_t, message_type_t>(buffer + MESSAGE_TYPE_POS, (message_type_t&)mt); 00061 } 00062 // -------------------------------------------------------------------- 00063 inline uint8_t msg_type() 00064 { 00065 return wiselib::read<OsModel, block_data_t, message_type_t>( buffer + MESSAGE_TYPE_POS ); 00066 } 00067 // -------------------------------------------------------------------- 00068 inline block_data_t* payload() 00069 { 00070 return 0; 00071 } 00072 // -------------------------------------------------------------------- 00073 inline size_t payload_size() 00074 { 00075 return 0; 00076 } 00077 // -------------------------------------------------------------------- 00078 inline void set_payload( size_t len, block_data_t *data ) 00079 { 00080 //NOT SUPPORTED 00081 } 00082 // -------------------------------------------------------------------- 00083 inline size_t buffer_size() 00084 { 00085 switch( msg_type() ) 00086 { 00087 case START_MOVEMENT: 00088 case STOP_MOVEMENT: 00089 return PAYLOAD_SIZE_POS; 00090 break; 00091 default: 00092 return PAYLOAD_SIZE_POS; 00093 } 00094 } 00095 00096 private: 00097 enum data_positions 00098 { 00099 MESSAGE_TYPE_POS = sizeof( message_id_t ), 00100 NODE_ID_POS = sizeof(message_id_t) + sizeof( message_type_t ), 00101 PAYLOAD_SIZE_POS = sizeof(message_id_t) + sizeof( message_type_t ), 00102 PAYLOAD_POS = sizeof(message_id_t) + sizeof( message_type_t ) + sizeof( size_t ) 00103 }; 00104 00105 block_data_t buffer[MAX_MESSAGE_LENGTH]; 00106 }; 00107 00108 template<typename OsModel_P, typename Radio_P> 00109 RoombaMovementMessage<OsModel_P, Radio_P>::RoombaMovementMessage() 00110 { 00111 message_id_t tmp = ROOMBA_MOVEMENT_MESSAGE_ID;//write expects reference 00112 wiselib::write<OsModel, block_data_t, message_id_t>( buffer, tmp ); 00113 set_msg_type( STOP_MOVEMENT ); 00114 } 00115 00116 #endif //__ROOMBA_MOVEMENT_MESSAGE_H__