diff options
author | Dario Nieuwenhuis <dirbaio@dirbaio.net> | 2020-11-25 22:21:48 +0100 |
---|---|---|
committer | Dario Nieuwenhuis <dirbaio@dirbaio.net> | 2020-11-25 22:21:48 +0100 |
commit | 90f1a3fc09e53b6437e8300675bbca54c4757637 (patch) | |
tree | 06df8ba3eb027896b32ecc2abb3425f5e161bc06 /examples/src/bin/ble_scan.rs | |
parent | 25402a14c284c2cb9f05d93034ae5caa1ede448f (diff) | |
download | nrf-softdevice-90f1a3fc09e53b6437e8300675bbca54c4757637.zip |
Somewhat decode advertising data in scan example.
Diffstat (limited to 'examples/src/bin/ble_scan.rs')
-rw-r--r-- | examples/src/bin/ble_scan.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/examples/src/bin/ble_scan.rs b/examples/src/bin/ble_scan.rs index 970b4ef..021c5e0 100644 --- a/examples/src/bin/ble_scan.rs +++ b/examples/src/bin/ble_scan.rs @@ -44,7 +44,22 @@ async fn ble_task(sd: &'static Softdevice) { params.peer_addr.addr_type(), params.peer_addr.addr ); - info!("data: {:[u8]}", slice::from_raw_parts(params.data.p_data, params.data.len as usize)); + let mut data = slice::from_raw_parts(params.data.p_data, params.data.len as usize); + while data.len() != 0 { + let len = data[0] as usize; + if data.len() < len+1 { + warn!("Advertisement data truncated?"); + break; + } + if len < 1 { + warn!("Advertisement data malformed?"); + break; + } + let key = data[1]; + let value = &data[2..len+1]; + info!("value {:u8}: {:[u8]}", key, value); + data = &data[len+1..]; + } None }) .await; |