Struct cyme::system_profiler::USBDevice
source · pub struct USBDevice {Show 18 fields
pub name: String,
pub vendor_id: Option<u16>,
pub product_id: Option<u16>,
pub location_id: DeviceLocation,
pub serial_num: Option<String>,
pub manufacturer: Option<String>,
pub bcd_device: Option<Version>,
pub bcd_usb: Option<Version>,
pub bus_power: Option<u16>,
pub bus_power_used: Option<u16>,
pub device_speed: Option<DeviceSpeed>,
pub extra_current_used: Option<u16>,
pub devices: Option<Vec<USBDevice>>,
pub class: Option<ClassCode>,
pub sub_class: Option<u8>,
pub protocol: Option<u8>,
pub extra: Option<USBDeviceExtra>,
pub profiler_error: Option<String>,
}
Expand description
USB device data based on JSON object output from system_profiler but now used for other platforms
Desgined to hold static data for the device, obtained from system_profiler Deserializer or cyme::lsusb. Fields should probably be non-pub with getters/setters but treat them as read-only.
Fields§
§name: String
The device product name as reported in descriptor or using usb_ids if None
vendor_id: Option<u16>
Unique vendor identifier - purchased from USB IF
product_id: Option<u16>
Vendor unique product identifier
location_id: DeviceLocation
DeviceLocation
information of position within bus
serial_num: Option<String>
Device serial number as reported by descriptor
manufacturer: Option<String>
The device manufacturer as provided in descriptor or using usb_ids if None
bcd_device: Option<Version>
The device release number set by the developer as a Version
bcd_usb: Option<Version>
The highest version of USB the device supports as a Version
bus_power: Option<u16>
macOS system_profiler only - actually bus current in mA not power!
bus_power_used: Option<u16>
macOS system_profiler only - actually bus current used in mA not power!
device_speed: Option<DeviceSpeed>
Advertised device capable speed
extra_current_used: Option<u16>
macOS system_profiler only - actually bus current used in mA not power!
devices: Option<Vec<USBDevice>>
Devices can be hub and have devices attached so need to walk each device’s devices…
class: Option<ClassCode>
USB device class
sub_class: Option<u8>
USB sub-class
protocol: Option<u8>
USB protocol
extra: Option<USBDeviceExtra>
Extra data obtained by libusb/udev exploration
profiler_error: Option<String>
Internal to store any non-critical errors captured whilst profiling, unable to open for example
Implementations§
source§impl USBDevice
impl USBDevice
sourcepub fn has_devices(&self) -> bool
pub fn has_devices(&self) -> bool
Does the device have child devices; devices
is Some and > 0
sourcepub fn has_interface_class(&self, c: &ClassCode) -> bool
pub fn has_interface_class(&self, c: &ClassCode) -> bool
Does the device have an interface with class
sourcepub fn get_root_hub(&self) -> Option<&USBDevice>
pub fn get_root_hub(&self) -> Option<&USBDevice>
Gets root_hub USBDevice
if it is one
root_hub returns Some(Self)
let d = cyme::system_profiler::USBDevice{ name: String::from("root_hub"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![] }, ..Default::default() };
assert_eq!(d.get_root_hub().is_some(), true);
Not a root_hub returns None
let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1] }, ..Default::default() };
assert_eq!(d.get_root_hub().is_some(), false);
sourcepub fn get_node(&self, port_path: &str) -> Option<&USBDevice>
pub fn get_node(&self, port_path: &str) -> Option<&USBDevice>
Recursively walk all USBDevice
from self, looking for the one with port_path
and returning reference
Will panic if port_path
is not a child device or if it sits shallower than self
sourcepub fn get_node_mut(&mut self, port_path: &str) -> Option<&mut USBDevice>
pub fn get_node_mut(&mut self, port_path: &str) -> Option<&mut USBDevice>
Recursively walk all USBDevice
from self, looking for the one with port_path
and returning mutable
Will panic if port_path
is not a child device or if it sits shallower than self
sourcepub fn get_branch_position(&self) -> u8
pub fn get_branch_position(&self) -> u8
Returns position on branch (parent), which is the last number in tree_positions
also sometimes refered to as port
sourcepub fn is_hub(&self) -> bool
pub fn is_hub(&self) -> bool
Returns true
if device is a hub based on device name - not perfect but most hubs advertise as a hub in name - or class code if it has one
// hub in name
let d = cyme::system_profiler::USBDevice{ name: String::from("My special hub"), ..Default::default() };
assert_eq!(d.is_hub(), true);
// Class is hub
let d = cyme::system_profiler::USBDevice{ name: String::from("Not named but Class"), class: Some(cyme::usb::ClassCode::Hub), ..Default::default() };
assert_eq!(d.is_hub(), true);
// not a hub
let d = cyme::system_profiler::USBDevice{ name: String::from("My special device"), ..Default::default() };
assert_eq!(d.is_hub(), false);
sourcepub fn port_path(&self) -> String
pub fn port_path(&self) -> String
Linux style port path where it can be found on system device path - normaly /sys/bus/usb/devices
Normal device
let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1, 2, 3] }, ..Default::default() };
assert_eq!(d.port_path(), "1-1.2.3");
Get a root_hub port path
let d = cyme::system_profiler::USBDevice{ name: String::from("root_hub"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![] }, ..Default::default() };
assert_eq!(d.port_path(), "1-0:1.0");
sourcepub fn parent_path(&self) -> Result<String, Error>
pub fn parent_path(&self) -> Result<String, Error>
Path of parent USBDevice
; one above in tree
Device with parent
let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1, 2, 3] }, ..Default::default() };
assert_eq!(d.parent_path(), Ok(String::from("1-1.2")));
Trunk device parent is path to bus
let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1] }, ..Default::default() };
assert_eq!(d.parent_path(), Ok(String::from("1-0")));
Cannot get parent for root_hub
let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![] }, ..Default::default() };
assert_eq!(d.parent_path().is_err(), true);
sourcepub fn trunk_path(&self) -> String
pub fn trunk_path(&self) -> String
Path of trunk USBDevice
; first in tree
let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1, 2, 3] }, ..Default::default() };
assert_eq!(d.trunk_path(), "1-1");
sourcepub fn is_trunk_device(&self) -> bool
pub fn is_trunk_device(&self) -> bool
Trunk device is first in tree
// trunk device only 1 position in tree
let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1] }, ..Default::default() };
assert_eq!(d.is_trunk_device(), true);
// not a trunk device
let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1, 2] }, ..Default::default() };
assert_eq!(d.is_trunk_device(), false);
sourcepub fn is_root_hub(&self) -> bool
pub fn is_root_hub(&self) -> bool
Root hub is a specific device on Linux, essentially the bus but sits in device tree because of system_profiler legacy
// a root hub no tree positions
let d = cyme::system_profiler::USBDevice{ name: String::from("root_hub"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![] }, ..Default::default() };
assert_eq!(d.is_root_hub(), true);
// not a root hub has tree positions
let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1] }, ..Default::default() };
assert_eq!(d.is_root_hub(), false);
sourcepub fn get_vendor_product_with_fallback(&self) -> (String, String)
pub fn get_vendor_product_with_fallback(&self) -> (String, String)
From lsusb.c: Attempt to get friendly vendor and product names from the udev hwdb. If either or both are not present, instead populate those from the device’s own string descriptors
sourcepub fn to_lsusb_string(&self) -> String
pub fn to_lsusb_string(&self) -> String
Generate a String from self like lsusb default list device
let d = cyme::system_profiler::USBDevice{
name: String::from("Test device"),
manufacturer: Some(String::from("Test Devices Inc.")),
vendor_id: Some(0x1234),
product_id: Some(0x4321),
location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 4, tree_positions: vec![1, 2, 3] },
..Default::default()
};
assert_eq!(d.to_lsusb_string(), "Bus 001 Device 004: ID 1234:4321 Test Devices Inc. Test device");
Trait Implementations§
source§impl Block<DeviceBlocks, USBDevice> for DeviceBlocks
impl Block<DeviceBlocks, USBDevice> for DeviceBlocks
source§fn default_blocks(verbose: bool) -> Vec<Self>
fn default_blocks(verbose: bool) -> Vec<Self>
verbose
for maximum verbositysource§fn len(&self, d: &[&USBDevice]) -> usize
fn len(&self, d: &[&USBDevice]) -> usize
source§fn generate_padding(d: &[&USBDevice]) -> HashMap<Self, usize>
fn generate_padding(d: &[&USBDevice]) -> HashMap<Self, usize>
d
Vec or heading if > this; values can then be padded to match thissource§fn format_value(
&self,
d: &USBDevice,
pad: &HashMap<Self, usize>,
settings: &PrintSettings
) -> Option<String>
fn format_value( &self, d: &USBDevice, pad: &HashMap<Self, usize>, settings: &PrintSettings ) -> Option<String>
source§fn colour(&self, s: &str, ct: &ColourTheme) -> ColoredString
fn colour(&self, s: &str, ct: &ColourTheme) -> ColoredString
source§fn heading(&self) -> &str
fn heading(&self) -> &str
source§fn heading_padded(&self, pad: &HashMap<Self, usize>) -> String
fn heading_padded(&self, pad: &HashMap<Self, usize>) -> String
source§fn block_length(&self) -> BlockLength
fn block_length(&self) -> BlockLength
BlockLength::Variable
will be heading usize without actual device data