Skip to content

Commit

Permalink
improve device detection error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gwen2018 committed Feb 1, 2025
1 parent a53e1e4 commit 59eebbe
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 40 deletions.
2 changes: 1 addition & 1 deletion include/librealsense2/rs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern "C" {

#define RS2_API_MAJOR_VERSION 2
#define RS2_API_MINOR_VERSION 57
#define RS2_API_PATCH_VERSION 53
#define RS2_API_PATCH_VERSION 54
#define RS2_API_BUILD_VERSION 0

#ifndef STRINGIFY
Expand Down
88 changes: 49 additions & 39 deletions src/linux/backend-v4l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ namespace librealsense
{
int fd = open(dev_name.c_str(), O_RDWR);
if (fd < 0)
throw linux_backend_exception("Mipi device capability could not be grabbed");
throw linux_backend_exception("Mipi device format could not be grabbed");

struct v4l2_fmtdesc fmtdesc;
memset(&fmtdesc,0,sizeof(fmtdesc));
Expand All @@ -856,54 +856,60 @@ namespace librealsense

uint16_t v4l_uvc_device::get_mipi_device_pid(const std::string& dev_name)
{
uint16_t device_pid = 0;
// GVD product ID
const uint8_t GVD_PID_OFFSET = 4;

const uint8_t GVD_PID_D430_GMSL = 0x0F;
const uint8_t GVD_PID_D457 = 0x12;

// device PID
uint16_t device_pid = 0;

struct v4l2_capability vcap;
int fd = open(dev_name.c_str(), O_RDWR);
if (fd < 0)
throw linux_backend_exception("Mipi device capability could not be grabbed");
throw linux_backend_exception("Mipi device PID could not be found");

uint8_t gvd[276];
struct v4l2_ext_control ctrl;
uint8_t gvd[276];
struct v4l2_ext_control ctrl;

memset(gvd,0,276);
memset(gvd,0,276);

ctrl.id = RS_CAMERA_CID_GVD;
ctrl.size = sizeof(gvd);
ctrl.p_u8 = gvd;
ctrl.id = RS_CAMERA_CID_GVD;
ctrl.size = sizeof(gvd);
ctrl.p_u8 = gvd;

struct v4l2_ext_controls ext;
struct v4l2_ext_controls ext;

ext.ctrl_class = V4L2_CTRL_CLASS_CAMERA;
ext.controls = &ctrl;
ext.count = 1;
ext.ctrl_class = V4L2_CTRL_CLASS_CAMERA;
ext.controls = &ctrl;
ext.count = 1;

if (ioctl(fd, VIDIOC_G_EXT_CTRLS, &ext) == 0)
{
// for (int i = 0; i < 16; i++)
// {
// std::cout << std::hex << (int) gvd[i] << std::endl;
// }
if (ioctl(fd, VIDIOC_G_EXT_CTRLS, &ext) == 0)
{
uint8_t product_pid = 0;

uint8_t product_pid = 0;
product_pid = gvd[4 + GVD_PID_OFFSET];

product_pid = gvd[4 + 4];
// std::cout << "product_id:" << (int) product_pid << std::endl;
switch(product_pid)
{
case(GVD_PID_D457):
device_pid = 0xABCD;
break;

switch(product_pid)
{
case(0x0F):
device_pid = 0xABCE;
break;
default:
device_pid = 0xABCD;
break;
}
}
case(GVD_PID_D430_GMSL):
device_pid = 0xABCE;
break;

default:
device_pid = 0x0000;
break;
}
}

::close(fd);

return device_pid;
return device_pid;
}

void v4l_uvc_device::get_mipi_device_info(const std::string& dev_name,
Expand Down Expand Up @@ -953,20 +959,24 @@ namespace librealsense

// find device PID from depth video node
static uint16_t device_pid = 0;
if (is_format_supported_on_node(dev_name, "Z16 "))
try
{
if (is_format_supported_on_node(dev_name, "Z16 "))
{
device_pid = get_mipi_device_pid(dev_name);
}
}
catch(const std::exception & e)
{
device_pid = get_mipi_device_pid(dev_name);
// std::cout << "depth video node name=" << name << ", device_pid=" << device_pid << std::endl;
LOG_WARNING("MIPI device product id detection issue, device will be skipped: " << e.what());
device_pid = 0;
}

// the following 2 lines need to be changed in order to enable multiple mipi devices support
// or maybe another field in the info structure - TBD
vid = 0x8086;
pid = device_pid;

// std::cout << "video_path:" << video_path << ", name:" << dev_name << ", pid=" << std::hex << (int) pid << std::endl;


static std::regex video_dev_index("\\d+$");
std::smatch match;
uint8_t ind{};
Expand Down

0 comments on commit 59eebbe

Please sign in to comment.