l500-factory.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 
10 #include "device.h"
11 #include "context.h"
12 #include "image.h"
13 #include "metadata-parser.h"
14 #include "../firmware_logger_device.h"
15 
16 #include "l500-factory.h"
17 #include "l500-depth.h"
18 #include "l500-motion.h"
19 #include "l500-color.h"
20 #include "l500-serializable.h"
21 
22 #include "../firmware_logger_device.h"
23 
24 namespace librealsense
25 {
26  using namespace ivcam2;
27 
28  class l515_device : public l500_depth,
29  public l500_options,
30  public l500_color,
31  public l500_motion,
32  public l500_serializable,
34  {
35  public:
36  l515_device(std::shared_ptr<context> ctx,
38  bool register_device_notifications)
39  : device(ctx, group, register_device_notifications),
40  l500_device(ctx, group),
41  l500_depth(ctx, group),
42  l500_options(ctx, group),
43  l500_color(ctx, group),
44  l500_motion(ctx, group),
45  l500_serializable(l500_device::_hw_monitor, get_depth_sensor()),
46  firmware_logger_device(ctx, group, l500_device::_hw_monitor,
47  get_firmware_logs_command(),
48  get_flash_logs_command())
49  {}
50 
51  std::shared_ptr<matcher> create_matcher(const frame_holder& frame) const override;
52 
53  std::vector<tagged_profile> get_profiles_tags() const override
54  {
55  std::vector<tagged_profile> tags;
56  auto depth_profiles = l500_depth::get_profiles_tags();
57  auto color_profiles = l500_color::get_profiles_tags();
58  auto motion_profiles = l500_motion::get_profiles_tags();
59 
60  tags.insert(tags.begin(), depth_profiles.begin(), depth_profiles.end());
61  tags.insert(tags.begin(), color_profiles.begin(), color_profiles.end());
62  tags.insert(tags.begin(), motion_profiles.begin(), motion_profiles.end());
63  return tags;
64  };
65  };
66 
67  class l535_device : public l500_depth,
68  public l500_options,
69  public l500_color,
70  public l500_motion,
71  public l500_serializable,
73  {
74  public:
75  l535_device(std::shared_ptr<context> ctx,
77  bool register_device_notifications)
78  : device(ctx, group, register_device_notifications),
79  l500_device(ctx, group),
80  l500_depth(ctx, group),
81  l500_options(ctx, group),
82  l500_color(ctx, group),
83  l500_motion(ctx, group),
84  l500_serializable(l500_device::_hw_monitor, get_depth_sensor()),
85  firmware_logger_device(ctx, group, l500_device::_hw_monitor,
86  get_firmware_logs_command(),
87  get_flash_logs_command())
88  {}
89 
90  std::shared_ptr<matcher> create_matcher(const frame_holder& frame) const override;
91 
92  std::vector<tagged_profile> get_profiles_tags() const override
93  {
94  std::vector<tagged_profile> tags;
95  auto depth_profiles = l500_depth::get_profiles_tags();
96  auto color_profiles = l500_color::get_profiles_tags();
97  auto motion_profiles = l500_motion::get_profiles_tags();
98 
99  tags.insert(tags.begin(), depth_profiles.begin(), depth_profiles.end());
100  tags.insert(tags.begin(), color_profiles.begin(), color_profiles.end());
101  tags.insert(tags.begin(), motion_profiles.begin(), motion_profiles.end());
102  return tags;
103  };
104  };
105 
106  class rs500_device : public l500_depth,
108  {
109  public:
110  rs500_device(std::shared_ptr<context> ctx,
112  bool register_device_notifications)
113  : device(ctx, group, register_device_notifications),
114  l500_device(ctx, group),
115  l500_depth(ctx, group),
116  firmware_logger_device(ctx, group,l500_device::_hw_monitor,
117  get_firmware_logs_command(),
118  get_flash_logs_command())
119  {}
120 
121  l500_color_sensor * get_color_sensor() override { return nullptr; }
122 
123  std::shared_ptr<matcher> create_matcher(const frame_holder& frame) const override;
124  };
125 
126  std::shared_ptr<device_interface> l500_info::create(std::shared_ptr<context> ctx,
127  bool register_device_notifications) const
128  {
129  if (_depth.size() == 0) throw std::runtime_error("Depth Camera not found!");
130  auto pid = _depth.front().pid;
131  platform::backend_device_group group{ get_device_data() };
132 
133  switch (pid)
134  {
135  case L500_PID:
136  return std::make_shared<rs500_device>(ctx, group, register_device_notifications);
137  case L515_PID_PRE_PRQ:
138  case L515_PID:
139  return std::make_shared<l515_device>(ctx, group, register_device_notifications);
140  case L535_PID:
141  return std::make_shared<l535_device>(ctx, group, register_device_notifications);
142  default:
143  throw std::runtime_error(to_string() << "Unsupported L500 model! 0x"
144  << std::hex << std::setw(4) << std::setfill('0') << (int)pid);
145  }
146  }
147 
148  std::vector<std::shared_ptr<device_info>> l500_info::pick_l500_devices(
149  std::shared_ptr<context> ctx,
151  {
152  std::vector<platform::uvc_device_info> chosen;
153  std::vector<std::shared_ptr<device_info>> results;
154 
155  auto correct_pid = filter_by_product(group.uvc_devices, { L500_PID, L515_PID, L535_PID, L515_PID_PRE_PRQ });
156  auto group_devices = group_devices_and_hids_by_unique_id(group_devices_by_unique_id(correct_pid), group.hid_devices);
157  for (auto& g : group_devices)
158  {
159  if (!g.first.empty() && mi_present(g.first, 0))
160  {
161  auto depth = get_mi(g.first, 0);
163 
165  LOG_DEBUG("try_fetch_usb_device(...) failed.");
166 
167  if(g.first[0].pid != L500_PID)
168  if (g.second.size() < 2)
169  {
170  LOG_DEBUG("L500 partial enum: " << g.second.size() << " HID devices were recognized (2+ expected)");
171 #if !defined(ANDROID) && !defined(__APPLE__) // Not supported by android & macos
172  continue;
173 #endif // Not supported by android & macos
174  }
175 
176  auto info = std::make_shared<l500_info>(ctx, g.first, hwm, g.second);
177  chosen.push_back(depth);
178  results.push_back(info);
179  }
180  else
181  {
182  LOG_DEBUG("L500 group_devices is empty.");
183  }
184  }
185 
186  trim_device_list(group.uvc_devices, chosen);
187 
188  return results;
189  }
190 
191  std::shared_ptr<matcher> rs500_device::create_matcher(const frame_holder& frame) const
192  {
193  return l500_depth::create_matcher(frame);
194  }
195 
196  std::shared_ptr<matcher> l515_device::create_matcher(const frame_holder & frame) const
197  {
198  LOG_DEBUG( "l515_device::create_matcher" );
199  std::vector<std::shared_ptr<matcher>> depth_rgb_matchers = { l500_depth::create_matcher(frame),
200  std::make_shared<identity_matcher>(_color_stream->get_unique_id(), _color_stream->get_stream_type())};
201 
202  auto ts_depth_rgb = std::make_shared<timestamp_composite_matcher>(depth_rgb_matchers);
203 
204  auto identity_gyro = std::make_shared<identity_matcher>(_gyro_stream->get_unique_id(), _gyro_stream->get_stream_type());
205  auto identity_accel = std::make_shared<identity_matcher>(_accel_stream->get_unique_id(), _accel_stream->get_stream_type());
206 
207  std::vector<std::shared_ptr<matcher>> depth_rgb_imu_matchers = {ts_depth_rgb, identity_gyro, identity_accel};
208  return std::make_shared<composite_identity_matcher>(depth_rgb_imu_matchers);
209  }
210 
211  std::shared_ptr<matcher> l535_device::create_matcher(const frame_holder & frame) const
212  {
213  LOG_DEBUG("l535_device::create_matcher");
214  std::vector<std::shared_ptr<matcher>> depth_rgb_matchers = { l500_depth::create_matcher(frame),
215  std::make_shared<identity_matcher>(_color_stream->get_unique_id(), _color_stream->get_stream_type()) };
216 
217  auto ts_depth_rgb = std::make_shared<timestamp_composite_matcher>(depth_rgb_matchers);
218 
219  auto identity_gyro = std::make_shared<identity_matcher>(_gyro_stream->get_unique_id(), _gyro_stream->get_stream_type());
220  auto identity_accel = std::make_shared<identity_matcher>(_accel_stream->get_unique_id(), _accel_stream->get_stream_type());
221 
222  std::vector<std::shared_ptr<matcher>> depth_rgb_imu_matchers = { ts_depth_rgb, identity_gyro, identity_accel };
223  return std::make_shared<composite_identity_matcher>(depth_rgb_imu_matchers);
224  }
225 }
std::vector< tagged_profile > get_profiles_tags() const override
GLboolean GLboolean g
std::vector< platform::uvc_device_info > filter_by_product(const std::vector< platform::uvc_device_info > &devices, const std::set< uint16_t > &pid_list)
Definition: context.cpp:478
std::vector< tagged_profile > get_profiles_tags() const override
void trim_device_list(std::vector< platform::usb_device_info > &devices, const std::vector< platform::usb_device_info > &chosen)
Definition: context.cpp:600
l500_color_sensor * get_color_sensor() override
bool try_fetch_usb_device(std::vector< platform::usb_device_info > &devices, const platform::uvc_device_info &info, platform::usb_device_info &result)
GLint GLint GLsizei GLsizei GLsizei depth
std::shared_ptr< matcher > create_matcher(const frame_holder &frame) const override
l515_device(std::shared_ptr< context > ctx, const platform::backend_device_group &group, bool register_device_notifications)
std::vector< tagged_profile > get_profiles_tags() const override
Definition: l500-depth.cpp:165
def info(name, value, persistent=False)
Definition: test.py:301
std::vector< hid_device_info > hid_devices
Definition: backend.h:527
std::vector< std::pair< std::vector< platform::uvc_device_info >, std::vector< platform::hid_device_info > > > group_devices_and_hids_by_unique_id(const std::vector< std::vector< platform::uvc_device_info >> &devices, const std::vector< platform::hid_device_info > &hids)
Definition: context.cpp:501
rs500_device(std::shared_ptr< context > ctx, const platform::backend_device_group &group, bool register_device_notifications)
std::vector< std::vector< platform::uvc_device_info > > group_devices_by_unique_id(const std::vector< platform::uvc_device_info > &devices)
Definition: context.cpp:583
l535_device(std::shared_ptr< context > ctx, const platform::backend_device_group &group, bool register_device_notifications)
GLboolean GLuint group
Definition: glext.h:5688
std::shared_ptr< device_interface > create(std::shared_ptr< context > ctx, bool register_device_notifications) const override
platform::uvc_device_info get_mi(const std::vector< platform::uvc_device_info > &devices, uint32_t mi)
Definition: context.cpp:634
std::shared_ptr< matcher > create_matcher(const frame_holder &frame) const override
std::vector< usb_device_info > usb_devices
Definition: backend.h:526
std::shared_ptr< matcher > create_matcher(const frame_holder &frame) const override
static std::vector< std::shared_ptr< device_info > > pick_l500_devices(std::shared_ptr< context > ctx, platform::backend_device_group &group)
const uint16_t L515_PID
Definition: l500-private.h:22
std::vector< tagged_profile > get_profiles_tags() const override
Definition: l500-color.cpp:715
const uint16_t L535_PID
Definition: l500-private.h:23
std::vector< tagged_profile > get_profiles_tags() const override
#define LOG_DEBUG(...)
Definition: src/types.h:239
std::vector< uvc_device_info > uvc_devices
Definition: backend.h:525
const uint16_t L515_PID_PRE_PRQ
Definition: l500-private.h:21
const uint16_t L500_PID
Definition: l500-private.h:20
std::shared_ptr< matcher > create_matcher(const frame_holder &frame) const override
Definition: l500-depth.cpp:181
bool mi_present(const std::vector< platform::uvc_device_info > &devices, uint32_t mi)
Definition: context.cpp:624
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:21