-
Notifications
You must be signed in to change notification settings - Fork 26
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
Scan feature loosing some bytes in LeAdvReport #137
Comments
As temporary hack, I just fill the missing bytes with 0. Maybe this will be useful to someone with a similar problem. ...
use heapless::Vec;
...
...
let mut fixed_report_data = Vec::<u8, 256>::new();
fix_adv_payload(&report.data, &mut fixed_report_data);
...
fn fix_adv_payload<const N: usize>(payload: &[u8], result: &mut Vec<u8, N>) {
// Workaround for bug https://github.com/embassy-rs/trouble/issues/137
if payload.is_empty() {
return;
}
let mut pos: usize = 0;
loop {
let chunk_len = payload[pos] as usize;
if chunk_len == 0 {
return;
}
result.push(payload[pos]).unwrap();
pos += 1;
let bytes_left = payload[pos..].len();
defmt::debug!(
"pos: {}, chunk_len: {}, bytes_left: {}",
pos,
chunk_len,
bytes_left
);
let offset = if bytes_left < chunk_len {
bytes_left
} else {
chunk_len
};
result.extend(payload[pos..pos + offset].iter().cloned());
if bytes_left < chunk_len {
// Probably at the end
result.extend(iter::repeat(0u8).take(chunk_len - bytes_left));
return;
}
pos += chunk_len;
if pos >= payload.len() {
return;
}
}
} |
@iamtio Maybe you could provide the the full ScanReport (you prob need to add derive(defmt::Format) on it in host/src/scan.rs), also using --release? It could be something related to the iterator parsing the data. |
Hi @lulf. Here is some more logs through probe-rs
The code can be found here - iamtio/trawm |
Description
Hello guys. Thanks for your awesome job done here in implementing BLE satck in Rust.
Looks like I found an issue with the scan feature.
Some advertisment packets (
LeAdvReport
) are losing the last byte and previous one sometimes is corrupted in the.data
on read. I haven't found any pattern when this happens, except if you build the code withcargo build ... --release
and without it. And even with--release
flag sometimes it doesn't work well, but for other Adv packet payloadsI am not quite sure that this bug is in
embassy-rs/trouble
or in theembassy-rs/bt-hci
project.Example log without
--release
flag:Example log with
--release
flag:As you can see we lost
0
at the end and the49
became4B
Platofrm details
How to reproduce
Cargo.toml
src/bin/rpi_ble_scan_bug.rs
The text was updated successfully, but these errors were encountered: