SickLMS1xxMessage.cc
Go to the documentation of this file.
1 
16 /* Auto-generated header */
18 
19 /* Implementation dependencies */
20 #include <iomanip>
21 #include <iostream>
22 #include <arpa/inet.h>
23 
25 #include <sicktoolbox/SickLMS1xxUtility.hh> // for byye-order conversions where necessary
26 
27 /* Associate the namespace */
28 namespace SickToolbox {
29 
35  _command_type(""),
36  _command("")
37  {
38 
39  /* Initialize the object */
40  Clear();
41 
42  }
43 
49  SickLMS1xxMessage::SickLMS1xxMessage( const uint8_t * const payload_buffer, const unsigned int payload_length ) :
51  _command_type("Unknown"),
52  _command("Unknown")
53  {
54 
55  /* Build the message object (implicit initialization) */
56  BuildMessage(payload_buffer,payload_length);
57 
58  }
59 
64  SickLMS1xxMessage::SickLMS1xxMessage( const uint8_t * const message_buffer ) :
66  _command_type("Unknown"),
67  _command("Unknown")
68  {
69 
70  /* Parse the message into the container (implicit initialization) */
71  ParseMessage(message_buffer);
72 
73  }
74 
80  void SickLMS1xxMessage::BuildMessage( const uint8_t * const payload_buffer, const unsigned int payload_length ) {
81 
82  /* Call the parent method
83  * NOTE: The parent method resets the object and assigns _message_length, _payload_length,
84  * _populated and copies the payload into the message buffer at the correct position
85  */
87  ::BuildMessage(payload_buffer,payload_length);
88 
89  /*
90  * Set the message header!
91  */
92  _message_buffer[0] = 0x02; // STX
93 
94  /*
95  * Set the message trailer!
96  */
97  _message_buffer[_message_length-1] = 0x03; // ETX
98 
99  /* Grab the (3-byte) command type */
100  char command_type[4] = {0};
101  for (int i = 0; i < 3; i++) {
102  command_type[i] = _message_buffer[i+1];
103  }
104  command_type[4] = '\0';
105  _command_type = command_type;
106 
107  /* Grab the command (max length is 14 bytes) */
108  char command[15] = {0};
109  int i = 0;
110  for (; (i < 14) && (_message_buffer[5+i] != 0x20); i++) {
111  command[i] = _message_buffer[5+i];
112  }
113  command[i] = '\0';
114  _command = command;
115 
116  }
117 
122  void SickLMS1xxMessage::ParseMessage( const uint8_t * const message_buffer ) throw (SickIOException) {
123 
124  /* Call the parent method
125  * NOTE: This method resets the object and assigns _populated as true
126  */
128  ::ParseMessage(message_buffer);
129 
130  /* Compute the message length */
131  int i = 1;
132  const char * token = NULL;
133  while (message_buffer[i-1] != 0x03) {
134 
135  if (i == 1) {
136 
137  /* Grab the command type */
138  if ((token = strtok((char *)&_message_buffer[1]," ")) == NULL) {
139  throw SickIOException("SickLMS1xxMessage::ParseMessage: strtok() failed!");
140  }
141 
142  _command_type = token;
143 
144  /* Grab the Command Code */
145  if ((token = strtok(NULL," ")) == NULL) {
146  throw SickIOException("SickLMS1xxMessage::ParseMessage: strtok() failed!");
147  }
148 
149  _command = token;
150 
151  }
152 
153  i++; // Update message length
154 
155  /* A sanity check */
157  throw SickIOException("SickLMS1xxMessage::ParseMessage: Message Exceeds Max Message Length!");
158  }
159 
160  }
161 
162  /* Compute the total message length */
164 
165  /* Copy the given packet into the buffer */
166  memcpy(_message_buffer,message_buffer,_message_length);
167 
168  }
169 
174 
175  /* Call the parent method and clear out class' protected members */
177 
178  /* Reset the class' additional fields */
179  _command_type = "Unknown";
180  _command = "Unknown";
181 
182  }
183 
187  void SickLMS1xxMessage::Print( ) const {
188 
189  //std::cout.setf(std::ios::hex,std::ios::basefield);
190  std::cout << "Command Type: " << GetCommandType() << std::endl;
191  std::cout << "Command Code: " << GetCommand() << std::endl;
192  std::cout << std::flush;
193 
194  /* Call parent's print function */
196 
197  }
198 
200 
201 } /* 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
void ParseMessage(const uint8_t *const message_buffer)
Parses a sequence of bytes into a SickLMS1xxMessage object.
void BuildMessage(const uint8_t *const payload_buffer, const unsigned int payload_length)
Constructs a well-formed Sick LMS 1xx message.
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
virtual void Print() const
Print data about this object.
Definition: SickMessage.hh:201
#define SICK_LMS_1XX_MSG_TRAILER_LEN
Sick LMS 1xx length of the message trailer.
std::string GetCommandType() const
virtual void Clear()
Reset all internal fields and buffers.
Definition: SickMessage.hh:185
Defines simple utility functions for working with the Sick LMS 1xx laser range finder units...
Provides an abstract parent for all Sick messages.
Definition: SickMessage.hh:32
Encapsulates the Sick LIDAR Matlab/C++ toolbox.
Definition: SickLD.cc:44
void Clear()
Reset all internal fields and buffers associated with the object.
#define SICK_LMS_1XX_MSG_HEADER_LEN
Sick LMS 1xx message header length in bytes.
Thrown instance where the driver can&#39;t read,write,drain,flush,... the buffers.
SickLMS1xxMessage()
A default constructor.
void Print() const
Print the message contents.
#define SICK_LMS_1XX_MSG_PAYLOAD_MAX_LEN
Sick LMS 1xx maximum payload length.


sicktoolbox
Author(s): Jason Derenick , Thomas Miller
autogenerated on Tue Sep 10 2019 03:37:34