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 <ifm3d/deserialize/deserialize_utils.hpp>
12 #include <ifm3d/device/device.h>
13 #include <ifm3d/device/err.h>
14 #include <ifm3d/fg/buffer.h>
15 #include <ifm3d/fg/organizer_utils.h>
16 
17 namespace ifm3d
18 {
19  namespace
20  {
21  constexpr auto ODS_INFO_TIMESTAMP_NS_INDEX = 0x0000;
22  constexpr auto ODS_INFO_ZONE_OCCUPIED_INDEX = 0x0008;
23  constexpr auto ODS_INFO_ZONE_CONFIG_ID_INDEX = 0x000B;
24  };
25 
27  class ODSInfoV1
28  {
29  public:
30  using Ptr = std::shared_ptr<ODSInfoV1>;
31 
32  bool
33  IsValid(const uint8_t*, size_t size)
34  {
35  return size >= ODS_INFO_V1_SIZE;
36  }
37 
38  void
39  Read(const uint8_t* data, size_t size)
40  {
41  if (!IsValid(data, size))
42  {
43  throw ifm3d::Error(IFM3D_CORRUPTED_STRUCT);
44  }
45  const uint8_t* start_ptr = data;
46  timestamp_ns =
47  mkval<std::uint64_t>(start_ptr + ODS_INFO_TIMESTAMP_NS_INDEX);
48  mkarray<uint8_t, 3>(start_ptr + ODS_INFO_ZONE_OCCUPIED_INDEX,
49  zone_occupied);
50  zone_config_id =
51  mkval<uint32_t>(start_ptr + ODS_INFO_ZONE_CONFIG_ID_INDEX);
52  };
53  /*@brief Timestamp of zone information [ns]*/
54  uint64_t timestamp_ns;
55  /*
56  * @brief array with 3 elements of unit8 values
57  * 0: zone is free
58  * 1: zone is occupied
59  */
60  std::array<uint8_t, 3> zone_occupied;
61  /*
62  * @brief user-specified ID to identify the zone configuration
63  */
64  uint32_t zone_config_id;
65  /*
66  *@brief size ofthe ODS_INFO_V1 in bytes
67  * */
68  static constexpr size_t ODS_INFO_V1_SIZE = 15;
69 
70  static ODSInfoV1
71  Deserialize(const Buffer& tof_info_buffer)
72  {
73  ODSInfoV1 ods_info_v1{};
74 
75  ods_info_v1.Read(tof_info_buffer.Ptr<uint8_t>(0),
76  tof_info_buffer.Size());
77  return ods_info_v1;
78  }
79  };
80 } // end namespace ifm3d
81 
82 #endif // IFM3D_DESERIALIZE_STRUCT_O3R__ODS_INFO_V1_HPP
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::Error
Definition: err.h:114
ifm3d::Buffer::Size
size_t Size() const
Return the size of the buffer in bytes.
ifm3d::Buffer::Ptr
T * Ptr(std::uint32_t row)
returns a pointer to the specified Buffer row.
ifm3d::ODSInfoV1
Definition: struct_o3r_ods_info_v1.hpp:27