mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-02 20:24:19 +00:00
Merge "uwb_hal: handle data_packet parsing" into main
This commit is contained in:
@@ -180,6 +180,8 @@ impl IUwbChipAsyncServer for UwbChip {
|
||||
let mut reader = AsyncFd::new(reader).unwrap();
|
||||
|
||||
loop {
|
||||
const MESSAGE_TYPE_MASK: u8 = 0b11100000;
|
||||
const DATA_MESSAGE_TYPE: u8 = 0b000;
|
||||
const UWB_HEADER_SIZE: usize = 4;
|
||||
let mut buffer = vec![0; UWB_HEADER_SIZE];
|
||||
|
||||
@@ -224,7 +226,16 @@ impl IUwbChipAsyncServer for UwbChip {
|
||||
// Read the remaining header bytes, if truncated.
|
||||
read_exact(reader.get_mut(), &mut buffer[read_len..]).unwrap();
|
||||
|
||||
let length = buffer[3] as usize + UWB_HEADER_SIZE;
|
||||
let common_header = buffer[0];
|
||||
let mt = (common_header & MESSAGE_TYPE_MASK) >> 5;
|
||||
let payload_length = if mt == DATA_MESSAGE_TYPE {
|
||||
let payload_length_fields: [u8; 2] = buffer[2..=3].try_into().unwrap();
|
||||
u16::from_le_bytes(payload_length_fields) as usize
|
||||
} else {
|
||||
buffer[3] as usize
|
||||
};
|
||||
|
||||
let length = payload_length + UWB_HEADER_SIZE;
|
||||
buffer.resize(length, 0);
|
||||
|
||||
// Read the payload bytes.
|
||||
|
||||
Reference in New Issue
Block a user