ifm3d
struct_o3r_ods_info_v1.hpp
1 // -*- c++ -*-
2 /*
3  * Copyright 2022-present ifm electronic, gmbh
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef IFM3D_DESERIALIZE_STRUCT_O3R__ODS_INFO_V1_HPP
8 #define IFM3D_DESERIALIZE_STRUCT_O3R__ODS_INFO_V1_HPP
9 
10 #include <array>
11 #include <chrono>
12 #include <ifm3d/device/device.h>
13 #include <ifm3d/device/err.h>
14 #include <ifm3d/fg/organizer_utils.h>
15 #include <ifm3d/fg/buffer.h>
16 #include <ifm3d/deserialize/deserialize_utils.hpp>
17 
18 namespace ifm3d
19 {
20  namespace
21  {
22  constexpr auto ODS_INFO_TIMESTAMP_NS_INDEX = 0x0000;
23  constexpr auto ODS_INFO_ZONE_OCCUPIED_INDEX = 0x0008;
24  constexpr auto ODS_INFO_ZONE_CONFIG_ID_INDEX = 0x000B;
25  };
26 
28  class ODSInfoV1
29  {
30  public:
31  using Ptr = std::shared_ptr<ODSInfoV1>;
32 
33  void
34  Read(const uint8_t* data, size_t size)
35  {
36  if (size < ods_info_v1_size)
37  {
38  throw ifm3d::Error(IFM3D_CORRUPTED_STRUCT);
39  }
40  const uint8_t* start_ptr = data;
41  timestamp_ns =
42  mkval<std::uint64_t>(start_ptr + ODS_INFO_TIMESTAMP_NS_INDEX);
43  mkarray<uint8_t, 3>(start_ptr + ODS_INFO_ZONE_OCCUPIED_INDEX,
44  zone_occupied);
45  zone_config_id =
46  mkval<uint32_t>(start_ptr + ODS_INFO_ZONE_CONFIG_ID_INDEX);
47  };
48  /*@brief Timestamp of zone information [ns]*/
49  uint64_t timestamp_ns;
50  /*
51  * @brief array with 3 elements of unit8 values
52  * 0: zone is free
53  * 1: zone is occupied
54  */
55  std::array<uint8_t, 3> zone_occupied;
56  /*
57  * @brief user-specified ID to identify the zone configuration
58  */
59  uint32_t zone_config_id;
60  /*
61  *@brief size ofthe ODS_INFO_V1 in bytes
62  * */
63  const size_t ods_info_v1_size = 15;
64 
65  static ODSInfoV1
66  Deserialize(const Buffer& tof_info_buffer)
67  {
68  ODSInfoV1 ods_info_v1;
69 
70  ods_info_v1.Read(tof_info_buffer.ptr<uint8_t>(0),
71  tof_info_buffer.size());
72  return ods_info_v1;
73  }
74  };
75 } // end namespace ifm3d
76 
77 #endif // IFM3D_DESERIALIZE_STRUCT_O3R__ODS_INFO_V1_HPP
ifm3d::Buffer::size
size_t size() const
Return the size of the buffer in bytes.
ifm3d::Buffer
The class Buffer represent a STL container to store data from the ifm devices in 2 dimension and supp...
Definition: buffer.h:98
ifm3d::Buffer::ptr
T * ptr(const std::uint32_t row)
returns a pointer to the specified Buffer row.
ifm3d::Error
Definition: err.h:112
ifm3d::ODSInfoV1
Definition: struct_o3r_ods_info_v1.hpp:28