SickLMS1xxBufferMonitor.cc
Go to the documentation of this file.
1 
17 /* Auto-generated header */
19 
20 /* Implementation dependencies */
21 #include <iostream>
22 #include <sys/ioctl.h>
23 
28 
29 /* Associate the namespace */
30 namespace SickToolbox {
31 
36 
42 
43  /* Flush the input buffer */
44  uint8_t byte_buffer = 0;
45  uint8_t payload_buffer[SickLMS1xxMessage::MESSAGE_PAYLOAD_MAX_LENGTH] = {0};
46 
47  try {
48 
49  /* Flush the TCP receive buffer */
51 
52  /* Search for STX in the byte stream */
53  do {
54 
55  /* Grab the next byte from the stream */
57 
58  }
59  while (byte_buffer != 0x02);
60 
61  /* Ok, now acquire the payload! (until ETX) */
62  int payload_length = 0;
63  do {
64 
65  payload_length++;
66  _readBytes(&payload_buffer[payload_length-1],1,DEFAULT_SICK_LMS_1XX_BYTE_TIMEOUT);
67 
68  }
69  while (payload_buffer[payload_length-1] != 0x03);
70  payload_length--;
71 
72  /* Build the return message object based upon the received payload
73  * NOTE: In constructing this message we ignore the header bytes
74  * buffered since the BuildMessage routine will insert the
75  * correct header automatically and verify the message size
76  */
77  sick_message.BuildMessage(payload_buffer,payload_length);
78 
79  /* Success */
80 
81  }
82 
83  catch(SickTimeoutException &sick_timeout) { /* This is ok! */ }
84 
85  /* Catch any serious IO buffer exceptions */
86  catch(SickIOException &sick_io_exception) {
87  throw;
88  }
89 
90  /* A sanity check */
91  catch (...) {
92  throw;
93  }
94 
95  }
96 
101 
102  char null_byte;
103  int num_bytes_waiting = 0;
104 
105  /* Acquire number of awaiting bytes */
106  if (ioctl(_sick_fd,FIONREAD,&num_bytes_waiting)) {
107  throw SickIOException("SickLMS1xxBufferMonitor::_flushTCPRecvBuffer: ioctl() failed!");
108  }
109 
110  /* Flush awaiting bytes */
111  for (int i = 0; i < num_bytes_waiting; i++) {
112 
113  /* Capture a single byte from the stream! */
114  if (read(_sick_fd,&null_byte,1) != 1) {
115  throw SickIOException("SickLMS1xxBufferMonitor::_flushTCPRecvBuffer: ioctl() failed!");
116  }
117 
118  }
119 
120  }
121 
126 
127 } /* namespace SickToolbox */
SickLMS1xxBufferMonitor()
A standard constructor.
Contains some simple exception classes.
void _readBytes(uint8_t *const dest_buffer, const int num_bytes_to_read, const unsigned int timeout_value=0) const
A class for monitoring the receive buffer when interfacing with a Sick LD LIDAR.
void _flushTCPRecvBuffer() const
Flushes TCP receive buffer contents.
Defines a class for monitoring the receive buffer when interfacing w/ a Sick LMS 1xx laser range find...
void GetNextMessageFromDataStream(SickLMS1xxMessage &sick_message)
Acquires the next message from the SickLMS1xx byte stream.
Defines simple utility functions for working with the Sick LMS 1xx laser range finder units...
Encapsulates the Sick LIDAR Matlab/C++ toolbox.
Definition: SickLD.cc:44
Thrown instance where the driver can&#39;t read,write,drain,flush,... the buffers.
#define DEFAULT_SICK_LMS_1XX_BYTE_TIMEOUT
Max allowable time between consecutive bytes.
Makes handling timeouts much easier.
A class to represent all messages sent to and from the Sick LMS 1xx unit.


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