forked from M-Labs/artiq-zynq
proto fw: extract packet type from mem
This commit is contained in:
parent
bfd03e13bd
commit
faaaa1d135
@ -169,12 +169,12 @@ pub enum RXPacket {
|
||||
}
|
||||
|
||||
impl RXPacket {
|
||||
pub fn read_from(reader: &mut Cursor<&mut [u8]>, packet_type: u8) -> Result<Self, Error> {
|
||||
match packet_type {
|
||||
pub fn read_from(reader: &mut Cursor<&mut [u8]>) -> Result<Self, Error> {
|
||||
match reader.read_4x_u8()? {
|
||||
0x03 => RXPacket::get_ctrl_packet(reader, false),
|
||||
0x06 => RXPacket::get_ctrl_packet(reader, true),
|
||||
0x07 => RXPacket::get_event_packet(reader),
|
||||
_ => Err(Error::UnknownPacket(packet_type)),
|
||||
ty => Err(Error::UnknownPacket(ty)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,7 +192,9 @@ impl RXPacket {
|
||||
let mut data: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE];
|
||||
reader.read(&mut data[0..length as usize])?;
|
||||
|
||||
let checksum = get_cxp_crc(&reader.get_ref()[0..reader.position()]);
|
||||
// Section 9.6.3 (CXP-001-2021)
|
||||
// only bytes after the first 4 are used in calculating the checksum
|
||||
let checksum = get_cxp_crc(&reader.get_ref()[4..reader.position()]);
|
||||
if reader.read_u32()? != checksum {
|
||||
return Err(Error::CorruptedPacket);
|
||||
}
|
||||
@ -241,7 +243,7 @@ impl RXPacket {
|
||||
let mut ev: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE];
|
||||
reader.read(&mut ev[0..ev_size as usize])?;
|
||||
|
||||
let checksum = get_cxp_crc(&reader.get_ref()[0..reader.position()]);
|
||||
let checksum = get_cxp_crc(&reader.get_ref()[4..reader.position()]);
|
||||
if reader.read_u32()? != checksum {
|
||||
println!("crc error");
|
||||
return Err(Error::CorruptedPacket);
|
||||
|
Loading…
Reference in New Issue
Block a user