36 #include "usb_buffer.pb.h"
42 #include <glog/logging.h>
47 #include <linux/videodev2.h>
59 LOG(
INFO) <<
"Looking for USB connected sensors";
61 const char *
path =
"/dev/";
67 return Status::UNREACHABLE;
71 char sset[] =
"video";
72 while ((dir =
readdir(
d)) !=
nullptr) {
73 if (strspn(sset, (dir->
d_name)) != 5) {
76 string driverPath(
path);
80 if (-1 == stat(driverPath.c_str(), &st)) {
81 LOG(
WARNING) <<
"Cannot identify '" << driverPath
92 fd = open(driverPath.c_str(), O_RDWR | O_NONBLOCK, 0);
100 struct v4l2_capability cap;
103 LOG(
WARNING) << driverPath <<
" is not V4L2 device";
110 struct v4l2_format
fmt;
112 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
120 if (strncmp(
reinterpret_cast<const char *
>(cap.card), devName.c_str(),
121 devName.length()) != 0) {
126 if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
127 LOG(
WARNING) << driverPath <<
" is no video capture device";
132 if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
133 LOG(
WARNING) << driverPath <<
" does not support streaming i/o";
141 DLOG(
INFO) <<
"Found USB capture device at: " << driverPath;
146 usb_payload::ClientRequest requestMsg;
147 requestMsg.set_func_name(usb_payload::FunctionName::SEARCH_SENSORS);
148 requestMsg.add_func_int32_param(
152 requestMsg.SerializeToString(&requestStr);
155 LOG(
ERROR) <<
"Request to search for sensors failed";
163 LOG(
ERROR) <<
"Request to search for sensors failed";
166 usb_payload::ServerResponse responseMsg;
167 bool parsed = responseMsg.ParseFromString(
responseStr);
169 LOG(
ERROR) <<
"Failed to deserialize string containing UVC gadget "
174 DLOG(
INFO) <<
"Received the following message with "
175 "available sensors from target: "
176 << responseMsg.DebugString();
179 LOG(
ERROR) <<
"Search for sensors operation failed on UVC gadget";
180 return static_cast<Status>(responseMsg.status());
184 m_sensorsInfo.emplace_back(sInfo);
185 m_sensorName = responseMsg.sensors_info().image_sensors().name();
187 m_sensorName = responseMsg.sensors_info().image_sensors().name();
189 m_kernelVersion = responseMsg.card_image_version().kernelversion();
190 m_sdVersion = responseMsg.card_image_version().sdversion();
191 m_uBootVersion = responseMsg.card_image_version().ubootversion();
200 std::vector<std::shared_ptr<DepthSensorInterface>> &depthSensors) {
202 depthSensors.clear();
204 for (
const auto &sInfo : m_sensorsInfo) {
206 std::make_shared<UsbDepthSensor>(m_sensorName, sInfo.driverPath);
207 depthSensors.emplace_back(sensor);
215 uBootVersion = m_uBootVersion;
221 kernelVersion = m_kernelVersion;
226 sdVersion = m_sdVersion;