diff --git a/examples/dp-scanner.rs b/examples/dp-scanner.rs index 046c2eb..8ab86c3 100644 --- a/examples/dp-scanner.rs +++ b/examples/dp-scanner.rs @@ -23,7 +23,6 @@ fn main() -> ! { .slot_bits(2500) // For generating the live-list as fast as possible, set GAP factor to 1. .gap_wait_rotations(1) - .max_retry_limit(3) .build(), ); // We must not poll() too often or to little. T_slot / 2 seems to be a good compromise. @@ -45,7 +44,7 @@ fn main() -> ! { Some(dp::scan::DpScanEvent::PeripheralFound(desc)) => { log::info!("Discovered peripheral #{}:", desc.address); log::info!(" - Ident: 0x{:04x}", desc.ident); - log::info!(" - Master: {:?}", desc.tied_to_master); + log::info!(" - Master: {:?}", desc.master_address); } Some(dp::scan::DpScanEvent::PeripheralLost(address)) => { log::info!("Lost peripheral #{}.", address); diff --git a/src/dp/peripheral.rs b/src/dp/peripheral.rs index 52a1554..18912ee 100644 --- a/src/dp/peripheral.rs +++ b/src/dp/peripheral.rs @@ -95,7 +95,7 @@ pub struct PeripheralDiagnostics<'a> { /// This ident number must match the one passed in [`PeripheralOptions`]. pub ident_number: u16, /// Address of the DP master this peripheral is locked to (if any) - pub master_address: u8, + pub master_address: Option, /// Extended diagnostics blocks pub extended_diagnostics: &'a crate::dp::ExtendedDiagnostics<'a>, } @@ -105,7 +105,7 @@ pub struct PeripheralDiagnostics<'a> { pub(crate) struct DiagnosticsInfo { pub flags: DiagnosticFlags, pub ident_number: u16, - pub master_address: u8, + pub master_address: Option, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] @@ -640,11 +640,17 @@ impl<'a> Peripheral<'a> { return None; } + let master_address = if t.pdu[3] == 255 { + None + } else { + Some(t.pdu[3]) + }; + let mut diag = DiagnosticsInfo { flags: DiagnosticFlags::from_bits_retain(u16::from_le_bytes( t.pdu[0..2].try_into().unwrap(), )), - master_address: t.pdu[3], + master_address, ident_number: u16::from_be_bytes(t.pdu[4..6].try_into().unwrap()), }; diff --git a/src/dp/scan.rs b/src/dp/scan.rs index 7279e03..4cb11f8 100644 --- a/src/dp/scan.rs +++ b/src/dp/scan.rs @@ -2,7 +2,7 @@ pub struct DpPeripheralDescription { pub address: crate::Address, pub ident: u16, - pub tied_to_master: Option, + pub master_address: Option, } #[derive(Debug, PartialEq, Eq, Clone)] @@ -46,11 +46,17 @@ impl DpScanner { return None; } + let master_address = if t.pdu[3] == 255 { + None + } else { + Some(t.pdu[3]) + }; + let mut diag = crate::dp::DiagnosticsInfo { flags: crate::dp::DiagnosticFlags::from_bits_retain(u16::from_le_bytes( t.pdu[0..2].try_into().unwrap(), )), - master_address: t.pdu[3], + master_address, ident_number: u16::from_be_bytes(t.pdu[4..6].try_into().unwrap()), }; @@ -128,8 +134,7 @@ impl crate::fdl::FdlApplication for DpScanner { let desc = DpPeripheralDescription { address, ident: diag.ident_number, - // TODO: Not always Some() - tied_to_master: Some(diag.master_address), + master_address: diag.master_address, }; if station_unknown {