proto fw: update csr

This commit is contained in:
morgan 2025-01-14 14:21:58 +08:00
parent abcfd37487
commit ab3620bac4

View File

@ -144,7 +144,7 @@ pub enum NameSpace {
}
#[derive(Debug)]
pub enum DownConnPacket {
pub enum RXPacket {
CtrlReply {
tag: Option<u8>,
length: u32,
@ -169,12 +169,12 @@ pub enum DownConnPacket {
},
}
impl DownConnPacket {
impl RXPacket {
pub fn read_from(reader: &mut Cursor<&mut [u8]>, packet_type: u8) -> Result<Self, Error> {
match packet_type {
0x03 => DownConnPacket::get_ctrl_packet(reader, false),
0x06 => DownConnPacket::get_ctrl_packet(reader, true),
0x07 => DownConnPacket::get_event_packet(reader),
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)),
}
}
@ -199,15 +199,15 @@ impl DownConnPacket {
}
if ackcode == 0x00 {
return Ok(DownConnPacket::CtrlReply { tag, length, data });
return Ok(RXPacket::CtrlReply { tag, length, data });
} else {
return Ok(DownConnPacket::CtrlDelay {
return Ok(RXPacket::CtrlDelay {
tag,
time: NetworkEndian::read_u32(&data[..4]),
});
}
}
0x01 => return Ok(DownConnPacket::CtrlAck { tag }),
0x01 => return Ok(RXPacket::CtrlAck { tag }),
_ => return Err(Error::CtrlAckError(ackcode)),
}
}
@ -248,7 +248,7 @@ impl DownConnPacket {
return Err(Error::CorruptedPacket);
}
Ok(DownConnPacket::Event {
Ok(RXPacket::Event {
conn_id,
packet_tag,
length,
@ -305,7 +305,7 @@ impl<Cursor: Write> CxpWrite for Cursor {
}
#[derive(Debug)]
pub enum UpConnPacket {
pub enum TXPacket {
CtrlRead {
tag: Option<u8>,
addr: u32,
@ -322,10 +322,10 @@ pub enum UpConnPacket {
},
}
impl UpConnPacket {
impl TXPacket {
pub fn write_to(&self, writer: &mut Cursor<&mut [u8]>) -> Result<(), Error> {
match *self {
UpConnPacket::CtrlRead { tag, addr, length } => {
TXPacket::CtrlRead { tag, addr, length } => {
match tag {
Some(t) => {
writer.write_4x_u8(0x05)?;
@ -347,7 +347,7 @@ impl UpConnPacket {
let checksum = get_cxp_crc(&writer.get_ref()[4..writer.position()]);
writer.write_u32(checksum)?;
}
UpConnPacket::CtrlWrite {
TXPacket::CtrlWrite {
tag,
addr,
length,
@ -375,7 +375,7 @@ impl UpConnPacket {
let checksum = get_cxp_crc(&writer.get_ref()[4..writer.position()]);
writer.write_u32(checksum)?;
}
UpConnPacket::EventAck { packet_tag } => {
TXPacket::EventAck { packet_tag } => {
writer.write_4x_u8(0x08)?;
writer.write_4x_u8(packet_tag)?;
}