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 
144  device& operator=(const std::shared_ptr<rs2_device> dev)
145  {
146  _dev.reset();
147  _dev = dev;
148  return *this;
149  }
150  device& operator=(const device& dev)
151  {
152  *this = nullptr;
153  _dev = dev._dev;
154  return *this;
155  }
156  device() : _dev(nullptr) {}
157 
158  // Note: this checks the validity of rs2::device (i.e., if it's connected to a realsense device), and does
159  // NOT reflect the current condition (connected/disconnected). Use is_connected() for that.
160  operator bool() const
161  {
162  return _dev != nullptr;
163  }
164  const std::shared_ptr<rs2_device>& get() const
165  {
166  return _dev;
167  }
168  bool operator<( device const & other ) const
169  {
170  // All RealSense cameras have an update-ID but not always a serial number
171  return std::strcmp( get_info( RS2_CAMERA_INFO_FIRMWARE_UPDATE_ID ),
173  < 0;
174  }
175 
176  bool is_connected() const
177  {
178  rs2_error * e = nullptr;
179  bool connected = rs2_device_is_connected( _dev.get(), &e );
180  error::handle( e );
181  return connected;
182  }
183 
184  // Minimum firmware version supported by this device's SKU (e.g. "5.10.0.17").
185  // Throws if the device does not implement the FW-update protocol or has no defined minimum.
186  std::string get_firmware_min_version() const
187  {
188  rs2_error * e = nullptr;
189  auto res = rs2_get_firmware_min_version( _dev.get(), &e );
190  error::handle( e );
191  return res ? std::string( res ) : std::string();
192  }
193 
194  template<class T>
195  bool is() const
196  {
197  T extension(*this);
198  return extension;
199  }
200 
201  template<class T>
202  T as() const
203  {
204  T extension(*this);
205  return extension;
206  }
207  virtual ~device()
208  {
209  }
210 
211  explicit operator std::shared_ptr<rs2_device>() { return _dev; };
212  explicit device(std::shared_ptr<rs2_device> dev) : _dev(dev) {}
213  protected:
214  friend class rs2::context;
215  friend class rs2::device_list;
216  friend class rs2::pipeline_profile;
217  friend class rs2::device_hub;
218 
219  std::shared_ptr<rs2_device> _dev;
220 
221  };
222 
223  template<class T>
225  {
226  T _callback;
227 
228  public:
229  explicit update_progress_callback(T callback) : _callback(callback) {}
230 
231  void on_update_progress(const float progress) override
232  {
233  _callback(progress);
234  }
235 
236  void release() override { delete this; }
237  };
238 
239  class updatable : public device
240  {
241  public:
242  updatable() : device() {}
244  : device(d.get())
245  {
246  rs2_error* e = nullptr;
247  if (rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_UPDATABLE, &e) == 0 && !e)
248  {
249  _dev.reset();
250  }
251  error::handle(e);
252  }
253 
254  // Move the device to update state, this will cause the updatable device to disconnect and reconnect as an update device.
255  void enter_update_state() const
256  {
257  rs2_error* e = nullptr;
258  rs2_enter_update_state(_dev.get(), &e);
259  error::handle(e);
260  }
261 
262  // Create backup of camera flash memory. Such backup does not constitute valid firmware image, and cannot be
263  // loaded back to the device, but it does contain all calibration and device information."
264  std::vector<uint8_t> create_flash_backup() const
265  {
266  std::vector<uint8_t> results;
267 
268  rs2_error* e = nullptr;
269  std::shared_ptr<const rs2_raw_data_buffer> list(
270  rs2_create_flash_backup_cpp(_dev.get(), nullptr, &e),
272  error::handle(e);
273 
274  auto size = rs2_get_raw_data_size(list.get(), &e);
275  error::handle(e);
276 
277  auto start = rs2_get_raw_data(list.get(), &e);
278 
279  results.insert(results.begin(), start, start + size);
280 
281  return results;
282  }
283 
284  template<class T>
285  std::vector<uint8_t> create_flash_backup(T callback) const
286  {
287  std::vector<uint8_t> results;
288 
289  rs2_error* e = nullptr;
290  std::shared_ptr<const rs2_raw_data_buffer> list(
291  rs2_create_flash_backup_cpp(_dev.get(), new update_progress_callback<T>(std::move(callback)), &e),
293  error::handle(e);
294 
295  auto size = rs2_get_raw_data_size(list.get(), &e);
296  error::handle(e);
297 
298  auto start = rs2_get_raw_data(list.get(), &e);
299 
300  results.insert(results.begin(), start, start + size);
301 
302  return results;
303  }
304 
305  // check firmware compatibility with SKU
306  bool check_firmware_compatibility(const std::vector<uint8_t>& image) const
307  {
308  rs2_error* e = nullptr;
309  auto res = !!rs2_check_firmware_compatibility(_dev.get(), image.data(), (int)image.size(), &e);
310  error::handle(e);
311  return res;
312  }
313 
314  // Update an updatable device to the provided unsigned firmware. This call is executed on the caller's thread.
315  void update_unsigned(const std::vector<uint8_t>& image, int update_mode = RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
316  {
317  rs2_error* e = nullptr;
318  rs2_update_firmware_unsigned_cpp(_dev.get(), image.data(), (int)image.size(), nullptr, update_mode, &e);
319  error::handle(e);
320  }
321 
322  // 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.
323  template<class T>
324  void update_unsigned(const std::vector<uint8_t>& image, T callback, int update_mode = RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
325  {
326  rs2_error* e = nullptr;
327  rs2_update_firmware_unsigned_cpp(_dev.get(), image.data(), int(image.size()), new update_progress_callback<T>(std::move(callback)), update_mode, &e);
328  error::handle(e);
329  }
330  };
331 
332  class update_device : public device
333  {
334  public:
337  : device(d.get())
338  {
339  rs2_error* e = nullptr;
341  {
342  _dev.reset();
343  }
344  error::handle(e);
345  }
346 
347  // Update an updatable device to the provided firmware.
348  // This call is executed on the caller's thread.
349  void update(const std::vector<uint8_t>& fw_image) const
350  {
351  rs2_error* e = nullptr;
352  rs2_update_firmware_cpp(_dev.get(), fw_image.data(), (int)fw_image.size(), NULL, &e);
353  error::handle(e);
354  }
355 
356  // Update an updatable device to the provided firmware.
357  // This call is executed on the caller's thread and it supports progress notifications via the callback.
358  template<class T>
359  void update(const std::vector<uint8_t>& fw_image, T callback) const
360  {
361  rs2_error* e = nullptr;
362  rs2_update_firmware_cpp(_dev.get(), fw_image.data(), int(fw_image.size()), new update_progress_callback<T>(std::move(callback)), &e);
363  error::handle(e);
364  }
365  };
366 
367  typedef std::vector<uint8_t> calibration_table;
368 
369  class calibrated_device : public device
370  {
371  public:
373  : device(d.get())
374  {}
375 
379  void write_calibration() const
380  {
381  rs2_error* e = nullptr;
382  rs2_write_calibration(_dev.get(), &e);
383  error::handle(e);
384  }
385 
390  {
391  rs2_error* e = nullptr;
393  error::handle(e);
394  }
395  };
396 
398  {
399  public:
401  : calibrated_device(d)
402  {
403  rs2_error* e = nullptr;
405  {
406  _dev.reset();
407  }
408  error::handle(e);
409  }
410 
446  template<class T>
447  calibration_table run_on_chip_calibration(std::string json_content, float* health, T callback, int timeout_ms = 5000) const
448  {
449  std::vector<uint8_t> results;
450 
451  rs2_error* e = nullptr;
452  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);
453  error::handle(e);
454 
455  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
456 
457  auto size = rs2_get_raw_data_size(list.get(), &e);
458  error::handle(e);
459 
460  auto start = rs2_get_raw_data(list.get(), &e);
461 
462  results.insert(results.begin(), start, start + size);
463 
464  return results;
465  }
466 
501  calibration_table run_on_chip_calibration(std::string json_content, float* health, int timeout_ms = 5000) const
502  {
503  std::vector<uint8_t> results;
504 
505  rs2_error* e = nullptr;
506  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);
507  error::handle(e);
508  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
509 
510  auto size = rs2_get_raw_data_size(list.get(), &e);
511  error::handle(e);
512 
513  auto start = rs2_get_raw_data(list.get(), &e);
514  error::handle(e);
515 
516  results.insert(results.begin(), start, start + size);
517 
518  return results;
519  }
520 
552  template<class T>
553  calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float* health, T callback, int timeout_ms = 5000) const
554  {
555  std::vector<uint8_t> results;
556 
557  rs2_error* e = nullptr;
558  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);
559  error::handle(e);
560  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
561 
562  auto size = rs2_get_raw_data_size(list.get(), &e);
563  error::handle(e);
564 
565  auto start = rs2_get_raw_data(list.get(), &e);
566 
567  results.insert(results.begin(), start, start + size);
568 
569  return results;
570  }
571 
602  calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float * health, int timeout_ms = 5000) const
603  {
604  std::vector<uint8_t> results;
605 
606  rs2_error* e = nullptr;
607  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);
608  error::handle(e);
609  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
610 
611  auto size = rs2_get_raw_data_size(list.get(), &e);
612  error::handle(e);
613 
614  auto start = rs2_get_raw_data(list.get(), &e);
615 
616  results.insert(results.begin(), start, start + size);
617 
618  return results;
619  }
620 
629  template<class T>
630  calibration_table process_calibration_frame(rs2::frame f, float* const health, T callback, int timeout_ms = 5000) const
631  {
632  std::vector<uint8_t> results;
633 
634  rs2_error* e = nullptr;
635  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);
636  error::handle(e);
637  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
638 
639  auto size = rs2_get_raw_data_size(list.get(), &e);
640  error::handle(e);
641 
642  auto start = rs2_get_raw_data(list.get(), &e);
643 
644  results.insert(results.begin(), start, start + size);
645 
646  return results;
647  }
648 
656  calibration_table process_calibration_frame(rs2::frame f, float* const health, int timeout_ms = 5000) const
657  {
658  std::vector<uint8_t> results;
659 
660  rs2_error* e = nullptr;
661  const rs2_raw_data_buffer* buf = rs2_process_calibration_frame(_dev.get(), f.get(), health, nullptr, timeout_ms, &e);
662  error::handle(e);
663  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
664 
665  auto size = rs2_get_raw_data_size(list.get(), &e);
666  error::handle(e);
667 
668  auto start = rs2_get_raw_data(list.get(), &e);
669 
670  results.insert(results.begin(), start, start + size);
671 
672  return results;
673  }
674 
680  {
681  std::vector<uint8_t> results;
682 
683  rs2_error* e = nullptr;
684  std::shared_ptr<const rs2_raw_data_buffer> list(
685  rs2_get_calibration_table(_dev.get(), &e),
687  error::handle(e);
688 
689  auto size = rs2_get_raw_data_size(list.get(), &e);
690  error::handle(e);
691 
692  auto start = rs2_get_raw_data(list.get(), &e);
693 
694  results.insert(results.begin(), start, start + size);
695 
696  return results;
697  }
698 
703  void set_calibration_table(const calibration_table& calibration)
704  {
705  rs2_error* e = nullptr;
706  rs2_set_calibration_table(_dev.get(), calibration.data(), static_cast< int >( calibration.size() ), &e);
707  error::handle(e);
708  }
709 
721  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,
722  float* ratio, float* angle) const
723  {
724  std::vector<uint8_t> results;
725 
726  rs2_error* e = nullptr;
727  std::shared_ptr<const rs2_raw_data_buffer> list(
728  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),
730  error::handle(e);
731 
732  auto size = rs2_get_raw_data_size(list.get(), &e);
733  error::handle(e);
734 
735  auto start = rs2_get_raw_data(list.get(), &e);
736 
737  results.insert(results.begin(), start, start + size);
738 
739  return results;
740  }
741 
753  template<class T>
754  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,
755  float* ratio, float* angle, T callback) const
756  {
757  std::vector<uint8_t> results;
758 
759  rs2_error* e = nullptr;
760  std::shared_ptr<const rs2_raw_data_buffer> list(
761  rs2_run_focal_length_calibration_cpp(_dev.get(), left.get().get(), right.get().get(), target_w, target_h, adjust_both_sides, ratio, angle,
762  new update_progress_callback<T>(std::move(callback)), &e),
764  error::handle(e);
765 
766  auto size = rs2_get_raw_data_size(list.get(), &e);
767  error::handle(e);
768 
769  auto start = rs2_get_raw_data(list.get(), &e);
770 
771  results.insert(results.begin(), start, start + size);
772 
773  return results;
774  }
775 
787  std::vector<uint8_t> run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only,
788  float* health, int health_size) const
789  {
790  std::vector<uint8_t> results;
791 
792  rs2_error* e = nullptr;
793  std::shared_ptr<const rs2_raw_data_buffer> list(
794  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),
796  error::handle(e);
797 
798  auto size = rs2_get_raw_data_size(list.get(), &e);
799  error::handle(e);
800 
801  auto start = rs2_get_raw_data(list.get(), &e);
802 
803  results.insert(results.begin(), start, start + size);
804 
805  return results;
806  }
807 
820  template<class T>
821  std::vector<uint8_t> run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only,
822  float* health, int health_size, T callback) const
823  {
824  std::vector<uint8_t> results;
825 
826  rs2_error* e = nullptr;
827  std::shared_ptr<const rs2_raw_data_buffer> list(
828  rs2_run_uv_map_calibration_cpp(_dev.get(), left.get().get(), color.get().get(), depth.get().get(), py_px_only, health, health_size,
829  new update_progress_callback<T>(std::move(callback)), &e),
831  error::handle(e);
832 
833  auto size = rs2_get_raw_data_size(list.get(), &e);
834  error::handle(e);
835 
836  auto start = rs2_get_raw_data(list.get(), &e);
837 
838  results.insert(results.begin(), start, start + size);
839 
840  return results;
841  }
842 
852  float target_width, float target_height) const
853  {
854  rs2_error* e = nullptr;
855  float result = rs2_calculate_target_z_cpp(_dev.get(), queue1.get().get(), queue2.get().get(), queue3.get().get(),
856  target_width, target_height, nullptr, &e);
857  error::handle(e);
858 
859  return result;
860  }
861 
871  template<class T>
873  float target_width, float target_height, T callback) const
874  {
875  rs2_error* e = nullptr;
876  float result = rs2_calculate_target_z_cpp(_dev.get(), queue1.get().get(), queue2.get().get(), queue3.get().get(),
877  target_width, target_height, new update_progress_callback<T>(std::move(callback)), &e);
878  error::handle(e);
879 
880  return result;
881  }
882 
883  std::string get_calibration_config() const
884  {
885  std::vector<uint8_t> result;
886 
887  rs2_error* e = nullptr;
888  auto buffer = rs2_get_calibration_config(_dev.get(), &e);
889 
890  std::shared_ptr<const rs2_raw_data_buffer> list(buffer, rs2_delete_raw_data);
891  error::handle(e);
892 
893  auto size = rs2_get_raw_data_size(list.get(), &e);
894  error::handle(e);
895 
896  auto start = rs2_get_raw_data(list.get(), &e);
897  error::handle(e);
898 
899  result.insert(result.begin(), start, start + size);
900 
901  return std::string(result.begin(), result.end());
902  }
903 
904  void set_calibration_config(const std::string& calibration_config_json_str) const
905  {
906  rs2_error* e = nullptr;
907  rs2_set_calibration_config(_dev.get(), calibration_config_json_str.c_str(), &e);
908  error::handle(e);
909  }
910  };
911 
912  /*
913  Wrapper around any callback function that is given to calibration_change_callback.
914  */
915  template< class callback >
917  {
918  //using callback = std::function< void( rs2_calibration_status ) >;
919  callback _callback;
920  public:
921  calibration_change_callback( callback cb ) : _callback( cb ) {}
922 
923  void on_calibration_change( rs2_calibration_status status ) noexcept override
924  {
925  try
926  {
927  _callback( status );
928  }
929  catch( ... ) { }
930  }
931  void release() override { delete this; }
932  };
933 
935  {
936  public:
937  calibration_change_device() = default;
939  : device(d.get())
940  {
941  rs2_error* e = nullptr;
943  {
944  _dev.reset();
945  }
946  error::handle(e);
947  }
948 
949  /*
950  Your callback should look like this, for example:
951  sensor.register_calibration_change_callback(
952  []( rs2_calibration_status ) noexcept
953  {
954  ...
955  })
956  */
957  template< typename T >
959  {
960  // We wrap the callback with an interface and pass it to librealsense, who will
961  // now manage its lifetime. Rather than deleting it, though, it will call its
962  // release() function, where (back in our context) it can be safely deleted:
963  rs2_error* e = nullptr;
965  _dev.get(),
966  new calibration_change_callback< T >(std::move(callback)),
967  &e);
968  error::handle(e);
969  }
970  };
971 
973  {
974  public:
975  device_calibration() = default;
977  {
978  rs2_error* e = nullptr;
980  {
981  _dev = d.get();
982  }
983  error::handle( e );
984  }
985 
990  {
991  rs2_error* e = nullptr;
992  rs2_trigger_device_calibration( _dev.get(), type, &e );
993  error::handle( e );
994  }
995  };
996 
997  class debug_protocol : public device
998  {
999  public:
1001  : device(d.get())
1002  {
1003  rs2_error* e = nullptr;
1004  if(rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_DEBUG, &e) == 0 && !e)
1005  {
1006  _dev.reset();
1007  }
1008  error::handle(e);
1009  }
1010 
1011  std::vector<uint8_t> build_command(uint32_t opcode,
1012  uint32_t param1 = 0,
1013  uint32_t param2 = 0,
1014  uint32_t param3 = 0,
1015  uint32_t param4 = 0,
1016  std::vector<uint8_t> const & data = {}) const
1017  {
1018  std::vector<uint8_t> results;
1019 
1020  rs2_error* e = nullptr;
1021  auto buffer = rs2_build_debug_protocol_command(_dev.get(), opcode, param1, param2, param3, param4,
1022  (void*)data.data(), (uint32_t)data.size(), &e);
1023  error::handle(e);
1024  std::shared_ptr< const rs2_raw_data_buffer > list( buffer, rs2_delete_raw_data );
1025 
1026  auto size = rs2_get_raw_data_size(list.get(), &e);
1027  error::handle(e);
1028 
1029  auto start = rs2_get_raw_data(list.get(), &e);
1030  error::handle(e);
1031 
1032  results.insert(results.begin(), start, start + size);
1033 
1034  return results;
1035  }
1036 
1037  std::vector<uint8_t> send_and_receive_raw_data(const std::vector<uint8_t>& input) const
1038  {
1039  std::vector<uint8_t> results;
1040 
1041  rs2_error* e = nullptr;
1042  std::shared_ptr<const rs2_raw_data_buffer> list(
1043  rs2_send_and_receive_raw_data(_dev.get(), (void*)input.data(), (uint32_t)input.size(), &e),
1045  error::handle(e);
1046 
1047  auto size = rs2_get_raw_data_size(list.get(), &e);
1048  error::handle(e);
1049 
1050  auto start = rs2_get_raw_data(list.get(), &e);
1051  error::handle(e);
1052 
1053  results.insert(results.begin(), start, start + size);
1054 
1055  return results;
1056  }
1057 
1058  std::string get_opcode_string(int opcode)
1059  {
1060  rs2_error* e = nullptr;
1061  char buffer[1024];
1062  rs2_hw_monitor_get_opcode_string(opcode, buffer, sizeof(buffer), _dev.get(), &e);
1063  return std::string(buffer);
1064  }
1065  };
1066 
1068  {
1069  public:
1070  explicit device_list(std::shared_ptr<rs2_device_list> list)
1071  : _list(std::move(list)) {}
1072 
1074  : _list(nullptr) {}
1075 
1076  operator std::vector<device>() const
1077  {
1078  std::vector<device> res;
1079  for (auto&& dev : *this) res.push_back(dev);
1080  return res;
1081  }
1082 
1083  bool contains(const device& dev) const
1084  {
1085  rs2_error* e = nullptr;
1086  auto res = !!(rs2_device_list_contains(_list.get(), dev.get().get(), &e));
1087  error::handle(e);
1088  return res;
1089  }
1090 
1091  device_list& operator=(std::shared_ptr<rs2_device_list> list)
1092  {
1093  _list = std::move(list);
1094  return *this;
1095  }
1096 
1097  device operator[](uint32_t index) const
1098  {
1099  rs2_error* e = nullptr;
1100  std::shared_ptr<rs2_device> dev(
1101  rs2_create_device(_list.get(), index, &e),
1103  error::handle(e);
1104 
1105  return device(dev);
1106  }
1107 
1108  uint32_t size() const
1109  {
1110  rs2_error* e = nullptr;
1111  auto size = rs2_get_device_count(_list.get(), &e);
1112  error::handle(e);
1113  return size;
1114  }
1115 
1116  device front() const { return std::move((*this)[0]); }
1117  device back() const
1118  {
1119  return std::move((*this)[size() - 1]);
1120  }
1121 
1123  {
1125  const device_list& device_list,
1126  uint32_t uint32_t)
1127  : _list(device_list),
1128  _index(uint32_t)
1129  {
1130  }
1131 
1132  public:
1134  {
1135  return _list[_index];
1136  }
1137  bool operator!=(const device_list_iterator& other) const
1138  {
1139  return other._index != _index || &other._list != &_list;
1140  }
1141  bool operator==(const device_list_iterator& other) const
1142  {
1143  return !(*this != other);
1144  }
1146  {
1147  _index++;
1148  return *this;
1149  }
1150  private:
1151  friend device_list;
1152  const device_list& _list;
1153  uint32_t _index;
1154  };
1155 
1157  {
1158  return device_list_iterator(*this, 0);
1159  }
1161  {
1162  return device_list_iterator(*this, size());
1163  }
1164  const rs2_device_list* get_list() const
1165  {
1166  return _list.get();
1167  }
1168 
1169  operator std::shared_ptr<rs2_device_list>() { return _list; };
1170 
1171  private:
1172  std::shared_ptr<rs2_device_list> _list;
1173  };
1174 }
1175 #endif // LIBREALSENSE_RS2_DEVICE_HPP
Definition: rs_types.hpp:115
device operator*() const
Definition: rs_device.hpp:1133
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:1117
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:335
bool is() const
Definition: rs_device.hpp:195
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:904
device_list(std::shared_ptr< rs2_device_list > list)
Definition: rs_device.hpp:1070
std::vector< uint8_t > send_and_receive_raw_data(const std::vector< uint8_t > &input) const
Definition: rs_device.hpp:1037
std::vector< uint8_t > create_flash_backup() const
Definition: rs_device.hpp:264
void release() override
Definition: rs_device.hpp:236
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:754
auto_calibrated_device(device d)
Definition: rs_device.hpp:400
device()
Definition: rs_device.hpp:156
const char * get_info(rs2_camera_info info) const
Definition: rs_device.hpp:115
device & operator=(const device &dev)
Definition: rs_device.hpp:150
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:1141
void update_unsigned(const std::vector< uint8_t > &image, int update_mode=RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
Definition: rs_device.hpp:315
void update(const std::vector< uint8_t > &fw_image) const
Definition: rs_device.hpp:349
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:372
Definition: rs_sensor.h:24
Definition: rs_sensor.h:38
void set_calibration_table(const calibration_table &calibration)
Definition: rs_device.hpp:703
void update_unsigned(const std::vector< uint8_t > &image, T callback, int update_mode=RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
Definition: rs_device.hpp:324
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:656
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:1091
calibration_change_device(device d)
Definition: rs_device.hpp:938
Definition: rs_device.hpp:224
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:168
void rs2_delete_raw_data(const rs2_raw_data_buffer *buffer)
std::string get_firmware_min_version() const
Definition: rs_device.hpp:186
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:602
Definition: rs_context.hpp:96
void reset_to_factory_calibration()
Definition: rs_device.hpp:389
std::string get_calibration_config() const
Definition: rs_device.hpp:883
int rs2_get_raw_data_size(const rs2_raw_data_buffer *buffer, rs2_error **error)
Definition: rs_device.hpp:239
T as() const
Definition: rs_device.hpp:202
void enter_update_state() const
Definition: rs_device.hpp:255
device_calibration(device d)
Definition: rs_device.hpp:976
device_list_iterator begin() const
Definition: rs_device.hpp:1156
std::vector< uint8_t > calibration_table
Definition: rs_device.hpp:367
Definition: rs_device.hpp:997
device operator[](uint32_t index) const
Definition: rs_device.hpp:1097
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:1116
uint32_t size() const
Definition: rs_device.hpp:1108
void trigger_device_calibration(rs2_calibration_type type)
Definition: rs_device.hpp:989
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:164
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:787
void update(const std::vector< uint8_t > &fw_image, T callback) const
Definition: rs_device.hpp:359
std::shared_ptr< rs2_device > _dev
Definition: rs_device.hpp:219
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:721
std::vector< uint8_t > create_flash_backup(T callback) const
Definition: rs_device.hpp:285
void rs2_hardware_reset(const rs2_device *device, rs2_error **error)
Definition: rs_types.h:188
Definition: rs_device.hpp:934
rs2_sensor_list * rs2_query_sensors(const rs2_device *device, rs2_error **error)
bool is_connected() const
Definition: rs_device.hpp:176
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:679
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:1011
void release() override
Definition: rs_device.hpp:931
void write_calibration() const
Definition: rs_device.hpp:379
update_device(device d)
Definition: rs_device.hpp:336
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:447
std::string get_opcode_string(int opcode)
Definition: rs_device.hpp:1058
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:821
calibration_change_callback(callback cb)
Definition: rs_device.hpp:921
Definition: rs_device.hpp:916
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:1083
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:630
bool supports(rs2_camera_info info) const
Definition: rs_device.hpp:102
update_progress_callback(T callback)
Definition: rs_device.hpp:229
device & operator=(const std::shared_ptr< rs2_device > dev)
Definition: rs_device.hpp:144
device_list_iterator & operator++()
Definition: rs_device.hpp:1145
device_list()
Definition: rs_device.hpp:1073
Definition: rs_device.hpp:397
updatable()
Definition: rs_device.hpp:242
Definition: rs_device.hpp:1067
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:306
Definition: rs_device.hpp:369
updatable(device d)
Definition: rs_device.hpp:243
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:1137
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:923
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)
Definition: rs_processing.hpp:133
void on_update_progress(const float progress) override
Definition: rs_device.hpp:231
struct rs2_device_list rs2_device_list
Definition: rs_types.h:303
debug_protocol(device d)
Definition: rs_device.hpp:1000
device_list_iterator end() const
Definition: rs_device.hpp:1160
void register_calibration_change_callback(T callback)
Definition: rs_device.hpp:958
Definition: rs_device.hpp:972
struct rs2_error rs2_error
Definition: rs_types.h:295
Definition: rs_device.hpp:1122
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:872
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:851
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:553
rs2_frame * get() const
Definition: rs_frame.hpp:616
Definition: rs_device.hpp:332
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:1164
T first() const
Definition: rs_device.hpp:88
virtual ~device()
Definition: rs_device.hpp:207
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:501
std::string get_type() const
Definition: rs_device.hpp:55
device(std::shared_ptr< rs2_device > dev)
Definition: rs_device.hpp:212
const char * rs2_get_device_info(const rs2_device *device, rs2_camera_info info, rs2_error **error)