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