Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix update_device::get_device_info #12160

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ namespace librealsense
devices.usb_devices = _backend->query_usb_devices();
devices.hid_devices = _backend->query_hid_devices();
}
return create_devices( devices, _playback_devices, mask );
auto const list = create_devices( devices, _playback_devices, mask );
LOG_INFO( "Found " << list.size() << " RealSense devices (mask 0x" << std::hex << mask << ")" );
for( auto & item : list )
LOG_INFO( "... " << item->get_address() );
return list;
}

std::vector< std::shared_ptr< device_info > >
Expand Down Expand Up @@ -295,8 +299,6 @@ namespace librealsense
list.push_back(dev);
}

if (list.size())
LOG_INFO( "Found " << list.size() << " RealSense devices (mask 0x" << std::hex << mask << ")" << std::dec );
return list;
}

Expand All @@ -315,22 +317,21 @@ namespace librealsense
[]( std::shared_ptr< device_info > first, std::shared_ptr< device_info > second )
{ return first->is_same_as( second ); } ) )
{
std::vector<rs2_device_info> rs2_devices_info_added;
std::vector<rs2_device_info> rs2_devices_info_removed;

auto devices_info_removed = subtract_sets(old_list, new_list);

for (size_t i = 0; i < devices_info_removed.size(); i++)
{
rs2_devices_info_removed.push_back({ shared_from_this(), devices_info_removed[i] });
LOG_DEBUG( "\nDevice disconnected:\n\n" << *devices_info_removed[i] );
LOG_DEBUG( "Device disconnected: " << devices_info_removed[i]->get_address() );
}

std::vector<rs2_device_info> rs2_devices_info_added;
auto devices_info_added = subtract_sets(new_list, old_list);
for (size_t i = 0; i < devices_info_added.size(); i++)
{
rs2_devices_info_added.push_back({ shared_from_this(), devices_info_added[i] });
LOG_DEBUG( "\nDevice connected:\n\n" << *devices_info_added[i] );
LOG_DEBUG( "Device connected: " << devices_info_added[i]->get_address() );
}

invoke_devices_changed_callbacks( rs2_devices_info_removed, rs2_devices_info_added );
Expand Down Expand Up @@ -371,6 +372,10 @@ namespace librealsense
_devices_changed_callback->on_devices_changed(new rs2_device_list({ shared_from_this(), removed }),
new rs2_device_list({ shared_from_this(), added }));
}
catch( std::exception const & e )
{
LOG_ERROR( "Exception thrown from user callback handler: " << e.what() );
}
catch (...)
{
LOG_ERROR("Exception thrown from user callback handler");
Expand Down
8 changes: 0 additions & 8 deletions src/ds/d400/d400-factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1179,20 +1179,12 @@ namespace librealsense
{
hwm_devices.push_back(hwm);
}
else
{
LOG_DEBUG("d400_try_fetch_usb_device(...) failed.");
}

auto info = std::make_shared<d400_info>( ctx, std::move( devices ), std::move( hwm_devices ), std::move( hids ) );
chosen.insert(chosen.end(), devices.begin(), devices.end());
results.push_back(info);

}
else
{
LOG_WARNING("DS5 group_devices is empty.");
}
}

trim_device_list(group.uvc_devices, chosen);
Expand Down
6 changes: 4 additions & 2 deletions src/ds/d400/d400-fw-update-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

