LibMultiSense/include/details/legacy/channel.hh
Go to the documentation of this file.
1 
37 #pragma once
38 
39 #include <set>
40 
41 #include "MultiSense/MultiSenseChannel.hh"
42 
43 #include <wire/Protocol.hh>
44 #include <utility/BufferStream.hh>
45 #include <wire/ImageMetaMessage.hh>
46 
47 #include "details/legacy/ip.hh"
50 #include "details/legacy/udp.hh"
52 
53 namespace multisense{
54 namespace legacy{
55 
56 template <typename T>
58 {
59 public:
60 
61  FrameNotifier() = default;
62 
64  {
65  m_cv.notify_all();
66  }
67 
71  void set_and_notify(const T &in_frame)
72  {
73  std::lock_guard<std::mutex> lock(m_mutex);
74  m_frame = in_frame;
75  m_cv.notify_all();
76  }
77 
81  template <class Rep, class Period>
82  std::optional<T> wait(const std::optional<std::chrono::duration<Rep, Period>>& timeout)
83  {
84  std::unique_lock<std::mutex> lock(m_mutex);
85 
86  std::optional<T> output_frame = std::nullopt;
87  if (timeout)
88  {
89  if (std::cv_status::no_timeout == m_cv.wait_for(lock, timeout.value()))
90  {
91  output_frame = std::move(m_frame);
92  }
93  }
94  else
95  {
96  m_cv.wait(lock);
97  output_frame = std::move(m_frame);
98  }
99 
100  //
101  // Reset the frame
102  //
103  m_frame = std::nullopt;
104 
105  return output_frame;
106  }
107 
108  std::optional<T> wait()
109  {
110  const std::optional<std::chrono::milliseconds> timeout = std::nullopt;
111  return wait(timeout);
112  }
113 
114 private:
115 
116  std::mutex m_mutex;
117  std::condition_variable m_cv;
118  std::optional<T> m_frame;
119 };
120 
121 
122 class LegacyChannel : public Channel
123 {
124 public:
125  explicit LegacyChannel(const Config &config);
126 
127  virtual ~LegacyChannel();
128 
135  Status start_streams(const std::vector<DataSource> &sources) final override;
136 
140  Status stop_streams(const std::vector<DataSource> &sources) final override;
141 
148  void add_image_frame_callback(std::function<void(const ImageFrame&)> callback) final override;
149 
156  void add_imu_frame_callback(std::function<void(const ImuFrame&)> callback) final override;
157 
161  Status connect(const Config &config) final override;
162 
166  void disconnect() final override;
167 
176  std::optional<ImageFrame> get_next_image_frame() final override;
177 
186  std::optional<ImuFrame> get_next_imu_frame() final override;
187 
191  MultiSenseConfig get_config() final override;
192 
196  Status set_config(const MultiSenseConfig &config) final override;
197 
202  StereoCalibration get_calibration() final override;
203 
208  Status set_calibration(const StereoCalibration &calibration) final override;
209 
213  MultiSenseInfo get_info() final override;
214 
219  Status set_device_info(const MultiSenseInfo::DeviceInfo &device_info, const std::string &key) final override;
220 
224  std::optional<MultiSenseStatus> get_system_status() final override;
225 
231  const std::optional<std::string> &broadcast_interface) final override;
232 
233 private:
234 
238  Status set_mtu(uint16_t mtu);
239 
243  Status set_mtu(const std::optional<uint16_t> &mtu);
244 
248  std::optional<MultiSenseConfig> query_configuration(bool has_aux_camera, bool has_imu, bool ptp_enabled);
249 
253  std::optional<StereoCalibration> query_calibration();
254 
258  std::optional<MultiSenseInfo> query_info();
259 
263  std::optional<MultiSenseInfo::DeviceInfo> query_device_info();
264 
268  void image_meta_callback(std::shared_ptr<const std::vector<uint8_t>> data);
269 
273  void image_callback(std::shared_ptr<const std::vector<uint8_t>> data);
274 
278  void disparity_callback(std::shared_ptr<const std::vector<uint8_t>> data);
279 
283  void imu_callback(std::shared_ptr<const std::vector<uint8_t>> data);
284 
288  void handle_and_dispatch(Image image,
289  int64_t frame_id,
290  const StereoCalibration &calibration,
291  const TimeT &capture_time,
292  const TimeT &ptp_capture_time);
293 
297  std::mutex m_mutex{};
298 
303 
307  std::mutex m_imu_callback_mutex{};
308 
312  std::atomic_bool m_connected = false;
313 
317  std::atomic_uint16_t m_current_mtu = 1500;
318 
323 
328 
332  std::atomic_uint16_t m_transmit_id = 0;
333 
338 
343 
348 
352  std::set<DataSource> m_active_streams{};
353 
357  std::function<void(const ImageFrame&)> m_user_image_frame_callback{};
358 
362  std::function<void(const ImuFrame&)> m_user_imu_frame_callback{};
363 
368 
373 
377  std::map<int64_t, crl::multisense::details::wire::ImageMeta> m_meta_cache{};
378 
382  std::map<int64_t, ImageFrame> m_frame_buffer{};
383 
387  std::atomic_uint32_t m_max_batched_imu_messages = 0;
388 
393 
399 
403  std::shared_ptr<BufferPool> m_buffer_pool = nullptr;
404 
408  std::unique_ptr<UdpReceiver> m_udp_receiver = nullptr;
409 
414 };
415 
416 }
417 }
multisense::legacy::LegacyChannel::m_current_imu_frame
ImuFrame m_current_imu_frame
A cache of IMU samples which will be internally filled until it reaches the sample threshold for disp...
Definition: LibMultiSense/include/details/legacy/channel.hh:398
multisense::legacy::LegacyChannel::m_connected
std::atomic_bool m_connected
Atomic flag to determine if we are connected to an active camera.
Definition: LibMultiSense/include/details/legacy/channel.hh:312
multisense::legacy::FrameNotifier::m_frame
std::optional< T > m_frame
Definition: LibMultiSense/include/details/legacy/channel.hh:118
multisense::legacy::LegacyChannel::query_configuration
std::optional< MultiSenseConfig > query_configuration(bool has_aux_camera, bool has_imu, bool ptp_enabled)
Query the full configuration.
Definition: LibMultiSense/details/legacy/channel.cc:846
multisense::MultiSenseInfo::NetworkInfo
The network configuration for the MultiSense.
Definition: LibMultiSense/include/MultiSense/MultiSenseTypes.hh:1267
multisense::MultiSenseConfig
Complete configuration object for configuring the MultiSense. Can be updated during camera operation.
Definition: LibMultiSense/include/MultiSense/MultiSenseTypes.hh:478
multisense::StereoCalibration
Definition: LibMultiSense/include/MultiSense/MultiSenseTypes.hh:166
multisense::legacy::LegacyChannel::m_image_callback_mutex
std::mutex m_image_callback_mutex
Internal mutex used to handle user callbacks for image data.
Definition: LibMultiSense/include/details/legacy/channel.hh:302
multisense::legacy::LegacyChannel::disparity_callback
void disparity_callback(std::shared_ptr< const std::vector< uint8_t >> data)
Disparity callback used to internally receive images sent from the MultiSense.
Definition: LibMultiSense/details/legacy/channel.cc:1086
multisense::legacy::MessageAssembler
Process incoming network data, and try the data into valid MultiSense Wire messages.
Definition: message.hh:224
multisense::legacy::LegacyChannel::m_imu_frame_notifier
FrameNotifier< ImuFrame > m_imu_frame_notifier
Notifier used to service the get_next_imu_frame member function.
Definition: LibMultiSense/include/details/legacy/channel.hh:372
multisense::Status
Status
Definition: LibMultiSense/include/MultiSense/MultiSenseTypes.hh:67
multisense::legacy::LegacyChannel::get_calibration
StereoCalibration get_calibration() final override
Get the current stereo calibration. The output calibration will correspond to the full-resolution ope...
Definition: LibMultiSense/details/legacy/channel.cc:587
multisense::legacy::FrameNotifier::m_cv
std::condition_variable m_cv
Definition: LibMultiSense/include/details/legacy/channel.hh:117
multisense::legacy::LegacyChannel::m_imu_scalars
ImuSampleScalars m_imu_scalars
Scalars to convert imu samples from wire units to standard LibMultiSense units.
Definition: LibMultiSense/include/details/legacy/channel.hh:392
multisense::legacy::LegacyChannel::m_max_batched_imu_messages
std::atomic_uint32_t m_max_batched_imu_messages
The max number of IMU messages which can be batched over the wire.
Definition: LibMultiSense/include/details/legacy/channel.hh:387
multisense::ImageFrame
A frame containing multiple images (indexed by DataSource).
Definition: LibMultiSense/include/MultiSense/MultiSenseTypes.hh:300
multisense::legacy::LegacyChannel::m_config
Config m_config
Channel config.
Definition: LibMultiSense/include/details/legacy/channel.hh:322
multisense::legacy::LegacyChannel::get_info
MultiSenseInfo get_info() final override
Get the device info associated with the camera.
Definition: LibMultiSense/details/legacy/channel.cc:635
multisense::legacy::LegacyChannel::m_udp_receiver
std::unique_ptr< UdpReceiver > m_udp_receiver
Helper object to receive UDP traffic. Internally manages a receive thread.
Definition: LibMultiSense/include/details/legacy/channel.hh:408
multisense::legacy::LegacyChannel::set_mtu
Status set_mtu(uint16_t mtu)
Try and set the MTU.
Definition: LibMultiSense/details/legacy/channel.cc:786
multisense::legacy::LegacyChannel::image_callback
void image_callback(std::shared_ptr< const std::vector< uint8_t >> data)
Image callback used to internally receive images sent from the MultiSense.
Definition: LibMultiSense/details/legacy/channel.cc:1018
ImageMetaMessage.hh
BufferStream.hh
message.hh
utilities.hh
multisense::TimeT
std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > TimeT
Definition: LibMultiSense/include/MultiSense/MultiSenseTypes.hh:65
multisense::legacy::LegacyChannel::start_streams
Status start_streams(const std::vector< DataSource > &sources) final override
Start a collection of image streams. Repeated calls to this function will not implicitly stop the pre...
Definition: LibMultiSense/details/legacy/channel.cc:140
multisense::legacy::FrameNotifier::wait
std::optional< T > wait()
Definition: LibMultiSense/include/details/legacy/channel.hh:108
multisense::legacy::LegacyChannel::add_image_frame_callback
void add_image_frame_callback(std::function< void(const ImageFrame &)> callback) final override
Add a image frame callback to get serviced inline with the receipt of a new frame....
Definition: LibMultiSense/details/legacy/channel.cc:217
multisense::legacy::LegacyChannel::set_network_config
Status set_network_config(const MultiSenseInfo::NetworkInfo &config, const std::optional< std::string > &broadcast_interface) final override
Update the network configuration of the MultiSense. This will require a hardware reboot of the MultiS...
Definition: LibMultiSense/details/legacy/channel.cc:741
multisense::legacy::LegacyChannel::query_device_info
std::optional< MultiSenseInfo::DeviceInfo > query_device_info()
Query the device_info from the camera.
Definition: LibMultiSense/details/legacy/channel.cc:992
multisense::legacy::LegacyChannel::get_system_status
std::optional< MultiSenseStatus > get_system_status() final override
Query the current MultiSense status.
Definition: LibMultiSense/details/legacy/channel.cc:678
multisense::legacy::LegacyChannel::stop_streams
Status stop_streams(const std::vector< DataSource > &sources) final override
Stop a collection of streams.
Definition: LibMultiSense/details/legacy/channel.cc:179
multisense::legacy::LegacyChannel::disconnect
void disconnect() final override
Disconnect from the camera.
Definition: LibMultiSense/details/legacy/channel.cc:339
multisense::Channel::Config
Definition: LibMultiSense/include/MultiSense/MultiSenseChannel.hh:85
multisense::ImuFrame
A collection of IMU samples from the camera.
Definition: LibMultiSense/include/MultiSense/MultiSenseTypes.hh:418
multisense::legacy::LegacyChannel::get_next_image_frame
std::optional< ImageFrame > get_next_image_frame() final override
A blocking call that waits for one image frame from the camera.
Definition: LibMultiSense/details/legacy/channel.cc:366
multisense::legacy::LegacyChannel::m_meta_cache
std::map< int64_t, crl::multisense::details::wire::ImageMeta > m_meta_cache
A cache of image metadata associated with a specific frame id.
Definition: LibMultiSense/include/details/legacy/channel.hh:377
udp.hh
multisense::legacy::LegacyChannel::m_user_imu_frame_callback
std::function< void(const ImuFrame &)> m_user_imu_frame_callback
The currently active imu frame user callback.
Definition: LibMultiSense/include/details/legacy/channel.hh:362
multisense::legacy::LegacyChannel::m_current_mtu
std::atomic_uint16_t m_current_mtu
The current MTU the camera is operating with.
Definition: LibMultiSense/include/details/legacy/channel.hh:317
multisense::legacy::LegacyChannel::imu_callback
void imu_callback(std::shared_ptr< const std::vector< uint8_t >> data)
Disparity callback used to internally receive images sent from the MultiSense.
Definition: LibMultiSense/details/legacy/channel.cc:1155
multisense::legacy::FrameNotifier
Definition: LibMultiSense/include/details/legacy/channel.hh:57
multisense::legacy::LegacyChannel
Definition: LibMultiSense/include/details/legacy/channel.hh:122
multisense::legacy::LegacyChannel::m_info
MultiSenseInfo m_info
The current cached device info stored here for convenience.
Definition: LibMultiSense/include/details/legacy/channel.hh:342
multisense::legacy::LegacyChannel::m_active_streams
std::set< DataSource > m_active_streams
The current set of active data streams the MultiSense is transmitting.
Definition: LibMultiSense/include/details/legacy/channel.hh:352
multisense::legacy::LegacyChannel::query_info
std::optional< MultiSenseInfo > query_info()
Query the MultiSense Info.
Definition: LibMultiSense/details/legacy/channel.cc:922
multisense::legacy::NetworkSocket
Convenience network socket object which contains the data corresponding to our connection.
Definition: udp.hh:51
multisense::legacy::LegacyChannel::m_frame_buffer
std::map< int64_t, ImageFrame > m_frame_buffer
A cache of image frames associated with a specific frame id.
Definition: LibMultiSense/include/details/legacy/channel.hh:382
multisense::legacy::LegacyChannel::m_message_assembler
MessageAssembler m_message_assembler
Helper object to assemble raw UDP packets into complete MultiSense wire messages.
Definition: LibMultiSense/include/details/legacy/channel.hh:413
multisense::legacy::FrameNotifier::m_mutex
std::mutex m_mutex
Definition: LibMultiSense/include/details/legacy/channel.hh:116
multisense::legacy::LegacyChannel::m_calibration
StereoCalibration m_calibration
The current cached calibration stored here for convenience.
Definition: LibMultiSense/include/details/legacy/channel.hh:337
multisense::MultiSenseInfo::DeviceInfo
The Device information associated with the MultiSense. The DeviceInfo is used to determine what featu...
Definition: LibMultiSense/include/MultiSense/MultiSenseTypes.hh:1290
multisense::legacy::FrameNotifier::wait
std::optional< T > wait(const std::optional< std::chrono::duration< Rep, Period >> &timeout)
Wait for the notifier to be valid. If the timeout is invalid, will wait forever.
Definition: LibMultiSense/include/details/legacy/channel.hh:82
multisense::legacy::LegacyChannel::~LegacyChannel
virtual ~LegacyChannel()
Definition: LibMultiSense/details/legacy/channel.cc:134
Protocol.hh
multisense::legacy::FrameNotifier::set_and_notify
void set_and_notify(const T &in_frame)
Copy a frame into the local storage, and notify all waiters that the frame is valid.
Definition: LibMultiSense/include/details/legacy/channel.hh:71
multisense::legacy::LegacyChannel::m_mutex
std::mutex m_mutex
Internal mutex used to handle updates from users.
Definition: LibMultiSense/include/details/legacy/channel.hh:297
multisense::legacy::LegacyChannel::set_calibration
Status set_calibration(const StereoCalibration &calibration) final override
Set the current stereo calibration. The calibration is expected to be or the full-resolution operatin...
Definition: LibMultiSense/details/legacy/channel.cc:599
multisense::Channel
Definition: LibMultiSense/include/MultiSense/MultiSenseChannel.hh:46
multisense::legacy::LegacyChannel::handle_and_dispatch
void handle_and_dispatch(Image image, int64_t frame_id, const StereoCalibration &calibration, const TimeT &capture_time, const TimeT &ptp_capture_time)
Handle internal process, and potentially dispatch a image.
Definition: LibMultiSense/details/legacy/channel.cc:1205
multisense::legacy::LegacyChannel::get_config
MultiSenseConfig get_config() final override
Get the current MultiSense configuration.
Definition: LibMultiSense/details/legacy/channel.cc:386
storage.hh
multisense::legacy::ImuSampleScalars
Values to scale IMU samples from the MultiSense camera into standard units LibMultiSense expects.
Definition: utilities.hh:81
multisense::legacy::LegacyChannel::m_multisense_config
MultiSenseConfig m_multisense_config
The current cached MultiSense configuration stored for convenience.
Definition: LibMultiSense/include/details/legacy/channel.hh:347
multisense::legacy::LegacyChannel::get_next_imu_frame
std::optional< ImuFrame > get_next_imu_frame() final override
A blocking call that waits for one imu frame from the camera.
Definition: LibMultiSense/details/legacy/channel.cc:376
multisense::legacy::LegacyChannel::m_buffer_pool
std::shared_ptr< BufferPool > m_buffer_pool
A collection of buffers to avoid dynamic allocation for incoming messages.
Definition: LibMultiSense/include/details/legacy/channel.hh:403
multisense
Definition: factory.cc:39
multisense::MultiSenseInfo
Static status info for the MultiSense. Will not change during camera operation.
Definition: LibMultiSense/include/MultiSense/MultiSenseTypes.hh:1262
multisense::legacy::LegacyChannel::m_user_image_frame_callback
std::function< void(const ImageFrame &)> m_user_image_frame_callback
The currently active image frame user callback.
Definition: LibMultiSense/include/details/legacy/channel.hh:357
ip.hh
multisense::legacy::LegacyChannel::connect
Status connect(const Config &config) final override
Initialize the connection to the camera.
Definition: LibMultiSense/details/legacy/channel.cc:231
multisense::legacy::LegacyChannel::set_config
Status set_config(const MultiSenseConfig &config) final override
Get set the current MultiSense configuration.
Definition: LibMultiSense/details/legacy/channel.cc:398
multisense::Image
Represents a single image plus metadata.
Definition: LibMultiSense/include/MultiSense/MultiSenseTypes.hh:187
multisense::legacy::LegacyChannel::query_calibration
std::optional< StereoCalibration > query_calibration()
Query the calibration from the camera.
Definition: LibMultiSense/details/legacy/channel.cc:905
multisense::legacy::LegacyChannel::m_socket
NetworkSocket m_socket
Active network socket for receiving and transmitting data.
Definition: LibMultiSense/include/details/legacy/channel.hh:327
multisense::legacy::FrameNotifier::FrameNotifier
FrameNotifier()=default
multisense::legacy::LegacyChannel::LegacyChannel
LegacyChannel(const Config &config)
Definition: LibMultiSense/details/legacy/channel.cc:120
multisense::legacy::LegacyChannel::set_device_info
Status set_device_info(const MultiSenseInfo::DeviceInfo &device_info, const std::string &key) final override
Set the camera's device info. This setting is protected via a key since invalid values in the device ...
Definition: LibMultiSense/details/legacy/channel.cc:647
multisense::legacy::LegacyChannel::m_transmit_id
std::atomic_uint16_t m_transmit_id
Monotonically increasing internal id used to uniquely identify requests sent to the camera.
Definition: LibMultiSense/include/details/legacy/channel.hh:332
multisense::legacy::LegacyChannel::add_imu_frame_callback
void add_imu_frame_callback(std::function< void(const ImuFrame &)> callback) final override
Add a imu frame callback to get serviced inline with the receipt of a new frame. Only a single imu fr...
Definition: LibMultiSense/details/legacy/channel.cc:224
multisense::legacy::FrameNotifier::~FrameNotifier
~FrameNotifier()
Definition: LibMultiSense/include/details/legacy/channel.hh:63
multisense::legacy::LegacyChannel::image_meta_callback
void image_meta_callback(std::shared_ptr< const std::vector< uint8_t >> data)
Image meta callback used to internally receive images sent from the MultiSense.
Definition: LibMultiSense/details/legacy/channel.cc:1009
multisense::legacy::LegacyChannel::m_imu_callback_mutex
std::mutex m_imu_callback_mutex
Internal mutex used to handle user callbacks imu data.
Definition: LibMultiSense/include/details/legacy/channel.hh:307
multisense::legacy::LegacyChannel::m_image_frame_notifier
FrameNotifier< ImageFrame > m_image_frame_notifier
Notifier used to service the get_next_image_frame member function.
Definition: LibMultiSense/include/details/legacy/channel.hh:367


multisense_lib
Author(s):
autogenerated on Thu Apr 17 2025 02:49:08