19 #ifndef SNARK_SENSORS_SICK_PACKET_H_
20 #define SNARK_SENSORS_SICK_PACKET_H_
26 #include <boost/array.hpp>
27 #include <boost/date_time/posix_time/posix_time.hpp>
28 #include <comma/packed/byte.h>
29 #include <comma/packed/little_endian.h>
30 #include <comma/packed/big_endian.h>
31 #include <comma/packed/struct.h>
33 namespace snark {
namespace sick {
namespace ldmrs {
36 struct timestamp :
public comma::packed::packed_struct< timestamp, 8 >
38 comma::packed::net_uint32 seconds;
39 comma::packed::net_uint32 fractions;
45 comma::packed::uint32 fractions;
46 comma::packed::uint32 seconds;
50 struct header :
public comma::packed::packed_struct< header, 24 >
54 enum types { scan_type = 0x2202, command_type = 0x2010, response_type = 0x2020, fault_type = 0x2030 };
75 comma::packed::net_uint16
type;
89 struct fault :
public comma::packed::packed_struct< fault, 16 >
91 comma::packed::uint16 faultRegister1;
92 comma::packed::uint16 faultRegister2;
93 comma::packed::uint16 warningRegister1;
94 comma::packed::uint16 warningRegister2;
95 boost::array< comma::packed::uint16, 4 > reserved;
99 std::ostream& operator<<( std::ostream&,
const fault& rhs );
102 struct scan :
public comma::packed::packed_struct< scan, 44 >
105 struct header :
public comma::packed::packed_struct< header, 44 >
109 enum Statuses { measurementFrequencyReached = 0x0008, externalSyncDetected = 0x0010, synced = 0x0020, syncMaster = 0x0040 };
141 boost::array< comma::packed::uint16, 7 >
padding;
145 struct point :
public comma::packed::packed_struct< point, 10 >
148 struct id :
public comma::packed::packed_struct< id, 1 >
154 unsigned int layer()
const;
157 unsigned int echo()
const;
164 enum { transparent = 0x01, dust = 0x02, rain = dust, noise = dust, dirt = 0x08 };
206 boost::posix_time::ptime operator[]( std::size_t index )
const;
209 boost::posix_time::ptime m_start;
210 boost::posix_time::ptime m_finish;
211 boost::posix_time::time_duration m_elapsed;
213 short m_finish_angle;
215 unsigned short m_steps;
219 struct scan_packet :
public comma::packed::packed_struct< scan_packet, header::size + scan::size >
228 struct header :
public comma::packed::packed_struct< header, 4 >
230 comma::packed::uint16 id;
231 comma::packed::net_uint16 padding;
237 comma::packed::uint16 id;
238 std::size_t payload_size()
const;
242 template <
typename C, std::
size_t Size >
243 struct command :
public comma::packed::packed_struct< C, header::size + Size >
246 command() { command_header.id = C::id; }
250 template <
typename C, std::
size_t Size >
251 struct response :
public comma::packed::packed_struct< typename C::response, response_header::size + Size >
256 bool ok()
const {
return (
header.id() & 0x8000 ) == 0; }
257 bool matches( comma::uint16
id ) {
return id == (
header.id() & 0x3fff ); }
262 reset_dsp_type = 0x0000
263 , get_status_type = 0x0001
264 , save_configuration_type = 0x0004
267 , reset_type = 0x001a
268 , start_type = 0x0020
270 , set_ntp_seconds_type = 0x0030
271 , set_ntp_fractions_type = 0x0031
277 enum {
id = reset_dsp_type };
285 enum {
id = get_status_type };
289 comma::packed::uint16 firmwareVersion;
290 comma::packed::uint16 fpgaVersion;
291 comma::packed::uint16 status;
292 comma::packed::uint32 reserved0;
293 comma::packed::uint16 temperature;
294 comma::packed::uint16 serialNumber0;
295 comma::packed::uint16 serialNumber1;
296 comma::packed::uint16 reserved1;
297 boost::array< comma::packed::uint16, 3 > fpgaVersionDate;
298 boost::array< comma::packed::uint16, 3 > dspVersionDate;
305 enum {
id = save_configuration_type };
313 enum {
id = set_type };
314 enum IndexValues { ip_address = 0x1000, tcp_port = 0x1001, subnet_mask = 0x1002, gateway = 0x1003, data_output_flag = 0x1012 };
315 comma::packed::uint16 index;
316 comma::packed::uint32 value;
324 enum {
id = get_type };
325 comma::packed::uint16 index;
329 comma::packed::uint16 index;
330 comma::packed::uint32 value;
337 enum {
id = reset_type };
345 enum {
id = start_type };
353 enum {
id = stop_type };
361 enum {
id = set_ntp_seconds_type };
362 comma::packed::uint16 reserved;
363 comma::packed::uint32 seconds;
374 enum {
id = set_ntp_fractions_type };
375 comma::packed::uint16 reserved;
376 comma::packed::uint32 fractions;
385 template <
typename C >
386 struct packet :
public comma::packed::packed_struct< packet< C >, ldmrs::header::size + C::size >
390 packet() {
header.type = ldmrs::header::command_type;
header.payload_size = C::size; }
391 packet(
const C&
command ) : command( command ) {
header.type = ldmrs::header::command_type;
header.payload_size = C::size; }
393 struct response :
public comma::packed::packed_struct< response, ldmrs::header::size + C::response::size >
396 typename C::response response;
397 response() {
header.type = ldmrs::header::response_type;
header.payload_size = C::response::size; }
398 response(
const typename C::response& response ) : response( response ) {
header.type = ldmrs::header::response_type;
header.payload_size = C::response::size; }
403 std::ostream& operator<<( std::ostream& os,
const commands::get_status::response& rhs );
404 std::ostream& operator<<( std::ostream& os,
const commands::get::response& rhs );
408 #endif // #ifndef SNARK_SENSORS_SICK_PACKET_H_