namespace librealsense
{
ds_update_device::ds_update_device(std::shared_ptr<context> const & ctx, std::shared_ptr<platform::usb_device> const & usb_device)
: update_device(ctx, usb_device), _product_line("D400")
ds_update_device::ds_update_device( std::shared_ptr< const device_info > const & dev_info,
std::shared_ptr< platform::usb_device > const & usb_device )
: update_device( dev_info, usb_device )
, _product_line( "D400" )
{
auto info = usb_device->get_info();
_name = ds::rs400_sku_names.find(info.pid) != ds::rs400_sku_names.end() ? ds::rs400_sku_names.at(info.pid) : "unknown";
Expand Down
2 changes: 1 addition & 1 deletion src/ds/d400/d400-fw-update-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace librealsense
class ds_update_device : public update_device
{
public:
ds_update_device( std::shared_ptr< context > const & ctx,
ds_update_device( std::shared_ptr< const device_info > const &,
std::shared_ptr< platform::usb_device > const & usb_device );
virtual ~ds_update_device() = default;

Expand Down
8 changes: 4 additions & 4 deletions src/fw-update/fw-update-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ namespace librealsense
return false;
}

update_device::update_device( std::shared_ptr< context > const & ctx,
update_device::update_device( std::shared_ptr< const device_info > const & dev_info,
std::shared_ptr< platform::usb_device > const & usb_device )
: _context(ctx), _usb_device(usb_device), _physical_port( usb_device->get_info().id), _pid(hexify(usb_device->get_info().pid))
: _dev_info(dev_info), _usb_device(usb_device), _physical_port( usb_device->get_info().id), _pid(hexify(usb_device->get_info().pid))
{
if (auto messenger = _usb_device->open(FW_UPDATE_INTERFACE_NUMBER))
{
Expand Down Expand Up @@ -242,12 +242,12 @@ namespace librealsense

std::shared_ptr<context> update_device::get_context() const
{
return _context;
return _dev_info->get_context();
}

std::shared_ptr< const device_info > update_device::get_device_info() const
{
throw std::runtime_error("update_device does not support get_device_data API");//TODO_MK
return _dev_info;
}

std::pair<uint32_t, rs2_extrinsics> update_device::get_extrinsics(const stream_interface& stream) const
Expand Down
4 changes: 2 additions & 2 deletions src/fw-update/fw-update-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace librealsense
class update_device : public update_device_interface
{
public:
update_device( std::shared_ptr< context > const & ctx,
update_device( std::shared_ptr< const device_info > const &,
std::shared_ptr< platform::usb_device > const & usb_device );
virtual ~update_device();

Expand Down Expand Up @@ -146,7 +146,7 @@ namespace librealsense
void read_device_info(std::shared_ptr<platform::usb_messenger> messenger);


const std::shared_ptr<context> _context;
const std::shared_ptr< const device_info > _dev_info;
const platform::rs_usb_device _usb_device;
std::vector<uint8_t> _serial_number_buffer;
std::string _highest_fw_version;
Expand Down
4 changes: 2 additions & 2 deletions src/fw-update/fw-update-factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ namespace librealsense
if (!usb)
continue;
if (ds::RS_RECOVERY_PID == info.pid)
return std::make_shared<ds_update_device>(get_context(), usb);
return std::make_shared< ds_update_device >( shared_from_this(), usb );
if (ds::RS_USB2_RECOVERY_PID == info.pid)
return std::make_shared<ds_update_device>(get_context(), usb);
return std::make_shared< ds_update_device >( shared_from_this(), usb );
}
}
throw std::runtime_error( rsutils::string::from()
Expand Down
4 changes: 4 additions & 0 deletions src/fw-update/fw-update-factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace librealsense
{
class fw_update_info : public platform::platform_device_info
{
typedef platform::platform_device_info super;

public:
std::shared_ptr< device_interface > create_device() override;

Expand All @@ -20,6 +22,8 @@ namespace librealsense
explicit fw_update_info(std::shared_ptr<context> ctx, platform::usb_device_info const & dfu)
: platform_device_info( ctx, { { dfu } } ) {}

std::string get_address() const override { return "recovery:" + super::get_address(); }

private:
const char* RECOVERY_MESSAGE = "Selected RealSense device is in recovery mode!\nEither perform a firmware update or reconnect the camera to fall-back to last working firmware if available!";
};
Expand Down
2 changes: 1 addition & 1 deletion src/platform/platform-device-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class platform_device_info : public device_info
for( auto & d : _group.uvc_devices )
return d.device_path;
for( auto & d : _group.usb_devices )
return d.serial;
return d.id;
throw std::runtime_error( "non-standard platform-device-info" );
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/uvc-device-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct uvc_device_info
bool has_metadata_node = false;
std::string metadata_node_id;

operator std::string()
operator std::string() const
{
std::ostringstream s;
s << "id- " << id << "\nvid- " << std::hex << vid << "\npid- " << std::hex << pid << "\nmi- " << std::dec << mi
Expand Down
2 changes: 1 addition & 1 deletion src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ namespace librealsense
uint16_t mi;
std::string unique_id;

operator std::string()
operator std::string() const
{
std::stringstream s;

Expand Down
10 changes: 9 additions & 1 deletion unit-tests/dds/dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,17 @@ def wait_for_devices( context, mask, n=1, timeout=3, throw=None ):
#
devices = context.query_devices( mask )
if len(devices) >= n:
if not exact or len(devices) == n:
if not exact:
return devices
if len(devices) == n:
if n == 1:
return devices[0]
return devices
if throw:
raise TimeoutError( f'timeout waiting for {n} device(s)' )
log.d( f'timeout waiting for {n} device(s)' )
if exact and n == 1:
if devices:
return device[0]
return None
return devices
6 changes: 3 additions & 3 deletions unit-tests/dds/test-librs-device-properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#
with test.closure( "Test D435i" ):
remote.run( 'instance = broadcast_device( d435i, d435i.device_info )' )
dds.wait_for_devices( context, only_sw_devices, n=1. )
dev = dds.wait_for_devices( context, only_sw_devices, n=1. )
test.check_equal( dev.get_info( rs.camera_info.name ), d435i.device_info.name )
test.check_equal( dev.get_info( rs.camera_info.serial_number ), d435i.device_info.serial )
test.check_equal( dev.get_info( rs.camera_info.physical_port ), d435i.device_info.topic_root )
Expand Down Expand Up @@ -59,7 +59,7 @@
#
with test.closure( "Test D405" ):
remote.run( 'instance = broadcast_device( d405, d405.device_info )' )
dds.wait_for_devices( context, only_sw_devices, n=1. )
dev = dds.wait_for_devices( context, only_sw_devices, n=1. )
test.check_equal( dev.get_info( rs.camera_info.name ), d405.device_info.name )
test.check_equal( dev.get_info( rs.camera_info.serial_number ), d405.device_info.serial )
test.check_equal( dev.get_info( rs.camera_info.physical_port ), d405.device_info.topic_root )
Expand All @@ -77,7 +77,7 @@
#
with test.closure( "Test D455" ):
remote.run( 'instance = broadcast_device( d455, d455.device_info )' )
dds.wait_for_devices( context, only_sw_devices, n=1. )
dev = dds.wait_for_devices( context, only_sw_devices, n=1. )
test.check_equal( dev.get_info( rs.camera_info.name ), d455.device_info.name )
test.check_equal( dev.get_info( rs.camera_info.serial_number ), d455.device_info.serial )
test.check_equal( dev.get_info( rs.camera_info.physical_port ), d455.device_info.topic_root )
Expand Down
2 changes: 1 addition & 1 deletion unit-tests/dds/test-metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def __exit__( self, type, value, traceback ):
from dds import wait_for_devices
context = rs.context( { 'dds': { 'domain': 123, 'participant': 'librs' }} )
only_sw_devices = int(rs.product_line.sw_only) | int(rs.product_line.any_intel)
device = wait_for_devices( context, only_sw_devices, n=1. )[0]
device = wait_for_devices( context, only_sw_devices, n=1. )
sensors = device.sensors
test.check_equal( len(sensors), 1, on_fail=test.RAISE )
sensor = sensors[0]
Expand Down
Loading