forked from M-Labs/artiq-zynq
proto fw: refactor DownConnPacket
This commit is contained in:
parent
3642d81612
commit
485739404f
|
@ -85,7 +85,16 @@ pub enum DownConnPacket {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fn capture_ctrl_packet(reader: &mut Cursor<&mut [u8]>, with_tag: bool) -> Result<DownConnPacket, Error> {
|
impl DownConnPacket {
|
||||||
|
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),
|
||||||
|
_ => Err(Error::UnknownPacket(packet_type)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_ctrl_packet(reader: &mut Cursor<&mut [u8]>, with_tag: bool) -> Result<Self, Error> {
|
||||||
let mut tag: Option<u8> = None;
|
let mut tag: Option<u8> = None;
|
||||||
if with_tag {
|
if with_tag {
|
||||||
tag = Some(reader.read_4x_u8()?);
|
tag = Some(reader.read_4x_u8()?);
|
||||||
|
@ -125,6 +134,7 @@ fn capture_ctrl_packet(reader: &mut Cursor<&mut [u8]>, with_tag: bool) -> Result
|
||||||
}
|
}
|
||||||
_ => return Err(Error::CtrlAckError(ackcode)),
|
_ => return Err(Error::CtrlAckError(ackcode)),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn receive(channel: usize) -> Result<(), Error> {
|
pub fn receive(channel: usize) -> Result<(), Error> {
|
||||||
|
@ -133,11 +143,8 @@ pub fn receive(channel: usize) -> Result<(), Error> {
|
||||||
let mut reader = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, MEM_LEN));
|
let mut reader = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, MEM_LEN));
|
||||||
let packet_type = (CXP[channel].downconn_packet_type_read)();
|
let packet_type = (CXP[channel].downconn_packet_type_read)();
|
||||||
|
|
||||||
let packet = match packet_type {
|
let packet = DownConnPacket::read_from(&mut reader, packet_type);
|
||||||
0x03 => capture_ctrl_packet(&mut reader, false),
|
|
||||||
0x06 => capture_ctrl_packet(&mut reader, true),
|
|
||||||
_ => return Err(Error::UnknownPacket(packet_type)),
|
|
||||||
};
|
|
||||||
println!("{:?}", packet);
|
println!("{:?}", packet);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -190,7 +197,6 @@ pub enum UpConnPacket {
|
||||||
|
|
||||||
impl UpConnPacket {
|
impl UpConnPacket {
|
||||||
pub fn write_to(&self, writer: &mut Cursor<&mut [u8]>) -> Result<(), Error> {
|
pub fn write_to(&self, writer: &mut Cursor<&mut [u8]>) -> Result<(), Error> {
|
||||||
// CoaXpress use big endian
|
|
||||||
match *self {
|
match *self {
|
||||||
UpConnPacket::CtrlRead { tag, addr, length } => {
|
UpConnPacket::CtrlRead { tag, addr, length } => {
|
||||||
match tag {
|
match tag {
|
||||||
|
|
Loading…
Reference in New Issue