MRPT  2.0.1
CObservationCANBusJ1939.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://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 
38  mrpt::serialization::CArchive& in, uint8_t version)
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 (unsigned char k : m_data) o << format("0x%02X", k) << " ";
97  o << " [Dec: ";
98  for (unsigned char k : m_data) o << int(k) << " ";
99  o << "]" << endl;
100 
101  o << "Raw frame: ";
102  for (char k : m_raw_frame) o << k;
103  o << endl;
104 }
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
This class stores a message from a CAN BUS with the protocol J1939.
STL namespace.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
This namespace contains representation of robot actions and observations.
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:54
mrpt::vision::TStereoCalibResults out
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:43
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...
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 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020