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/deserialize/deserialize_utils.hpp>
11 #include <ifm3d/deserialize/struct_tof_info_v3.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 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  auto version = mkval<std::uint32_t>(data + TOF_INFO_VERSION_INDEX);
36 
37  return size >= TOF_INFO_V4_SIZE && version >= 4;
38  }
39 
40  void
41  Read(const uint8_t* data, size_t size)
42  {
43  if (!IsValid(data, size))
44  {
45  throw ifm3d::Error(IFM3D_CORRUPTED_STRUCT);
46  }
47 
48  TOFInfoV3::Read(data, size);
49  const uint8_t* start_ptr = data;
51  mkval<std::uint32_t>(start_ptr + TOF_INFO_MEASUREMENT_BLOCK_INDEX);
52  measurement_range_min =
53  mkval<float>(start_ptr + TOF_INFO_MEASUREMENT_RANGE_MIN_INDEX);
54  measurement_range_max =
55  mkval<float>(start_ptr + TOF_INFO_MEASUREMENT_RANGE_MAX_INDEX);
56  };
63  /*
64  * @brief Current minimum measurement range [m].
65  * The value is based on the camera-individual ToF calibration.
66  * It is influenced by temperature.
67  **/
68  float measurement_range_min{};
69  /*
70  * @brief Current maximum measurement range [m].
71  * The value is based on the camera-individual ToF calibration.
72  * It is influenced by temperature.
73  **/
74  float measurement_range_max{};
78  static constexpr size_t TOF_INFO_V4_SIZE = 428;
79 
80  static TOFInfoV4
81  Deserialize(const Buffer& tof_info_buffer)
82  {
83  TOFInfoV4 tof_info_v4;
84 
85  tof_info_v4.Read(tof_info_buffer.Ptr<uint8_t>(0),
86  tof_info_buffer.Size());
87  return tof_info_v4;
88  }
89  };
90 } // end namespace ifm3d
91 
92 #endif // IFM3D_DESERIALIZE_STRUCT_TOF_INFO_V3_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::TOFInfoV3
Definition: struct_tof_info_v3.hpp:38
ifm3d::Error
Definition: err.h:114
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:78
ifm3d::TOFInfoV4
Definition: struct_tof_info_v4.hpp:27
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::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:62