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  {
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 
133  device& operator=(const std::shared_ptr<rs2_device> dev)
134  {
135  _dev.reset();
136  _dev = dev;
137  return *this;
138  }
139  device& operator=(const device& dev)
140  {
141  *this = nullptr;
142  _dev = dev._dev;
143  return *this;
144  }
145  device() : _dev(nullptr) {}
146 
147  // Note: this checks the validity of rs2::device (i.e., if it's connected to a realsense device), and does
148  // NOT reflect the current condition (connected/disconnected). Use is_connected() for that.
149  operator bool() const
150  {
151  return _dev != nullptr;
152  }
153  const std::shared_ptr<rs2_device>& get() const
154  {
155  return _dev;
156  }
157  bool operator<( device const & other ) const
158  {
159  // All RealSense cameras have an update-ID but not always a serial number
160  return std::strcmp( get_info( RS2_CAMERA_INFO_FIRMWARE_UPDATE_ID ),
162  < 0;
163  }
164 
165  bool is_connected() const
166  {
167  rs2_error * e = nullptr;
168  bool connected = rs2_device_is_connected( _dev.get(), &e );
169  error::handle( e );
170  return connected;
171  }
172 
173  template<class T>
174  bool is() const
175  {
176  T extension(*this);
177  return extension;
178  }
179 
180  template<class T>
181  T as() const
182  {
183  T extension(*this);
184  return extension;
185  }
186  virtual ~device()
187  {
188  }
189 
190  explicit operator std::shared_ptr<rs2_device>() { return _dev; };
191  explicit device(std::shared_ptr<rs2_device> dev) : _dev(dev) {}
192  protected:
193  friend class rs2::context;
194  friend class rs2::device_list;
195  friend class rs2::pipeline_profile;
196  friend class rs2::device_hub;
197 
198  std::shared_ptr<rs2_device> _dev;
199 
200  };
201 
202  template<class T>
204  {
205  T _callback;
206 
207  public:
208  explicit update_progress_callback(T callback) : _callback(callback) {}
209 
210  void on_update_progress(const float progress) override
211  {
212  _callback(progress);
213  }
214 
215  void release() override { delete this; }
216  };
217 
218  class updatable : public device
219  {
220  public:
221  updatable() : device() {}
223  : device(d.get())
224  {
225  rs2_error* e = nullptr;
226  if (rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_UPDATABLE, &e) == 0 && !e)
227  {
228  _dev.reset();
229  }
230  error::handle(e);
231  }
232 
233  // Move the device to update state, this will cause the updatable device to disconnect and reconnect as an update device.
234  void enter_update_state() const
235  {
236  rs2_error* e = nullptr;
237  rs2_enter_update_state(_dev.get(), &e);
238  error::handle(e);
239  }
240 
241  // Create backup of camera flash memory. Such backup does not constitute valid firmware image, and cannot be
242  // loaded back to the device, but it does contain all calibration and device information."
243  std::vector<uint8_t> create_flash_backup() const
244  {
245  std::vector<uint8_t> results;
246 
247  rs2_error* e = nullptr;
248  std::shared_ptr<const rs2_raw_data_buffer> list(
249  rs2_create_flash_backup_cpp(_dev.get(), nullptr, &e),
251  error::handle(e);
252 
253  auto size = rs2_get_raw_data_size(list.get(), &e);
254  error::handle(e);
255 
256  auto start = rs2_get_raw_data(list.get(), &e);
257 
258  results.insert(results.begin(), start, start + size);
259 
260  return results;
261  }
262 
263  template<class T>
264  std::vector<uint8_t> create_flash_backup(T callback) 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(), new update_progress_callback<T>(std::move(callback)), &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  // check firmware compatibility with SKU
285  bool check_firmware_compatibility(const std::vector<uint8_t>& image) const
286  {
287  rs2_error* e = nullptr;
288  auto res = !!rs2_check_firmware_compatibility(_dev.get(), image.data(), (int)image.size(), &e);
289  error::handle(e);
290  return res;
291  }
292 
293  // Update an updatable device to the provided unsigned firmware. This call is executed on the caller's thread.
294  void update_unsigned(const std::vector<uint8_t>& image, int update_mode = RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
295  {
296  rs2_error* e = nullptr;
297  rs2_update_firmware_unsigned_cpp(_dev.get(), image.data(), (int)image.size(), nullptr, update_mode, &e);
298  error::handle(e);
299  }
300 
301  // 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.
302  template<class T>
303  void update_unsigned(const std::vector<uint8_t>& image, T callback, 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()), new update_progress_callback<T>(std::move(callback)), update_mode, &e);
307  error::handle(e);
308  }
309  };
310 
311  class update_device : public device
312  {
313  public:
316  : device(d.get())
317  {
318  rs2_error* e = nullptr;
320  {
321  _dev.reset();
322  }
323  error::handle(e);
324  }
325 
326  // Update an updatable device to the provided firmware.
327  // This call is executed on the caller's thread.
328  void update(const std::vector<uint8_t>& fw_image) const
329  {
330  rs2_error* e = nullptr;
331  rs2_update_firmware_cpp(_dev.get(), fw_image.data(), (int)fw_image.size(), NULL, &e);
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 and it supports progress notifications via the callback.
337  template<class T>
338  void update(const std::vector<uint8_t>& fw_image, T callback) const
339  {
340  rs2_error* e = nullptr;
341  rs2_update_firmware_cpp(_dev.get(), fw_image.data(), int(fw_image.size()), new update_progress_callback<T>(std::move(callback)), &e);
342  error::handle(e);
343  }
344  };
345 
346  typedef std::vector<uint8_t> calibration_table;
347 
348  class calibrated_device : public device
349  {
350  public:
352  : device(d.get())
353  {}
354 
358  void write_calibration() const
359  {
360  rs2_error* e = nullptr;
361  rs2_write_calibration(_dev.get(), &e);
362  error::handle(e);
363  }
364 
369  {
370  rs2_error* e = nullptr;
372  error::handle(e);
373  }
374  };
375 
377  {
378  public:
380  : calibrated_device(d)
381  {
382  rs2_error* e = nullptr;
384  {
385  _dev.reset();
386  }
387  error::handle(e);
388  }
389 
425  template<class T>
426  calibration_table run_on_chip_calibration(std::string json_content, float* health, T callback, int timeout_ms = 5000) const
427  {
428  std::vector<uint8_t> results;
429 
430  rs2_error* e = nullptr;
431  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);
432  error::handle(e);
433 
434  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
435 
436  auto size = rs2_get_raw_data_size(list.get(), &e);
437  error::handle(e);
438 
439  auto start = rs2_get_raw_data(list.get(), &e);
440 
441  results.insert(results.begin(), start, start + size);
442 
443  return results;
444  }
445 
480  calibration_table run_on_chip_calibration(std::string json_content, float* health, int timeout_ms = 5000) const
481  {
482  std::vector<uint8_t> results;
483 
484  rs2_error* e = nullptr;
485  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);
486  error::handle(e);
487  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
488 
489  auto size = rs2_get_raw_data_size(list.get(), &e);
490  error::handle(e);
491 
492  auto start = rs2_get_raw_data(list.get(), &e);
493  error::handle(e);
494 
495  results.insert(results.begin(), start, start + size);
496 
497  return results;
498  }
499 
531  template<class T>
532  calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float* health, T callback, int timeout_ms = 5000) const
533  {
534  std::vector<uint8_t> results;
535 
536  rs2_error* e = nullptr;
537  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);
538  error::handle(e);
539  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
540 
541  auto size = rs2_get_raw_data_size(list.get(), &e);
542  error::handle(e);
543 
544  auto start = rs2_get_raw_data(list.get(), &e);
545 
546  results.insert(results.begin(), start, start + size);
547 
548  return results;
549  }
550 
581  calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float * health, int timeout_ms = 5000) const
582  {
583  std::vector<uint8_t> results;
584 
585  rs2_error* e = nullptr;
586  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);
587  error::handle(e);
588  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
589 
590  auto size = rs2_get_raw_data_size(list.get(), &e);
591  error::handle(e);
592 
593  auto start = rs2_get_raw_data(list.get(), &e);
594 
595  results.insert(results.begin(), start, start + size);
596 
597  return results;
598  }
599 
608  template<class T>
609  calibration_table process_calibration_frame(rs2::frame f, float* const health, T callback, int timeout_ms = 5000) const
610  {
611  std::vector<uint8_t> results;
612 
613  rs2_error* e = nullptr;
614  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);
615  error::handle(e);
616  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
617 
618  auto size = rs2_get_raw_data_size(list.get(), &e);
619  error::handle(e);
620 
621  auto start = rs2_get_raw_data(list.get(), &e);
622 
623  results.insert(results.begin(), start, start + size);
624 
625  return results;
626  }
627 
635  calibration_table process_calibration_frame(rs2::frame f, float* const health, int timeout_ms = 5000) const
636  {
637  std::vector<uint8_t> results;
638 
639  rs2_error* e = nullptr;
640  const rs2_raw_data_buffer* buf = rs2_process_calibration_frame(_dev.get(), f.get(), health, nullptr, timeout_ms, &e);
641  error::handle(e);
642  std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
643 
644  auto size = rs2_get_raw_data_size(list.get(), &e);
645  error::handle(e);
646 
647  auto start = rs2_get_raw_data(list.get(), &e);
648 
649  results.insert(results.begin(), start, start + size);
650 
651  return results;
652  }
653 
659  {
660  std::vector<uint8_t> results;
661 
662  rs2_error* e = nullptr;
663  std::shared_ptr<const rs2_raw_data_buffer> list(
664  rs2_get_calibration_table(_dev.get(), &e),
666  error::handle(e);
667 
668  auto size = rs2_get_raw_data_size(list.get(), &e);
669  error::handle(e);
670 
671  auto start = rs2_get_raw_data(list.get(), &e);
672 
673  results.insert(results.begin(), start, start + size);
674 
675  return results;
676  }
677 
682  void set_calibration_table(const calibration_table& calibration)
683  {
684  rs2_error* e = nullptr;
685  rs2_set_calibration_table(_dev.get(), calibration.data(), static_cast< int >( calibration.size() ), &e);
686  error::handle(e);
687  }
688 
700  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,
701  float* ratio, float* angle) const
702  {
703  std::vector<uint8_t> results;
704 
705  rs2_error* e = nullptr;
706  std::shared_ptr<const rs2_raw_data_buffer> list(
707  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),
709  error::handle(e);
710 
711  auto size = rs2_get_raw_data_size(list.get(), &e);
712  error::handle(e);
713 
714  auto start = rs2_get_raw_data(list.get(), &e);
715 
716  results.insert(results.begin(), start, start + size);
717 
718  return results;
719  }
720 
732  template<class T>
733  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,
734  float* ratio, float* angle, T callback) const
735  {
736  std::vector<uint8_t> results;
737 
738  rs2_error* e = nullptr;
739  std::shared_ptr<const rs2_raw_data_buffer> list(
740  rs2_run_focal_length_calibration_cpp(_dev.get(), left.get().get(), right.get().get(), target_w, target_h, adjust_both_sides, ratio, angle,
741  new update_progress_callback<T>(std::move(callback)), &e),
743  error::handle(e);
744 
745  auto size = rs2_get_raw_data_size(list.get(), &e);
746  error::handle(e);
747 
748  auto start = rs2_get_raw_data(list.get(), &e);
749 
750  results.insert(results.begin(), start, start + size);
751 
752  return results;
753  }
754 
766  std::vector<uint8_t> run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only,
767  float* health, int health_size) const
768  {
769  std::vector<uint8_t> results;
770 
771  rs2_error* e = nullptr;
772  std::shared_ptr<const rs2_raw_data_buffer> list(
773  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),
775  error::handle(e);
776 
777  auto size = rs2_get_raw_data_size(list.get(), &e);
778  error::handle(e);
779 
780  auto start = rs2_get_raw_data(list.get(), &e);
781 
782  results.insert(results.begin(), start, start + size);
783 
784  return results;
785  }
786 
799  template<class T>
800  std::vector<uint8_t> run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only,
801  float* health, int health_size, T callback) const
802  {
803  std::vector<uint8_t> results;
804 
805  rs2_error* e = nullptr;
806  std::shared_ptr<const rs2_raw_data_buffer> list(
807  rs2_run_uv_map_calibration_cpp(_dev.get(), left.get().get(), color.get().get(), depth.get().get(), py_px_only, health, health_size,
808  new update_progress_callback<T>(std::move(callback)), &e),
810  error::handle(e);
811 
812  auto size = rs2_get_raw_data_size(list.get(), &e);
813  error::handle(e);
814 
815  auto start = rs2_get_raw_data(list.get(), &e);
816 
817  results.insert(results.begin(), start, start + size);
818 
819  return results;
820  }
821 
831  float target_width, float target_height) const
832  {
833  rs2_error* e = nullptr;
834  float result = rs2_calculate_target_z_cpp(_dev.get(), queue1.get().get(), queue2.get().get(), queue3.get().get(),
835  target_width, target_height, nullptr, &e);
836  error::handle(e);
837 
838  return result;
839  }
840 
850  template<class T>
852  float target_width, float target_height, T callback) 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, new update_progress_callback<T>(std::move(callback)), &e);
857  error::handle(e);
858 
859  return result;
860  }
861 
862  std::string get_calibration_config() const
863  {
864  std::vector<uint8_t> result;
865 
866  rs2_error* e = nullptr;
867  auto buffer = rs2_get_calibration_config(_dev.get(), &e);
868 
869  std::shared_ptr<const rs2_raw_data_buffer> list(buffer, rs2_delete_raw_data);
870  error::handle(e);
871 
872  auto size = rs2_get_raw_data_size(list.get(), &e);
873  error::handle(e);
874 
875  auto start = rs2_get_raw_data(list.get(), &e);
876  error::handle(e);
877 
878  result.insert(result.begin(), start, start + size);
879 
880  return std::string(result.begin(), result.end());
881  }
882 
883  void set_calibration_config(const std::string& calibration_config_json_str) const
884  {
885  rs2_error* e = nullptr;
886  rs2_set_calibration_config(_dev.get(), calibration_config_json_str.c_str(), &e);
887  error::handle(e);
888  }
889  };
890 
891  /*
892  Wrapper around any callback function that is given to calibration_change_callback.
893  */
894  template< class callback >
896  {
897  //using callback = std::function< void( rs2_calibration_status ) >;
898  callback _callback;
899  public:
900  calibration_change_callback( callback cb ) : _callback( cb ) {}
901 
902  void on_calibration_change( rs2_calibration_status status ) noexcept override
903  {
904  try
905  {
906  _callback( status );
907  }
908  catch( ... ) { }
909  }
910  void release() override { delete this; }
911  };
912 
914  {
915  public:
916  calibration_change_device() = default;
918  : device(d.get())
919  {
920  rs2_error* e = nullptr;
922  {
923  _dev.reset();
924  }
925  error::handle(e);
926  }
927 
928  /*
929  Your callback should look like this, for example:
930  sensor.register_calibration_change_callback(
931  []( rs2_calibration_status ) noexcept
932  {
933  ...
934  })
935  */
936  template< typename T >
938  {
939  // We wrap the callback with an interface and pass it to librealsense, who will
940  // now manage its lifetime. Rather than deleting it, though, it will call its
941  // release() function, where (back in our context) it can be safely deleted:
942  rs2_error* e = nullptr;
944  _dev.get(),
945  new calibration_change_callback< T >(std::move(callback)),
946  &e);
947  error::handle(e);
948  }
949  };
950 
952  {
953  public:
954  device_calibration() = default;
956  {
957  rs2_error* e = nullptr;
959  {
960  _dev = d.get();
961  }
962  error::handle( e );
963  }
964 
969  {
970  rs2_error* e = nullptr;
971  rs2_trigger_device_calibration( _dev.get(), type, &e );
972  error::handle( e );
973  }
974  };
975 
976  class debug_protocol : public device
977  {
978  public:
980  : device(d.get())
981  {
982  rs2_error* e = nullptr;
983  if(rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_DEBUG, &e) == 0 && !e)
984  {
985  _dev.reset();
986  }
987  error::handle(e);
988  }
989 
990  std::vector<uint8_t> build_command(uint32_t opcode,
991  uint32_t param1 = 0,
992  uint32_t param2 = 0,
993  uint32_t param3 = 0,
994  uint32_t param4 = 0,
995  std::vector<uint8_t> const & data = {}) const
996  {
997  std::vector<uint8_t> results;
998 
999  rs2_error* e = nullptr;
1000  auto buffer = rs2_build_debug_protocol_command(_dev.get(), opcode, param1, param2, param3, param4,
1001  (void*)data.data(), (uint32_t)data.size(), &e);
1002  error::handle(e);
1003  std::shared_ptr< const rs2_raw_data_buffer > list( buffer, rs2_delete_raw_data );
1004 
1005  auto size = rs2_get_raw_data_size(list.get(), &e);
1006  error::handle(e);
1007 
1008  auto start = rs2_get_raw_data(list.get(), &e);
1009  error::handle(e);
1010 
1011  results.insert(results.begin(), start, start + size);
1012 
1013  return results;
1014  }
1015 
1016  std::vector<uint8_t> send_and_receive_raw_data(const std::vector<uint8_t>& input) const
1017  {
1018  std::vector<uint8_t> results;
1019 
1020  rs2_error* e = nullptr;
1021  std::shared_ptr<const rs2_raw_data_buffer> list(
1022  rs2_send_and_receive_raw_data(_dev.get(), (void*)input.data(), (uint32_t)input.size(), &e),
1024  error::handle(e);
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::string get_opcode_string(int opcode)
1038  {
1039  rs2_error* e = nullptr;
1040  char buffer[1024];
1041  rs2_hw_monitor_get_opcode_string(opcode, buffer, sizeof(buffer), _dev.get(), &e);
1042  return std::string(buffer);
1043  }
1044  };
1045 
1047  {
1048  public:
1049  explicit device_list(std::shared_ptr<rs2_device_list> list)
1050  : _list(std::move(list)) {}
1051 
1053  : _list(nullptr) {}
1054 
1055  operator std::vector<device>() const
1056  {
1057  std::vector<device> res;
1058  for (auto&& dev : *this) res.push_back(dev);
1059  return res;
1060  }
1061 
1062  bool contains(const device& dev) const
1063  {
1064  rs2_error* e = nullptr;
1065  auto res = !!(rs2_device_list_contains(_list.get(), dev.get().get(), &e));
1066  error::handle(e);
1067  return res;
1068  }
1069 
1070  device_list& operator=(std::shared_ptr<rs2_device_list> list)
1071  {
1072  _list = std::move(list);
1073  return *this;
1074  }
1075 
1076  device operator[](uint32_t index) const
1077  {
1078  rs2_error* e = nullptr;
1079  std::shared_ptr<rs2_device> dev(
1080  rs2_create_device(_list.get(), index, &e),
1082  error::handle(e);
1083 
1084  return device(dev);
1085  }
1086 
1087  uint32_t size() const
1088  {
1089  rs2_error* e = nullptr;
1090  auto size = rs2_get_device_count(_list.get(), &e);
1091  error::handle(e);
1092  return size;
1093  }
1094 
1095  device front() const { return std::move((*this)[0]); }
1096  device back() const
1097  {
1098  return std::move((*this)[size() - 1]);
1099  }
1100 
1102  {
1104  const device_list& device_list,
1105  uint32_t uint32_t)
1106  : _list(device_list),
1107  _index(uint32_t)
1108  {
1109  }
1110 
1111  public:
1113  {
1114  return _list[_index];
1115  }
1116  bool operator!=(const device_list_iterator& other) const
1117  {
1118  return other._index != _index || &other._list != &_list;
1119  }
1120  bool operator==(const device_list_iterator& other) const
1121  {
1122  return !(*this != other);
1123  }
1125  {
1126  _index++;
1127  return *this;
1128  }
1129  private:
1130  friend device_list;
1131  const device_list& _list;
1132  uint32_t _index;
1133  };
1134 
1136  {
1137  return device_list_iterator(*this, 0);
1138  }
1140  {
1141  return device_list_iterator(*this, size());
1142  }
1143  const rs2_device_list* get_list() const
1144  {
1145  return _list.get();
1146  }
1147 
1148  operator std::shared_ptr<rs2_device_list>() { return _list; };
1149 
1150  private:
1151  std::shared_ptr<rs2_device_list> _list;
1152  };
1153 }
1154 #endif // LIBREALSENSE_RS2_DEVICE_HPP
Definition: rs_types.hpp:115
device operator*() const
Definition: rs_device.hpp:1112
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:1096
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:314
bool is() const
Definition: rs_device.hpp:174
Definition: rs_frame.hpp:354
struct rs2_raw_data_buffer rs2_raw_data_buffer
Definition: rs_types.h:233
int rs2_device_list_contains(const rs2_device_list *info_list, const rs2_device *device, rs2_error **error)
Definition: rs_types.h:194
void set_calibration_config(const std::string &calibration_config_json_str) const
Definition: rs_device.hpp:883
device_list(std::shared_ptr< rs2_device_list > list)
Definition: rs_device.hpp:1049
std::vector< uint8_t > send_and_receive_raw_data(const std::vector< uint8_t > &input) const
Definition: rs_device.hpp:1016
std::vector< uint8_t > create_flash_backup() const
Definition: rs_device.hpp:243
void release() override
Definition: rs_device.hpp:215
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:733
auto_calibrated_device(device d)
Definition: rs_device.hpp:379
device()
Definition: rs_device.hpp:145
const char * get_info(rs2_camera_info info) const
Definition: rs_device.hpp:115
device & operator=(const device &dev)
Definition: rs_device.hpp:139
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:1120
void update_unsigned(const std::vector< uint8_t > &image, int update_mode=RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
Definition: rs_device.hpp:294
void update(const std::vector< uint8_t > &fw_image) const
Definition: rs_device.hpp:328
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:351
Definition: rs_sensor.h:24
Definition: rs_sensor.h:38
void set_calibration_table(const calibration_table &calibration)
Definition: rs_device.hpp:682
void update_unsigned(const std::vector< uint8_t > &image, T callback, int update_mode=RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
Definition: rs_device.hpp:303
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:635
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:1070
calibration_change_device(device d)
Definition: rs_device.hpp:917
Definition: rs_device.hpp:203
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:157
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:581
Definition: rs_context.hpp:96
void reset_to_factory_calibration()
Definition: rs_device.hpp:368
std::string get_calibration_config() const
Definition: rs_device.hpp:862
int rs2_get_raw_data_size(const rs2_raw_data_buffer *buffer, rs2_error **error)
Definition: rs_device.hpp:218
T as() const
Definition: rs_device.hpp:181
void enter_update_state() const
Definition: rs_device.hpp:234
device_calibration(device d)
Definition: rs_device.hpp:955
device_list_iterator begin() const
Definition: rs_device.hpp:1135
std::vector< uint8_t > calibration_table
Definition: rs_device.hpp:346
Definition: rs_device.hpp:976
device operator[](uint32_t index) const
Definition: rs_device.hpp:1076
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:1095
uint32_t size() const
Definition: rs_device.hpp:1087
void trigger_device_calibration(rs2_calibration_type type)
Definition: rs_device.hpp:968
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:153
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:766
void update(const std::vector< uint8_t > &fw_image, T callback) const
Definition: rs_device.hpp:338
std::shared_ptr< rs2_device > _dev
Definition: rs_device.hpp:198
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:700
std::vector< uint8_t > create_flash_backup(T callback) const
Definition: rs_device.hpp:264
void rs2_hardware_reset(const rs2_device *device, rs2_error **error)
Definition: rs_types.h:176
Definition: rs_device.hpp:913
rs2_sensor_list * rs2_query_sensors(const rs2_device *device, rs2_error **error)
bool is_connected() const
Definition: rs_device.hpp:165
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:658
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:990
void release() override
Definition: rs_device.hpp:910
void write_calibration() const
Definition: rs_device.hpp:358
update_device(device d)
Definition: rs_device.hpp:315
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:426
std::string get_opcode_string(int opcode)
Definition: rs_device.hpp:1037
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:800
calibration_change_callback(callback cb)
Definition: rs_device.hpp:900
Definition: rs_device.hpp:895
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:1062
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:180
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)
Definition: rs_types.h:140
calibration_table process_calibration_frame(rs2::frame f, float *const health, T callback, int timeout_ms=5000) const
Definition: rs_device.hpp:609
bool supports(rs2_camera_info info) const
Definition: rs_device.hpp:102
update_progress_callback(T callback)
Definition: rs_device.hpp:208
device & operator=(const std::shared_ptr< rs2_device > dev)
Definition: rs_device.hpp:133
device_list_iterator & operator++()
Definition: rs_device.hpp:1124
device_list()
Definition: rs_device.hpp:1052
Definition: rs_device.hpp:376
updatable()
Definition: rs_device.hpp:221
Definition: rs_device.hpp:1046
bool check_firmware_compatibility(const std::vector< uint8_t > &image) const
Definition: rs_device.hpp:285
Definition: rs_device.hpp:348
updatable(device d)
Definition: rs_device.hpp:222
void rs2_enter_update_state(const rs2_device *device, rs2_error **error)
Definition: rs_types.h:188
Definition: rs_context.hpp:234
bool operator!=(const device_list_iterator &other) const
Definition: rs_device.hpp:1116
Definition: rs_types.h:177
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:902
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:134
void on_update_progress(const float progress) override
Definition: rs_device.hpp:210
struct rs2_device_list rs2_device_list
Definition: rs_types.h:239
debug_protocol(device d)
Definition: rs_device.hpp:979
device_list_iterator end() const
Definition: rs_device.hpp:1139
void register_calibration_change_callback(T callback)
Definition: rs_device.hpp:937
Definition: rs_device.hpp:951
struct rs2_error rs2_error
Definition: rs_types.h:231
Definition: rs_device.hpp:1101
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:851
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:830
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:532
rs2_frame * get() const
Definition: rs_frame.hpp:601
Definition: rs_device.hpp:311
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:1143
T first() const
Definition: rs_device.hpp:88
virtual ~device()
Definition: rs_device.hpp:186
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:480
std::string get_type() const
Definition: rs_device.hpp:55
device(std::shared_ptr< rs2_device > dev)
Definition: rs_device.hpp:191
const char * rs2_get_device_info(const rs2_device *device, rs2_camera_info info, rs2_error **error)