Main MRPT website > C++ reference for MRPT 1.9.9
CObservationCANBusJ1939.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "obs-precomp.h" // Precompiled headers
11 
14 #include <iostream>
15 
16 using namespace mrpt::obs;
17 using namespace mrpt::poses;
18 using namespace std;
19 
20 // This must be added to any CSerializable class implementation file.
22 
23 uint8_t CObservationCANBusJ1939::serializeGetVersion() const { return 1; }
26 {
27  out << m_pgn << m_src_address << m_priority << m_pdu_format;
28  out << m_pdu_spec << m_data_length;
29  out.WriteAs<uint32_t>(m_data.size());
30  if (!m_data.empty()) out.WriteBuffer(&m_data[0], m_data.size());
31  out.WriteAs<uint32_t>(m_raw_frame.size());
32  if (!m_raw_frame.empty())
33  out.WriteBuffer(&m_raw_frame[0], m_raw_frame.size());
34  out << sensorLabel << timestamp;
35 }
36 
39 {
40  switch (version)
41  {
42  case 0:
43  case 1:
44  {
45  uint32_t i, n;
46 
47  m_data.clear();
48  m_raw_frame.clear();
49 
50  in >> m_pgn;
51  in >> m_src_address;
52  in >> m_priority;
53  in >> m_pdu_format;
54  in >> m_pdu_spec;
55  in >> m_data_length;
56 
57  in >> n;
58  m_data.resize(n);
59  for (i = 0; i < n; ++i) in >> m_data[i];
60 
61  in >> n;
62  m_raw_frame.resize(n);
63  uint8_t aux;
64  for (i = 0; i < n; ++i)
65  {
66  in >> aux;
67  m_raw_frame[i] = char(aux);
68  }
69 
70  in >> sensorLabel;
71  in >> timestamp;
72  }
73  break;
74  default:
76  };
77 }
78 
80 {
82 
83  o << "Priority: " << format("0x%02X", m_priority)
84  << " [Dec: " << int(m_priority) << "]" << endl;
85  o << "Parameter Group Number (PGN): " << format("0x%04X", m_pgn)
86  << " [Dec: " << int(m_pgn) << "]" << endl;
87  o << "PDU Format: " << format("0x%02X", m_pdu_format)
88  << " [Dec: " << int(m_pdu_format) << "]" << endl;
89  o << "PDU Spec: " << format("0x%02X", m_pdu_spec)
90  << " [Dec: " << int(m_pdu_spec) << "]" << endl;
91  o << "Source address: " << format("0x%02X", m_src_address)
92  << " [Dec: " << int(m_src_address) << "]" << endl;
93  o << "Data length: " << format("0x%02X", m_data_length)
94  << " [Dec: " << int(m_data_length) << "]" << endl;
95  o << "Data: ";
96  for (uint8_t k = 0; k < m_data.size(); ++k)
97  o << format("0x%02X", m_data[k]) << " ";
98  o << " [Dec: ";
99  for (uint8_t k = 0; k < m_data.size(); ++k) o << int(m_data[k]) << " ";
100  o << "]" << endl;
101 
102  o << "Raw frame: ";
103  for (uint8_t k = 0; k < m_raw_frame.size(); ++k) o << m_raw_frame[k];
104  o << endl;
105 }
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
This class stores a message from a CAN BUS with the protocol J1939.
GLenum GLsizei n
Definition: glext.h:5074
STL namespace.
void WriteAs(const TYPE_FROM_ACTUAL &value)
Definition: CArchive.h:152
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
Definition: CArchive.cpp:48
unsigned char uint8_t
Definition: rptypes.h:41
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
This namespace contains representation of robot actions and observations.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:43
GLuint in
Definition: glext.h:7274
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
void getDescriptionAsText(std::ostream &o) const override
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
unsigned __int32 uint32_t
Definition: rptypes.h:47
virtual void getDescriptionAsText(std::ostream &o) const
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019