Skip to content

Commit

Permalink
PR #13612 from remibettan: Adding API connection_type to camera info
Browse files Browse the repository at this point in the history
  • Loading branch information
remibettan authored Jan 2, 2025
2 parents f7f622e + 5714a40 commit 509f0bf
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 67 deletions.
48 changes: 19 additions & 29 deletions common/device-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2246,42 +2246,32 @@ namespace rs2
else
{
ImGui::Text(" %s", ss.str().c_str());

if (dev.supports(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR))
{
std::string desc = dev.get_info(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR);
ss.str("");
ss << " " << textual_icons::usb_type << " " << desc;
ImGui::SameLine();
if (!starts_with(desc, "3.")) ImGui::PushStyleColor(ImGuiCol_Text, yellow);
else ImGui::PushStyleColor(ImGuiCol_Text, light_grey);
ImGui::Text(" %s", ss.str().c_str());
ImGui::PopStyleColor();
ss.str("");
ss << "The camera was detected by the OS as connected to a USB " << desc << " port";
ImGui::PushFont(window.get_font());
ImGui::PushStyleColor(ImGuiCol_Text, light_grey);
if (ImGui::IsItemHovered())
ImGui::SetTooltip(" %s", ss.str().c_str());
ImGui::PopStyleColor();
ImGui::PopFont();
}
else if(dev.supports(RS2_CAMERA_INFO_PRODUCT_ID))
if (dev.supports(RS2_CAMERA_INFO_CONNECTION_TYPE))
{
std::string device_pid = dev.get_info(RS2_CAMERA_INFO_PRODUCT_ID);
if(device_pid == "ABCD")// Specific for D457
auto connection_type = dev.get_info(RS2_CAMERA_INFO_CONNECTION_TYPE);
if (connection_type == std::string("USB") && dev.supports(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR))
{
ss.str( "" );
ss << " " << "GMSL";
std::string desc = dev.get_info(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR);
ss.str("");
ss << " " << textual_icons::usb_type << " " << desc;
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Text, white);
if (!starts_with(desc, "3.")) ImGui::PushStyleColor(ImGuiCol_Text, yellow);
else ImGui::PushStyleColor(ImGuiCol_Text, light_grey);
ImGui::Text(" %s", ss.str().c_str());
ImGui::PopStyleColor();
ss.str("");
ss << "The camera was detected by the OS as connected to a USB " << desc << " port";
ImGui::PushFont(window.get_font());
ImGui::PushStyleColor(ImGuiCol_Text, light_grey);
if (ImGui::IsItemHovered())
ImGui::SetTooltip(" %s", ss.str().c_str());
ImGui::PopStyleColor();
ImGui::PopFont();
}
else if(device_pid == "DDS")
else
{
ss.str( "" );
ss << " " << "DDS";
ss.str("");
ss << " " << connection_type;
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::Text(" %s", ss.str().c_str());
Expand Down
1 change: 1 addition & 0 deletions include/librealsense2/h/rs_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef enum rs2_camera_info {
RS2_CAMERA_INFO_FIRMWARE_UPDATE_ID , /**< Firmware update ID */
RS2_CAMERA_INFO_IP_ADDRESS , /**< IP address for remote camera. */
RS2_CAMERA_INFO_DFU_DEVICE_PATH , /**< DFU Device node path */
RS2_CAMERA_INFO_CONNECTION_TYPE , /**< Connection type, for example USB, GMSL, DDS */
RS2_CAMERA_INFO_COUNT /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */
} rs2_camera_info;
const char* rs2_camera_info_to_string(rs2_camera_info info);
Expand Down
13 changes: 2 additions & 11 deletions include/librealsense2/hpp/rs_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,8 @@ namespace rs2
*/
std::string get_type() const
{
if( supports( RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR ) )
return "USB";
if( supports( RS2_CAMERA_INFO_PRODUCT_ID ) )
{
std::string pid = get_info( RS2_CAMERA_INFO_PRODUCT_ID );
if( pid == "ABCD" ) // Specific for D457
return "GMSL";
if( pid == "BBCD" ) // Specific for D457 Recovery DFU
return "GMSL";
return pid; // for DDS devices, this will be "DDS"
}
if( supports( RS2_CAMERA_INFO_CONNECTION_TYPE ) )
return get_info(RS2_CAMERA_INFO_CONNECTION_TYPE);
return {};
}

Expand Down
1 change: 1 addition & 0 deletions src/dds/rs-dds-device-proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ dds_device_proxy::dds_device_proxy( std::shared_ptr< const device_info > const &
if( j.nested( "product-line" ).get_ex( str ) )
register_info( RS2_CAMERA_INFO_PRODUCT_LINE, str );
register_info( RS2_CAMERA_INFO_CAMERA_LOCKED, j.nested( "locked" ).default_value( true ) ? "YES" : "NO" );
register_info(RS2_CAMERA_INFO_CONNECTION_TYPE, "DDS" );

// Assumes dds_device initialization finished
struct sensor_info
Expand Down
5 changes: 5 additions & 0 deletions src/ds/d400/d400-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,12 @@ namespace librealsense
register_info(RS2_CAMERA_INFO_DFU_DEVICE_PATH, group.uvc_devices.front().dfu_device_path);

if (usb_modality)
{
register_info(RS2_CAMERA_INFO_CONNECTION_TYPE, "USB");
register_info(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR, usb_type_str);
}
else
register_info(RS2_CAMERA_INFO_CONNECTION_TYPE, "GMSL");

std::string curr_version= _fw_version;

Expand Down
3 changes: 3 additions & 0 deletions src/ds/d500/d500-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,10 @@ namespace librealsense
register_info(RS2_CAMERA_INFO_CAMERA_LOCKED, _is_locked ? "YES" : "NO");

if (usb_modality)
{
register_info(RS2_CAMERA_INFO_CONNECTION_TYPE, "USB");
register_info(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR, usb_type_str);
}

register_features();

Expand Down
1 change: 1 addition & 0 deletions src/platform-camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ platform_camera::platform_camera( std::shared_ptr< const device_info > const & d
if( usb_spec_names.count( usb_mode ) && ( usb_undefined != usb_mode ) )
usb_type_str = usb_spec_names.at( usb_mode );

register_info(RS2_CAMERA_INFO_CONNECTION_TYPE, "USB");
register_info( RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR, usb_type_str );
register_info( RS2_CAMERA_INFO_SERIAL_NUMBER, uvc_infos.front().unique_id );
register_info( RS2_CAMERA_INFO_PHYSICAL_PORT, uvc_infos.front().device_path );
Expand Down
1 change: 1 addition & 0 deletions src/to-string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ const char * get_string( rs2_camera_info value )
CASE( FIRMWARE_UPDATE_ID )
CASE( IP_ADDRESS )
CASE( DFU_DEVICE_PATH )
CASE( CONNECTION_TYPE )
default:
assert( ! is_valid( value ) );
return UNKNOWN_VALUE;
Expand Down
10 changes: 8 additions & 2 deletions tools/data-collect/rs-data-collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@ void data_collector::parse_and_configure(cli::value<string>& config_file)
configure_sensors();

// Report results
std::string connection_type = _dev->supports(RS2_CAMERA_INFO_CONNECTION_TYPE) ?
std::string(_dev->get_info(RS2_CAMERA_INFO_CONNECTION_TYPE)) : std::string(" ");
if (connection_type == "USB" && _dev->supports(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR))
{
connection_type += " Type: ";
connection_type += _dev->get_info(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR);
}
std::cout << "\nDevice selected: \n\t" << _dev->get_info(RS2_CAMERA_INFO_NAME)
<< (_dev->supports(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR) ?
std::string((stringify() << ". USB Type: " << _dev->get_info(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR))) : "")
<< ". " << connection_type << " "
<< "\n\tS.N: " << (_dev->supports(RS2_CAMERA_INFO_SERIAL_NUMBER) ? _dev->get_info(RS2_CAMERA_INFO_SERIAL_NUMBER) : "")
<< "\n\tFW Ver: " << _dev->get_info(RS2_CAMERA_INFO_FIRMWARE_VERSION)
<< "\n\nUser streams requested: " << user_requests.size()
Expand Down
14 changes: 9 additions & 5 deletions tools/depth-quality/depth-quality-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,25 @@ namespace rs2
rs2::pipeline_profile active_profile;

// Adjust settings according to USB type
bool usb3_device = true;
bool usb2_device = false;
auto devices = _ctx.query_devices();
if (devices.size())
{
auto dev = devices[0];
if (dev.supports(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR))
if (dev.supports(RS2_CAMERA_INFO_CONNECTION_TYPE))
{
std::string usb_type = dev.get_info(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR);
usb3_device = !(std::string::npos != usb_type.find("2."));
auto connection_type = dev.get_info(RS2_CAMERA_INFO_CONNECTION_TYPE);
if (connection_type == std::string("USB") && dev.supports(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR))
{
std::string usb_type = dev.get_info(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR);
usb2_device = (std::string::npos != usb_type.find("2."));
}
}
}
else
return valid_config;

int requested_fps = usb3_device ? 30 : 15;
int requested_fps = usb2_device ? 15 : 30;

// open Depth and Infrared streams using default profile
{
Expand Down
17 changes: 8 additions & 9 deletions tools/fw-update/rs-fw-update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,14 @@ int write_fw_to_mipi_device( const rs2::device & dev, const std::vector< uint8_t

bool is_mipi_device( const rs2::device & dev )
{
std::string usb_type = "unknown";

if( dev.supports( RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR ) )
usb_type = dev.get_info( RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR );

bool d457_device = strcmp( dev.get_info( RS2_CAMERA_INFO_PRODUCT_ID ), "ABCD" ) == 0;

// Currently only D457 model has MIPI connection
return d457_device && usb_type.compare( "unknown" ) == 0;
bool is_mipi_device = false;
if (dev.supports(RS2_CAMERA_INFO_CONNECTION_TYPE))
{
auto connection_type = dev.get_info(RS2_CAMERA_INFO_CONNECTION_TYPE);
if (connection_type == "GMSL")
is_mipi_device = true;
}
return is_mipi_device;
}

int main( int argc, char ** argv )
Expand Down
13 changes: 4 additions & 9 deletions tools/realsense-viewer/realsense-viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,16 +469,11 @@ int main(int argc, const char** argv) try

auto dev = connected_devs[i];
std::string dev_type;
if( dev.supports( RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR ) )
if (dev.supports(RS2_CAMERA_INFO_CONNECTION_TYPE))
{
dev_type = "USB";
dev_type += dev.get_info( RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR );
}
else if( dev.supports( RS2_CAMERA_INFO_PRODUCT_ID ) )
{
dev_type = dev.get_info( RS2_CAMERA_INFO_PRODUCT_ID );
if( dev_type == "ABCD" ) // Specific for D457
dev_type = "GMSL";
dev_type = dev.get_info(RS2_CAMERA_INFO_CONNECTION_TYPE);
if (dev_type == "USB" && dev.supports( RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR ))
dev_type += dev.get_info( RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR );
}

std::string line = rsutils::string::from() << dev.get_info( RS2_CAMERA_INFO_NAME ) << " (" << dev_type
Expand Down
12 changes: 10 additions & 2 deletions wrappers/python/pyrs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ void init_device(py::module &m) {
if( self.supports( RS2_CAMERA_INFO_CAMERA_LOCKED )
&& strcmp( "YES", self.get_info( RS2_CAMERA_INFO_CAMERA_LOCKED ) ) )
ss << " UNLOCKED";
if( self.supports( RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR ) )
ss << " on USB" << self.get_info( RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR );
if (self.supports(RS2_CAMERA_INFO_CONNECTION_TYPE))
{
auto connection_type = self.get_info(RS2_CAMERA_INFO_CONNECTION_TYPE);
ss << " on ";
ss << connection_type;
if (connection_type == "USB")
if (self.supports(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR))
ss << self.get_info(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR);
}

else if( self.supports( RS2_CAMERA_INFO_PHYSICAL_PORT ) )
ss << " @ " << self.get_info( RS2_CAMERA_INFO_PHYSICAL_PORT );
ss << ")>";
Expand Down

0 comments on commit 509f0bf

Please sign in to comment.