ifm3d
struct_tof_info_v4.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_TOF_INFO_V4_HPP
8 #define IFM3D_DESERIALIZE_STRUCT_TOF_INFO_V4_HPP
9 
10 #include <ifm3d/device/device.h>
11 #include <ifm3d/device/err.h>
12 #include <ifm3d/fg/organizer_utils.h>
13 #include <ifm3d/fg/buffer.h>
14 #include <ifm3d/deserialize/deserialize_utils.hpp>
15 #include <ifm3d/deserialize/struct_tof_info_v3.hpp>
16 
17 namespace ifm3d
18 {
19  namespace
20  {
21  constexpr auto TOF_INFO_MEASUREMENT_BLOCK_INDEX = 0x01A0;
22  constexpr auto TOF_INFO_MEASUREMENT_RANGE_MIN_INDEX = 0x01A4;
23  constexpr auto TOF_INFO_MEASUREMENT_RANGE_MAX_INDEX = 0x01A8;
24  };
25 
27  class TOFInfoV4 : public TOFInfoV3
28  {
29  public:
30  using Ptr = std::shared_ptr<TOFInfoV4>;
31 
32  static bool
33  IsValid(const uint8_t* data, size_t size)
34  {
35  uint32_t version = mkval<std::uint32_t>(data + TOF_INFO_VERSION_INDEX);
36 
37  if (size < tof_info_v4_size || version < 4)
38  {
39  return false;
40  }
41  return true;
42  }
43 
44  void
45  Read(const uint8_t* data, size_t size)
46  {
47  if (!IsValid(data, size))
48  {
49  throw ifm3d::Error(IFM3D_CORRUPTED_STRUCT);
50  }
51 
52  TOFInfoV3::Read(data, size);
53  const uint8_t* start_ptr = data;
55  mkval<std::uint32_t>(start_ptr + TOF_INFO_MEASUREMENT_BLOCK_INDEX);
56  measurement_range_min =
57  mkval<float>(start_ptr + TOF_INFO_MEASUREMENT_RANGE_MIN_INDEX);
58  measurement_range_max =
59  mkval<float>(start_ptr + TOF_INFO_MEASUREMENT_RANGE_MAX_INDEX);
60  };
66  uint32_t measurement_block_index;
67  /*
68  * @brief Current minimum measurement range [m].
69  * The value is based on the camera-individual ToF calibration.
70  * It is influenced by temperature.
71  **/
72  float measurement_range_min;
73  /*
74  * @brief Current maximum measurement range [m].
75  * The value is based on the camera-individual ToF calibration.
76  * It is influenced by temperature.
77  **/
78  float measurement_range_max;
82  static constexpr size_t tof_info_v4_size = 428;
83 
84  static TOFInfoV4
85  Deserialize(const Buffer& tof_info_buffer)
86  {
87  TOFInfoV4 tof_info_v4;
88 
89  tof_info_v4.Read(tof_info_buffer.ptr<uint8_t>(0),
90  tof_info_buffer.size());
91  return tof_info_v4;
92  }
93  };
94 } // end namespace ifm3d
95 
96 #endif // IFM3D_DESERIALIZE_STRUCT_TOF_INFO_V3_HPP
ifm3d::Buffer::size
size_t size() const
Return the size of the buffer in bytes.
ifm3d::TOFInfoV4::tof_info_v4_size
static constexpr size_t tof_info_v4_size
size of ToFInfoV4 in bytes
Definition: struct_tof_info_v4.hpp:82
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::TOFInfoV3
Definition: struct_tof_info_v3.hpp:38
ifm3d::Error
Definition: err.h:114
ifm3d::TOFInfoV4
Definition: struct_tof_info_v4.hpp:27
ifm3d::TOFInfoV4::measurement_block_index
uint32_t measurement_block_index
Current measurement block index (range 0 to N-1, where N is the number of sub-modes).
Definition: struct_tof_info_v4.hpp:60