diff --git a/src/libboard_artiq/src/cxp_proto.rs b/src/libboard_artiq/src/cxp_proto.rs index fb4eed9..7793e24 100644 --- a/src/libboard_artiq/src/cxp_proto.rs +++ b/src/libboard_artiq/src/cxp_proto.rs @@ -169,12 +169,12 @@ pub enum RXPacket { } impl RXPacket { - pub fn read_from(reader: &mut Cursor<&mut [u8]>, packet_type: u8) -> Result { - match packet_type { + pub fn read_from(reader: &mut Cursor<&mut [u8]>) -> Result { + 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);