00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef SICK_LMS_MESSAGE_HH
00017 #define SICK_LMS_MESSAGE_HH
00018
00019
00020 #include "SickConfig.hh"
00021
00022
00023 #include <string.h>
00024 #include <netinet/in.h>
00025 #include "SickMessage.hh"
00026 #include "SickException.hh"
00027
00028 #define CRC16_GEN_POL 0x8005
00029
00030
00031 #define MKSHORT(a,b) ((unsigned short) (a) | ((unsigned short)(b) << 8))
00032
00033 #define SICK_LMS_MSG_HEADER_LEN (4)
00034 #define SICK_LMS_MSG_PAYLOAD_MAX_LEN (812)
00035 #define SICK_LMS_MSG_TRAILER_LEN (2)
00036
00037
00038 namespace SickToolbox {
00039
00040
00041
00042
00043
00044
00045
00046 class SickLMSMessage : public SickMessage< SICK_LMS_MSG_HEADER_LEN, SICK_LMS_MSG_PAYLOAD_MAX_LEN, SICK_LMS_MSG_TRAILER_LEN >
00047 {
00048
00049 public:
00050
00051
00052 SickLMSMessage( );
00053
00054
00055 SickLMSMessage( const uint8_t dest_address, const uint8_t * const payload_buffer, const unsigned int payload_length );
00056
00057
00058 SickLMSMessage( uint8_t * const message_buffer );
00059
00060
00061 void BuildMessage( uint8_t dest_address, const uint8_t * const payload_buffer,
00062 const unsigned int payload_length );
00063
00064
00065 void ParseMessage( const uint8_t * const message_buffer );
00066
00067
00068 uint8_t GetDestAddress( ) const { return _message_buffer[1]; }
00069
00070
00071 uint8_t GetCommandCode( ) const { return _message_buffer[MESSAGE_HEADER_LENGTH]; }
00072
00073
00074 uint8_t GetStatusByte( ) const { return _message_buffer[MESSAGE_HEADER_LENGTH+_payload_length-1]; }
00075
00076
00077 uint16_t GetChecksum( ) const { return _checksum; }
00078
00079
00080 void Clear( );
00081
00082
00083 void Print( ) const;
00084
00085
00086 ~SickLMSMessage();
00087
00088 protected:
00089
00090
00091 uint16_t _checksum;
00092
00093 private:
00094
00095
00096 uint16_t _computeCRC( uint8_t * data, unsigned int data_length ) const;
00097
00098 };
00099
00100 }
00101
00102 #endif //SICK_LMS_MESSAGE_HH