RealSense Cross Platform API
RealSense Cross-platform API
Loading...
Searching...
No Matches
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
12namespace 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),
33
34 auto size = rs2_get_sensors_count(list.get(), &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),
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 }
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 template<class T>
185 bool is() const
186 {
187 T extension(*this);
188 return extension;
189 }
190
191 template<class T>
192 T as() const
193 {
194 T extension(*this);
195 return extension;
196 }
197 virtual ~device()
198 {
199 }
200
201 explicit operator std::shared_ptr<rs2_device>() { return _dev; };
202 explicit device(std::shared_ptr<rs2_device> dev) : _dev(dev) {}
203 protected:
204 friend class rs2::context;
205 friend class rs2::device_list;
207 friend class rs2::device_hub;
208
209 std::shared_ptr<rs2_device> _dev;
210
211 };
212
213 template<class T>
215 {
216 T _callback;
217
218 public:
219 explicit update_progress_callback(T callback) : _callback(callback) {}
220
221 void on_update_progress(const float progress) override
222 {
223 _callback(progress);
224 }
225
226 void release() override { delete this; }
227 };
228
229 class updatable : public device
230 {
231 public:
234 : device(d.get())
235 {
236 rs2_error* e = nullptr;
238 {
239 _dev.reset();
240 }
241 error::handle(e);
242 }
243
244 // Move the device to update state, this will cause the updatable device to disconnect and reconnect as an update device.
246 {
247 rs2_error* e = nullptr;
248 rs2_enter_update_state(_dev.get(), &e);
249 error::handle(e);
250 }
251
252 // Create backup of camera flash memory. Such backup does not constitute valid firmware image, and cannot be
253 // loaded back to the device, but it does contain all calibration and device information."
254 std::vector<uint8_t> create_flash_backup() const
255 {
256 std::vector<uint8_t> results;
257
258 rs2_error* e = nullptr;
259 std::shared_ptr<const rs2_raw_data_buffer> list(
260 rs2_create_flash_backup_cpp(_dev.get(), nullptr, &e),
262 error::handle(e);
263
264 auto size = rs2_get_raw_data_size(list.get(), &e);
265 error::handle(e);
266
267 auto start = rs2_get_raw_data(list.get(), &e);
268
269 results.insert(results.begin(), start, start + size);
270
271 return results;
272 }
273
274 template<class T>
275 std::vector<uint8_t> create_flash_backup(T callback) const
276 {
277 std::vector<uint8_t> results;
278
279 rs2_error* e = nullptr;
280 std::shared_ptr<const rs2_raw_data_buffer> list(
281 rs2_create_flash_backup_cpp(_dev.get(), new update_progress_callback<T>(std::move(callback)), &e),
283 error::handle(e);
284
285 auto size = rs2_get_raw_data_size(list.get(), &e);
286 error::handle(e);
287
288 auto start = rs2_get_raw_data(list.get(), &e);
289
290 results.insert(results.begin(), start, start + size);
291
292 return results;
293 }
294
295 // check firmware compatibility with SKU
296 bool check_firmware_compatibility(const std::vector<uint8_t>& image) const
297 {
298 rs2_error* e = nullptr;
299 auto res = !!rs2_check_firmware_compatibility(_dev.get(), image.data(), (int)image.size(), &e);
300 error::handle(e);
301 return res;
302 }
303
304 // Update an updatable device to the provided unsigned firmware. This call is executed on the caller's thread.
305 void update_unsigned(const std::vector<uint8_t>& image, int update_mode = RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
306 {
307 rs2_error* e = nullptr;
308 rs2_update_firmware_unsigned_cpp(_dev.get(), image.data(), (int)image.size(), nullptr, update_mode, &e);
309 error::handle(e);
310 }
311
312 // 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.
313 template<class T>
314 void update_unsigned(const std::vector<uint8_t>& image, T callback, int update_mode = RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
315 {
316 rs2_error* e = nullptr;
317 rs2_update_firmware_unsigned_cpp(_dev.get(), image.data(), int(image.size()), new update_progress_callback<T>(std::move(callback)), update_mode, &e);
318 error::handle(e);
319 }
320 };
321
322 class update_device : public device
323 {
324 public:
327 : device(d.get())
328 {
329 rs2_error* e = nullptr;
331 {
332 _dev.reset();
333 }
334 error::handle(e);
335 }
336
337 // Update an updatable device to the provided firmware.
338 // This call is executed on the caller's thread.
339 void update(const std::vector<uint8_t>& fw_image) const
340 {
341 rs2_error* e = nullptr;
342 rs2_update_firmware_cpp(_dev.get(), fw_image.data(), (int)fw_image.size(), NULL, &e);
343 error::handle(e);
344 }
345
346 // Update an updatable device to the provided firmware.
347 // This call is executed on the caller's thread and it supports progress notifications via the callback.
348 template<class T>
349 void update(const std::vector<uint8_t>& fw_image, T callback) const
350 {
351 rs2_error* e = nullptr;
352 rs2_update_firmware_cpp(_dev.get(), fw_image.data(), int(fw_image.size()), new update_progress_callback<T>(std::move(callback)), &e);
353 error::handle(e);
354 }
355 };
356
357 typedef std::vector<uint8_t> calibration_table;
358
360 {
361 public:
363 : device(d.get())
364 {}
365
369 void write_calibration() const
370 {
371 rs2_error* e = nullptr;
372 rs2_write_calibration(_dev.get(), &e);
373 error::handle(e);
374 }
375
380 {
381 rs2_error* e = nullptr;
383 error::handle(e);
384 }
385 };
386
388 {
389 public:
392 {
393 rs2_error* e = nullptr;
395 {
396 _dev.reset();
397 }
398 error::handle(e);
399 }
400
436 template<class T>
437 calibration_table run_on_chip_calibration(std::string json_content, float* health, T callback, int timeout_ms = 5000) const
438 {
439 std::vector<uint8_t> results;
440
441 rs2_error* e = nullptr;
442 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);
443 error::handle(e);
444
445 std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
446
447 auto size = rs2_get_raw_data_size(list.get(), &e);
448 error::handle(e);
449
450 auto start = rs2_get_raw_data(list.get(), &e);
451
452 results.insert(results.begin(), start, start + size);
453
454 return results;
455 }
456
491 calibration_table run_on_chip_calibration(std::string json_content, float* health, int timeout_ms = 5000) const
492 {
493 std::vector<uint8_t> results;
494
495 rs2_error* e = nullptr;
496 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);
497 error::handle(e);
498 std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
499
500 auto size = rs2_get_raw_data_size(list.get(), &e);
501 error::handle(e);
502
503 auto start = rs2_get_raw_data(list.get(), &e);
504 error::handle(e);
505
506 results.insert(results.begin(), start, start + size);
507
508 return results;
509 }
510
542 template<class T>
543 calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float* health, T callback, int timeout_ms = 5000) const
544 {
545 std::vector<uint8_t> results;
546
547 rs2_error* e = nullptr;
548 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);
549 error::handle(e);
550 std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
551
552 auto size = rs2_get_raw_data_size(list.get(), &e);
553 error::handle(e);
554
555 auto start = rs2_get_raw_data(list.get(), &e);
556
557 results.insert(results.begin(), start, start + size);
558
559 return results;
560 }
561
592 calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float * health, int timeout_ms = 5000) const
593 {
594 std::vector<uint8_t> results;
595
596 rs2_error* e = nullptr;
597 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);
598 error::handle(e);
599 std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
600
601 auto size = rs2_get_raw_data_size(list.get(), &e);
602 error::handle(e);
603
604 auto start = rs2_get_raw_data(list.get(), &e);
605
606 results.insert(results.begin(), start, start + size);
607
608 return results;
609 }
610
619 template<class T>
620 calibration_table process_calibration_frame(rs2::frame f, float* const health, T callback, int timeout_ms = 5000) const
621 {
622 std::vector<uint8_t> results;
623
624 rs2_error* e = nullptr;
625 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);
626 error::handle(e);
627 std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
628
629 auto size = rs2_get_raw_data_size(list.get(), &e);
630 error::handle(e);
631
632 auto start = rs2_get_raw_data(list.get(), &e);
633
634 results.insert(results.begin(), start, start + size);
635
636 return results;
637 }
638
646 calibration_table process_calibration_frame(rs2::frame f, float* const health, int timeout_ms = 5000) const
647 {
648 std::vector<uint8_t> results;
649
650 rs2_error* e = nullptr;
651 const rs2_raw_data_buffer* buf = rs2_process_calibration_frame(_dev.get(), f.get(), health, nullptr, timeout_ms, &e);
652 error::handle(e);
653 std::shared_ptr<const rs2_raw_data_buffer> list(buf, rs2_delete_raw_data);
654
655 auto size = rs2_get_raw_data_size(list.get(), &e);
656 error::handle(e);
657
658 auto start = rs2_get_raw_data(list.get(), &e);
659
660 results.insert(results.begin(), start, start + size);
661
662 return results;
663 }
664
670 {
671 std::vector<uint8_t> results;
672
673 rs2_error* e = nullptr;
674 std::shared_ptr<const rs2_raw_data_buffer> list(
677 error::handle(e);
678
679 auto size = rs2_get_raw_data_size(list.get(), &e);
680 error::handle(e);
681
682 auto start = rs2_get_raw_data(list.get(), &e);
683
684 results.insert(results.begin(), start, start + size);
685
686 return results;
687 }
688
694 {
695 rs2_error* e = nullptr;
696 rs2_set_calibration_table(_dev.get(), calibration.data(), static_cast< int >( calibration.size() ), &e);
697 error::handle(e);
698 }
699
711 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,
712 float* ratio, float* angle) const
713 {
714 std::vector<uint8_t> results;
715
716 rs2_error* e = nullptr;
717 std::shared_ptr<const rs2_raw_data_buffer> list(
718 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),
720 error::handle(e);
721
722 auto size = rs2_get_raw_data_size(list.get(), &e);
723 error::handle(e);
724
725 auto start = rs2_get_raw_data(list.get(), &e);
726
727 results.insert(results.begin(), start, start + size);
728
729 return results;
730 }
731
743 template<class T>
744 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,
745 float* ratio, float* angle, T callback) const
746 {
747 std::vector<uint8_t> results;
748
749 rs2_error* e = nullptr;
750 std::shared_ptr<const rs2_raw_data_buffer> list(
751 rs2_run_focal_length_calibration_cpp(_dev.get(), left.get().get(), right.get().get(), target_w, target_h, adjust_both_sides, ratio, angle,
752 new update_progress_callback<T>(std::move(callback)), &e),
754 error::handle(e);
755
756 auto size = rs2_get_raw_data_size(list.get(), &e);
757 error::handle(e);
758
759 auto start = rs2_get_raw_data(list.get(), &e);
760
761 results.insert(results.begin(), start, start + size);
762
763 return results;
764 }
765
777 std::vector<uint8_t> run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only,
778 float* health, int health_size) const
779 {
780 std::vector<uint8_t> results;
781
782 rs2_error* e = nullptr;
783 std::shared_ptr<const rs2_raw_data_buffer> list(
784 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),
786 error::handle(e);
787
788 auto size = rs2_get_raw_data_size(list.get(), &e);
789 error::handle(e);
790
791 auto start = rs2_get_raw_data(list.get(), &e);
792
793 results.insert(results.begin(), start, start + size);
794
795 return results;
796 }
797
810 template<class T>
811 std::vector<uint8_t> run_uv_map_calibration(rs2::frame_queue left, rs2::frame_queue color, rs2::frame_queue depth, int py_px_only,
812 float* health, int health_size, T callback) const
813 {
814 std::vector<uint8_t> results;
815
816 rs2_error* e = nullptr;
817 std::shared_ptr<const rs2_raw_data_buffer> list(
818 rs2_run_uv_map_calibration_cpp(_dev.get(), left.get().get(), color.get().get(), depth.get().get(), py_px_only, health, health_size,
819 new update_progress_callback<T>(std::move(callback)), &e),
821 error::handle(e);
822
823 auto size = rs2_get_raw_data_size(list.get(), &e);
824 error::handle(e);
825
826 auto start = rs2_get_raw_data(list.get(), &e);
827
828 results.insert(results.begin(), start, start + size);
829
830 return results;
831 }
832
842 float target_width, float target_height) const
843 {
844 rs2_error* e = nullptr;
845 float result = rs2_calculate_target_z_cpp(_dev.get(), queue1.get().get(), queue2.get().get(), queue3.get().get(),
846 target_width, target_height, nullptr, &e);
847 error::handle(e);
848
849 return result;
850 }
851
861 template<class T>
863 float target_width, float target_height, T callback) const
864 {
865 rs2_error* e = nullptr;
866 float result = rs2_calculate_target_z_cpp(_dev.get(), queue1.get().get(), queue2.get().get(), queue3.get().get(),
867 target_width, target_height, new update_progress_callback<T>(std::move(callback)), &e);
868 error::handle(e);
869
870 return result;
871 }
872
873 std::string get_calibration_config() const
874 {
875 std::vector<uint8_t> result;
876
877 rs2_error* e = nullptr;
878 auto buffer = rs2_get_calibration_config(_dev.get(), &e);
879
880 std::shared_ptr<const rs2_raw_data_buffer> list(buffer, rs2_delete_raw_data);
881 error::handle(e);
882
883 auto size = rs2_get_raw_data_size(list.get(), &e);
884 error::handle(e);
885
886 auto start = rs2_get_raw_data(list.get(), &e);
887 error::handle(e);
888
889 result.insert(result.begin(), start, start + size);
890
891 return std::string(result.begin(), result.end());
892 }
893
894 void set_calibration_config(const std::string& calibration_config_json_str) const
895 {
896 rs2_error* e = nullptr;
897 rs2_set_calibration_config(_dev.get(), calibration_config_json_str.c_str(), &e);
898 error::handle(e);
899 }
900 };
901
902 /*
903 Wrapper around any callback function that is given to calibration_change_callback.
904 */
905 template< class callback >
907 {
908 //using callback = std::function< void( rs2_calibration_status ) >;
909 callback _callback;
910 public:
911 calibration_change_callback( callback cb ) : _callback( cb ) {}
912
913 void on_calibration_change( rs2_calibration_status status ) noexcept override
914 {
915 try
916 {
917 _callback( status );
918 }
919 catch( ... ) { }
920 }
921 void release() override { delete this; }
922 };
923
925 {
926 public:
929 : device(d.get())
930 {
931 rs2_error* e = nullptr;
933 {
934 _dev.reset();
935 }
936 error::handle(e);
937 }
938
939 /*
940 Your callback should look like this, for example:
941 sensor.register_calibration_change_callback(
942 []( rs2_calibration_status ) noexcept
943 {
944 ...
945 })
946 */
947 template< typename T >
949 {
950 // We wrap the callback with an interface and pass it to librealsense, who will
951 // now manage its lifetime. Rather than deleting it, though, it will call its
952 // release() function, where (back in our context) it can be safely deleted:
953 rs2_error* e = nullptr;
955 _dev.get(),
956 new calibration_change_callback< T >(std::move(callback)),
957 &e);
958 error::handle(e);
959 }
960 };
961
963 {
964 public:
967 {
968 rs2_error* e = nullptr;
970 {
971 _dev = d.get();
972 }
973 error::handle( e );
974 }
975
980 {
981 rs2_error* e = nullptr;
982 rs2_trigger_device_calibration( _dev.get(), type, &e );
983 error::handle( e );
984 }
985 };
986
987 class debug_protocol : public device
988 {
989 public:
991 : device(d.get())
992 {
993 rs2_error* e = nullptr;
994 if(rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_DEBUG, &e) == 0 && !e)
995 {
996 _dev.reset();
997 }
998 error::handle(e);
999 }
1000
1001 std::vector<uint8_t> build_command(uint32_t opcode,
1002 uint32_t param1 = 0,
1003 uint32_t param2 = 0,
1004 uint32_t param3 = 0,
1005 uint32_t param4 = 0,
1006 std::vector<uint8_t> const & data = {}) const
1007 {
1008 std::vector<uint8_t> results;
1009
1010 rs2_error* e = nullptr;
1011 auto buffer = rs2_build_debug_protocol_command(_dev.get(), opcode, param1, param2, param3, param4,
1012 (void*)data.data(), (uint32_t)data.size(), &e);
1013 error::handle(e);
1014 std::shared_ptr< const rs2_raw_data_buffer > list( buffer, rs2_delete_raw_data );
1015
1016 auto size = rs2_get_raw_data_size(list.get(), &e);
1017 error::handle(e);
1018
1019 auto start = rs2_get_raw_data(list.get(), &e);
1020 error::handle(e);
1021
1022 results.insert(results.begin(), start, start + size);
1023
1024 return results;
1025 }
1026
1027 std::vector<uint8_t> send_and_receive_raw_data(const std::vector<uint8_t>& input) const
1028 {
1029 std::vector<uint8_t> results;
1030
1031 rs2_error* e = nullptr;
1032 std::shared_ptr<const rs2_raw_data_buffer> list(
1033 rs2_send_and_receive_raw_data(_dev.get(), (void*)input.data(), (uint32_t)input.size(), &e),
1035 error::handle(e);
1036
1037 auto size = rs2_get_raw_data_size(list.get(), &e);
1038 error::handle(e);
1039
1040 auto start = rs2_get_raw_data(list.get(), &e);
1041 error::handle(e);
1042
1043 results.insert(results.begin(), start, start + size);
1044
1045 return results;
1046 }
1047
1048 std::string get_opcode_string(int opcode)
1049 {
1050 rs2_error* e = nullptr;
1051 char buffer[1024];
1052 rs2_hw_monitor_get_opcode_string(opcode, buffer, sizeof(buffer), _dev.get(), &e);
1053 return std::string(buffer);
1054 }
1055 };
1056
1058 {
1059 public:
1060 explicit device_list(std::shared_ptr<rs2_device_list> list)
1061 : _list(std::move(list)) {}
1062
1064 : _list(nullptr) {}
1065
1066 operator std::vector<device>() const
1067 {
1068 std::vector<device> res;
1069 for (auto&& dev : *this) res.push_back(dev);
1070 return res;
1071 }
1072
1073 bool contains(const device& dev) const
1074 {
1075 rs2_error* e = nullptr;
1076 auto res = !!(rs2_device_list_contains(_list.get(), dev.get().get(), &e));
1077 error::handle(e);
1078 return res;
1079 }
1080
1081 device_list& operator=(std::shared_ptr<rs2_device_list> list)
1082 {
1083 _list = std::move(list);
1084 return *this;
1085 }
1086
1087 device operator[](uint32_t index) const
1088 {
1089 rs2_error* e = nullptr;
1090 std::shared_ptr<rs2_device> dev(
1091 rs2_create_device(_list.get(), index, &e),
1093 error::handle(e);
1094
1095 return device(dev);
1096 }
1097
1098 uint32_t size() const
1099 {
1100 rs2_error* e = nullptr;
1101 auto size = rs2_get_device_count(_list.get(), &e);
1102 error::handle(e);
1103 return size;
1104 }
1105
1106 device front() const { return std::move((*this)[0]); }
1107 device back() const
1108 {
1109 return std::move((*this)[size() - 1]);
1110 }
1111
1112 class device_list_iterator
1113 {
1114 device_list_iterator(
1115 const device_list& device_list,
1116 uint32_t uint32_t)
1117 : _list(device_list),
1118 _index(uint32_t)
1119 {
1120 }
1121
1122 public:
1124 {
1125 return _list[_index];
1126 }
1127 bool operator!=(const device_list_iterator& other) const
1128 {
1129 return other._index != _index || &other._list != &_list;
1130 }
1131 bool operator==(const device_list_iterator& other) const
1132 {
1133 return !(*this != other);
1134 }
1135 device_list_iterator& operator++()
1136 {
1137 _index++;
1138 return *this;
1139 }
1140 private:
1141 friend device_list;
1142 const device_list& _list;
1143 uint32_t _index;
1144 };
1145
1147 {
1148 return device_list_iterator(*this, 0);
1149 }
1151 {
1152 return device_list_iterator(*this, size());
1153 }
1155 {
1156 return _list.get();
1157 }
1158
1159 operator std::shared_ptr<rs2_device_list>() { return _list; };
1160
1161 private:
1162 std::shared_ptr<rs2_device_list> _list;
1163 };
1164}
1165#endif // LIBREALSENSE_RS2_DEVICE_HPP
calibration_table process_calibration_frame(rs2::frame f, float *const health, T callback, int timeout_ms=5000) const
Definition rs_device.hpp:620
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:543
auto_calibrated_device(device d)
Definition rs_device.hpp:390
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:841
std::string get_calibration_config() const
Definition rs_device.hpp:873
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:711
calibration_table get_calibration_table()
Definition rs_device.hpp:669
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:744
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:777
calibration_table run_on_chip_calibration(std::string json_content, float *health, int timeout_ms=5000) const
Definition rs_device.hpp:491
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:862
void set_calibration_table(const calibration_table &calibration)
Definition rs_device.hpp:693
calibration_table run_tare_calibration(float ground_truth_mm, std::string json_content, float *health, int timeout_ms=5000) const
Definition rs_device.hpp:592
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:811
void set_calibration_config(const std::string &calibration_config_json_str) const
Definition rs_device.hpp:894
calibration_table run_on_chip_calibration(std::string json_content, float *health, T callback, int timeout_ms=5000) const
Definition rs_device.hpp:437
calibration_table process_calibration_frame(rs2::frame f, float *const health, int timeout_ms=5000) const
Definition rs_device.hpp:646
calibrated_device(device d)
Definition rs_device.hpp:362
void write_calibration() const
Definition rs_device.hpp:369
void reset_to_factory_calibration()
Definition rs_device.hpp:379
Definition rs_device.hpp:907
calibration_change_callback(callback cb)
Definition rs_device.hpp:911
void on_calibration_change(rs2_calibration_status status) noexcept override
Definition rs_device.hpp:913
void release() override
Definition rs_device.hpp:921
calibration_change_device(device d)
Definition rs_device.hpp:928
void register_calibration_change_callback(T callback)
Definition rs_device.hpp:948
Definition rs_context.hpp:97
std::string get_opcode_string(int opcode)
Definition rs_device.hpp:1048
debug_protocol(device d)
Definition rs_device.hpp:990
std::vector< uint8_t > send_and_receive_raw_data(const std::vector< uint8_t > &input) const
Definition rs_device.hpp:1027
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:1001
void trigger_device_calibration(rs2_calibration_type type)
Definition rs_device.hpp:979
device_calibration(device d)
Definition rs_device.hpp:966
Definition rs_context.hpp:235
Definition rs_device.hpp:1113
device_list_iterator & operator++()
Definition rs_device.hpp:1135
device operator*() const
Definition rs_device.hpp:1123
bool operator==(const device_list_iterator &other) const
Definition rs_device.hpp:1131
bool operator!=(const device_list_iterator &other) const
Definition rs_device.hpp:1127
Definition rs_device.hpp:1058
device_list(std::shared_ptr< rs2_device_list > list)
Definition rs_device.hpp:1060
device back() const
Definition rs_device.hpp:1107
device operator[](uint32_t index) const
Definition rs_device.hpp:1087
bool contains(const device &dev) const
Definition rs_device.hpp:1073
device_list & operator=(std::shared_ptr< rs2_device_list > list)
Definition rs_device.hpp:1081
uint32_t size() const
Definition rs_device.hpp:1098
device_list_iterator end() const
Definition rs_device.hpp:1150
device front() const
Definition rs_device.hpp:1106
const rs2_device_list * get_list() const
Definition rs_device.hpp:1154
device_list_iterator begin() const
Definition rs_device.hpp:1146
device_list()
Definition rs_device.hpp:1063
Definition rs_device.hpp:20
bool is_connected() const
Definition rs_device.hpp:176
std::string get_description() const
Definition rs_device.hpp:65
device(std::shared_ptr< rs2_device > dev)
Definition rs_device.hpp:202
virtual ~device()
Definition rs_device.hpp:197
void hardware_reset()
Definition rs_device.hpp:126
T as() const
Definition rs_device.hpp:192
bool operator<(device const &other) const
Definition rs_device.hpp:168
T first() const
Definition rs_device.hpp:88
device & operator=(const std::shared_ptr< rs2_device > dev)
Definition rs_device.hpp:144
std::string get_type() const
Definition rs_device.hpp:55
device & operator=(const device &dev)
Definition rs_device.hpp:150
const std::shared_ptr< rs2_device > & get() const
Definition rs_device.hpp:164
bool is() const
Definition rs_device.hpp:185
std::shared_ptr< rs2_device > _dev
Definition rs_device.hpp:209
std::vector< sensor > query_sensors() const
Definition rs_device.hpp:26
bool is_in_recovery_mode()
Definition rs_device.hpp:136
const char * get_info(rs2_camera_info info) const
Definition rs_device.hpp:115
device()
Definition rs_device.hpp:156
bool supports(rs2_camera_info info) const
Definition rs_device.hpp:102
Definition rs_types.hpp:116
static void handle(rs2_error *e)
Definition rs_types.hpp:167
Definition rs_processing.hpp:134
std::shared_ptr< rs2_frame_queue > get()
Definition rs_processing.hpp:239
Definition rs_frame.hpp:355
rs2_frame * get() const
Definition rs_frame.hpp:601
Definition rs_pipeline.hpp:19
Definition rs_sensor.hpp:104
bool check_firmware_compatibility(const std::vector< uint8_t > &image) const
Definition rs_device.hpp:296
updatable()
Definition rs_device.hpp:232
std::vector< uint8_t > create_flash_backup() const
Definition rs_device.hpp:254
void enter_update_state() const
Definition rs_device.hpp:245
void update_unsigned(const std::vector< uint8_t > &image, int update_mode=RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
Definition rs_device.hpp:305
updatable(device d)
Definition rs_device.hpp:233
void update_unsigned(const std::vector< uint8_t > &image, T callback, int update_mode=RS2_UNSIGNED_UPDATE_MODE_UPDATE) const
Definition rs_device.hpp:314
std::vector< uint8_t > create_flash_backup(T callback) const
Definition rs_device.hpp:275
update_device()
Definition rs_device.hpp:325
update_device(device d)
Definition rs_device.hpp:326
void update(const std::vector< uint8_t > &fw_image) const
Definition rs_device.hpp:339
void update(const std::vector< uint8_t > &fw_image, T callback) const
Definition rs_device.hpp:349
Definition rs_device.hpp:215
void release() override
Definition rs_device.hpp:226
update_progress_callback(T callback)
Definition rs_device.hpp:219
void on_update_progress(const float progress) override
Definition rs_device.hpp:221
Definition rs_processing_gl.hpp:13
std::vector< uint8_t > calibration_table
Definition rs_device.hpp:357
const unsigned char * rs2_get_raw_data(const rs2_raw_data_buffer *buffer, rs2_error **error)
int rs2_get_raw_data_size(const rs2_raw_data_buffer *buffer, rs2_error **error)
void rs2_delete_raw_data(const rs2_raw_data_buffer *buffer)
void rs2_hw_monitor_get_opcode_string(int opcode, char *buffer, size_t buffer_size, rs2_device *device, rs2_error **error)
rs2_device * rs2_create_device(const rs2_device_list *info_list, int index, rs2_error **error)
void rs2_set_calibration_config(rs2_device *device, const char *calibration_config_json_str, rs2_error **error)
int rs2_get_device_count(const rs2_device_list *info_list, rs2_error **error)
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)
int rs2_device_is_connected(const rs2_device *device, rs2_error **error)
rs2_calibration_type
Definition rs_device.h:409
void rs2_trigger_device_calibration(rs2_device *dev, rs2_calibration_type type, rs2_error **error)
void rs2_reset_to_factory_calibration(const rs2_device *device, rs2_error **e)
int rs2_is_in_recovery_mode(const rs2_device *device, rs2_error **error)
#define RS2_UNSIGNED_UPDATE_MODE_UPDATE
Definition rs_device.h:235
void rs2_set_calibration_table(const rs2_device *device, const void *calibration, int calibration_size, rs2_error **error)
void rs2_delete_device(rs2_device *device)
const rs2_raw_data_buffer * rs2_get_calibration_table(const rs2_device *dev, rs2_error **error)
const rs2_raw_data_buffer * rs2_get_calibration_config(rs2_device *device, rs2_error **error)
int rs2_is_device_extendable_to(const rs2_device *device, rs2_extension extension, rs2_error **error)
void rs2_write_calibration(const rs2_device *device, rs2_error **e)
void rs2_enter_update_state(const rs2_device *device, rs2_error **error)
int rs2_check_firmware_compatibility(const rs2_device *device, const void *fw_image, int fw_image_size, rs2_error **error)
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)
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)
int rs2_supports_device_info(const rs2_device *device, rs2_camera_info info, 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)
const rs2_raw_data_buffer * rs2_create_flash_backup_cpp(const rs2_device *device, rs2_update_progress_callback *callback, rs2_error **error)
int rs2_device_list_contains(const rs2_device_list *info_list, const rs2_device *device, rs2_error **error)
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_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_hardware_reset(const rs2_device *device, rs2_error **error)
rs2_sensor_list * rs2_query_sensors(const rs2_device *device, rs2_error **error)
const char * rs2_get_device_info(const rs2_device *device, rs2_camera_info info, rs2_error **error)
void rs2_register_calibration_change_callback_cpp(rs2_device *dev, rs2_calibration_change_callback *callback, rs2_error **error)
rs2_calibration_status
Definition rs_device.h:421
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)
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)
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)
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)
void rs2_delete_sensor_list(rs2_sensor_list *info_list)
void rs2_delete_sensor(rs2_sensor *sensor)
rs2_sensor * rs2_create_sensor(const rs2_sensor_list *list, int index, rs2_error **error)
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
@ RS2_CAMERA_INFO_CONNECTION_TYPE
Definition rs_sensor.h:38
@ RS2_CAMERA_INFO_SERIAL_NUMBER
Definition rs_sensor.h:24
@ RS2_CAMERA_INFO_FIRMWARE_UPDATE_ID
Definition rs_sensor.h:35
@ RS2_CAMERA_INFO_NAME
Definition rs_sensor.h:23
@ RS2_EXTENSION_DEBUG
Definition rs_types.h:140
@ RS2_EXTENSION_UPDATABLE
Definition rs_types.h:176
@ RS2_EXTENSION_AUTO_CALIBRATED_DEVICE
Definition rs_types.h:180
@ RS2_EXTENSION_DEVICE_CALIBRATION
Definition rs_types.h:188
@ RS2_EXTENSION_UPDATE_DEVICE
Definition rs_types.h:177
@ RS2_EXTENSION_CALIBRATION_CHANGE_DEVICE
Definition rs_types.h:194
struct rs2_device_list rs2_device_list
Definition rs_types.h:284
struct rs2_error rs2_error
Definition rs_types.h:276
struct rs2_raw_data_buffer rs2_raw_data_buffer
Definition rs_types.h:278
Definition rs_types.hpp:74
Definition rs_types.hpp:98