Main MRPT website > C++ reference for MRPT 1.5.7
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  ---------------------------------------------------------------*/
26 void CObservationCANBusJ1939::writeToStream(mrpt::utils::CStream &out, int *version) const
27 {
28  if (version)
29  *version = 1;
30  else
31  {
32  uint32_t i,n = m_data.size();
33  out << m_pgn;
34  out << m_src_address;
35  out << m_priority;
36  out << m_pdu_format;
37  out << m_pdu_spec;
38  out << m_data_length;
39  out << n;
40 
41  for(i=0;i<n;i++)
42  out << m_data[i];
43 
44  n = m_raw_frame.size();
45  out << n;
46  for(i=0;i<n;i++)
47  out << uint8_t(m_raw_frame[i]);
48 
49  out << sensorLabel
50  << timestamp;
51  }
52 }
53 
54 /*---------------------------------------------------------------
55  Implements the reading from a CStream capability of CSerializable objects
56  ---------------------------------------------------------------*/
58 {
59  switch(version)
60  {
61  case 0:
62  case 1:
63  {
64  uint32_t i,n;
65 
66  m_data.clear();
67  m_raw_frame.clear();
68 
69  in >> m_pgn;
70  in >> m_src_address;
71  in >> m_priority;
72  in >> m_pdu_format;
73  in >> m_pdu_spec;
74  in >> m_data_length;
75 
76  in >> n;
77  m_data.resize(n);
78  for(i=0;i<n;++i)
79  in >> m_data[i];
80 
81  in >> n;
82  m_raw_frame.resize(n);
83  uint8_t aux;
84  for(i=0;i<n;++i)
85  {
86  in >> aux;
87  m_raw_frame[i] = char(aux);
88  }
89 
90  in >> sensorLabel;
91  in >> timestamp;
92 
93  } break;
94  default:
96 
97  };
98 
99 }
100 
102 {
104 
105  o << "Priority: " << format("0x%02X",m_priority) << " [Dec: " << int(m_priority) << "]" << endl;
106  o << "Parameter Group Number (PGN): " << format("0x%04X",m_pgn) << " [Dec: " << int(m_pgn) << "]" << endl;
107  o << "PDU Format: " << format("0x%02X",m_pdu_format) << " [Dec: " << int(m_pdu_format) << "]" << endl;
108  o << "PDU Spec: " << format("0x%02X",m_pdu_spec) << " [Dec: " << int(m_pdu_spec) << "]" << endl;
109  o << "Source address: " << format("0x%02X",m_src_address) << " [Dec: " << int(m_src_address) << "]" << endl;
110  o << "Data length: " << format("0x%02X",m_data_length) << " [Dec: " << int(m_data_length) << "]" << endl;
111  o << "Data: ";
112  for(uint8_t k = 0; k < m_data.size(); ++k)
113  o << format("0x%02X",m_data[k]) << " ";
114  o << " [Dec: ";
115  for(uint8_t k = 0; k < m_data.size(); ++k)
116  o << int(m_data[k]) << " ";
117  o << "]" << endl;
118 
119  o << "Raw frame: ";
120  for(uint8_t k = 0; k < m_raw_frame.size(); ++k)
121  o << m_raw_frame[k];
122  o << endl;
123 
124 
125 }
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
GLvoid *typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1745
#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.
STL namespace.
GLuint in
Definition: glew.h:7146
virtual void getDescriptionAsText(std::ostream &o) const
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
unsigned char uint8_t
Definition: rptypes.h:43
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
GLsizei n
Definition: glew.h:5051
void getDescriptionAsText(std::ostream &o) const MRPT_OVERRIDE
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
This namespace contains representation of robot actions and observations.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:21
int version
Definition: mrpt_jpeglib.h:898
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
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.
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
unsigned __int32 uint32_t
Definition: rptypes.h:49



Page generated by Doxygen 1.8.11 for MRPT 1.5.7 Git: 2190203 Tue May 15 02:01:15 2018 +0200 at miƩ may 16 12:40:16 CEST 2018