00001 00016 #ifndef SICK_LMS_2XX_MESSAGE_HH 00017 #define SICK_LMS_2XX_MESSAGE_HH 00018 00019 /* Definition dependencies */ 00020 #include <string.h> 00021 #include <netinet/in.h> 00022 #include "SickMessage.hh" 00023 #include "SickException.hh" 00024 00025 #define CRC16_GEN_POL 0x8005 ///< Used to compute CRCs 00026 00028 #define MKSHORT(a,b) ((unsigned short) (a) | ((unsigned short)(b) << 8)) 00029 00030 #define SICK_LMS_2XX_MSG_HEADER_LEN (4) ///< Sick LMS message length in bytes 00031 #define SICK_LMS_2XX_MSG_PAYLOAD_MAX_LEN (812) ///< Sick LMS max payload length in bytes 00032 #define SICK_LMS_2XX_MSG_TRAILER_LEN (2) ///< Sick LMS message trailer length in bytes 00033 00034 /* Associate the namespace */ 00035 namespace SickToolbox { 00036 00043 class SickLMS2xxMessage : public SickMessage< SICK_LMS_2XX_MSG_HEADER_LEN, SICK_LMS_2XX_MSG_PAYLOAD_MAX_LEN, SICK_LMS_2XX_MSG_TRAILER_LEN > 00044 { 00045 00046 public: 00047 00049 SickLMS2xxMessage( ); 00050 00052 SickLMS2xxMessage( const uint8_t dest_address, const uint8_t * const payload_buffer, const unsigned int payload_length ); 00053 00055 SickLMS2xxMessage( uint8_t * const message_buffer ); 00056 00058 void BuildMessage( uint8_t dest_address, const uint8_t * const payload_buffer, 00059 const unsigned int payload_length ); 00060 00062 void ParseMessage( const uint8_t * const message_buffer ); 00063 00065 uint8_t GetDestAddress( ) const { return _message_buffer[1]; } 00066 00068 uint8_t GetCommandCode( ) const { return _message_buffer[MESSAGE_HEADER_LENGTH]; } 00069 00071 uint8_t GetStatusByte( ) const { return _message_buffer[MESSAGE_HEADER_LENGTH+_payload_length-1]; } 00072 00074 uint16_t GetChecksum( ) const { return _checksum; } 00075 00077 void Clear( ); 00078 00080 void Print( ) const; 00081 00083 ~SickLMS2xxMessage(); 00084 00085 protected: 00086 00088 uint16_t _checksum; 00089 00090 private: 00091 00093 uint16_t _computeCRC( uint8_t * data, unsigned int data_length ) const; 00094 00095 }; 00096 00097 } /* namespace SickToolbox */ 00098 00099 #endif //SICK_LMS_2XX_MESSAGE_HH