ifm3d
struct_rgb_info_v2.hpp
1 // -*- c++ -*-
2 /*
3  * Copyright 2026-present ifm electronic, gmbh
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef IFM3D_DESERIALIZE_STRUCT_RGB_INFO_V2_HPP
8 #define IFM3D_DESERIALIZE_STRUCT_RGB_INFO_V2_HPP
9 
10 #include <ifm3d/deserialize/deserialize_utils.hpp>
11 #include <ifm3d/deserialize/struct_rgb_info_v1.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 RGB_INFO_ROLLING_SHUTTER_ROW_OFFSET_NS_INDEX = 0x0134;
22  }; // end anonymous namespace
23 
25  class RGBInfoV2 : public RGBInfoV1
26  {
27 
28  public:
29  using Ptr = std::shared_ptr<RGBInfoV2>;
30 
31  static bool
32  IsValid(const uint8_t* data, size_t size)
33  {
34  auto version = mkval<std::uint32_t>(data + RGB_INFO_VERSION_INDEX);
35 
36  return size >= RGB_INFO_V2_SIZE && version >= 1;
37  }
38 
39  void
40  Read(const uint8_t* data, size_t size)
41  {
42  if (!IsValid(data, size))
43  {
44  throw ifm3d::Error(IFM3D_CORRUPTED_STRUCT);
45  }
46  RGBInfoV1::Read(data, size);
47  const uint8_t* start_ptr = data;
48  rolling_shutter_row_offset_ns = mkval<std::uint32_t>(
49  start_ptr + RGB_INFO_ROLLING_SHUTTER_ROW_OFFSET_NS_INDEX);
50  };
51 
58  static constexpr size_t RGB_INFO_V2_SIZE = 312;
59 
60  static RGBInfoV2
61  Deserialize(const Buffer& rgb_info_buffer)
62  {
63  RGBInfoV2 rgb_info_v2{};
64 
65  rgb_info_v2.Read(rgb_info_buffer.Ptr<uint8_t>(0),
66  rgb_info_buffer.Size());
67  return rgb_info_v2;
68  }
69  };
70 } // end namespace ifm3d
71 
72 #endif // IFM3D_DESERIALIZE_STRUCT_RGB_INFO_V2_HPP
The class Buffer represent a STL container to store data from the ifm devices in 2 dimension and supp...
Definition: buffer.h:99
T * Ptr(std::uint32_t row)
returns a pointer to the specified Buffer row.
size_t Size() const
Return the size of the buffer in bytes.
Exception wrapper for library and system errors encountered by the library.
Definition: err.h:126
Definition: struct_rgb_info_v1.hpp:32
Definition: struct_rgb_info_v2.hpp:26
std::uint32_t rolling_shutter_row_offset_ns
Rolling-shutter offset between consecutive row timestamps, given in [nanoseconds].
Definition: struct_rgb_info_v2.hpp:57