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