monitoring_frame_deserialization.h
Go to the documentation of this file.
1 // Copyright (c) 2020-2022 Pilz GmbH & Co. KG
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU Lesser General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
15 #ifndef PSEN_SCAN_V2_STANDALONE_MONITORING_FRAME_DESERIALIZATION_H
16 #define PSEN_SCAN_V2_STANDALONE_MONITORING_FRAME_DESERIALIZATION_H
17 
18 #include <istream>
19 #include <stdexcept>
20 #include <string>
21 #include <vector>
22 #include <bitset>
23 
31 
33 {
49 namespace data_conversion_layer
50 {
51 namespace monitoring_frame
52 {
53 static constexpr uint32_t DEFAULT_DEVICE_STATUS{ 0 };
54 static constexpr uint32_t OP_CODE_MONITORING_FRAME{ 0xCA };
55 static constexpr uint32_t ONLINE_WORKING_MODE{ 0x00 };
56 static constexpr uint32_t GUI_MONITORING_TRANSACTION{ 0x05 };
57 static constexpr uint16_t NUMBER_OF_BYTES_SCAN_COUNTER{ 4 };
58 static constexpr uint16_t NUMBER_OF_BYTES_ZONE_SET{ 1 };
59 static constexpr uint16_t NUMBER_OF_BYTES_SINGLE_MEASUREMENT{ 2 };
60 static constexpr uint16_t NO_SIGNAL_ARRIVED{ 59956 };
61 static constexpr uint16_t SIGNAL_TOO_LATE{ 59958 };
62 static constexpr uint16_t NUMBER_OF_BYTES_SINGLE_INTENSITY{ 2 };
63 
68 {
69 public:
70  using DeviceStatus = uint32_t;
71  using OpCode = uint32_t;
72  using WorkingMode = uint32_t;
73  using TransactionType = uint32_t;
76 
77 public:
78  FixedFields(DeviceStatus device_status,
79  OpCode op_code,
80  WorkingMode working_mode,
81  TransactionType transaction_type,
82  configuration::ScannerId scanner_id,
83  FromTheta from_theta,
85 
86 public:
87  DeviceStatus deviceStatus() const;
88  OpCode opCode() const;
89  WorkingMode workingMode() const;
92  FromTheta fromTheta() const;
93  Resolution resolution() const;
94 
95 private:
103 };
116 {
117 public:
118  using Id = uint8_t;
119  using Length = uint16_t;
120 
121 public:
122  AdditionalFieldHeader(Id id, Length length);
123 
124 public:
125  Id id() const;
126  Length length() const;
127 
128  static std::string idToString(Id id);
129 
130 private:
133 };
134 
136 {
137  io_pin_data = 0x01,
138  scan_counter = 0x02,
139  zone_set = 0x03,
140  diagnostics = 0x04,
141  measurements = 0x05,
142  intensities = 0x06,
143  end_of_frame = 0x09
144 };
145 
146 AdditionalFieldHeader readAdditionalField(std::istream& is, const std::size_t& max_num_bytes);
147 
148 monitoring_frame::Message deserialize(const data_conversion_layer::RawData& data, const std::size_t& num_bytes);
149 FixedFields readFixedFields(std::istream& is);
150 namespace diagnostic
151 {
152 std::vector<diagnostic::Message> deserializeMessages(std::istream& is);
153 }
154 
155 namespace io
156 {
157 template <size_t ChunkSize>
158 void deserializePinField(std::istream& is, std::array<std::bitset<8>, ChunkSize>& pin_states)
159 {
160  for (auto& byte_states : pin_states)
161  {
162  const auto raw_byte = raw_processing::read<uint8_t>(is);
163  byte_states |= std::bitset<8>(raw_byte);
164  }
165 }
166 PinData deserializePins(std::istream& is);
167 } // namespace io
168 
172 class DecodingFailure : public std::runtime_error
173 {
174 public:
175  DecodingFailure(const std::string& msg = "Error while decoding laser scanner measurement data");
176 };
177 
191 {
192 public:
193  AdditionalFieldUnexpectedSize(const std::string& msg);
194 };
195 
196 inline DecodingFailure::DecodingFailure(const std::string& msg) : std::runtime_error(msg)
197 {
198 }
199 
201 {
202 }
203 
205 {
206  return id_;
207 }
208 
210 {
211  return length_;
212 }
213 
215 {
216  return device_status_;
217 }
218 
220 {
221  return op_code_;
222 }
223 
225 {
226  return working_mode_;
227 }
228 
230 {
231  return transaction_type_;
232 }
233 
235 {
236  return scanner_id_;
237 }
238 
240 {
241  return from_theta_;
242 }
243 
245 {
246  return resolution_;
247 }
248 
249 } // namespace monitoring_frame
250 } // namespace data_conversion_layer
251 } // namespace psen_scan_v2_standalone
252 
253 #endif // PSEN_SCAN_V2_STANDALONE_MONITORING_FRAME_DESERIALIZATION_H
Higher level data type representing a single monitoring frame.
monitoring_frame::Message deserialize(const data_conversion_layer::RawData &data, const std::size_t &num_bytes)
AdditionalFieldHeader readAdditionalField(std::istream &is, const std::size_t &max_num_bytes)
psen_scan_v2_standalone::util::TenthOfDegree TenthOfDegree
FixedFields(DeviceStatus device_status, OpCode op_code, WorkingMode working_mode, TransactionType transaction_type, configuration::ScannerId scanner_id, FromTheta from_theta, Resolution resolution)
DecodingFailure(const std::string &msg="Error while decoding laser scanner measurement data")
Represents the IO PIN field of a monitoring frame.
Definition: io_pin_data.h:72
void deserializePinField(std::istream &is, std::array< std::bitset< 8 >, ChunkSize > &pin_states)
Root namespace in which the software components to communicate with the scanner (firmware-version: 2)...
Definition: udp_client.h:41
Definition for the type and length of an additional field in a monitoring frame.
Exception thrown on problems during the extraction of the measurement data.
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
Helper class representing angles in tenth of degree.


psen_scan_v2
Author(s): Pilz GmbH + Co. KG
autogenerated on Sat Nov 5 2022 02:13:36