RealSense Cross Platform API
RealSense Cross-platform API
rs_device.hpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017-2024 RealSense, Inc. All Rights Reserved.
3 
4 #ifndef LIBREALSENSE_RS2_DEVICE_HPP
5 #define LIBREALSENSE_RS2_DEVICE_HPP
6 
7 #include "rs_types.hpp"
8 #include "rs_sensor.hpp"
9 #include <vector>
10 #include <string>
11 
12 namespace rs2
13 {
14  class context;
15  class device_list;
16  class pipeline_profile;
17  class device_hub;
18 
19  class device
20  {
21  public:
26  std::vector<sensor> query_sensors() const
27  {
28  rs2_error* e = nullptr;
29  std::shared_ptr<rs2_sensor_list> list(
30  rs2_query_sensors(_dev.get(), &e),
32  error::handle(e);
33 
34  auto size = rs2_get_sensors_count(list.get(), &e);
35  error::handle(e);
36 
37  std::vector<sensor> results;
38  for (auto i = 0; i < size; i++)
39  {
40  std::shared_ptr<rs2_sensor> dev(
41  rs2_create_sensor(list.get(), i, &e),
43  error::handle(e);
44 
45  sensor rs2_dev(dev);
46  results.push_back(rs2_dev);
47  }
48 
49  return results;
50  }
51 
55  std::string get_type() const
56  {
59  return {};
60  }
61 
65  std::string get_description() const
66  {
67  std::ostringstream os;
68  auto type = get_type();
70  {
71  if( ! type.empty() )
72  os << "[" << type << "] ";
74  }
75  else
76  {
77  if( ! type.empty() )
78  os << type << " device";
79  else
80  os << "unknown device";
81  }
83  os << " s/n " << get_info( RS2_CAMERA_INFO_SERIAL_NUMBER );
84  return os.str();
85  }
86 
87  template<class T>
88  T first() const
89  {
90  for (auto&& s : query_sensors())
91  {
92  if (auto t = s.as<T>()) return t;
93  }
94  throw rs2::error("Could not find requested sensor type!");
95  }
96 
102  bool supports(rs2_camera_info info) const
103  {
104  rs2_error* e = nullptr;
105  auto is_supported = rs2_supports_device_info(_dev.get(), info, &e);
106  error::handle(e);
107  return is_supported > 0;
108  }
109 
115  const char* get_info(rs2_camera_info info) const
116  {
117  rs2_error* e = nullptr;
118  auto result = rs2_get_device_info(_dev.get(), info, &e);
119  error::handle(e);
120  return result;
121  }
122 
127  {
128  rs2_error* e = nullptr;
129  rs2_hardware_reset(_dev.get(), &e);
130  error::handle(e);
131  }
132 
137  {
138  rs2_error* e = nullptr;
139  auto result = rs2_is_in_recovery_mode(_dev.get(), &e);
140  error::handle(e);
141  return result;
142  }
143 
151  double get_device_time_ms() const
152  {
153  rs2_error* e = nullptr;
154  auto result = rs2_get_device_time_ms(_dev.get(), &e);
155  error::handle(e);
156  return result;
157  }
158 
159  device& operator=(const std::shared_ptr<rs2_device> dev)
160  {
161  _dev.reset();
162  _dev = dev;
163  return *this;
164  }
165  device& operator=(const device& dev)
166  {
167  *this = nullptr;
168  _dev = dev._dev;
169  return *this;
170  }
171  device() : _dev(nullptr) {}
172 
173  // Note: this checks the validity of rs2::device (i.e., if it's connected to a realsense device), and does
174  // NOT reflect the current condition (connected/disconnected). Use is_connected() for that.
175  operator bool() const
176  {
177  return _dev != nullptr;
178  }
179  const std::shared_ptr<rs2_device>& get() const
180  {
181  return _dev;
182  }
183  bool operator<( device const & other ) const
184  {
185  // All RealSense cameras have an update-ID but not always a serial number
186  return std::strcmp( get_info( RS2_CAMERA_INFO_FIRMWARE_UPDATE_ID ),
188  < 0;
189  }
190 
191  bool is_connected() const
192  {
193  rs2_error * e = nullptr;
194  bool connected = rs2_device_is_connected( _dev.get(), &e );
195  error::handle( e );
196  return connected;
197  }
198 
199  // Minimum firmware version supported by this device's SKU (e.g. "5.10.0.17").
200  // Throws if the device does not implement the FW-update protocol or has no defined minimum.
201  std::string get_firmware_min_version() const
202  {
203  rs2_error * e = nullptr;
204  auto res = rs2_get_firmware_min_version( _dev.get(), &e );
205  error::handle( e );
206  return res ? std::string( res ) : std::string();
207  }
208 
209  template<class T>
210  bool is() const
211  {
212  T extension(*this);
213  return extension;
214  }
215 
216  template<class T>
217  T as() const
218  {
219  T extension(*this);
220  return extension;
221  }
222  virtual ~device()
223  {
224  }
225 
226  explicit operator std::shared_ptr<rs2_device>() { return _dev; };
227  explicit device(std::shared_ptr<rs2_device> dev) : _dev(dev) {}
228  protected:
229  friend class rs2::context;
230  friend class rs2::device_list;
231  friend class rs2::pipeline_profile;
232  friend class rs2::device_hub;
233 
234  std::shared_ptr<rs2_device> _dev;
235 
236  };
237 
238  template<class T>
240  {
241  T _callback;
242 
243  public:
244  explicit update_progress_callback(T callback) : _callback(callback) {}
245 
246  void on_update_progress(const float progress) override
247  {
248  _callback(progress);
249  }
250 
251  void release() override { delete this; }
252  };
253 
254  class updatable : public device
255  {
256  public:
257  updatable() : device() {}
259  : device(d.get())
260  {
261  rs2_error* e = nullptr;
262  if (rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_UPDATABLE, &e) == 0 && !e)
263  {
264  _dev.reset();
265  }
266  error::handle(e);
267  }
268 
269  // Move the device to update state, this will cause the updatable device to disconnect and reconnect as an update device.
270  void enter_update_state() const
271  {
272  rs2_error* e = nullptr;
273  rs2_enter_update_state(_dev.get(), &e);
274  error::handle(e);
275  }
276 
277  // Create backup of camera flash memory. Such backup does not constitute valid firmware image, and cannot be
278  // loaded back to the device, but it does contain all calibration and device information."
279  std::vector<uint8_t> create_flash_backup() const
280  {
281  std::vector<uint8_t> results;
282 
283  rs2_error* e = nullptr;
284  std::shared_ptr<const rs2_raw_data_buffer> list(
285  rs2_create_flash_backup_cpp(_dev.get(), nullptr, &e),
287  error::handle(e);
288 
289  auto size = rs2_get_raw_data_size(list.get(), &e);
290  error::handle(e);
291 
292  auto start = rs2_get_raw_data(list.get(), &e);
293 
294  results.insert(results.begin(), start, start + size);
295 
296  return results;
297  }
298 
299  template<class T>
300  std::vector<uint8_t> create_flash_backup(T callback) const
301  {
302  std::vector<uint8_t> results;
303 
304  rs2_error* e = nullptr;
305  std::shared_ptr<const rs2_raw_data_buffer> list(
306  rs2_create_flash_backup_cpp(_dev.get(), new update_progress_callback<T>(std::move(callback)), &e),
308  error::handle(e);
309 
310  auto size = rs2_get_raw_data_size(list.get(), &e);
311  error::handle(e);
312 
313  auto start = rs2_get_raw_data(list.get(), &e);
314 
315  results.insert(results.begin(), start, start + size);
316 
317  return results;
318  }
319 
320  // check firmware compatibility with SKU
321  bool check_firmware_compatibility(const std::vector<uint8_t>& image) const
322  {
323  rs2_error* e = nullptr;
324  auto res = !!rs2_check_firmware_compatibility(_dev.get(), image.data(), (int)image.size(), &e);
325  error::handle(e);
326  return res;
327  }
328 
329  // Update an updatable device to the provided unsigned firmware. This call is executed on the caller's thread.
330  void update_unsigned(const std::vector<uint8_t>& image, int update_mode = RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
331  {
332  rs2_error* e = nullptr;
333  rs2_update_firmware_unsigned_cpp(_dev.get(), image.data(), (int)image.size(), nullptr, update_mode, &e);
334  error::handle(e);
335  }
336 
337  // Update an updatable device to the provided unsigned firmware. This call is executed on the caller's thread and it supports progress notifications via the callback.
338  template<class T>
339  void update_unsigned(const std::vector<uint8_t>& image, T callback, int update_mode = RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
340  {
341  rs2_error* e = nullptr;
342  rs2_update_firmware_unsigned_cpp(_dev.get(), image.data(), int(image.size()), new update_progress_callback<T>(std::move(callback)), update_mode, &e);
343  error::handle(e);
344  }
345  };
346 
347  class update_device : public device
348  {
349  public:
352  : device(d.get())
353  {
354  rs2_error* e = nullptr;
356  {
357  _dev.reset();
358  }
359  error::handle(e);
360  }
361 
362  // Update an updatable device to the provided firmware.
363  // This call is executed on the caller's thread.
364  void update(const std::vector<uint8_t>& fw_image) const
365  {
366  rs2_error* e = nullptr;
367  rs2_update_firmware_cpp(_dev.get(), fw_image.data(), (int)fw_image.size(), NULL, &e);
368  error::handle(e);
369  }
370 
371  // Update an updatable device to the provided firmware.
372  // This call is executed on the caller's thread and it supports progress notifications via the callback.
373  template<class T>
374  void update(const std::vector<uint8_t>& fw_image, T callback) const
375  {
376  rs2_error* e = nullptr;
377  rs2_update_firmware_cpp(_dev.get(), fw_image.data(), int(fw_image.size()), new update_progress_callback<T>(std::move(callback)), &e);
378  error::handle(e);
379  }
380  };
381 
382  typedef std::vector<uint8_t> calibration_table;
383 
384  class calibrated_device : public device
385  {
386  public:
388  : device(d.get())
389  {}
390 
394  void write_calibration() const
395  {
396  rs2_error* e = nullptr;
397  rs2_write_calibration(_dev.get(), &e);
398  error::handle(e);
399  }
400 
405  {
406  rs2_error* e = nullptr;
408  error::handle(e);
409  }
410  };
411 
413  {
414  public:
416  : calibrated_device(d)
417  {
418  rs2_error* e = nullptr;
420  {
421  _dev.reset();
422  }
423  error::handle(e);
424  }
425 
461  template<class T>
462  calibration_table run_on_chip_calibration(std::string json_content, float* health, T callback, int timeout_ms = 5000) const
463  {
464  std::vector<uint8_t> results;
465 
466  rs2_error* e = nullptr;
467  auto buf = rs2_run_on_chip_calibration_cpp(_dev.get(), json_content.data(), int(json_content.size()), health, new update_progress_callback<T>(std::move(callback)), timeout_ms, &e);
468  error::handle(e);
469 
470  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
471 
472  auto size = rs2_get_raw_data_size(list.get(), &e);
473  error::handle(e);
474 
475  auto start = rs2_get_raw_data(list.get(), &e);
476 
477  results.insert(results.begin(), start, start + size);
478 
479  return results;
480  }
481 
516  calibration_table run_on_chip_calibration(std::string json_content, float* health, int timeout_ms = 5000) const
517  {
518  std::vector<uint8_t> results;
519 
520  rs2_error* e = nullptr;
521  const rs2_raw_data_buffer* buf = rs2_run_on_chip_calibration_cpp(_dev.get(), json_content.data(), static_cast< int >( json_content.size() ), health, nullptr, timeout_ms, &e);
522  error::handle(e);
523  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
524 
525  auto size = rs2_get_raw_data_size(list.get(), &e);
526  error::handle(e);
527 
528  auto start = rs2_get_raw_data(list.get(), &e);
529  error::handle(e);
530 
531  results.insert(results.begin(), start, start + size);
532 
533  return results;
534  }
535 
567  template<class T>
568  calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float* health, T callback, int timeout_ms = 5000) const
569  {
570  std::vector<uint8_t> results;
571 
572  rs2_error* e = nullptr;
573  const rs2_raw_data_buffer* buf = rs2_run_tare_calibration_cpp(_dev.get(), ground_truth_mm, json_content.data(), int(json_content.size()), health, new update_progress_callback<T>(std::move(callback)), timeout_ms, &e);
574  error::handle(e);
575  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
576 
577  auto size = rs2_get_raw_data_size(list.get(), &e);
578  error::handle(e);
579 
580  auto start = rs2_get_raw_data(list.get(), &e);
581 
582  results.insert(results.begin(), start, start + size);
583 
584  return results;
585  }
586 
617  calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float * health, int timeout_ms = 5000) const
618  {
619  std::vector<uint8_t> results;
620 
621  rs2_error* e = nullptr;
622  const rs2_raw_data_buffer* buf = rs2_run_tare_calibration_cpp(_dev.get(), ground_truth_mm, json_content.data(), static_cast< int >( json_content.size() ), health, nullptr, timeout_ms, &e);
623  error::handle(e);
624  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
625 
626  auto size = rs2_get_raw_data_size(list.get(), &e);
627  error::handle(e);
628 
629  auto start = rs2_get_raw_data(list.get(), &e);
630 
631  results.insert(results.begin(), start, start + size);
632 
633  return results;
634  }
635 
644  template<class T>
645  calibration_table process_calibration_frame(rs2::frame f, float* const health, T callback, int timeout_ms = 5000) const
646  {
647  std::vector<uint8_t> results;
648 
649  rs2_error* e = nullptr;
650  const rs2_raw_data_buffer* buf = rs2_process_calibration_frame(_dev.get(), f.get(), health, new update_progress_callback<T>(std::move(callback)), timeout_ms, &e);
651  error::handle(e);
652  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
653 
654  auto size = rs2_get_raw_data_size(list.get(), &e);
655  error::handle(e);
656 
657  auto start = rs2_get_raw_data(list.get(), &e);
658 
659  results.insert(results.begin(), start, start + size);
660 
661  return results;
662  }
663 
671  calibration_table process_calibration_frame(rs2::frame f, float* const health, int timeout_ms = 5000) const
672  {
673  std::vector<uint8_t> results;
674 
675  rs2_error* e = nullptr;
676  const rs2_raw_data_buffer* buf = rs2_process_calibration_frame(_dev.get(), f.get(), health, nullptr, timeout_ms, &e);
677  error::handle(e);
678  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
679 
680  auto size = rs2_get_raw_data_size(list.get(), &e);
681  error::handle(e);
682 
683  auto start = rs2_get_raw_data(list.get(), &e);
684 
685  results.insert(results.begin(), start, start + size);
686 
687  return results;
688  }
689 
695  {
696  std::vector<uint8_t> results;
697 
698  rs2_error* e = nullptr;
699  std::shared_ptr<const rs2_raw_data_buffer> list(
700  rs2_get_calibration_table(_dev.get(), &e),
702  error::handle(e);
703 
704  auto size = rs2_get_raw_data_size(list.get(), &e);
705  error::handle(e);
706 
707  auto start = rs2_get_raw_data(list.get(), &e);
708 
709  results.insert(results.begin(), start, start + size);
710 
711  return results;
712  }
713 
718  void set_calibration_table(const calibration_table& calibration)
719  {
720  rs2_error* e = nullptr;
721  rs2_set_calibration_table(_dev.get(), calibration.data(), static_cast< int >( calibration.size() ), &e);
722  error::handle(e);
723  }
724 
736  std::vector<uint8_t> run_focal_length_calibration(rs2::frame_queue left, rs2::frame_queue right, float target_w, float target_h, int adjust_both_sides,
737  float* ratio, float* angle) const
738  {
739  std::vector<uint8_t> results;
740 
741  rs2_error* e = nullptr;
742  std::shared_ptr<const rs2_raw_data_buffer> list(
743  rs2_run_focal_length_calibration_cpp(_dev.get(), left.get().get(), right.get().get(), target_w, target_h, adjust_both_sides, ratio, angle, nullptr, &e),
745  error::handle(e);
746 
747  auto size = rs2_get_raw_data_size(list.get(), &e);
748  error::handle(e);
749 
750  auto start = rs2_get_raw_data(list.get(), &e);
751 
752  results.insert(results.begin(), start, start + size);
753 
754  return results;
755  }
756 
768  template<class T>
769  std::vector<uint8_t> run_focal_length_calibration(rs2::frame_queue left, rs2::frame_queue right, float target_w, float target_h, int adjust_both_sides,
770  float* ratio, float* angle, T callback) const
771  {
772  std::vector<uint8_t> results;
773 
774  rs2_error* e = nullptr;
775  std::shared_ptr<const rs2_raw_data_buffer> list(
776  rs2_run_focal_length_calibration_cpp(_dev.get(), left.get().get(), right.get().get(), target_w, target_h, adjust_both_sides, ratio, angle,
777  new update_progress_callback<T>(std::move(callback)), &e),
779  error::handle(e);
780 
781  auto size = rs2_get_raw_data_size(list.get(), &e);
782  error::handle(e);
783 
784  auto start = rs2_get_raw_data(list.get(), &e);
785 
786  results.insert(results.begin(), start, start + size);
787 
788  return results;
789  }
790 
802  std::vector<uint8_t> run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only,
803  float* health, int health_size) const
804  {
805  std::vector<uint8_t> results;
806 
807  rs2_error* e = nullptr;
808  std::shared_ptr<const rs2_raw_data_buffer> list(
809  rs2_run_uv_map_calibration_cpp(_dev.get(), left.get().get(), color.get().get(), depth.get().get(), py_px_only, health, health_size, nullptr, &e),
811  error::handle(e);
812 
813  auto size = rs2_get_raw_data_size(list.get(), &e);
814  error::handle(e);
815 
816  auto start = rs2_get_raw_data(list.get(), &e);
817 
818  results.insert(results.begin(), start, start + size);
819 
820  return results;
821  }
822 
835  template<class T>
836  std::vector<uint8_t> run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only,
837  float* health, int health_size, T callback) const
838  {
839  std::vector<uint8_t> results;
840 
841  rs2_error* e = nullptr;
842  std::shared_ptr<const rs2_raw_data_buffer> list(
843  rs2_run_uv_map_calibration_cpp(_dev.get(), left.get().get(), color.get().get(), depth.get().get(), py_px_only, health, health_size,
844  new update_progress_callback<T>(std::move(callback)), &e),
846  error::handle(e);
847 
848  auto size = rs2_get_raw_data_size(list.get(), &e);
849  error::handle(e);
850 
851  auto start = rs2_get_raw_data(list.get(), &e);
852 
853  results.insert(results.begin(), start, start + size);
854 
855  return results;
856  }
857 
867  float target_width, float target_height) const
868  {
869  rs2_error* e = nullptr;
870  float result = rs2_calculate_target_z_cpp(_dev.get(), queue1.get().get(), queue2.get().get(), queue3.get().get(),
871  target_width, target_height, nullptr, &e);
872  error::handle(e);
873 
874  return result;
875  }
876 
886  template<class T>
888  float target_width, float target_height, T callback) const
889  {
890  rs2_error* e = nullptr;
891  float result = rs2_calculate_target_z_cpp(_dev.get(), queue1.get().get(), queue2.get().get(), queue3.get().get(),
892  target_width, target_height, new update_progress_callback<T>(std::move(callback)), &e);
893  error::handle(e);
894 
895  return result;
896  }
897 
898  std::string get_calibration_config() const
899  {
900  std::vector<uint8_t> result;
901 
902  rs2_error* e = nullptr;
903  auto buffer = rs2_get_calibration_config(_dev.get(), &e);
904 
905  std::shared_ptr<const rs2_raw_data_buffer> list(buffer, rs2_delete_raw_data);
906  error::handle(e);
907 
908  auto size = rs2_get_raw_data_size(list.get(), &e);
909  error::handle(e);
910 
911  auto start = rs2_get_raw_data(list.get(), &e);
912  error::handle(e);
913 
914  result.insert(result.begin(), start, start + size);
915 
916  return std::string(result.begin(), result.end());
917  }
918 
919  void set_calibration_config(const std::string& calibration_config_json_str) const
920  {
921  rs2_error* e = nullptr;
922  rs2_set_calibration_config(_dev.get(), calibration_config_json_str.c_str(), &e);
923  error::handle(e);
924  }
925  };
926 
927  /*
928  Wrapper around any callback function that is given to calibration_change_callback.
929  */
930  template< class callback >
932  {
933  //using callback = std::function< void( rs2_calibration_status ) >;
934  callback _callback;
935  public:
936  calibration_change_callback( callback cb ) : _callback( cb ) {}
937 
938  void on_calibration_change( rs2_calibration_status status ) noexcept override
939  {
940  try
941  {
942  _callback( status );
943  }
944  catch( ... ) { }
945  }
946  void release() override { delete this; }
947  };
948 
950  {
951  public:
952  calibration_change_device() = default;
954  : device(d.get())
955  {
956  rs2_error* e = nullptr;
958  {
959  _dev.reset();
960  }
961  error::handle(e);
962  }
963 
964  /*
965  Your callback should look like this, for example:
966  sensor.register_calibration_change_callback(
967  []( rs2_calibration_status ) noexcept
968  {
969  ...
970  })
971  */
972  template< typename T >
974  {
975  // We wrap the callback with an interface and pass it to librealsense, who will
976  // now manage its lifetime. Rather than deleting it, though, it will call its
977  // release() function, where (back in our context) it can be safely deleted:
978  rs2_error* e = nullptr;
980  _dev.get(),
981  new calibration_change_callback< T >(std::move(callback)),
982  &e);
983  error::handle(e);
984  }
985  };
986 
988  {
989  public:
990  device_calibration() = default;
992  {
993  rs2_error* e = nullptr;
995  {
996  _dev = d.get();
997  }
998  error::handle( e );
999  }
1000 
1005  {
1006  rs2_error* e = nullptr;
1007  rs2_trigger_device_calibration( _dev.get(), type, &e );
1008  error::handle( e );
1009  }
1010  };
1011 
1012  class debug_protocol : public device
1013  {
1014  public:
1016  : device(d.get())
1017  {
1018  rs2_error* e = nullptr;
1019  if(rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_DEBUG, &e) == 0 && !e)
1020  {
1021  _dev.reset();
1022  }
1023  error::handle(e);
1024  }
1025 
1026  std::vector<uint8_t> build_command(uint32_t opcode,
1027  uint32_t param1 = 0,
1028  uint32_t param2 = 0,
1029  uint32_t param3 = 0,
1030  uint32_t param4 = 0,
1031  std::vector<uint8_t> const & data = {}) const
1032  {
1033  std::vector<uint8_t> results;
1034 
1035  rs2_error* e = nullptr;
1036  auto buffer = rs2_build_debug_protocol_command(_dev.get(), opcode, param1, param2, param3, param4,
1037  (void*)data.data(), (uint32_t)data.size(), &e);
1038  error::handle(e);
1039  std::shared_ptr< const rs2_raw_data_buffer > list( buffer, rs2_delete_raw_data );
1040 
1041  auto size = rs2_get_raw_data_size(list.get(), &e);
1042  error::handle(e);
1043 
1044  auto start = rs2_get_raw_data(list.get(), &e);
1045  error::handle(e);
1046 
1047  results.insert(results.begin(), start, start + size);
1048 
1049  return results;
1050  }
1051 
1052  std::vector<uint8_t> send_and_receive_raw_data(const std::vector<uint8_t>& input) const
1053  {
1054  std::vector<uint8_t> results;
1055 
1056  rs2_error* e = nullptr;
1057  std::shared_ptr<const rs2_raw_data_buffer> list(
1058  rs2_send_and_receive_raw_data(_dev.get(), (void*)input.data(), (uint32_t)input.size(), &e),
1060  error::handle(e);
1061 
1062  auto size = rs2_get_raw_data_size(list.get(), &e);
1063  error::handle(e);
1064 
1065  auto start = rs2_get_raw_data(list.get(), &e);
1066  error::handle(e);
1067 
1068  results.insert(results.begin(), start, start + size);
1069 
1070  return results;
1071  }
1072 
1073  std::string get_opcode_string(int opcode)
1074  {
1075  rs2_error* e = nullptr;
1076  char buffer[1024];
1077  rs2_hw_monitor_get_opcode_string(opcode, buffer, sizeof(buffer), _dev.get(), &e);
1078  return std::string(buffer);
1079  }
1080  };
1081 
1083  {
1084  public:
1085  explicit device_list(std::shared_ptr<rs2_device_list> list)
1086  : _list(std::move(list)) {}
1087 
1089  : _list(nullptr) {}
1090 
1091  operator std::vector<device>() const
1092  {
1093  std::vector<device> res;
1094  for (auto&& dev : *this) res.push_back(dev);
1095  return res;
1096  }
1097 
1098  bool contains(const device& dev) const
1099  {
1100  rs2_error* e = nullptr;
1101  auto res = !!(rs2_device_list_contains(_list.get(), dev.get().get(), &e));
1102  error::handle(e);
1103  return res;
1104  }
1105 
1106  device_list& operator=(std::shared_ptr<rs2_device_list> list)
1107  {
1108  _list = std::move(list);
1109  return *this;
1110  }
1111 
1112  device operator[](uint32_t index) const
1113  {
1114  rs2_error* e = nullptr;
1115  std::shared_ptr<rs2_device> dev(
1116  rs2_create_device(_list.get(), index, &e),
1118  error::handle(e);
1119 
1120  return device(dev);
1121  }
1122 
1123  uint32_t size() const
1124  {
1125  rs2_error* e = nullptr;
1126  auto size = rs2_get_device_count(_list.get(), &e);
1127  error::handle(e);
1128  return size;
1129  }
1130 
1131  device front() const { return std::move((*this)[0]); }
1132  device back() const
1133  {
1134  return std::move((*this)[size() - 1]);
1135  }
1136 
1138  {
1140  const device_list& device_list,
1141  uint32_t uint32_t)
1142  : _list(device_list),
1143  _index(uint32_t)
1144  {
1145  }
1146 
1147  public:
1149  {
1150  return _list[_index];
1151  }
1152  bool operator!=(const device_list_iterator& other) const
1153  {
1154  return other._index != _index || &other._list != &_list;
1155  }
1156  bool operator==(const device_list_iterator& other) const
1157  {
1158  return !(*this != other);
1159  }
1161  {
1162  _index++;
1163  return *this;
1164  }
1165  private:
1166  friend device_list;
1167  const device_list& _list;
1168  uint32_t _index;
1169  };
1170 
1172  {
1173  return device_list_iterator(*this, 0);
1174  }
1176  {
1177  return device_list_iterator(*this, size());
1178  }
1179  const rs2_device_list* get_list() const
1180  {
1181  return _list.get();
1182  }
1183 
1184  operator std::shared_ptr<rs2_device_list>() { return _list; };
1185 
1186  private:
1187  std::shared_ptr<rs2_device_list> _list;
1188  };
1189 }
1190 #endif // LIBREALSENSE_RS2_DEVICE_HPP
Definition: rs_types.hpp:115
device operator*() const
Definition: rs_device.hpp:1148
void rs2_set_calibration_table(const rs2_device *device, const void *calibration, int calibration_size, rs2_error **error)
device back() const
Definition: rs_device.hpp:1132
int rs2_get_sensors_count(const rs2_sensor_list *info_list, rs2_error **error)
rs2_camera_info
Read-only strings that can be queried from the device. Not all information attributes are available o...
Definition: rs_sensor.h:22
float rs2_calculate_target_z_cpp(rs2_device *device, rs2_frame_queue *queue1, rs2_frame_queue *queue2, rs2_frame_queue *queue3, float target_width, float target_height, rs2_update_progress_callback *callback, rs2_error **error)
Definition: rs_sensor.hpp:103
update_device()
Definition: rs_device.hpp:350
bool is() const
Definition: rs_device.hpp:210
Definition: rs_frame.hpp:369
struct rs2_raw_data_buffer rs2_raw_data_buffer
Definition: rs_types.h:297
bool is_in_recovery_mode()
Definition: rs_device.hpp:136
int rs2_device_list_contains(const rs2_device_list *info_list, const rs2_device *device, rs2_error **error)
Definition: rs_types.h:206
void set_calibration_config(const std::string &calibration_config_json_str) const
Definition: rs_device.hpp:919
device_list(std::shared_ptr< rs2_device_list > list)
Definition: rs_device.hpp:1085
std::vector< uint8_t > send_and_receive_raw_data(const std::vector< uint8_t > &input) const
Definition: rs_device.hpp:1052
std::vector< uint8_t > create_flash_backup() const
Definition: rs_device.hpp:279
void release() override
Definition: rs_device.hpp:251
rs2_calibration_type
Definition: rs_device.h:419
std::vector< sensor > query_sensors() const
Definition: rs_device.hpp:26
std::vector< uint8_t > run_focal_length_calibration(rs2::frame_queue left, rs2::frame_queue right, float target_w, float target_h, int adjust_both_sides, float *ratio, float *angle, T callback) const
Definition: rs_device.hpp:769
auto_calibrated_device(device d)
Definition: rs_device.hpp:415
device()
Definition: rs_device.hpp:171
const char * get_info(rs2_camera_info info) const
Definition: rs_device.hpp:115
device & operator=(const device &dev)
Definition: rs_device.hpp:165
void rs2_register_calibration_change_callback_cpp(rs2_device *dev, rs2_calibration_change_callback *callback, rs2_error **error)
int rs2_check_firmware_compatibility(const rs2_device *device, const void *fw_image, int fw_image_size, rs2_error **error)
void rs2_trigger_device_calibration(rs2_device *dev, rs2_calibration_type type, rs2_error **error)
Definition: rs_pipeline.hpp:18
bool operator==(const device_list_iterator &other) const
Definition: rs_device.hpp:1156
void update_unsigned(const std::vector< uint8_t > &image, int update_mode=RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
Definition: rs_device.hpp:330
void update(const std::vector< uint8_t > &fw_image) const
Definition: rs_device.hpp:364
const rs2_raw_data_buffer * rs2_get_calibration_table(const rs2_device *dev, rs2_error **error)
rs2_sensor * rs2_create_sensor(const rs2_sensor_list *list, int index, rs2_error **error)
calibrated_device(device d)
Definition: rs_device.hpp:387
Definition: rs_sensor.h:24
Definition: rs_sensor.h:38
void set_calibration_table(const calibration_table &calibration)
Definition: rs_device.hpp:718
void update_unsigned(const std::vector< uint8_t > &image, T callback, int update_mode=RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
Definition: rs_device.hpp:339
const rs2_raw_data_buffer * rs2_build_debug_protocol_command(rs2_device *device, unsigned opcode, unsigned param1, unsigned param2, unsigned param3, unsigned param4, void *data, unsigned size_of_data, rs2_error **error)
void rs2_delete_device(rs2_device *device)
calibration_table process_calibration_frame(rs2::frame f, float *const health, int timeout_ms=5000) const
Definition: rs_device.hpp:671
const unsigned char * rs2_get_raw_data(const rs2_raw_data_buffer *buffer, rs2_error **error)
void rs2_write_calibration(const rs2_device *device, rs2_error **e)
rs2_device * rs2_create_device(const rs2_device_list *info_list, int index, rs2_error **error)
device_list & operator=(std::shared_ptr< rs2_device_list > list)
Definition: rs_device.hpp:1106
calibration_change_device(device d)
Definition: rs_device.hpp:953
Definition: rs_device.hpp:239
Definition: rs_context.hpp:11
Definition: rs_types.hpp:73
Definition: rs_sensor.h:23
const rs2_raw_data_buffer * rs2_run_focal_length_calibration_cpp(rs2_device *device, rs2_frame_queue *left_queue, rs2_frame_queue *right_queue, float target_width, float target_height, int adjust_both_sides, float *ratio, float *angle, rs2_update_progress_callback *progress_callback, rs2_error **error)
bool operator<(device const &other) const
Definition: rs_device.hpp:183
void rs2_delete_raw_data(const rs2_raw_data_buffer *buffer)
std::string get_firmware_min_version() const
Definition: rs_device.hpp:201
const rs2_raw_data_buffer * rs2_run_uv_map_calibration_cpp(rs2_device *device, rs2_frame_queue *left_queue, rs2_frame_queue *color_queue, rs2_frame_queue *depth_queue, int py_px_only, float *health, int health_size, rs2_update_progress_callback *progress_callback, rs2_error **error)
calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float *health, int timeout_ms=5000) const
Definition: rs_device.hpp:617
Definition: rs_context.hpp:96
void reset_to_factory_calibration()
Definition: rs_device.hpp:404
std::string get_calibration_config() const
Definition: rs_device.hpp:898
int rs2_get_raw_data_size(const rs2_raw_data_buffer *buffer, rs2_error **error)
Definition: rs_device.hpp:254
T as() const
Definition: rs_device.hpp:217
void enter_update_state() const
Definition: rs_device.hpp:270
device_calibration(device d)
Definition: rs_device.hpp:991
device_list_iterator begin() const
Definition: rs_device.hpp:1171
std::vector< uint8_t > calibration_table
Definition: rs_device.hpp:382
Definition: rs_device.hpp:1012
device operator[](uint32_t index) const
Definition: rs_device.hpp:1112
int rs2_supports_device_info(const rs2_device *device, rs2_camera_info info, rs2_error **error)
#define RS2_UNSIGNED_UPDATE_MODE_UPDATE
Definition: rs_device.h:235
rs2_calibration_status
Definition: rs_device.h:431
void rs2_delete_sensor(rs2_sensor *sensor)
int rs2_is_device_extendable_to(const rs2_device *device, rs2_extension extension, rs2_error **error)
device front() const
Definition: rs_device.hpp:1131
uint32_t size() const
Definition: rs_device.hpp:1123
void trigger_device_calibration(rs2_calibration_type type)
Definition: rs_device.hpp:1004
void hardware_reset()
Definition: rs_device.hpp:126
const rs2_raw_data_buffer * rs2_get_calibration_config(rs2_device *device, rs2_error **error)
const std::shared_ptr< rs2_device > & get() const
Definition: rs_device.hpp:179
std::vector< uint8_t > run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only, float *health, int health_size) const
Definition: rs_device.hpp:802
void update(const std::vector< uint8_t > &fw_image, T callback) const
Definition: rs_device.hpp:374
std::shared_ptr< rs2_device > _dev
Definition: rs_device.hpp:234
std::vector< uint8_t > run_focal_length_calibration(rs2::frame_queue left, rs2::frame_queue right, float target_w, float target_h, int adjust_both_sides, float *ratio, float *angle) const
Definition: rs_device.hpp:736
std::vector< uint8_t > create_flash_backup(T callback) const
Definition: rs_device.hpp:300
void rs2_hardware_reset(const rs2_device *device, rs2_error **error)
Definition: rs_types.h:188
double get_device_time_ms() const
Definition: rs_device.hpp:151
Definition: rs_device.hpp:949
rs2_sensor_list * rs2_query_sensors(const rs2_device *device, rs2_error **error)
bool is_connected() const
Definition: rs_device.hpp:191
void rs2_update_firmware_cpp(const rs2_device *device, const void *fw_image, int fw_image_size, rs2_update_progress_callback *callback, rs2_error **error)
calibration_table get_calibration_table()
Definition: rs_device.hpp:694
std::vector< uint8_t > build_command(uint32_t opcode, uint32_t param1=0, uint32_t param2=0, uint32_t param3=0, uint32_t param4=0, std::vector< uint8_t > const &data={}) const
Definition: rs_device.hpp:1026
void release() override
Definition: rs_device.hpp:946
void write_calibration() const
Definition: rs_device.hpp:394
update_device(device d)
Definition: rs_device.hpp:351
static void handle(rs2_error *e)
Definition: rs_types.hpp:167
calibration_table run_on_chip_calibration(std::string json_content, float *health, T callback, int timeout_ms=5000) const
Definition: rs_device.hpp:462
std::string get_opcode_string(int opcode)
Definition: rs_device.hpp:1073
void rs2_reset_to_factory_calibration(const rs2_device *device, rs2_error **e)
int rs2_device_is_connected(const rs2_device *device, rs2_error **error)
std::vector< uint8_t > run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only, float *health, int health_size, T callback) const
Definition: rs_device.hpp:836
calibration_change_callback(callback cb)
Definition: rs_device.hpp:936
Definition: rs_device.hpp:931
const rs2_raw_data_buffer * rs2_create_flash_backup_cpp(const rs2_device *device, rs2_update_progress_callback *callback, rs2_error **error)
bool contains(const device &dev) const
Definition: rs_device.hpp:1098
const rs2_raw_data_buffer * rs2_send_and_receive_raw_data(rs2_device *device, void *raw_data_to_send, unsigned size_of_raw_data_to_send, rs2_error **error)
Definition: rs_types.h:192
Definition: rs_types.hpp:97
void rs2_hw_monitor_get_opcode_string(int opcode, char *buffer, size_t buffer_size, rs2_device *device, rs2_error **error)
int rs2_is_in_recovery_mode(const rs2_device *device, rs2_error **error)
Definition: rs_types.h:152
calibration_table process_calibration_frame(rs2::frame f, float *const health, T callback, int timeout_ms=5000) const
Definition: rs_device.hpp:645
bool supports(rs2_camera_info info) const
Definition: rs_device.hpp:102
update_progress_callback(T callback)
Definition: rs_device.hpp:244
device & operator=(const std::shared_ptr< rs2_device > dev)
Definition: rs_device.hpp:159
device_list_iterator & operator++()
Definition: rs_device.hpp:1160
device_list()
Definition: rs_device.hpp:1088
Definition: rs_device.hpp:412
updatable()
Definition: rs_device.hpp:257
Definition: rs_device.hpp:1082
const char * rs2_get_firmware_min_version(const rs2_device *device, rs2_error **error)
bool check_firmware_compatibility(const std::vector< uint8_t > &image) const
Definition: rs_device.hpp:321
Definition: rs_device.hpp:384
updatable(device d)
Definition: rs_device.hpp:258
void rs2_enter_update_state(const rs2_device *device, rs2_error **error)
Definition: rs_types.h:200
Definition: rs_context.hpp:251
bool operator!=(const device_list_iterator &other) const
Definition: rs_device.hpp:1152
Definition: rs_types.h:189
void rs2_update_firmware_unsigned_cpp(const rs2_device *device, const void *fw_image, int fw_image_size, rs2_update_progress_callback *callback, int update_mode, rs2_error **error)
std::string get_description() const
Definition: rs_device.hpp:65
void on_calibration_change(rs2_calibration_status status) noexcept override
Definition: rs_device.hpp:938
void rs2_delete_sensor_list(rs2_sensor_list *info_list)
Definition: rs_sensor.h:35
void rs2_set_calibration_config(rs2_device *device, const char *calibration_config_json_str, rs2_error **error)
const rs2_raw_data_buffer * rs2_process_calibration_frame(rs2_device *dev, const rs2_frame *f, float *const health, rs2_update_progress_callback *progress_callback, int timeout_ms, rs2_error **error)
double rs2_get_device_time_ms(const rs2_device *device, rs2_error **error)
Definition: rs_processing.hpp:133
void on_update_progress(const float progress) override
Definition: rs_device.hpp:246
struct rs2_device_list rs2_device_list
Definition: rs_types.h:303
debug_protocol(device d)
Definition: rs_device.hpp:1015
device_list_iterator end() const
Definition: rs_device.hpp:1175
void register_calibration_change_callback(T callback)
Definition: rs_device.hpp:973
Definition: rs_device.hpp:987
struct rs2_error rs2_error
Definition: rs_types.h:295
Definition: rs_device.hpp:1137
float calculate_target_z(rs2::frame_queue queue1, rs2::frame_queue queue2, rs2::frame_queue queue3, float target_width, float target_height, T callback) const
Definition: rs_device.hpp:887
std::shared_ptr< rs2_frame_queue > get()
Definition: rs_processing.hpp:239
Definition: rs_device.hpp:19
float calculate_target_z(rs2::frame_queue queue1, rs2::frame_queue queue2, rs2::frame_queue queue3, float target_width, float target_height) const
Definition: rs_device.hpp:866
int rs2_get_device_count(const rs2_device_list *info_list, rs2_error **error)
calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float *health, T callback, int timeout_ms=5000) const
Definition: rs_device.hpp:568
rs2_frame * get() const
Definition: rs_frame.hpp:635
Definition: rs_device.hpp:347
const rs2_raw_data_buffer * rs2_run_on_chip_calibration_cpp(rs2_device *device, const void *json_content, int content_size, float *health, rs2_update_progress_callback *progress_callback, int timeout_ms, rs2_error **error)
const rs2_device_list * get_list() const
Definition: rs_device.hpp:1179
T first() const
Definition: rs_device.hpp:88
virtual ~device()
Definition: rs_device.hpp:222
const rs2_raw_data_buffer * rs2_run_tare_calibration_cpp(rs2_device *dev, float ground_truth_mm, const void *json_content, int content_size, float *health, rs2_update_progress_callback *progress_callback, int timeout_ms, rs2_error **error)
calibration_table run_on_chip_calibration(std::string json_content, float *health, int timeout_ms=5000) const
Definition: rs_device.hpp:516
std::string get_type() const
Definition: rs_device.hpp:55
device(std::shared_ptr< rs2_device > dev)
Definition: rs_device.hpp:227
const char * rs2_get_device_info(const rs2_device *device, rs2_camera_info info, rs2_error **error)