SickPLSMessage.cc
Go to the documentation of this file.
1 
16 /* Auto-generated header */
17 //#include "SickConfig.hh"
18 
19 /* Implementation dependencies */
20 #include <iomanip>
21 #include <iostream>
22 
23 #include "SickPLSMessage.hh"
24 #include "SickPLSUtility.hh"
25 
26 /* Associate the namespace */
27 namespace SickToolbox
28 {
29 
34 {
35 
36  /* Initialize the object */
37  Clear();
38 }
39 
46 SickPLSMessage::SickPLSMessage( const uint8_t dest_address, const uint8_t * const payload_buffer, const unsigned int payload_length ) :
48 {
49 
50  /* Build the message */
51  BuildMessage(dest_address,payload_buffer,payload_length);
52 }
53 
58 SickPLSMessage::SickPLSMessage( uint8_t * const message_buffer ) :
60 {
61 
62  /* Parse the byte sequence into a message object */
63  ParseMessage(message_buffer);
64 }
65 
72 void SickPLSMessage::BuildMessage( const uint8_t dest_address, const uint8_t * const payload_buffer,
73  const unsigned int payload_length )
74 {
75 
76  /* Call the parent method!
77  * NOTE: The parent method resets the object and assigns _message_length, _payload_length,
78  * _populated and copies the payload into the message buffer at the correct position
79  */
81  ::BuildMessage(payload_buffer,payload_length);
82 
83  /*
84  * Set the message header!
85  */
86  _message_buffer[0] = 0x02; // Start of transmission (stx)
87  _message_buffer[1] = dest_address; // Sick PLS address
88 
89  /* Include the payload length in the header */
90  uint16_t payload_length_16 = host_to_sick_pls_byte_order((uint16_t)_payload_length);
91  memcpy(&_message_buffer[2],&payload_length_16,2);
92 
93  /*
94  * Set the message trailer!
95  */
97  memcpy(&_message_buffer[_payload_length+4],&_checksum,2);
98 
99 }
100 
105 void SickPLSMessage::ParseMessage( const uint8_t * const message_buffer )
106 {
107 
108  /* Call the parent method!
109  * NOTE: This method resets the object and assigns _populated as true
110  */
112  ::ParseMessage(message_buffer);
113 
114  /* Extract the payload length */
115  uint16_t payload_length_16 = 0;
116  memcpy(&payload_length_16,&message_buffer[2],2);
117  _payload_length = (unsigned int)sick_pls_to_host_byte_order(payload_length_16);
118 
119  /* Compute the total message length */
121 
122  /* Copy the give message into the buffer */
123  memcpy(_message_buffer, message_buffer,_message_length);
124 
125  /* Extract the checksum from the frame */
126  memcpy(&_checksum,&_message_buffer[_payload_length+MESSAGE_HEADER_LENGTH],2);
128 
129 }
130 
135 {
136 
137  /* Call the parent method and clear out class' protected members */
139 
140  /* Reset the class' additional fields */
141  _checksum = 0;
142 
143 }
144 
149 {
150 
151  std::cout.setf(std::ios::hex,std::ios::basefield);
152  std::cout << "Checksum: " << (unsigned int) GetChecksum() << std::endl;
153  std::cout << "Dest. Addr.: " << (unsigned int) GetDestAddress() << std::endl;
154  std::cout << "Command Code: " << (unsigned int) GetCommandCode() << std::endl;
155  std::cout << std::flush;
156 
157  /* Call parent's print function */
159 }
160 
167 uint16_t SickPLSMessage::_computeCRC( uint8_t * data, unsigned int data_length ) const
168 {
169 
170  uint16_t uCrc16;
171  uint8_t abData[2];
172  uCrc16 = abData[0] = 0;
173  while (data_length-- )
174  {
175  abData[1] = abData[0];
176  abData[0] = *data++;
177  if(uCrc16 & 0x8000)
178  {
179  uCrc16 = (uCrc16 & 0x7fff) << 1;
180  uCrc16 ^= CRC16_GEN_POL;
181  }
182  else
183  {
184  uCrc16 <<= 1;
185  }
186  uCrc16 ^= MKSHORT(abData[0],abData[1]);
187  }
188  return uCrc16;
189 }
190 
192 
193 } /* namespace SickToolbox */
virtual void ParseMessage(const uint8_t *const message_buffer)=0
Parses a sequence of bytes into a Sick message.
Definition: SickMessage.hh:133
Defines simple utility functions for working with the Sick LMS 2xx laser range finder units...
void Clear()
Reset all internal fields and buffers associated with the object.
void ParseMessage(const uint8_t *const message_buffer)
Parses a sequence of bytes into a well-formed message.
#define SICK_PLS_MSG_HEADER_LEN
Sick LMS message length in bytes.
void BuildMessage(const uint8_t *const payload_buffer, const unsigned int payload_length)
Constructs a Sick message given the parameter values.
Definition: SickMessage.hh:111
uint16_t sick_pls_to_host_byte_order(uint16_t value)
Converts Sick LMS byte order (little-endian) to host byte order (little-endian)
#define CRC16_GEN_POL
Used to compute CRCs.
Definition of class SickPLSMessage.
SickPLSMessage()
A default constructor.
uint16_t GetChecksum() const
#define SICK_PLS_MSG_PAYLOAD_MAX_LEN
Sick LMS max payload length in bytes.
void Print() const
Print the message contents.
virtual void Print() const
Print data about this object.
Definition: SickMessage.hh:201
uint16_t host_to_sick_pls_byte_order(uint16_t value)
Converts host byte order (little-endian) to Sick LMS byte order (little-endian)
uint8_t GetCommandCode() const
#define SICK_PLS_MSG_TRAILER_LEN
Sick LMS message trailer length in bytes.
virtual void Clear()
Reset all internal fields and buffers.
Definition: SickMessage.hh:185
#define MKSHORT(a, b)
uint16_t _computeCRC(uint8_t *data, unsigned int data_length) const
Computes the CRC16 of the given data buffer.
Provides an abstract parent for all Sick messages.
Definition: SickMessage.hh:32
void BuildMessage(uint8_t dest_address, const uint8_t *const payload_buffer, const unsigned int payload_length)
Consructs a message object from given parameter values.
uint8_t GetDestAddress() const


asr_mild_base_laserscanner
Author(s): Aumann Florian, Borella Jocelyn, Dehmani Souheil, Marek Felix, Reckling Reno
autogenerated on Mon Jun 10 2019 12:41:37