ds5-device.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2016 Intel Corporation. All Rights Reserved.
3 
4 #include <mutex>
5 #include <chrono>
6 #include <vector>
7 #include <iterator>
8 #include <cstddef>
9 #include <string>
10 
11 #include "device.h"
12 #include "context.h"
13 #include "image.h"
14 #include "metadata-parser.h"
15 
16 #include "ds5-device.h"
17 #include "ds5-private.h"
18 #include "ds5-options.h"
19 #include "ds5-timestamp.h"
20 #include "stream.h"
21 #include "environment.h"
22 #include "ds5-color.h"
23 #include "ds5-nonmonochrome.h"
24 
25 #include "proc/decimation-filter.h"
26 #include "proc/threshold.h"
28 #include "proc/spatial-filter.h"
29 #include "proc/colorizer.h"
30 #include "proc/temporal-filter.h"
31 #include "proc/y8i-to-y8y8.h"
32 #include "proc/y12i-to-y16y16.h"
37 #include "proc/depth-decompress.h"
38 #include "proc/hdr-merge.h"
40 #include "hdr-config.h"
41 #include "ds5-thermal-monitor.h"
42 #include "../common/fw/firmware-version.h"
44 #include "../third-party/json.hpp"
45 
46 #ifdef HWM_OVER_XU
47 constexpr bool hw_mon_over_xu = true;
48 #else
49 constexpr bool hw_mon_over_xu = false;
50 #endif
51 
52 namespace librealsense
53 {
54  std::map<uint32_t, rs2_format> ds5_depth_fourcc_to_rs2_format = {
55  {rs_fourcc('Y','U','Y','2'), RS2_FORMAT_YUYV},
56  {rs_fourcc('Y','U','Y','V'), RS2_FORMAT_YUYV},
57  {rs_fourcc('U','Y','V','Y'), RS2_FORMAT_UYVY},
58  {rs_fourcc('G','R','E','Y'), RS2_FORMAT_Y8},
59  {rs_fourcc('Y','8','I',' '), RS2_FORMAT_Y8I},
60  {rs_fourcc('W','1','0',' '), RS2_FORMAT_W10},
61  {rs_fourcc('Y','1','6',' '), RS2_FORMAT_Y16},
62  {rs_fourcc('Y','1','2','I'), RS2_FORMAT_Y12I},
63  {rs_fourcc('Z','1','6',' '), RS2_FORMAT_Z16},
64  {rs_fourcc('Z','1','6','H'), RS2_FORMAT_Z16H},
65  {rs_fourcc('R','G','B','2'), RS2_FORMAT_BGR8},
66  {rs_fourcc('M','J','P','G'), RS2_FORMAT_MJPEG},
67  {rs_fourcc('B','Y','R','2'), RS2_FORMAT_RAW16}
68 
69  };
70  std::map<uint32_t, rs2_stream> ds5_depth_fourcc_to_rs2_stream = {
71  {rs_fourcc('Y','U','Y','2'), RS2_STREAM_COLOR},
72  {rs_fourcc('Y','U','Y','V'), RS2_STREAM_COLOR},
73  {rs_fourcc('U','Y','V','Y'), RS2_STREAM_INFRARED},
74  {rs_fourcc('G','R','E','Y'), RS2_STREAM_INFRARED},
75  {rs_fourcc('Y','8','I',' '), RS2_STREAM_INFRARED},
76  {rs_fourcc('W','1','0',' '), RS2_STREAM_INFRARED},
77  {rs_fourcc('Y','1','6',' '), RS2_STREAM_INFRARED},
78  {rs_fourcc('Y','1','2','I'), RS2_STREAM_INFRARED},
79  {rs_fourcc('R','G','B','2'), RS2_STREAM_INFRARED},
80  {rs_fourcc('Z','1','6',' '), RS2_STREAM_DEPTH},
81  {rs_fourcc('Z','1','6','H'), RS2_STREAM_DEPTH},
82  {rs_fourcc('B','Y','R','2'), RS2_STREAM_COLOR},
83  {rs_fourcc('M','J','P','G'), RS2_STREAM_COLOR}
84  };
85 
87  const hw_monitor& hwm,
89  : _hw_monitor(hwm), _cmd(cmd) {}
90 
92  {
93  command cmd(_cmd);
94  cmd.param1 = roi.min_y;
95  cmd.param2 = roi.max_y;
96  cmd.param3 = roi.min_x;
97  cmd.param4 = roi.max_x;
98  _hw_monitor.send(cmd);
99  }
100 
102  {
103  region_of_interest roi;
104  command cmd(_cmd + 1);
105  auto res = _hw_monitor.send(cmd);
106 
107  if (res.size() < 4 * sizeof(uint16_t))
108  {
109  throw std::runtime_error("Invalid result size!");
110  }
111 
112  auto words = reinterpret_cast<uint16_t*>(res.data());
113 
114  roi.min_y = words[0];
115  roi.max_y = words[1];
116  roi.min_x = words[2];
117  roi.max_x = words[3];
118 
119  return roi;
120  }
121 
122  std::vector<uint8_t> ds5_device::send_receive_raw_data(const std::vector<uint8_t>& input)
123  {
124  return _hw_monitor->send(input);
125  }
126 
128  {
130  _hw_monitor->send(cmd);
131  }
132 
134  {
135  // Stop all data streaming/exchange pipes with HW
136  stop_activity();
137  using namespace std;
138  using namespace std::chrono;
139 
140  try {
141  LOG_INFO("entering to update state, device disconnect is expected");
143  cmd.param1 = 1;
144  _hw_monitor->send(cmd);
145  std::vector<uint8_t> gvd_buff(HW_MONITOR_BUFFER_SIZE);
146  for (auto i = 0; i < 50; i++)
147  {
148  _hw_monitor->get_gvd(gvd_buff.size(), gvd_buff.data(), ds::GVD);
149  this_thread::sleep_for(milliseconds(50));
150  }
151  throw std::runtime_error("Device still connected!");
152 
153  }
154  catch (std::exception& e)
155  {
156  LOG_WARNING(e.what());
157  }
158  catch (...) {
159  // The set command returns a failure because switching to DFU resets the device while the command is running.
160  }
161  }
162 
164  {
165  int flash_size = 1024 * 2048;
166  int max_bulk_size = 1016;
167  int max_iterations = int(flash_size / max_bulk_size + 1);
168 
169  std::vector<uint8_t> flash;
170  flash.reserve(flash_size);
171 
172  LOG_DEBUG("Flash backup started...");
173  uvc_sensor& raw_depth_sensor = get_raw_depth_sensor();
174  raw_depth_sensor.invoke_powered([&](platform::uvc_device& dev)
175  {
176  for (int i = 0; i < max_iterations; i++)
177  {
178  int offset = max_bulk_size * i;
179  int size = max_bulk_size;
180  if (i == max_iterations - 1)
181  {
182  size = flash_size - offset;
183  }
184 
185  bool appended = false;
186 
187  const int retries = 3;
188  for (int j = 0; j < retries && !appended; j++)
189  {
190  try
191  {
193  cmd.param1 = offset;
194  cmd.param2 = size;
195  auto res = _hw_monitor->send(cmd);
196 
197  flash.insert(flash.end(), res.begin(), res.end());
198  appended = true;
199  LOG_DEBUG("Flash backup - " << flash.size() << "/" << flash_size << " bytes downloaded");
200  }
201  catch (...)
202  {
203  if (i < retries - 1) std::this_thread::sleep_for(std::chrono::milliseconds(100));
204  else throw;
205  }
206  }
207 
208  if (callback) callback->on_update_progress((float)i / max_iterations);
209  }
210  if (callback) callback->on_update_progress(1.0);
211  });
212 
213  return flash;
214  }
215 
216  void update_flash_section(std::shared_ptr<hw_monitor> hwm, const std::vector<uint8_t>& image, uint32_t offset, uint32_t size, update_progress_callback_ptr callback, float continue_from, float ratio)
217  {
218  size_t sector_count = size / ds::FLASH_SECTOR_SIZE;
219  size_t first_sector = offset / ds::FLASH_SECTOR_SIZE;
220 
221  if (sector_count * ds::FLASH_SECTOR_SIZE != size)
222  sector_count++;
223 
224  sector_count += first_sector;
225 
226  for (auto sector_index = first_sector; sector_index < sector_count; sector_index++)
227  {
228  command cmdFES(ds::FES);
229  cmdFES.require_response = false;
230  cmdFES.param1 = (int)sector_index;
231  cmdFES.param2 = 1;
232  auto res = hwm->send(cmdFES);
233 
234  for (int i = 0; i < ds::FLASH_SECTOR_SIZE; )
235  {
236  auto index = sector_index * ds::FLASH_SECTOR_SIZE + i;
237  if (index >= offset + size)
238  break;
239  int packet_size = std::min((int)(HW_MONITOR_COMMAND_SIZE - (i % HW_MONITOR_COMMAND_SIZE)), (int)(ds::FLASH_SECTOR_SIZE - i));
240  command cmdFWB(ds::FWB);
241  cmdFWB.require_response = false;
242  cmdFWB.param1 = (int)index;
243  cmdFWB.param2 = packet_size;
244  cmdFWB.data.assign(image.data() + index, image.data() + index + packet_size);
245  res = hwm->send(cmdFWB);
246  i += packet_size;
247  }
248 
249  if (callback)
250  callback->on_update_progress(continue_from + (float)sector_index / (float)sector_count * ratio);
251  }
252  }
253 
254  void update_section(std::shared_ptr<hw_monitor> hwm, const std::vector<uint8_t>& merged_image, flash_section fs, uint32_t tables_size,
255  update_progress_callback_ptr callback, float continue_from, float ratio)
256  {
257  auto first_table_offset = fs.tables.front().offset;
258  float total_size = float(fs.app_size + tables_size);
259 
260  float app_ratio = fs.app_size / total_size * ratio;
261  float tables_ratio = tables_size / total_size * ratio;
262 
263  update_flash_section(hwm, merged_image, fs.offset, fs.app_size, callback, continue_from, app_ratio);
264  update_flash_section(hwm, merged_image, first_table_offset, tables_size, callback, app_ratio, tables_ratio);
265  }
266 
267  void update_flash_internal(std::shared_ptr<hw_monitor> hwm, const std::vector<uint8_t>& image, std::vector<uint8_t>& flash_backup, update_progress_callback_ptr callback, int update_mode)
268  {
269  auto flash_image_info = ds::get_flash_info(image);
270  auto flash_backup_info = ds::get_flash_info(flash_backup);
271  auto merged_image = merge_images(flash_backup_info, flash_image_info, image);
272 
273  // update read-write section
274  auto first_table_offset = flash_image_info.read_write_section.tables.front().offset;
275  auto tables_size = flash_image_info.header.read_write_start_address + flash_image_info.header.read_write_size - first_table_offset;
276  update_section(hwm, merged_image, flash_image_info.read_write_section, tables_size, callback, 0, update_mode == RS2_UNSIGNED_UPDATE_MODE_READ_ONLY ? 0.5f : 1.0f);
277 
278  if (update_mode == RS2_UNSIGNED_UPDATE_MODE_READ_ONLY)
279  {
280  // update read-only section
281  auto first_table_offset = flash_image_info.read_only_section.tables.front().offset;
282  auto tables_size = flash_image_info.header.read_only_start_address + flash_image_info.header.read_only_size - first_table_offset;
283  update_section(hwm, merged_image, flash_image_info.read_only_section, tables_size, callback, 0.5, 0.5);
284  }
285  }
286 
287  void ds5_device::update_flash(const std::vector<uint8_t>& image, update_progress_callback_ptr callback, int update_mode)
288  {
289  if (_is_locked)
290  throw std::runtime_error("this camera is locked and doesn't allow direct flash write, for firmware update use rs2_update_firmware method (DFU)");
291 
292  auto& raw_depth_sensor = get_raw_depth_sensor();
293  raw_depth_sensor.invoke_powered([&](platform::uvc_device& dev)
294  {
295  command cmdPFD(ds::PFD);
296  cmdPFD.require_response = false;
297  auto res = _hw_monitor->send(cmdPFD);
298 
299  switch (update_mode)
300  {
302  update_flash_section(_hw_monitor, image, 0, ds::FLASH_SIZE, callback, 0, 1.0);
303  break;
306  {
307  auto flash_backup = backup_flash(nullptr);
308  update_flash_internal(_hw_monitor, image, flash_backup, callback, update_mode);
309  break;
310  }
311  default:
312  throw std::runtime_error("invalid update mode value");
313  }
314 
315  if (callback) callback->on_update_progress(1.0);
316 
317  command cmdHWRST(ds::HWRST);
318  res = _hw_monitor->send(cmdHWRST);
319  });
320  }
321 
323  {
324  public:
325  explicit ds5_depth_sensor(ds5_device* owner,
326  std::shared_ptr<uvc_sensor> uvc_sensor)
327  : synthetic_sensor(ds::DEPTH_STEREO, uvc_sensor, owner, ds5_depth_fourcc_to_rs2_format, ds5_depth_fourcc_to_rs2_stream),
328  _owner(owner),
329  _depth_units(-1),
330  _hdr_cfg(nullptr)
331  { }
332 
334  {
336  };
337 
339  {
341 
342  if (ds::try_get_intrinsic_by_resolution_new(*_owner->_new_calib_table_raw,
343  profile.width, profile.height, &result))
344  {
345  return result;
346  }
347  else
348  {
350  *_owner->_coefficients_table_raw,
352  profile.width, profile.height);
353  }
354  }
355 
356  void open(const stream_profiles& requests) override
357  {
358  _depth_units = get_option(RS2_OPTION_DEPTH_UNITS).query();
359  synthetic_sensor::open(requests);
360 
361  // needed in order to restore the HDR sub-preset when streaming is turned off and on
362  if (_hdr_cfg && _hdr_cfg->is_enabled())
363  get_option(RS2_OPTION_HDR_ENABLED).set(1.f);
364 
365  // Activate Thermal Compensation tracking
366  if (supports_option(RS2_OPTION_THERMAL_COMPENSATION))
367  _owner->_thermal_monitor->update(true);
368  }
369 
370  void close() override
371  {
372  // Deactivate Thermal Compensation tracking
373  if (supports_option(RS2_OPTION_THERMAL_COMPENSATION))
374  _owner->_thermal_monitor->update(false);
375 
377  }
378 
379  /*
380  Infrared profiles are initialized with the following logic:
381  - If device has color sensor (D415 / D435), infrared profile is chosen with Y8 format
382  - If device does not have color sensor:
383  * if it is a rolling shutter device (D400 / D410 / D415 / D405), infrared profile is chosen with RGB8 format
384  * for other devices (D420 / D430), infrared profile is chosen with Y8 format
385  */
387  {
389 
390  auto&& results = synthetic_sensor::init_stream_profiles();
391 
392  for (auto&& p : results)
393  {
394  // Register stream types
395  if (p->get_stream_type() == RS2_STREAM_DEPTH)
396  {
397  assign_stream(_owner->_depth_stream, p);
398  }
399  else if (p->get_stream_type() == RS2_STREAM_INFRARED && p->get_stream_index() < 2)
400  {
401  assign_stream(_owner->_left_ir_stream, p);
402  }
403  else if (p->get_stream_type() == RS2_STREAM_INFRARED && p->get_stream_index() == 2)
404  {
405  assign_stream(_owner->_right_ir_stream, p);
406  }
407  else if (p->get_stream_type() == RS2_STREAM_COLOR)
408  {
409  assign_stream(_owner->_color_stream, p);
410  }
411  auto&& vid_profile = dynamic_cast<video_stream_profile_interface*>(p.get());
412 
413  // Register intrinsics
414  if (p->get_format() != RS2_FORMAT_Y16) // Y16 format indicate unrectified images, no intrinsics are available for these
415  {
416  const auto&& profile = to_profile(p.get());
417  std::weak_ptr<ds5_depth_sensor> wp =
418  std::dynamic_pointer_cast<ds5_depth_sensor>(this->shared_from_this());
419  vid_profile->set_intrinsics([profile, wp]()
420  {
421  auto sp = wp.lock();
422  if (sp)
423  return sp->get_intrinsics(profile);
424  else
425  return rs2_intrinsics{};
426  });
427  }
428  }
429 
430  return results;
431  }
432 
433  float get_depth_scale() const override
434  {
435  if (_depth_units < 0)
436  _depth_units = get_option(RS2_OPTION_DEPTH_UNITS).query();
437  return _depth_units;
438  }
439 
440  void set_depth_scale(float val){ _depth_units = val; }
441 
442  void init_hdr_config(const option_range& exposure_range, const option_range& gain_range)
443  {
444  _hdr_cfg = std::make_shared<hdr_config>(*(_owner->_hw_monitor), get_raw_sensor(),
445  exposure_range, gain_range);
446  }
447 
448  std::shared_ptr<hdr_config> get_hdr_config() { return _hdr_cfg; }
449 
450  float get_stereo_baseline_mm() const override { return _owner->get_stereo_baseline_mm(); }
451 
452  void create_snapshot(std::shared_ptr<depth_sensor>& snapshot) const override
453  {
454  snapshot = std::make_shared<depth_sensor_snapshot>(get_depth_scale());
455  }
456 
457  void create_snapshot(std::shared_ptr<depth_stereo_sensor>& snapshot) const override
458  {
459  snapshot = std::make_shared<depth_stereo_sensor_snapshot>(get_depth_scale(), get_stereo_baseline_mm());
460  }
461 
462  void enable_recording(std::function<void(const depth_sensor&)> recording_function) override
463  {
464  //does not change over time
465  }
466 
467  void enable_recording(std::function<void(const depth_stereo_sensor&)> recording_function) override
468  {
469  //does not change over time
470  }
471  protected:
473  mutable std::atomic<float> _depth_units;
475  std::shared_ptr<hdr_config> _hdr_cfg;
476  };
477 
479  {
480  public:
482  std::shared_ptr<uvc_sensor> uvc_sensor)
483  : ds5_depth_sensor(owner, uvc_sensor), _owner(owner)
484  {}
485 
487  {
489 
490  auto&& results = synthetic_sensor::init_stream_profiles();
491 
492  for (auto&& p : results)
493  {
494  // Register stream types
495  if (p->get_stream_type() == RS2_STREAM_DEPTH)
496  {
497  assign_stream(_owner->_depth_stream, p);
498  }
499  else if (p->get_stream_type() == RS2_STREAM_INFRARED && p->get_stream_index() < 2)
500  {
501  assign_stream(_owner->_left_ir_stream, p);
502  }
503  else if (p->get_stream_type() == RS2_STREAM_INFRARED && p->get_stream_index() == 2)
504  {
505  assign_stream(_owner->_right_ir_stream, p);
506  }
507  else if (p->get_stream_type() == RS2_STREAM_COLOR)
508  {
509  assign_stream(_owner->_color_stream, p);
510  }
511  auto&& video = dynamic_cast<video_stream_profile_interface*>(p.get());
512 
513  // Register intrinsics
514  if (p->get_format() != RS2_FORMAT_Y16) // Y16 format indicate unrectified images, no intrinsics are available for these
515  {
516  const auto&& profile = to_profile(p.get());
517  std::weak_ptr<ds5_depth_sensor> wp = std::dynamic_pointer_cast<ds5_depth_sensor>(this->shared_from_this());
518  video->set_intrinsics([profile, wp]()
519  {
520  auto sp = wp.lock();
521  if (sp)
522  return sp->get_intrinsics(profile);
523  else
524  return rs2_intrinsics{};
525  });
526  }
527  }
528 
529  return results;
530  }
531 
532  private:
534  };
535 
537  {
540  auto ret = _hw_monitor->send(cmd);
541  if (ret.empty())
542  throw invalid_value_exception("command result is empty!");
543 
544  return (0 != ret.front());
545  }
546 
548  {
549  using namespace ds;
550  auto table = check_calib<coefficients_table>(*_coefficients_table_raw);
551  return fabs(table->baseline);
552  }
553 
555  {
556  command cmd(ds::GETINTCAL, table_id);
557  return _hw_monitor->send(cmd);
558  }
559 
560  std::vector<uint8_t> ds5_device::get_new_calibration_table() const
561  {
562  if (_fw_version >= firmware_version("5.11.9.5"))
563  {
565  return _hw_monitor->send(cmd);
566  }
567  return {};
568  }
569 
571  {
572  using namespace ds;
573  std::array<unsigned char,HW_MONITOR_BUFFER_SIZE> gvd_buf;
574  _hw_monitor->get_gvd(gvd_buf.size(), gvd_buf.data(), GVD);
575 
576  // Opaque retrieval
577  d400_caps val{d400_caps::CAP_UNDEFINED};
578  if (gvd_buf[active_projector]) // DepthActiveMode
579  val |= d400_caps::CAP_ACTIVE_PROJECTOR;
580  if (gvd_buf[rgb_sensor]) // WithRGB
581  val |= d400_caps::CAP_RGB_SENSOR;
582  if (gvd_buf[imu_sensor])
583  {
584  val |= d400_caps::CAP_IMU_SENSOR;
585  if (gvd_buf[imu_acc_chip_id] == I2C_IMU_BMI055_ID_ACC)
586  val |= d400_caps::CAP_BMI_055;
587  else if (gvd_buf[imu_acc_chip_id] == I2C_IMU_BMI085_ID_ACC)
588  val |= d400_caps::CAP_BMI_085;
589  else if (hid_bmi_055_pid.end() != hid_bmi_055_pid.find(_pid))
590  val |= d400_caps::CAP_BMI_055;
591  else if (hid_bmi_085_pid.end() != hid_bmi_085_pid.find(_pid))
592  val |= d400_caps::CAP_BMI_085;
593  else
594  LOG_WARNING("The IMU sensor is undefined for PID " << std::hex << _pid << " and imu_chip_id: " << gvd_buf[imu_acc_chip_id] << std::dec);
595  }
596  if (0xFF != (gvd_buf[fisheye_sensor_lb] & gvd_buf[fisheye_sensor_hb]))
597  val |= d400_caps::CAP_FISHEYE_SENSOR;
598  if (0x1 == gvd_buf[depth_sensor_type])
599  val |= d400_caps::CAP_ROLLING_SHUTTER; // e.g. ASRC
600  if (0x2 == gvd_buf[depth_sensor_type])
601  val |= d400_caps::CAP_GLOBAL_SHUTTER; // e.g. AWGC
602 
603  return val;
604  }
605 
606  std::shared_ptr<synthetic_sensor> ds5_device::create_depth_device(std::shared_ptr<context> ctx,
607  const std::vector<platform::uvc_device_info>& all_device_infos)
608  {
609  using namespace ds;
610 
611  auto&& backend = ctx->get_backend();
612 
613  std::vector<std::shared_ptr<platform::uvc_device>> depth_devices;
614  for (auto&& info : filter_by_mi(all_device_infos, 0)) // Filter just mi=0, DEPTH
615  depth_devices.push_back(backend.create_uvc_device(info));
616 
617  std::unique_ptr<frame_timestamp_reader> timestamp_reader_backup(new ds5_timestamp_reader(backend.create_time_service()));
618  std::unique_ptr<frame_timestamp_reader> timestamp_reader_metadata(new ds5_timestamp_reader_from_metadata(std::move(timestamp_reader_backup)));
619  auto enable_global_time_option = std::shared_ptr<global_time_option>(new global_time_option());
620  auto raw_depth_ep = std::make_shared<uvc_sensor>("Raw Depth Sensor", std::make_shared<platform::multi_pins_uvc_device>(depth_devices),
621  std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(timestamp_reader_metadata), _tf_keeper, enable_global_time_option)), this);
622 
623  raw_depth_ep->register_xu(depth_xu); // make sure the XU is initialized every time we power the camera
624 
625  auto depth_ep = std::make_shared<ds5_depth_sensor>(this, raw_depth_ep);
626 
627  depth_ep->register_info(RS2_CAMERA_INFO_PHYSICAL_PORT, filter_by_mi(all_device_infos, 0).front().device_path);
628 
629  depth_ep->register_option(RS2_OPTION_GLOBAL_TIME_ENABLED, enable_global_time_option);
630 
631  depth_ep->register_processing_block(processing_block_factory::create_id_pbf(RS2_FORMAT_Y8, RS2_STREAM_INFRARED, 1));
632  depth_ep->register_processing_block(processing_block_factory::create_id_pbf(RS2_FORMAT_Z16, RS2_STREAM_DEPTH));
633 
634  depth_ep->register_processing_block({ {RS2_FORMAT_W10} }, { {RS2_FORMAT_RAW10, RS2_STREAM_INFRARED, 1} }, []() { return std::make_shared<w10_converter>(RS2_FORMAT_RAW10); });
635  depth_ep->register_processing_block({ {RS2_FORMAT_W10} }, { {RS2_FORMAT_Y10BPACK, RS2_STREAM_INFRARED, 1} }, []() { return std::make_shared<w10_converter>(RS2_FORMAT_Y10BPACK); });
636 
637  return depth_ep;
638  }
639 
640  ds5_device::ds5_device(std::shared_ptr<context> ctx,
642  : device(ctx, group), global_time_interface(),
644  _device_capabilities(ds::d400_caps::CAP_UNDEFINED),
645  _depth_stream(new stream(RS2_STREAM_DEPTH)),
646  _left_ir_stream(new stream(RS2_STREAM_INFRARED, 1)),
647  _right_ir_stream(new stream(RS2_STREAM_INFRARED, 2)),
648  _color_stream(nullptr)
649  {
651  init(ctx, group);
652  }
653 
654  void ds5_device::init(std::shared_ptr<context> ctx,
656  {
657  using namespace ds;
658 
659  auto&& backend = ctx->get_backend();
660  auto& raw_sensor = get_raw_depth_sensor();
661  auto pid = group.uvc_devices.front().pid;
662 
663  if (((hw_mon_over_xu) && (RS400_IMU_PID != pid)) || (!group.usb_devices.size()))
664  {
665  _hw_monitor = std::make_shared<hw_monitor>(
666  std::make_shared<locked_transfer>(
667  std::make_shared<command_transfer_over_xu>(
668  raw_sensor, depth_xu, DS5_HWMONITOR),
669  raw_sensor));
670  }
671  else
672  {
673  _hw_monitor = std::make_shared<hw_monitor>(
674  std::make_shared<locked_transfer>(
675  backend.create_usb_device(group.usb_devices.front()), raw_sensor));
676  }
677 
678  // Define Left-to-Right extrinsics calculation (lazy)
679  // Reference CS - Right-handed; positive [X,Y,Z] point to [Left,Up,Forward] accordingly.
680  _left_right_extrinsics = std::make_shared<lazy<rs2_extrinsics>>([this]()
681  {
683  auto table = check_calib<coefficients_table>(*_coefficients_table_raw);
684  ext.translation[0] = 0.001f * table->baseline; // mm to meters
685  return ext;
686  });
687 
690 
694 
696  _new_calib_table_raw = [this]() { return get_new_calibration_table(); };
697 
698  _pid = group.uvc_devices.front().pid;
699  std::string device_name = (rs400_sku_names.end() != rs400_sku_names.find(_pid)) ? rs400_sku_names.at(_pid) : "RS4xx";
700 
701  std::vector<uint8_t> gvd_buff(HW_MONITOR_BUFFER_SIZE);
702  _hw_monitor->get_gvd(gvd_buff.size(), gvd_buff.data(), GVD);
703 
704  auto optic_serial = _hw_monitor->get_module_serial_string(gvd_buff, module_serial_offset);
705  auto asic_serial = _hw_monitor->get_module_serial_string(gvd_buff, module_asic_serial_offset);
706  auto fwv = _hw_monitor->get_firmware_version_string(gvd_buff, camera_fw_version_offset);
708 
710  if (_fw_version >= firmware_version("5.10.4.0"))
712 
713  auto& depth_sensor = get_depth_sensor();
714  auto& raw_depth_sensor = get_raw_depth_sensor();
715 
716  auto advanced_mode = is_camera_in_advanced_mode();
717 
718  using namespace platform;
719  auto _usb_mode = usb3_type;
720  std::string usb_type_str(usb_spec_names.at(_usb_mode));
721  bool usb_modality = (_fw_version >= firmware_version("5.9.8.0"));
722  if (usb_modality)
723  {
724  _usb_mode = raw_depth_sensor.get_usb_specification();
725  if (usb_spec_names.count(_usb_mode) && (usb_undefined != _usb_mode))
726  usb_type_str = usb_spec_names.at(_usb_mode);
727  else // Backend fails to provide USB descriptor - occurs with RS3 build. Requires further work
728  usb_modality = false;
729  }
730 
731  if (_fw_version >= firmware_version("5.12.1.1"))
732  {
734  }
735 
736 
737  depth_sensor.register_processing_block(
738  { {RS2_FORMAT_Y8I} },
740  []() { return std::make_shared<y8i_to_y8y8>(); }
741  ); // L+R
742 
743  depth_sensor.register_processing_block(
744  { RS2_FORMAT_Y12I },
746  []() {return std::make_shared<y12i_to_y16y16>(); }
747  );
748 
749  auto pid_hex_str = hexify(_pid);
750 
751  if ((_pid == RS416_PID || _pid == RS416_RGB_PID) && _fw_version >= firmware_version("5.12.0.1"))
752  {
754  std::make_shared<uvc_xu_option<uint8_t>>(raw_depth_sensor, depth_xu, DS5_HARDWARE_PRESET,
755  "Hardware pipe configuration"));
756  depth_sensor.register_option(RS2_OPTION_LED_POWER,
757  std::make_shared<uvc_xu_option<uint16_t>>(raw_depth_sensor, depth_xu, DS5_LED_PWR,
758  "Set the power level of the LED, with 0 meaning LED off"));
759  }
760 
761 
762  if (_fw_version >= firmware_version("5.6.3.0"))
763  {
764  _is_locked = _hw_monitor->is_camera_locked(GVD, is_camera_locked_offset);
765  }
766 
767  if (_fw_version >= firmware_version("5.5.8.0"))
768  {
770  std::make_shared<uvc_xu_option<uint8_t>>(raw_depth_sensor, depth_xu, DS5_EXT_TRIGGER,
771  "Generate trigger from the camera to external device once per frame"));
772 
773  auto error_control = std::make_shared<uvc_xu_option<uint8_t>>(raw_depth_sensor, depth_xu, DS5_ERROR_REPORTING, "Error reporting");
774 
775  _polling_error_handler = std::make_shared<polling_error_handler>(1000,
776  error_control,
777  raw_depth_sensor.get_notifications_processor(),
778  std::make_shared<ds5_notification_decoder>());
779 
780  depth_sensor.register_option(RS2_OPTION_ERROR_POLLING_ENABLED, std::make_shared<polling_errors_disable>(_polling_error_handler));
781 
783  std::make_shared<asic_and_projector_temperature_options>(raw_depth_sensor,
785  }
786 
787  if ((val_in_range(pid, { RS455_PID })) && (_fw_version >= firmware_version("5.12.11.0")))
788  {
789  auto thermal_compensation_toggle = std::make_shared<protected_xu_option<uint8_t>>(raw_depth_sensor, depth_xu,
790  ds::DS5_THERMAL_COMPENSATION, "Toggle Thermal Compensation Mechanism");
791 
792  auto temperature_sensor = depth_sensor.get_option_handler(RS2_OPTION_ASIC_TEMPERATURE);
793 
794  _thermal_monitor = std::make_shared<ds5_thermal_monitor>(temperature_sensor, thermal_compensation_toggle);
795 
797  std::make_shared<thermal_compensation>(_thermal_monitor,thermal_compensation_toggle));
798 
799  }
800  // minimal firmware version in which hdr feature is supported
801  firmware_version hdr_firmware_version("5.12.8.100");
802 
803  std::shared_ptr<option> exposure_option = nullptr;
804  std::shared_ptr<option> gain_option = nullptr;
805  std::shared_ptr<hdr_option> hdr_enabled_option = nullptr;
806 
807  //EXPOSURE AND GAIN - preparing uvc options
808  auto uvc_xu_exposure_option = std::make_shared<uvc_xu_option<uint32_t>>(raw_depth_sensor,
809  depth_xu,
810  DS5_EXPOSURE,
811  "Depth Exposure (usec)");
812  option_range exposure_range = uvc_xu_exposure_option->get_range();
813  auto uvc_pu_gain_option = std::make_shared<uvc_pu_option>(raw_depth_sensor, RS2_OPTION_GAIN);
814  option_range gain_range = uvc_pu_gain_option->get_range();
815 
816  //AUTO EXPOSURE
817  auto enable_auto_exposure = std::make_shared<uvc_xu_option<uint8_t>>(raw_depth_sensor,
818  depth_xu,
820  "Enable Auto Exposure");
821  depth_sensor.register_option(RS2_OPTION_ENABLE_AUTO_EXPOSURE, enable_auto_exposure);
822 
823  // register HDR options
824  //auto global_shutter_mask = d400_caps::CAP_GLOBAL_SHUTTER;
825  if ((_fw_version >= hdr_firmware_version))// && ((_device_capabilities & global_shutter_mask) == global_shutter_mask) )
826  {
827  auto ds5_depth = As<ds5_depth_sensor, synthetic_sensor>(&get_depth_sensor());
828  ds5_depth->init_hdr_config(exposure_range, gain_range);
829  auto&& hdr_cfg = ds5_depth->get_hdr_config();
830 
831  // values from 4 to 14 - for internal use
832  // value 15 - saved for emiter on off subpreset
833  option_range hdr_id_range = { 0.f /*min*/, 3.f /*max*/, 1.f /*step*/, 1.f /*default*/ };
834  auto hdr_id_option = std::make_shared<hdr_option>(hdr_cfg, RS2_OPTION_SEQUENCE_NAME, hdr_id_range,
835  std::map<float, std::string>{ {0.f, "0"}, { 1.f, "1" }, { 2.f, "2" }, { 3.f, "3" } });
836  depth_sensor.register_option(RS2_OPTION_SEQUENCE_NAME, hdr_id_option);
837 
838  option_range hdr_sequence_size_range = { 2.f /*min*/, 2.f /*max*/, 1.f /*step*/, 2.f /*default*/ };
839  auto hdr_sequence_size_option = std::make_shared<hdr_option>(hdr_cfg, RS2_OPTION_SEQUENCE_SIZE, hdr_sequence_size_range,
840  std::map<float, std::string>{ { 2.f, "2" } });
841  depth_sensor.register_option(RS2_OPTION_SEQUENCE_SIZE, hdr_sequence_size_option);
842 
843  option_range hdr_sequ_id_range = { 0.f /*min*/, 2.f /*max*/, 1.f /*step*/, 0.f /*default*/ };
844  auto hdr_sequ_id_option = std::make_shared<hdr_option>(hdr_cfg, RS2_OPTION_SEQUENCE_ID, hdr_sequ_id_range,
845  std::map<float, std::string>{ {0.f, "UVC"}, { 1.f, "1" }, { 2.f, "2" } });
846  depth_sensor.register_option(RS2_OPTION_SEQUENCE_ID, hdr_sequ_id_option);
847 
848  option_range hdr_enable_range = { 0.f /*min*/, 1.f /*max*/, 1.f /*step*/, 0.f /*default*/ };
849  hdr_enabled_option = std::make_shared<hdr_option>(hdr_cfg, RS2_OPTION_HDR_ENABLED, hdr_enable_range);
850  depth_sensor.register_option(RS2_OPTION_HDR_ENABLED, hdr_enabled_option);
851 
852  //EXPOSURE AND GAIN - preparing hdr options
853  auto hdr_exposure_option = std::make_shared<hdr_option>(hdr_cfg, RS2_OPTION_EXPOSURE, exposure_range);
854  auto hdr_gain_option = std::make_shared<hdr_option>(hdr_cfg, RS2_OPTION_GAIN, gain_range);
855 
856  //EXPOSURE AND GAIN - preparing hybrid options
857  auto hdr_conditional_exposure_option = std::make_shared<hdr_conditional_option>(hdr_cfg, uvc_xu_exposure_option, hdr_exposure_option);
858  auto hdr_conditional_gain_option = std::make_shared<hdr_conditional_option>(hdr_cfg, uvc_pu_gain_option, hdr_gain_option);
859 
860  exposure_option = hdr_conditional_exposure_option;
861  gain_option = hdr_conditional_gain_option;
862 
863  std::vector<std::pair<std::shared_ptr<option>, std::string>> options_and_reasons = { std::make_pair(hdr_enabled_option,
864  "Auto Exposure cannot be set while HDR is enabled") };
866  std::make_shared<gated_option>(
867  enable_auto_exposure,
868  options_and_reasons));
869  }
870  else
871  {
872  exposure_option = uvc_xu_exposure_option;
873  gain_option = uvc_pu_gain_option;
874  }
875 
876  //EXPOSURE
877  depth_sensor.register_option(RS2_OPTION_EXPOSURE,
878  std::make_shared<auto_disabling_control>(
879  exposure_option,
880  enable_auto_exposure));
881 
882  //GAIN
883  depth_sensor.register_option(RS2_OPTION_GAIN,
884  std::make_shared<auto_disabling_control>(
885  gain_option,
886  enable_auto_exposure));
887 
888  // Alternating laser pattern is applicable for global shutter/active SKUs
889  auto mask = d400_caps::CAP_GLOBAL_SHUTTER | d400_caps::CAP_ACTIVE_PROJECTOR;
890  // Alternating laser pattern should be set and query in a different way according to the firmware version
891  bool is_fw_version_using_id = (_fw_version >= firmware_version("5.12.8.100"));
892  if ((_fw_version >= firmware_version("5.11.3.0")) && ((_device_capabilities & mask) == mask))
893  {
894  auto alternating_emitter_opt = std::make_shared<alternating_emitter_option>(*_hw_monitor, &raw_depth_sensor, is_fw_version_using_id);
895  auto emitter_always_on_opt = std::make_shared<emitter_always_on_option>(*_hw_monitor, &depth_sensor);
896 
897  if ((_fw_version >= firmware_version("5.12.1.0")) && ((_device_capabilities & d400_caps::CAP_GLOBAL_SHUTTER) == d400_caps::CAP_GLOBAL_SHUTTER))
898  {
899  std::vector<std::pair<std::shared_ptr<option>, std::string>> options_and_reasons = { std::make_pair(alternating_emitter_opt,
900  "Emitter always ON cannot be set while Emitter ON/OFF is enabled")};
902  std::make_shared<gated_option>(
903  emitter_always_on_opt,
904  options_and_reasons));
905  }
906 
907  if (_fw_version >= hdr_firmware_version)
908  {
909  std::vector<std::pair<std::shared_ptr<option>, std::string>> options_and_reasons = { std::make_pair(hdr_enabled_option, "Emitter ON/OFF cannot be set while HDR is enabled"),
910  std::make_pair(emitter_always_on_opt, "Emitter ON/OFF cannot be set while Emitter always ON is enabled") };
911  depth_sensor.register_option(RS2_OPTION_EMITTER_ON_OFF,
912  std::make_shared<gated_option>(
913  alternating_emitter_opt,
914  options_and_reasons
915  ));
916  }
917  else if ((_fw_version >= firmware_version("5.12.1.0")) && ((_device_capabilities & d400_caps::CAP_GLOBAL_SHUTTER) == d400_caps::CAP_GLOBAL_SHUTTER))
918  {
919  std::vector<std::pair<std::shared_ptr<option>, std::string>> options_and_reasons = { std::make_pair(emitter_always_on_opt,
920  "Emitter ON/OFF cannot be set while Emitter always ON is enabled") };
921  depth_sensor.register_option(RS2_OPTION_EMITTER_ON_OFF,
922  std::make_shared<gated_option>(
923  alternating_emitter_opt,
924  options_and_reasons));
925  }
926  else
927  {
928  depth_sensor.register_option(RS2_OPTION_EMITTER_ON_OFF, alternating_emitter_opt);
929  }
930  }
931  else if (_fw_version >= firmware_version("5.10.9.0") &&
932  _fw_version.experimental()) // Not yet available in production firmware
933  {
934  depth_sensor.register_option(RS2_OPTION_EMITTER_ON_OFF, std::make_shared<emitter_on_and_off_option>(*_hw_monitor, &raw_depth_sensor));
935  }
936 
937  if (_fw_version >= firmware_version("5.12.12.100") && (_device_capabilities & d400_caps::CAP_GLOBAL_SHUTTER) == d400_caps::CAP_GLOBAL_SHUTTER)
938  {
940  std::make_shared<external_sync_mode>(*_hw_monitor, &raw_depth_sensor, 3));
941  }
942  else if (_fw_version >= firmware_version("5.12.4.0") && (_device_capabilities & d400_caps::CAP_GLOBAL_SHUTTER) == d400_caps::CAP_GLOBAL_SHUTTER)
943  {
945  std::make_shared<external_sync_mode>(*_hw_monitor, &raw_depth_sensor, 2));
946  }
947  else if (_fw_version >= firmware_version("5.9.15.1"))
948  {
950  std::make_shared<external_sync_mode>(*_hw_monitor, &raw_depth_sensor, 1));
951  }
952 
953 
954  roi_sensor_interface* roi_sensor = dynamic_cast<roi_sensor_interface*>(&depth_sensor);
955  if (roi_sensor)
956  roi_sensor->set_roi_method(std::make_shared<ds5_auto_exposure_roi_method>(*_hw_monitor));
957 
958  depth_sensor.register_option(RS2_OPTION_STEREO_BASELINE, std::make_shared<const_value_option>("Distance in mm between the stereo imagers",
959  lazy<float>([this]() { return get_stereo_baseline_mm(); })));
960 
961  if (advanced_mode && _fw_version >= firmware_version("5.6.3.0"))
962  {
963  auto depth_scale = std::make_shared<depth_scale_option>(*_hw_monitor);
964  auto depth_sensor = As<ds5_depth_sensor, synthetic_sensor>(&get_depth_sensor());
966 
967  depth_scale->add_observer([depth_sensor](float val)
968  {
969  depth_sensor->set_depth_scale(val);
970  });
971 
973  }
974  else
975  depth_sensor.register_option(RS2_OPTION_DEPTH_UNITS, std::make_shared<const_value_option>("Number of meters represented by a single depth unit",
976  lazy<float>([]() { return 0.001f; })));
977  // Metadata registration
979 
980  // Auto exposure and gain limit
981  if (_fw_version >= firmware_version("5.12.10.11"))
982  {
983  auto exposure_range = depth_sensor.get_option(RS2_OPTION_EXPOSURE).get_range();
984  auto gain_range = depth_sensor.get_option(RS2_OPTION_GAIN).get_range();
985  depth_sensor.register_option(RS2_OPTION_AUTO_EXPOSURE_LIMIT, std::make_shared<auto_exposure_limit_option>(*_hw_monitor, &depth_sensor, exposure_range));
986  depth_sensor.register_option(RS2_OPTION_AUTO_GAIN_LIMIT, std::make_shared<auto_gain_limit_option>(*_hw_monitor, &depth_sensor, gain_range));
987  }
988 
989  // attributes of md_capture_timing
990  auto md_prop_offset = offsetof(metadata_raw, mode) +
991  offsetof(md_depth_mode, depth_y_mode) +
992  offsetof(md_depth_y_normal_mode, intel_capture_timing);
993 
997 
998  // attributes of md_capture_stats
999  md_prop_offset = offsetof(metadata_raw, mode) +
1000  offsetof(md_depth_mode, depth_y_mode) +
1001  offsetof(md_depth_y_normal_mode, intel_capture_stats);
1002 
1004 
1005  // attributes of md_depth_control
1006  md_prop_offset = offsetof(metadata_raw, mode) +
1007  offsetof(md_depth_mode, depth_y_mode) +
1008  offsetof(md_depth_y_normal_mode, intel_depth_control);
1009 
1013 
1016  [](const rs2_metadata_type& param) { return param == 1 ? 1 : 0; })); // starting at version 2.30.1 this control is superceeded by RS2_FRAME_METADATA_FRAME_EMITTER_MODE
1024 
1025  // md_configuration - will be used for internal validation only
1026  md_prop_offset = offsetof(metadata_raw, mode) + offsetof(md_depth_mode, depth_y_mode) + offsetof(md_depth_y_normal_mode, intel_configuration);
1027 
1033  depth_sensor.register_metadata((rs2_frame_metadata_value)RS2_FRAME_METADATA_ACTUAL_FPS, std::make_shared<ds5_md_attribute_actual_fps> ());
1034 
1035  if (_fw_version >= firmware_version("5.12.7.0"))
1036  {
1038  }
1039 
1040  if (_fw_version >= hdr_firmware_version)
1041  {
1042  // attributes of md_capture_timing
1043  auto md_prop_offset = offsetof(metadata_raw, mode) + offsetof(md_depth_mode, depth_y_mode) + offsetof(md_depth_y_normal_mode, intel_configuration);
1044 
1048  [](const rs2_metadata_type& param) {
1049  // bit mask and offset used to get data from bitfield
1052  }));
1053 
1054  depth_sensor.register_metadata(RS2_FRAME_METADATA_SEQUENCE_ID,
1057  [](const rs2_metadata_type& param) {
1058  // bit mask and offset used to get data from bitfield
1061  }));
1062 
1066  [](const rs2_metadata_type& param) {
1067  // bit mask and offset used to get data from bitfield
1070  }));
1071  }
1072 
1073 
1074  register_info(RS2_CAMERA_INFO_NAME, device_name);
1079  register_info(RS2_CAMERA_INFO_PHYSICAL_PORT, group.uvc_devices.front().device_path);
1081  register_info(RS2_CAMERA_INFO_ADVANCED_MODE, ((advanced_mode) ? "YES" : "NO"));
1086 
1087  if (usb_modality)
1089 
1090  std::string curr_version= _fw_version;
1091 
1092  }
1093 
1095  {
1096  if (ds::ds5_fw_error_report.find(static_cast<uint8_t>(value)) != ds::ds5_fw_error_report.end())
1098 
1099  return{ RS2_NOTIFICATION_CATEGORY_HARDWARE_ERROR, value, RS2_LOG_SEVERITY_WARN, (to_string() << "D400 HW report - unresolved type " << value) };
1100  }
1101 
1102  void ds5_device::create_snapshot(std::shared_ptr<debug_interface>& snapshot) const
1103  {
1104  //TODO: Implement
1105  }
1106  void ds5_device::enable_recording(std::function<void(const debug_interface&)> record_action)
1107  {
1108  //TODO: Implement
1109  }
1110 
1112  {
1114  return platform::usb_undefined;
1116  for (auto u : platform::usb_spec_names)
1117  {
1118  if (u.second.compare(str) == 0)
1119  return u.first;
1120  }
1121  return platform::usb_undefined;
1122  }
1123 
1124 
1126  {
1128  //if (dynamic_cast<const platform::playback_backend*>(&(get_context()->get_backend())) != nullptr)
1129  //{
1130  // throw not_implemented_exception("device time not supported for backend.");
1131  //}
1132 
1133 #ifdef RASPBERRY_PI
1134  // TODO: This is temporary work-around since global timestamp seems to compromise RPi stability
1135  using namespace std::chrono;
1136  return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
1137 #else
1138  if (!_hw_monitor)
1139  throw wrong_api_call_sequence_exception("_hw_monitor is not initialized yet");
1140 
1142  auto res = _hw_monitor->send(cmd);
1143 
1144  if (res.size() < sizeof(uint32_t))
1145  {
1146  LOG_DEBUG("size(res):" << res.size());
1147  throw std::runtime_error("Not enough bytes returned from the firmware!");
1148  }
1149  uint32_t dt = *(uint32_t*)res.data();
1150  double ts = dt * TIMESTAMP_USEC_TO_MSEC;
1151  return ts;
1152 #endif
1153  }
1154 
1156  {
1157  return command{ ds::GLD, 0x1f4 };
1158  }
1159 
1161  {
1162  return command{ ds::FRB, 0x17a000, 0x3f8 };
1163  }
1164 
1165  std::shared_ptr<synthetic_sensor> ds5u_device::create_ds5u_depth_device(std::shared_ptr<context> ctx,
1166  const std::vector<platform::uvc_device_info>& all_device_infos)
1167  {
1168  using namespace ds;
1169 
1170  auto&& backend = ctx->get_backend();
1171 
1172  std::vector<std::shared_ptr<platform::uvc_device>> depth_devices;
1173  for (auto&& info : filter_by_mi(all_device_infos, 0)) // Filter just mi=0, DEPTH
1174  depth_devices.push_back(backend.create_uvc_device(info));
1175 
1176  std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_backup(new ds5_timestamp_reader(backend.create_time_service()));
1177  std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_metadata(new ds5_timestamp_reader_from_metadata(std::move(ds5_timestamp_reader_backup)));
1178 
1179  auto enable_global_time_option = std::shared_ptr<global_time_option>(new global_time_option());
1180  auto raw_depth_ep = std::make_shared<uvc_sensor>(ds::DEPTH_STEREO, std::make_shared<platform::multi_pins_uvc_device>(depth_devices), std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(ds5_timestamp_reader_metadata), _tf_keeper, enable_global_time_option)), this);
1181  auto depth_ep = std::make_shared<ds5u_depth_sensor>(this, raw_depth_ep);
1182 
1183  depth_ep->register_option(RS2_OPTION_GLOBAL_TIME_ENABLED, enable_global_time_option);
1184 
1185  raw_depth_ep->register_xu(depth_xu); // make sure the XU is initialized every time we power the camera
1186 
1187  depth_ep->register_processing_block({ {RS2_FORMAT_W10} }, { {RS2_FORMAT_RAW10, RS2_STREAM_INFRARED, 1} }, []() { return std::make_shared<w10_converter>(RS2_FORMAT_RAW10); });
1188  depth_ep->register_processing_block({ {RS2_FORMAT_W10} }, { {RS2_FORMAT_Y10BPACK, RS2_STREAM_INFRARED, 1} }, []() { return std::make_shared<w10_converter>(RS2_FORMAT_Y10BPACK); });
1189 
1190  depth_ep->register_processing_block(processing_block_factory::create_pbf_vector<uyvy_converter>(RS2_FORMAT_UYVY, map_supported_color_formats(RS2_FORMAT_UYVY), RS2_STREAM_INFRARED));
1191 
1192 
1193  return depth_ep;
1194  }
1195 
1196  ds5u_device::ds5u_device(std::shared_ptr<context> ctx,
1198  : ds5_device(ctx, group), device(ctx, group)
1199  {
1200  using namespace ds;
1201 
1202  // Override the basic ds5 sensor with the development version
1204 
1205  init(ctx, group);
1206 
1207  auto& depth_ep = get_depth_sensor();
1208 
1209  // Inhibit specific unresolved options
1210  depth_ep.unregister_option(RS2_OPTION_OUTPUT_TRIGGER_ENABLED);
1211  depth_ep.unregister_option(RS2_OPTION_ERROR_POLLING_ENABLED);
1212  depth_ep.unregister_option(RS2_OPTION_ASIC_TEMPERATURE);
1213  depth_ep.unregister_option(RS2_OPTION_ENABLE_AUTO_WHITE_BALANCE);
1214 
1215  // Enable laser etc.
1216  auto pid = group.uvc_devices.front().pid;
1217  if (pid != RS_USB2_PID)
1218  {
1219  auto& depth_ep = get_raw_depth_sensor();
1220  auto emitter_enabled = std::make_shared<emitter_option>(depth_ep);
1221  depth_ep.register_option(RS2_OPTION_EMITTER_ENABLED, emitter_enabled);
1222 
1223  auto laser_power = std::make_shared<uvc_xu_option<uint16_t>>(depth_ep,
1224  depth_xu,
1226  "Manual laser power in mw. applicable only when laser power mode is set to Manual");
1227  depth_ep.register_option(RS2_OPTION_LASER_POWER,
1228  std::make_shared<auto_disabling_control>(
1229  laser_power,
1230  emitter_enabled,
1231  std::vector<float>{0.f, 2.f}, 1.f));
1232 
1233  depth_ep.register_option(RS2_OPTION_PROJECTOR_TEMPERATURE,
1234  std::make_shared<asic_and_projector_temperature_options>(depth_ep,
1236  }
1237  }
1238 
1240  {
1242  res.push_back(std::make_shared<hdr_merge>()); // Requires HDR
1243  res.push_back(std::make_shared<sequence_id_filter>());
1244  res.push_back(std::make_shared<threshold>());
1245  res.push_back(std::make_shared<disparity_transform>(true));
1246  res.push_back(std::make_shared<spatial_filter>());
1247  res.push_back(std::make_shared<temporal_filter>());
1248  res.push_back(std::make_shared<hole_filling_filter>());
1249  res.push_back(std::make_shared<disparity_transform>(false));
1250  return res;
1251  }
1252 
1253 }
static const textual_icon lock
Definition: model-views.h:218
stream_profiles init_stream_profiles() override
Definition: ds5-device.cpp:486
std::shared_ptr< md_attribute_parser_base > make_rs400_sensor_ts_parser(std::shared_ptr< md_attribute_parser_base > frame_ts_parser, std::shared_ptr< md_attribute_parser_base > sensor_ts_parser)
A helper function to create a specialized parser for RS4xx sensor timestamp.
const std::string DEPTH_STEREO
Definition: ds5-private.h:331
static const double TIMESTAMP_USEC_TO_MSEC
Definition: src/types.h:92
bool try_get_intrinsic_by_resolution_new(const vector< uint8_t > &raw_data, uint32_t width, uint32_t height, rs2_intrinsics *result)
GLuint GLuint end
firmware_version _fw_version
Definition: ds5-device.h:88
void enable_recording(std::function< void(const depth_sensor &)> recording_function) override
Definition: ds5-device.cpp:462
std::shared_ptr< hw_monitor > _hw_monitor
Definition: ds5-device.h:87
const uint8_t I2C_IMU_BMI085_ID_ACC
Definition: ds5-private.h:640
const uint32_t FLASH_SIZE
Definition: ds5-private.h:167
void set(const region_of_interest &roi) override
Definition: ds5-device.cpp:91
auto invoke_powered(T action) -> decltype(action(*static_cast< platform::uvc_device * >(nullptr)))
Definition: sensor.h:343
std::shared_ptr< synthetic_sensor > create_depth_device(std::shared_ptr< context > ctx, const std::vector< platform::uvc_device_info > &all_device_infos)
Definition: ds5-device.cpp:606
void create_snapshot(std::shared_ptr< depth_sensor > &snapshot) const override
Definition: ds5-device.cpp:452
processing_blocks get_ds5_depth_recommended_proccesing_blocks()
void enable_recording(std::function< void(const debug_interface &)> record_action) override
void open(const stream_profiles &requests) override
Definition: sensor.cpp:1422
metadata_raw - metadata structure layout as transmitted and received by backend
Definition: src/metadata.h:678
ds5_depth_sensor(ds5_device *owner, std::shared_ptr< uvc_sensor > uvc_sensor)
Definition: ds5-device.cpp:325
GLfloat GLfloat p
Definition: glext.h:12687
platform::usb_spec get_usb_spec() const
const uint8_t DS5_LASER_POWER
Definition: ds5-private.h:54
float translation[3]
Definition: rs_sensor.h:99
const uint8_t DS5_EXT_TRIGGER
Definition: ds5-private.h:57
ds5u_device(std::shared_ptr< context > ctx, const platform::backend_device_group &group)
bool val_in_range(const T &val, const std::initializer_list< T > &list)
Definition: src/types.h:174
#define LOG_WARNING(...)
Definition: src/types.h:241
double dt
Definition: boing.c:106
lazy< std::vector< uint8_t > > _coefficients_table_raw
Definition: ds5-device.h:100
GLfloat value
GLint GLuint mask
virtual stream_profiles init_stream_profiles() override
Definition: sensor.cpp:1225
const uint8_t DS5_HWMONITOR
Definition: ds5-private.h:51
const uint8_t DS5_ERROR_REPORTING
Definition: ds5-private.h:56
void register_same_extrinsics(const stream_interface &from, const stream_interface &to)
Definition: environment.cpp:23
synthetic_sensor & get_depth_sensor()
Definition: ds5-device.h:41
unsigned short uint16_t
Definition: stdint.h:79
static const std::map< usb_spec, std::string > usb_spec_names
Definition: usb-types.h:124
void init_hdr_config(const option_range &exposure_range, const option_range &gain_range)
Definition: ds5-device.cpp:442
const uint8_t DS5_HARDWARE_PRESET
Definition: ds5-private.h:55
GLsizei const GLchar *const * string
void init(std::shared_ptr< context > ctx, const platform::backend_device_group &group)
Definition: ds5-device.cpp:654
const uint8_t DS5_LED_PWR
Definition: ds5-private.h:61
void update_section(std::shared_ptr< hw_monitor > hwm, const std::vector< uint8_t > &merged_image, flash_section fs, uint32_t tables_size, update_progress_callback_ptr callback, float continue_from, float ratio)
Definition: ds5-device.cpp:254
e
Definition: rmse.py:177
rs2_extrinsics identity_matrix()
Definition: src/types.h:611
void enable_recording(std::function< void(const depth_stereo_sensor &)> recording_function) override
Definition: ds5-device.cpp:467
const uint8_t DS5_THERMAL_COMPENSATION
Definition: ds5-private.h:62
GLenum GLenum GLsizei void * image
ds5_device(std::shared_ptr< context > ctx, const platform::backend_device_group &group)
Definition: ds5-device.cpp:640
GLuint index
std::shared_ptr< rs2_update_progress_callback > update_progress_callback_ptr
Definition: src/types.h:1077
#define D4XX_RECOMMENDED_FIRMWARE_VERSION
GLuint GLfloat * val
std::shared_ptr< lazy< rs2_extrinsics > > _left_right_extrinsics
Definition: ds5-device.h:105
const uint16_t RS400_IMU_PID
Definition: ds5-private.h:33
def info(name, value, persistent=False)
Definition: test.py:301
const uint16_t RS416_RGB_PID
Definition: ds5-private.h:46
std::shared_ptr< time_diff_keeper > _tf_keeper
std::shared_ptr< ds5_thermal_monitor > _thermal_monitor
Definition: ds5-device.h:104
GLdouble f
std::shared_ptr< synthetic_sensor > create_ds5u_depth_device(std::shared_ptr< context > ctx, const std::vector< platform::uvc_device_info > &all_device_infos)
void register_extrinsics(const stream_interface &from, const stream_interface &to, std::weak_ptr< lazy< rs2_extrinsics >> extr)
Definition: environment.cpp:28
GLenum mode
std::string hexify(const T &val)
Definition: src/types.h:185
void register_info(rs2_camera_info info, const std::string &val)
Definition: sensor.cpp:602
static const std::map< std::uint16_t, std::string > rs400_sku_names
Definition: ds5-private.h:128
const uint16_t RS455_PID
Definition: ds5-private.h:48
GLsizeiptr size
bool is_camera_in_advanced_mode() const
Definition: ds5-device.cpp:536
void update_flash_section(std::shared_ptr< hw_monitor > hwm, const std::vector< uint8_t > &image, uint32_t offset, uint32_t size, update_progress_callback_ptr callback, float continue_from, float ratio)
Definition: ds5-device.cpp:216
processing_blocks get_depth_recommended_proccesing_blocks()
Definition: sensor.cpp:228
stream_profiles init_stream_profiles() override
Definition: ds5-device.cpp:386
void enter_update_state() const override
Definition: ds5-device.cpp:133
#define RS2_UNSIGNED_UPDATE_MODE_UPDATE
Definition: rs_device.h:206
notification decode(int value) override
std::vector< uint8_t > send(std::vector< uint8_t > const &data) const
Definition: hw-monitor.cpp:115
unsigned int uint32_t
Definition: stdint.h:80
constexpr bool hw_mon_over_xu
Definition: ds5-device.cpp:49
std::shared_ptr< hdr_config > get_hdr_config()
Definition: ds5-device.cpp:448
GLboolean GLuint group
Definition: glext.h:5688
GLdouble GLdouble x2
int assign_sensor(const std::shared_ptr< sensor_interface > &sensor_base, uint8_t idx)
Definition: device.cpp:169
uint32_t rs_fourcc(const T a, const T b, const T c, const T d)
Definition: src/types.h:1846
#define RS2_UNSIGNED_UPDATE_MODE_READ_ONLY
Definition: rs_device.h:207
static processing_block_factory create_id_pbf(rs2_format format, rs2_stream stream, int idx=0)
std::shared_ptr< hdr_config > _hdr_cfg
Definition: ds5-device.cpp:475
std::vector< uint8_t > data
Definition: hw-monitor.h:240
std::shared_ptr< stream_interface > _depth_stream
Definition: ds5-device.h:92
ds::d400_caps parse_device_capabilities() const
Definition: ds5-device.cpp:570
def find(dir, mask)
Definition: file.py:25
def callback(frame)
Definition: t265_stereo.py:91
std::vector< uint8_t > get_new_calibration_table() const
Definition: ds5-device.cpp:560
const int REGISTER_CLOCK_0
Definition: ds5-private.h:165
rs2_intrinsics get_intrinsic_by_resolution(const vector< uint8_t > &raw_data, calibration_table_id table_id, uint32_t width, uint32_t height)
std::vector< uint8_t > backup_flash(update_progress_callback_ptr callback) override
Definition: ds5-device.cpp:163
GLint j
command get_flash_logs_command() const
const std::map< uint8_t, std::string > ds5_fw_error_report
Definition: ds5-private.h:751
const uint16_t RS_USB2_PID
Definition: ds5-private.h:30
float get_depth_scale(rs2::device dev)
const ds5u_device * _owner
Definition: ds5-device.cpp:533
std::shared_ptr< polling_error_handler > _polling_error_handler
Definition: ds5-device.h:103
std::vector< uint8_t > merge_images(flash_info from, flash_info to, const std::vector< uint8_t > image)
float get_depth_scale() const override
Definition: ds5-device.cpp:433
std::shared_ptr< stream_interface > _left_ir_stream
Definition: ds5-device.h:93
std::shared_ptr< md_attribute_parser_base > make_uvc_header_parser(Attribute St::*attribute, attrib_modifyer mod=nullptr)
A utility function to create UVC metadata header parser.
bool supports_info(rs2_camera_info info) const override
Definition: sensor.cpp:596
ds::d400_caps _device_capabilities
Definition: ds5-device.h:90
std::vector< uint8_t > send_receive_raw_data(const std::vector< uint8_t > &input) override
Definition: ds5-device.cpp:122
const platform::extension_unit depth_xu
Definition: ds5-private.h:159
const std::string & get_info(rs2_camera_info info) const override
Definition: sensor.cpp:621
command get_firmware_logs_command() const
std::vector< std::shared_ptr< stream_profile_interface >> stream_profiles
Definition: streaming.h:165
const uint8_t DS5_ENABLE_AUTO_EXPOSURE
Definition: ds5-private.h:60
const uint8_t DS5_EXPOSURE
Definition: ds5-private.h:53
const uint16_t RS416_PID
Definition: ds5-private.h:43
static environment & get_instance()
int add_sensor(const std::shared_ptr< sensor_interface > &sensor_base)
Definition: device.cpp:163
void get_gvd(size_t sz, unsigned char *gvd, uint8_t gvd_cmd) const
Definition: hw-monitor.cpp:191
extrinsics_graph & get_extrinsics_graph()
#define RS2_UNSIGNED_UPDATE_MODE_FULL
Definition: rs_device.h:208
ds5_auto_exposure_roi_method(const hw_monitor &hwm, ds::fw_cmd cmd=ds::fw_cmd::SETAEROI)
Definition: ds5-device.cpp:86
GLenum GLenum GLsizei void * table
firmware_version _recommended_fw_version
Definition: ds5-device.h:89
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented...
Definition: rs_sensor.h:96
LOG_INFO("Log message using LOG_INFO()")
uvc_sensor & get_raw_depth_sensor()
Definition: ds5-device.h:46
const uint8_t I2C_IMU_BMI055_ID_ACC
Definition: ds5-private.h:639
GLuint GLfloat GLfloat GLfloat x1
Definition: glext.h:9721
const uint16_t HW_MONITOR_COMMAND_SIZE
Definition: hw-monitor.h:40
std::shared_ptr< md_attribute_parser_base > make_attribute_parser(Attribute S::*attribute, Flag flag, unsigned long long offset, attrib_modifyer mod=nullptr)
A helper function to create a specialized attribute parser. Return it as a pointer to a base-class...
virtual double get_device_time_ms() override
GLenum GLenum GLenum input
Definition: glext.h:10805
stream_profile to_profile(const stream_profile_interface *sp)
Definition: src/stream.h:185
long long rs2_metadata_type
Definition: rs_types.h:301
std::vector< usb_device_info > usb_devices
Definition: backend.h:526
float get_stereo_baseline_mm() const override
Definition: ds5-device.cpp:450
int min(int a, int b)
Definition: lz4s.c:73
GLenum GLfloat param
region_of_interest get() const override
Definition: ds5-device.cpp:101
GLint GLsizei count
std::vector< flash_table > tables
std::vector< rs2_format > map_supported_color_formats(rs2_format source_format)
Definition: device.cpp:263
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
Video stream intrinsics.
Definition: rs_types.h:58
ds5u_depth_sensor(ds5u_device *owner, std::shared_ptr< uvc_sensor > uvc_sensor)
Definition: ds5-device.cpp:481
static const std::set< std::uint16_t > hid_bmi_085_pid
Definition: ds5-private.h:116
void register_stream_to_extrinsic_group(const stream_interface &stream, uint32_t groupd_index)
Definition: device.cpp:246
float get_stereo_baseline_mm() const
Definition: ds5-device.cpp:547
rs2_intrinsics get_intrinsics(const stream_profile &profile) const override
Definition: ds5-device.cpp:338
void update_flash_internal(std::shared_ptr< hw_monitor > hwm, const std::vector< uint8_t > &image, std::vector< uint8_t > &flash_backup, update_progress_callback_ptr callback, int update_mode)
Definition: ds5-device.cpp:267
int i
processing_blocks get_recommended_processing_blocks() const override
Definition: ds5-device.cpp:333
#define offsetof(STRUCTURE, FIELD)
Definition: sqlite3.c:11372
GLuint res
Definition: glext.h:8856
void update_flash(const std::vector< uint8_t > &image, update_progress_callback_ptr callback, int update_mode) override
Definition: ds5-device.cpp:287
const uint32_t FLASH_SECTOR_SIZE
Definition: ds5-private.h:168
#define LOG_DEBUG(...)
Definition: src/types.h:239
std::vector< platform::uvc_device_info > filter_by_mi(const std::vector< platform::uvc_device_info > &devices, uint32_t mi)
Definition: context.cpp:644
std::vector< uvc_device_info > uvc_devices
Definition: backend.h:525
static const std::set< std::uint16_t > hid_bmi_055_pid
Definition: ds5-private.h:110
lazy< std::vector< uint8_t > > _new_calib_table_raw
Definition: ds5-device.h:101
void create_snapshot(std::shared_ptr< debug_interface > &snapshot) const override
const uint16_t HW_MONITOR_BUFFER_SIZE
Definition: hw-monitor.h:41
void create_snapshot(std::shared_ptr< depth_stereo_sensor > &snapshot) const override
Definition: ds5-device.cpp:457
std::shared_ptr< stream_interface > _right_ir_stream
Definition: ds5-device.h:94
GLuint64EXT * result
Definition: glext.h:10921
void hardware_reset() override
Definition: ds5-device.cpp:127
std::atomic< float > _depth_units
Definition: ds5-device.cpp:473
rs2_frame_metadata_value
Per-Frame-Metadata is the set of read-only properties that might be exposed for each individual frame...
Definition: rs_frame.h:29
std::vector< uint8_t > get_raw_calibration_table(ds::calibration_table_id table_id) const
Definition: ds5-device.cpp:554
std::map< uint32_t, rs2_format > ds5_depth_fourcc_to_rs2_format
Definition: ds5-device.cpp:54
GLintptr offset
void open(const stream_profiles &requests) override
Definition: ds5-device.cpp:356
virtual void set_roi_method(std::shared_ptr< region_of_interest_method > roi_method)=0
std::map< uint32_t, rs2_stream > ds5_depth_fourcc_to_rs2_stream
Definition: ds5-device.cpp:70
flash_info get_flash_info(const std::vector< uint8_t > &flash_buffer)
std::string to_string(T value)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:12