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-2017, 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 
13 #include <mrpt/utils/CStream.h>
14 
15 using namespace mrpt::obs;
16 using namespace mrpt::utils;
17 using namespace mrpt::poses;
18 using namespace std;
19 
20 // This must be added to any CSerializable class implementation file.
22 
23 /*---------------------------------------------------------------
24  Implements the writing to a CStream capability of CSerializable objects
25  ---------------------------------------------------------------*/
27  mrpt::utils::CStream& out, int* version) const
28 {
29  if (version)
30  *version = 1;
31  else
32  {
33  uint32_t i, n = m_data.size();
34  out << m_pgn;
35  out << m_src_address;
36  out << m_priority;
37  out << m_pdu_format;
38  out << m_pdu_spec;
39  out << m_data_length;
40  out << n;
41 
42  for (i = 0; i < n; i++) out << m_data[i];
43 
44  n = m_raw_frame.size();
45  out << n;
46  for (i = 0; i < n; i++) out << uint8_t(m_raw_frame[i]);
47 
48  out << sensorLabel << timestamp;
49  }
50 }
51 
52 /*---------------------------------------------------------------
53  Implements the reading from a CStream capability of CSerializable objects
54  ---------------------------------------------------------------*/
56  mrpt::utils::CStream& in, int version)
57 {
58  switch (version)
59  {
60  case 0:
61  case 1:
62  {
63  uint32_t i, n;
64 
65  m_data.clear();
66  m_raw_frame.clear();
67 
68  in >> m_pgn;
69  in >> m_src_address;
70  in >> m_priority;
71  in >> m_pdu_format;
72  in >> m_pdu_spec;
73  in >> m_data_length;
74 
75  in >> n;
76  m_data.resize(n);
77  for (i = 0; i < n; ++i) in >> m_data[i];
78 
79  in >> n;
80  m_raw_frame.resize(n);
81  uint8_t aux;
82  for (i = 0; i < n; ++i)
83  {
84  in >> aux;
85  m_raw_frame[i] = char(aux);
86  }
87 
88  in >> sensorLabel;
89  in >> timestamp;
90  }
91  break;
92  default:
94  };
95 }
96 
98 {
100 
101  o << "Priority: " << format("0x%02X", m_priority)
102  << " [Dec: " << int(m_priority) << "]" << endl;
103  o << "Parameter Group Number (PGN): " << format("0x%04X", m_pgn)
104  << " [Dec: " << int(m_pgn) << "]" << endl;
105  o << "PDU Format: " << format("0x%02X", m_pdu_format)
106  << " [Dec: " << int(m_pdu_format) << "]" << endl;
107  o << "PDU Spec: " << format("0x%02X", m_pdu_spec)
108  << " [Dec: " << int(m_pdu_spec) << "]" << endl;
109  o << "Source address: " << format("0x%02X", m_src_address)
110  << " [Dec: " << int(m_src_address) << "]" << endl;
111  o << "Data length: " << format("0x%02X", m_data_length)
112  << " [Dec: " << int(m_data_length) << "]" << endl;
113  o << "Data: ";
114  for (uint8_t k = 0; k < m_data.size(); ++k)
115  o << format("0x%02X", m_data[k]) << " ";
116  o << " [Dec: ";
117  for (uint8_t k = 0; k < m_data.size(); ++k) o << int(m_data[k]) << " ";
118  o << "]" << endl;
119 
120  o << "Raw frame: ";
121  for (uint8_t k = 0; k < m_raw_frame.size(); ++k) o << m_raw_frame[k];
122  o << endl;
123 }
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
#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.
unsigned char uint8_t
Definition: rptypes.h:41
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
void readFromStream(mrpt::utils::CStream &in, int version) override
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
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:19
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:41
GLuint in
Definition: glext.h:7274
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
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: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019