Intel® RealSense™ Cross Platform API
Intel 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 Intel Corporation. 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 <array>
10 #include <cstring>
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  {
58  return "USB";
60  {
61  std::string pid = get_info( RS2_CAMERA_INFO_PRODUCT_ID );
62  if( pid == "ABCD" ) // Specific for D457
63  return "GMSL";
64  if( pid == "BBCD" ) // Specific for D457 Recovery DFU
65  return "GMSL";
66  return pid; // for DDS devices, this will be "DDS"
67  }
68  return {};
69  }
70 
74  std::string get_description() const
75  {
76  std::ostringstream os;
77  auto type = get_type();
79  {
80  if( ! type.empty() )
81  os << "[" << type << "] ";
83  }
84  else
85  {
86  if( ! type.empty() )
87  os << type << " device";
88  else
89  os << "unknown device";
90  }
92  os << " s/n " << get_info( RS2_CAMERA_INFO_SERIAL_NUMBER );
93  return os.str();
94  }
95 
96  template<class T>
97  T first() const
98  {
99  for (auto&& s : query_sensors())
100  {
101  if (auto t = s.as<T>()) return t;
102  }
103  throw rs2::error("Could not find requested sensor type!");
104  }
105 
111  bool supports(rs2_camera_info info) const
112  {
113  rs2_error* e = nullptr;
114  auto is_supported = rs2_supports_device_info(_dev.get(), info, &e);
115  error::handle(e);
116  return is_supported > 0;
117  }
118 
124  const char* get_info(rs2_camera_info info) const
125  {
126  rs2_error* e = nullptr;
127  auto result = rs2_get_device_info(_dev.get(), info, &e);
128  error::handle(e);
129  return result;
130  }
131 
136  {
137  rs2_error* e = nullptr;
138  rs2_hardware_reset(_dev.get(), &e);
139  error::handle(e);
140  }
141 
142  device& operator=(const std::shared_ptr<rs2_device> dev)
143  {
144  _dev.reset();
145  _dev = dev;
146  return *this;
147  }
148  device& operator=(const device& dev)
149  {
150  *this = nullptr;
151  _dev = dev._dev;
152  return *this;
153  }
154  device() : _dev(nullptr) {}
155 
156  // Note: this checks the validity of rs2::device (i.e., if it's connected to a realsense device), and does
157  // NOT reflect the current condition (connected/disconnected). Use is_connected() for that.
158  operator bool() const
159  {
160  return _dev != nullptr;
161  }
162  const std::shared_ptr<rs2_device>& get() const
163  {
164  return _dev;
165  }
166  bool operator<( device const & other ) const
167  {
168  // All RealSense cameras have an update-ID but not always a serial number
169  return std::strcmp( get_info( RS2_CAMERA_INFO_FIRMWARE_UPDATE_ID ),
171  < 0;
172  }
173 
174  bool is_connected() const
175  {
176  rs2_error * e = nullptr;
177  bool connected = rs2_device_is_connected( _dev.get(), &e );
178  error::handle( e );
179  return connected;
180  }
181 
182  template<class T>
183  bool is() const
184  {
185  T extension(*this);
186  return extension;
187  }
188 
189  template<class T>
190  T as() const
191  {
192  T extension(*this);
193  return extension;
194  }
195  virtual ~device()
196  {
197  }
198 
199  explicit operator std::shared_ptr<rs2_device>() { return _dev; };
200  explicit device(std::shared_ptr<rs2_device> dev) : _dev(dev) {}
201  protected:
202  friend class rs2::context;
203  friend class rs2::device_list;
204  friend class rs2::pipeline_profile;
205  friend class rs2::device_hub;
206 
207  std::shared_ptr<rs2_device> _dev;
208 
209  };
210 
211  template<class T>
213  {
214  T _callback;
215 
216  public:
217  explicit update_progress_callback(T callback) : _callback(callback) {}
218 
219  void on_update_progress(const float progress) override
220  {
221  _callback(progress);
222  }
223 
224  void release() override { delete this; }
225  };
226 
227  class updatable : public device
228  {
229  public:
230  updatable() : device() {}
232  : device(d.get())
233  {
234  rs2_error* e = nullptr;
235  if (rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_UPDATABLE, &e) == 0 && !e)
236  {
237  _dev.reset();
238  }
239  error::handle(e);
240  }
241 
242  // Move the device to update state, this will cause the updatable device to disconnect and reconnect as an update device.
243  void enter_update_state() const
244  {
245  rs2_error* e = nullptr;
246  rs2_enter_update_state(_dev.get(), &e);
247  error::handle(e);
248  }
249 
250  // Create backup of camera flash memory. Such backup does not constitute valid firmware image, and cannot be
251  // loaded back to the device, but it does contain all calibration and device information."
252  std::vector<uint8_t> create_flash_backup() const
253  {
254  std::vector<uint8_t> results;
255 
256  rs2_error* e = nullptr;
257  std::shared_ptr<const rs2_raw_data_buffer> list(
258  rs2_create_flash_backup_cpp(_dev.get(), nullptr, &e),
260  error::handle(e);
261 
262  auto size = rs2_get_raw_data_size(list.get(), &e);
263  error::handle(e);
264 
265  auto start = rs2_get_raw_data(list.get(), &e);
266 
267  results.insert(results.begin(), start, start + size);
268 
269  return results;
270  }
271 
272  template<class T>
273  std::vector<uint8_t> create_flash_backup(T callback) const
274  {
275  std::vector<uint8_t> results;
276 
277  rs2_error* e = nullptr;
278  std::shared_ptr<const rs2_raw_data_buffer> list(
279  rs2_create_flash_backup_cpp(_dev.get(), new update_progress_callback<T>(std::move(callback)), &e),
281  error::handle(e);
282 
283  auto size = rs2_get_raw_data_size(list.get(), &e);
284  error::handle(e);
285 
286  auto start = rs2_get_raw_data(list.get(), &e);
287 
288  results.insert(results.begin(), start, start + size);
289 
290  return results;
291  }
292 
293  // check firmware compatibility with SKU
294  bool check_firmware_compatibility(const std::vector<uint8_t>& image) const
295  {
296  rs2_error* e = nullptr;
297  auto res = !!rs2_check_firmware_compatibility(_dev.get(), image.data(), (int)image.size(), &e);
298  error::handle(e);
299  return res;
300  }
301 
302  // Update an updatable device to the provided unsigned firmware. This call is executed on the caller's thread.
303  void update_unsigned(const std::vector<uint8_t>& image, int update_mode = RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
304  {
305  rs2_error* e = nullptr;
306  rs2_update_firmware_unsigned_cpp(_dev.get(), image.data(), (int)image.size(), nullptr, update_mode, &e);
307  error::handle(e);
308  }
309 
310  // 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.
311  template<class T>
312  void update_unsigned(const std::vector<uint8_t>& image, T callback, int update_mode = RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
313  {
314  rs2_error* e = nullptr;
315  rs2_update_firmware_unsigned_cpp(_dev.get(), image.data(), int(image.size()), new update_progress_callback<T>(std::move(callback)), update_mode, &e);
316  error::handle(e);
317  }
318  };
319 
320  class update_device : public device
321  {
322  public:
325  : device(d.get())
326  {
327  rs2_error* e = nullptr;
329  {
330  _dev.reset();
331  }
332  error::handle(e);
333  }
334 
335  // Update an updatable device to the provided firmware.
336  // This call is executed on the caller's thread.
337  void update(const std::vector<uint8_t>& fw_image) const
338  {
339  rs2_error* e = nullptr;
340  rs2_update_firmware_cpp(_dev.get(), fw_image.data(), (int)fw_image.size(), NULL, &e);
341  error::handle(e);
342  }
343 
344  // Update an updatable device to the provided firmware.
345  // This call is executed on the caller's thread and it supports progress notifications via the callback.
346  template<class T>
347  void update(const std::vector<uint8_t>& fw_image, T callback) const
348  {
349  rs2_error* e = nullptr;
350  rs2_update_firmware_cpp(_dev.get(), fw_image.data(), int(fw_image.size()), new update_progress_callback<T>(std::move(callback)), &e);
351  error::handle(e);
352  }
353  };
354 
355  typedef std::vector<uint8_t> calibration_table;
356 
357  class calibrated_device : public device
358  {
359  public:
361  : device(d.get())
362  {}
363 
367  void write_calibration() const
368  {
369  rs2_error* e = nullptr;
370  rs2_write_calibration(_dev.get(), &e);
371  error::handle(e);
372  }
373 
378  {
379  rs2_error* e = nullptr;
381  error::handle(e);
382  }
383  };
384 
386  {
387  public:
389  : calibrated_device(d)
390  {
391  rs2_error* e = nullptr;
393  {
394  _dev.reset();
395  }
396  error::handle(e);
397  }
398 
434  template<class T>
435  calibration_table run_on_chip_calibration(std::string json_content, float* health, T callback, int timeout_ms = 5000) const
436  {
437  std::vector<uint8_t> results;
438 
439  rs2_error* e = nullptr;
440  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);
441  error::handle(e);
442 
443  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
444 
445  auto size = rs2_get_raw_data_size(list.get(), &e);
446  error::handle(e);
447 
448  auto start = rs2_get_raw_data(list.get(), &e);
449 
450  results.insert(results.begin(), start, start + size);
451 
452  return results;
453  }
454 
489  calibration_table run_on_chip_calibration(std::string json_content, float* health, int timeout_ms = 5000) const
490  {
491  std::vector<uint8_t> results;
492 
493  rs2_error* e = nullptr;
494  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);
495  error::handle(e);
496  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
497 
498  auto size = rs2_get_raw_data_size(list.get(), &e);
499  error::handle(e);
500 
501  auto start = rs2_get_raw_data(list.get(), &e);
502  error::handle(e);
503 
504  results.insert(results.begin(), start, start + size);
505 
506  return results;
507  }
508 
540  template<class T>
541  calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float* health, T callback, int timeout_ms = 5000) const
542  {
543  std::vector<uint8_t> results;
544 
545  rs2_error* e = nullptr;
546  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);
547  error::handle(e);
548  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
549 
550  auto size = rs2_get_raw_data_size(list.get(), &e);
551  error::handle(e);
552 
553  auto start = rs2_get_raw_data(list.get(), &e);
554 
555  results.insert(results.begin(), start, start + size);
556 
557  return results;
558  }
559 
590  calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float * health, int timeout_ms = 5000) const
591  {
592  std::vector<uint8_t> results;
593 
594  rs2_error* e = nullptr;
595  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);
596  error::handle(e);
597  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
598 
599  auto size = rs2_get_raw_data_size(list.get(), &e);
600  error::handle(e);
601 
602  auto start = rs2_get_raw_data(list.get(), &e);
603 
604  results.insert(results.begin(), start, start + size);
605 
606  return results;
607  }
608 
617  template<class T>
618  calibration_table process_calibration_frame(rs2::frame f, float* const health, T callback, int timeout_ms = 5000) const
619  {
620  std::vector<uint8_t> results;
621 
622  rs2_error* e = nullptr;
623  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);
624  error::handle(e);
625  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
626 
627  auto size = rs2_get_raw_data_size(list.get(), &e);
628  error::handle(e);
629 
630  auto start = rs2_get_raw_data(list.get(), &e);
631 
632  results.insert(results.begin(), start, start + size);
633 
634  return results;
635  }
636 
644  calibration_table process_calibration_frame(rs2::frame f, float* const health, int timeout_ms = 5000) const
645  {
646  std::vector<uint8_t> results;
647 
648  rs2_error* e = nullptr;
649  const rs2_raw_data_buffer* buf = rs2_process_calibration_frame(_dev.get(), f.get(), health, nullptr, timeout_ms, &e);
650  error::handle(e);
651  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
652 
653  auto size = rs2_get_raw_data_size(list.get(), &e);
654  error::handle(e);
655 
656  auto start = rs2_get_raw_data(list.get(), &e);
657 
658  results.insert(results.begin(), start, start + size);
659 
660  return results;
661  }
662 
668  {
669  std::vector<uint8_t> results;
670 
671  rs2_error* e = nullptr;
672  std::shared_ptr<const rs2_raw_data_buffer> list(
673  rs2_get_calibration_table(_dev.get(), &e),
675  error::handle(e);
676 
677  auto size = rs2_get_raw_data_size(list.get(), &e);
678  error::handle(e);
679 
680  auto start = rs2_get_raw_data(list.get(), &e);
681 
682  results.insert(results.begin(), start, start + size);
683 
684  return results;
685  }
686 
691  void set_calibration_table(const calibration_table& calibration)
692  {
693  rs2_error* e = nullptr;
694  rs2_set_calibration_table(_dev.get(), calibration.data(), static_cast< int >( calibration.size() ), &e);
695  error::handle(e);
696  }
697 
705  {
706  rs2_error* e = nullptr;
707  rs2_calibration_config calib_config;
708  rs2_json_string_to_calibration_config(_dev.get(), json_str.c_str(), &calib_config, &e);
709  error::handle(e);
710  return calib_config;
711  }
712 
719  std::string calibration_config_to_json_string(const rs2_calibration_config& calib_config) const
720  {
721  std::vector<uint8_t> result;
722 
723  rs2_error* e = nullptr;
724  auto buffer = rs2_calibration_config_to_json_string(_dev.get(), &calib_config, &e);
725 
726  std::shared_ptr<const rs2_raw_data_buffer> list(buffer, rs2_delete_raw_data);
727  error::handle(e);
728 
729  auto size = rs2_get_raw_data_size(list.get(), &e);
730  error::handle(e);
731 
732  auto start = rs2_get_raw_data(list.get(), &e);
733  error::handle(e);
734 
735  result.insert(result.begin(), start, start + size);
736 
737  return std::string(result.begin(), result.end());
738  }
739 
751  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,
752  float* ratio, float* angle) const
753  {
754  std::vector<uint8_t> results;
755 
756  rs2_error* e = nullptr;
757  std::shared_ptr<const rs2_raw_data_buffer> list(
758  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),
760  error::handle(e);
761 
762  auto size = rs2_get_raw_data_size(list.get(), &e);
763  error::handle(e);
764 
765  auto start = rs2_get_raw_data(list.get(), &e);
766 
767  results.insert(results.begin(), start, start + size);
768 
769  return results;
770  }
771 
783  template<class T>
784  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,
785  float* ratio, float* angle, T callback) const
786  {
787  std::vector<uint8_t> results;
788 
789  rs2_error* e = nullptr;
790  std::shared_ptr<const rs2_raw_data_buffer> list(
791  rs2_run_focal_length_calibration_cpp(_dev.get(), left.get().get(), right.get().get(), target_w, target_h, adjust_both_sides, ratio, angle,
792  new update_progress_callback<T>(std::move(callback)), &e),
794  error::handle(e);
795 
796  auto size = rs2_get_raw_data_size(list.get(), &e);
797  error::handle(e);
798 
799  auto start = rs2_get_raw_data(list.get(), &e);
800 
801  results.insert(results.begin(), start, start + size);
802 
803  return results;
804  }
805 
817  std::vector<uint8_t> run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only,
818  float* health, int health_size) const
819  {
820  std::vector<uint8_t> results;
821 
822  rs2_error* e = nullptr;
823  std::shared_ptr<const rs2_raw_data_buffer> list(
824  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),
826  error::handle(e);
827 
828  auto size = rs2_get_raw_data_size(list.get(), &e);
829  error::handle(e);
830 
831  auto start = rs2_get_raw_data(list.get(), &e);
832 
833  results.insert(results.begin(), start, start + size);
834 
835  return results;
836  }
837 
850  template<class T>
851  std::vector<uint8_t> run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only,
852  float* health, int health_size, T callback) const
853  {
854  std::vector<uint8_t> results;
855 
856  rs2_error* e = nullptr;
857  std::shared_ptr<const rs2_raw_data_buffer> list(
858  rs2_run_uv_map_calibration_cpp(_dev.get(), left.get().get(), color.get().get(), depth.get().get(), py_px_only, health, health_size,
859  new update_progress_callback<T>(std::move(callback)), &e),
861  error::handle(e);
862 
863  auto size = rs2_get_raw_data_size(list.get(), &e);
864  error::handle(e);
865 
866  auto start = rs2_get_raw_data(list.get(), &e);
867 
868  results.insert(results.begin(), start, start + size);
869 
870  return results;
871  }
872 
882  float target_width, float target_height) const
883  {
884  rs2_error* e = nullptr;
885  float result = rs2_calculate_target_z_cpp(_dev.get(), queue1.get().get(), queue2.get().get(), queue3.get().get(),
886  target_width, target_height, nullptr, &e);
887  error::handle(e);
888 
889  return result;
890  }
891 
901  template<class T>
903  float target_width, float target_height, T callback) const
904  {
905  rs2_error* e = nullptr;
906  float result = rs2_calculate_target_z_cpp(_dev.get(), queue1.get().get(), queue2.get().get(), queue3.get().get(),
907  target_width, target_height, new update_progress_callback<T>(std::move(callback)), &e);
908  error::handle(e);
909 
910  return result;
911  }
912 
919  {
920  rs2_error* e = nullptr;
921  rs2_calibration_config calib_config;
922  rs2_get_calibration_config(_dev.get(), &calib_config, &e);
923  error::handle(e);
924  return calib_config;
925  }
926 
934  {
935  rs2_error* e = nullptr;
936  rs2_set_calibration_config(_dev.get(), &calib_config, &e);
937  error::handle(e);
938  }
939  };
940 
941  /*
942  Wrapper around any callback function that is given to calibration_change_callback.
943  */
944  template< class callback >
946  {
947  //using callback = std::function< void( rs2_calibration_status ) >;
948  callback _callback;
949  public:
950  calibration_change_callback( callback cb ) : _callback( cb ) {}
951 
952  void on_calibration_change( rs2_calibration_status status ) noexcept override
953  {
954  try
955  {
956  _callback( status );
957  }
958  catch( ... ) { }
959  }
960  void release() override { delete this; }
961  };
962 
964  {
965  public:
966  calibration_change_device() = default;
968  : device(d.get())
969  {
970  rs2_error* e = nullptr;
972  {
973  _dev.reset();
974  }
975  error::handle(e);
976  }
977 
978  /*
979  Your callback should look like this, for example:
980  sensor.register_calibration_change_callback(
981  []( rs2_calibration_status ) noexcept
982  {
983  ...
984  })
985  */
986  template< typename T >
988  {
989  // We wrap the callback with an interface and pass it to librealsense, who will
990  // now manage its lifetime. Rather than deleting it, though, it will call its
991  // release() function, where (back in our context) it can be safely deleted:
992  rs2_error* e = nullptr;
994  _dev.get(),
995  new calibration_change_callback< T >(std::move(callback)),
996  &e);
997  error::handle(e);
998  }
999  };
1000 
1002  {
1003  public:
1004  device_calibration() = default;
1006  {
1007  rs2_error* e = nullptr;
1009  {
1010  _dev = d.get();
1011  }
1012  error::handle( e );
1013  }
1014 
1019  {
1020  rs2_error* e = nullptr;
1021  rs2_trigger_device_calibration( _dev.get(), type, &e );
1022  error::handle( e );
1023  }
1024  };
1025 
1026  class debug_protocol : public device
1027  {
1028  public:
1030  : device(d.get())
1031  {
1032  rs2_error* e = nullptr;
1033  if(rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_DEBUG, &e) == 0 && !e)
1034  {
1035  _dev.reset();
1036  }
1037  error::handle(e);
1038  }
1039 
1040  std::vector<uint8_t> build_command(uint32_t opcode,
1041  uint32_t param1 = 0,
1042  uint32_t param2 = 0,
1043  uint32_t param3 = 0,
1044  uint32_t param4 = 0,
1045  std::vector<uint8_t> const & data = {}) const
1046  {
1047  std::vector<uint8_t> results;
1048 
1049  rs2_error* e = nullptr;
1050  auto buffer = rs2_build_debug_protocol_command(_dev.get(), opcode, param1, param2, param3, param4,
1051  (void*)data.data(), (uint32_t)data.size(), &e);
1052  std::shared_ptr<const rs2_raw_data_buffer> list(buffer, rs2_delete_raw_data);
1053  error::handle(e);
1054 
1055  auto size = rs2_get_raw_data_size(list.get(), &e);
1056  error::handle(e);
1057 
1058  auto start = rs2_get_raw_data(list.get(), &e);
1059  error::handle(e);
1060 
1061  results.insert(results.begin(), start, start + size);
1062 
1063  return results;
1064  }
1065 
1066  std::vector<uint8_t> send_and_receive_raw_data(const std::vector<uint8_t>& input) const
1067  {
1068  std::vector<uint8_t> results;
1069 
1070  rs2_error* e = nullptr;
1071  std::shared_ptr<const rs2_raw_data_buffer> list(
1072  rs2_send_and_receive_raw_data(_dev.get(), (void*)input.data(), (uint32_t)input.size(), &e),
1074  error::handle(e);
1075 
1076  auto size = rs2_get_raw_data_size(list.get(), &e);
1077  error::handle(e);
1078 
1079  auto start = rs2_get_raw_data(list.get(), &e);
1080  error::handle(e);
1081 
1082  results.insert(results.begin(), start, start + size);
1083 
1084  return results;
1085  }
1086  };
1087 
1089  {
1090  public:
1091  explicit device_list(std::shared_ptr<rs2_device_list> list)
1092  : _list(std::move(list)) {}
1093 
1095  : _list(nullptr) {}
1096 
1097  operator std::vector<device>() const
1098  {
1099  std::vector<device> res;
1100  for (auto&& dev : *this) res.push_back(dev);
1101  return res;
1102  }
1103 
1104  bool contains(const device& dev) const
1105  {
1106  rs2_error* e = nullptr;
1107  auto res = !!(rs2_device_list_contains(_list.get(), dev.get().get(), &e));
1108  error::handle(e);
1109  return res;
1110  }
1111 
1112  device_list& operator=(std::shared_ptr<rs2_device_list> list)
1113  {
1114  _list = std::move(list);
1115  return *this;
1116  }
1117 
1118  device operator[](uint32_t index) const
1119  {
1120  rs2_error* e = nullptr;
1121  std::shared_ptr<rs2_device> dev(
1122  rs2_create_device(_list.get(), index, &e),
1124  error::handle(e);
1125 
1126  return device(dev);
1127  }
1128 
1129  uint32_t size() const
1130  {
1131  rs2_error* e = nullptr;
1132  auto size = rs2_get_device_count(_list.get(), &e);
1133  error::handle(e);
1134  return size;
1135  }
1136 
1137  device front() const { return std::move((*this)[0]); }
1138  device back() const
1139  {
1140  return std::move((*this)[size() - 1]);
1141  }
1142 
1144  {
1146  const device_list& device_list,
1147  uint32_t uint32_t)
1148  : _list(device_list),
1149  _index(uint32_t)
1150  {
1151  }
1152 
1153  public:
1155  {
1156  return _list[_index];
1157  }
1158  bool operator!=(const device_list_iterator& other) const
1159  {
1160  return other._index != _index || &other._list != &_list;
1161  }
1162  bool operator==(const device_list_iterator& other) const
1163  {
1164  return !(*this != other);
1165  }
1167  {
1168  _index++;
1169  return *this;
1170  }
1171  private:
1172  friend device_list;
1173  const device_list& _list;
1174  uint32_t _index;
1175  };
1176 
1178  {
1179  return device_list_iterator(*this, 0);
1180  }
1182  {
1183  return device_list_iterator(*this, size());
1184  }
1185  const rs2_device_list* get_list() const
1186  {
1187  return _list.get();
1188  }
1189 
1190  operator std::shared_ptr<rs2_device_list>() { return _list; };
1191 
1192  private:
1193  std::shared_ptr<rs2_device_list> _list;
1194  };
1195 }
1196 #endif // LIBREALSENSE_RS2_DEVICE_HPP
Definition: rs_types.hpp:110
device operator*() const
Definition: rs_device.hpp:1154
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:1138
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:102
update_device()
Definition: rs_device.hpp:323
bool is() const
Definition: rs_device.hpp:183
Definition: rs_frame.hpp:345
struct rs2_raw_data_buffer rs2_raw_data_buffer
Definition: rs_types.h:231
int rs2_device_list_contains(const rs2_device_list *info_list, const rs2_device *device, rs2_error **error)
Definition: rs_types.h:193
device_list(std::shared_ptr< rs2_device_list > list)
Definition: rs_device.hpp:1091
std::vector< uint8_t > send_and_receive_raw_data(const std::vector< uint8_t > &input) const
Definition: rs_device.hpp:1066
std::vector< uint8_t > create_flash_backup() const
Definition: rs_device.hpp:252
void release() override
Definition: rs_device.hpp:224
rs2_calibration_type
Definition: rs_device.h:402
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:784
auto_calibrated_device(device d)
Definition: rs_device.hpp:388
device()
Definition: rs_device.hpp:154
const char * get_info(rs2_camera_info info) const
Definition: rs_device.hpp:124
device & operator=(const device &dev)
Definition: rs_device.hpp:148
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:1162
void update_unsigned(const std::vector< uint8_t > &image, int update_mode=RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
Definition: rs_device.hpp:303
void update(const std::vector< uint8_t > &fw_image) const
Definition: rs_device.hpp:337
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:360
Definition: rs_sensor.h:24
void set_calibration_config(const rs2_calibration_config &calib_config)
Definition: rs_device.hpp:933
void set_calibration_table(const calibration_table &calibration)
Definition: rs_device.hpp:691
Definition: rs_sensor.h:30
void update_unsigned(const std::vector< uint8_t > &image, T callback, int update_mode=RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
Definition: rs_device.hpp:312
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:644
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:1112
calibration_change_device(device d)
Definition: rs_device.hpp:967
Definition: rs_device.hpp:212
Definition: rs_context.hpp:11
Definition: rs_types.hpp:68
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:166
void rs2_delete_raw_data(const rs2_raw_data_buffer *buffer)
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:590
Definition: rs_context.hpp:96
void reset_to_factory_calibration()
Definition: rs_device.hpp:377
int rs2_get_raw_data_size(const rs2_raw_data_buffer *buffer, rs2_error **error)
Definition: rs_device.hpp:227
T as() const
Definition: rs_device.hpp:190
void rs2_get_calibration_config(rs2_device *device, rs2_calibration_config *calib_config, rs2_error **error)
void enter_update_state() const
Definition: rs_device.hpp:243
device_calibration(device d)
Definition: rs_device.hpp:1005
device_list_iterator begin() const
Definition: rs_device.hpp:1177
std::vector< uint8_t > calibration_table
Definition: rs_device.hpp:355
Definition: rs_device.hpp:1026
device operator[](uint32_t index) const
Definition: rs_device.hpp:1118
rs2_calibration_config get_calibration_config() const
Definition: rs_device.hpp:918
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:229
rs2_calibration_status
Definition: rs_device.h:414
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:1137
Definition: rs_sensor.h:32
uint32_t size() const
Definition: rs_device.hpp:1129
void trigger_device_calibration(rs2_calibration_type type)
Definition: rs_device.hpp:1018
void hardware_reset()
Definition: rs_device.hpp:135
const std::shared_ptr< rs2_device > & get() const
Definition: rs_device.hpp:162
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:817
void update(const std::vector< uint8_t > &fw_image, T callback) const
Definition: rs_device.hpp:347
std::shared_ptr< rs2_device > _dev
Definition: rs_device.hpp:207
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:751
Definition: rs_types.h:299
std::vector< uint8_t > create_flash_backup(T callback) const
Definition: rs_device.hpp:273
void rs2_hardware_reset(const rs2_device *device, rs2_error **error)
Definition: rs_types.h:175
Definition: rs_device.hpp:963
rs2_sensor_list * rs2_query_sensors(const rs2_device *device, rs2_error **error)
bool is_connected() const
Definition: rs_device.hpp:174
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:667
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:1040
void release() override
Definition: rs_device.hpp:960
void write_calibration() const
Definition: rs_device.hpp:367
update_device(device d)
Definition: rs_device.hpp:324
static void handle(rs2_error *e)
Definition: rs_types.hpp:162
calibration_table run_on_chip_calibration(std::string json_content, float *health, T callback, int timeout_ms=5000) const
Definition: rs_device.hpp:435
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:851
calibration_change_callback(callback cb)
Definition: rs_device.hpp:950
rs2_calibration_config json_string_to_calibration_config(const std::string &json_str) const
Definition: rs_device.hpp:704
Definition: rs_device.hpp:945
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:1104
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:179
Definition: rs_types.hpp:92
Definition: rs_types.h:139
calibration_table process_calibration_frame(rs2::frame f, float *const health, T callback, int timeout_ms=5000) const
Definition: rs_device.hpp:618
bool supports(rs2_camera_info info) const
Definition: rs_device.hpp:111
update_progress_callback(T callback)
Definition: rs_device.hpp:217
device & operator=(const std::shared_ptr< rs2_device > dev)
Definition: rs_device.hpp:142
device_list_iterator & operator++()
Definition: rs_device.hpp:1166
device_list()
Definition: rs_device.hpp:1094
Definition: rs_device.hpp:385
updatable()
Definition: rs_device.hpp:230
Definition: rs_device.hpp:1088
bool check_firmware_compatibility(const std::vector< uint8_t > &image) const
Definition: rs_device.hpp:294
Definition: rs_device.hpp:357
std::string calibration_config_to_json_string(const rs2_calibration_config &calib_config) const
Definition: rs_device.hpp:719
updatable(device d)
Definition: rs_device.hpp:231
void rs2_json_string_to_calibration_config(rs2_device *device, const char *json_str, rs2_calibration_config *calib_config, rs2_error **error)
void rs2_enter_update_state(const rs2_device *device, rs2_error **error)
Definition: rs_types.h:187
Definition: rs_context.hpp:234
bool operator!=(const device_list_iterator &other) const
Definition: rs_device.hpp:1158
Definition: rs_types.h:176
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:74
void on_calibration_change(rs2_calibration_status status) noexcept override
Definition: rs_device.hpp:952
void rs2_delete_sensor_list(rs2_sensor_list *info_list)
Definition: rs_sensor.h:35
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)
Definition: rs_processing.hpp:134
void on_update_progress(const float progress) override
Definition: rs_device.hpp:219
struct rs2_device_list rs2_device_list
Definition: rs_types.h:237
debug_protocol(device d)
Definition: rs_device.hpp:1029
void rs2_set_calibration_config(rs2_device *device, rs2_calibration_config const *calib_config, rs2_error **error)
device_list_iterator end() const
Definition: rs_device.hpp:1181
void register_calibration_change_callback(T callback)
Definition: rs_device.hpp:987
Definition: rs_device.hpp:1001
struct rs2_error rs2_error
Definition: rs_types.h:229
Definition: rs_device.hpp:1143
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:902
std::shared_ptr< rs2_frame_queue > get()
Definition: rs_processing.hpp:240
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:881
int rs2_get_device_count(const rs2_device_list *info_list, rs2_error **error)
const rs2_raw_data_buffer * rs2_calibration_config_to_json_string(rs2_device *device, rs2_calibration_config const *calib_config, 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:541
rs2_frame * get() const
Definition: rs_frame.hpp:592
Definition: rs_device.hpp:320
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:1185
T first() const
Definition: rs_device.hpp:97
virtual ~device()
Definition: rs_device.hpp:195
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:489
std::string get_type() const
Definition: rs_device.hpp:55
device(std::shared_ptr< rs2_device > dev)
Definition: rs_device.hpp:200
const char * rs2_get_device_info(const rs2_device *device, rs2_camera_info info, rs2_error **error)