1
0
Fork 0

drtio-proto: (N)ACK -> Reply { succeeded }

This commit is contained in:
occheung 2024-09-04 10:00:48 +08:00
parent 960864c847
commit 59954829a2
3 changed files with 79 additions and 38 deletions

View File

@ -332,6 +332,16 @@ pub enum Packet {
CoreMgmtAllocatorDebugRequest { CoreMgmtAllocatorDebugRequest {
destination: u8, destination: u8,
}, },
CoreMgmtFlashRequest {
destination: u8,
last: bool,
length: u16,
data: [u8; MASTER_PAYLOAD_MAX_SIZE],
},
CoreMgmtDropLinkAck {
destination: u8,
},
CoreMgmtDropLink,
CoreMgmtGetLogReply { CoreMgmtGetLogReply {
last: bool, last: bool,
length: u16, length: u16,
@ -342,8 +352,9 @@ pub enum Packet {
length: u16, length: u16,
value: [u8; SAT_PAYLOAD_MAX_SIZE], value: [u8; SAT_PAYLOAD_MAX_SIZE],
}, },
CoreMgmtAck, CoreMgmtReply {
CoreMgmtNack, succeeded: bool,
},
} }
impl Packet { impl Packet {
@ -684,6 +695,23 @@ impl Packet {
destination: reader.read_u8()?, destination: reader.read_u8()?,
}, },
0xdb => { 0xdb => {
let destination = reader.read_u8()?;
let last = reader.read_bool()?;
let length = reader.read_u16()?;
let mut data: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE];
reader.read_exact(&mut data[0..length as usize])?;
Packet::CoreMgmtFlashRequest {
destination: destination,
last: last,
length: length,
data: data,
}
}
0xdc => Packet::CoreMgmtDropLinkAck {
destination: reader.read_u8()?,
},
0xdd => Packet::CoreMgmtDropLink,
0xde => {
let last = reader.read_bool()?; let last = reader.read_bool()?;
let length = reader.read_u16()?; let length = reader.read_u16()?;
let mut data: [u8; SAT_PAYLOAD_MAX_SIZE] = [0; SAT_PAYLOAD_MAX_SIZE]; let mut data: [u8; SAT_PAYLOAD_MAX_SIZE] = [0; SAT_PAYLOAD_MAX_SIZE];
@ -694,7 +722,7 @@ impl Packet {
data: data, data: data,
} }
} }
0xdc => { 0xdf => {
let last = reader.read_bool()?; let last = reader.read_bool()?;
let length = reader.read_u16()?; let length = reader.read_u16()?;
let mut value: [u8; SAT_PAYLOAD_MAX_SIZE] = [0; SAT_PAYLOAD_MAX_SIZE]; let mut value: [u8; SAT_PAYLOAD_MAX_SIZE] = [0; SAT_PAYLOAD_MAX_SIZE];
@ -705,8 +733,9 @@ impl Packet {
value: value, value: value,
} }
} }
0xdd => Packet::CoreMgmtAck, 0xe0 => Packet::CoreMgmtReply {
0xde => Packet::CoreMgmtNack, succeeded: reader.read_bool()?,
},
ty => return Err(Error::UnknownPacket(ty)), ty => return Err(Error::UnknownPacket(ty)),
}) })
@ -1153,20 +1182,39 @@ impl Packet {
writer.write_u8(0xda)?; writer.write_u8(0xda)?;
writer.write_u8(destination)?; writer.write_u8(destination)?;
} }
Packet::CoreMgmtGetLogReply { last, length, data } => { Packet::CoreMgmtFlashRequest {
destination,
last,
length,
data,
} => {
writer.write_u8(0xdb)?; writer.write_u8(0xdb)?;
writer.write_u8(destination)?;
writer.write_bool(last)?;
writer.write_u16(length)?;
writer.write_all(&data[..length as usize])?;
}
Packet::CoreMgmtDropLinkAck { destination } => {
writer.write_u8(0xdc)?;
writer.write_u8(destination)?;
}
Packet::CoreMgmtDropLink => writer.write_u8(0xdd)?,
Packet::CoreMgmtGetLogReply { last, length, data } => {
writer.write_u8(0xde)?;
writer.write_bool(last)?; writer.write_bool(last)?;
writer.write_u16(length)?; writer.write_u16(length)?;
writer.write_all(&data[0..length as usize])?; writer.write_all(&data[0..length as usize])?;
} }
Packet::CoreMgmtConfigReadReply { last, length, value } => { Packet::CoreMgmtConfigReadReply { last, length, value } => {
writer.write_u8(0xdc)?; writer.write_u8(0xdf)?;
writer.write_bool(last)?; writer.write_bool(last)?;
writer.write_u16(length)?; writer.write_u16(length)?;
writer.write_all(&value[0..length as usize])?; writer.write_all(&value[0..length as usize])?;
} }
Packet::CoreMgmtAck => writer.write_u8(0xdd)?, Packet::CoreMgmtReply { succeeded } => {
Packet::CoreMgmtNack => writer.write_u8(0xde)?, writer.write_u8(0xe0)?;
writer.write_bool(succeeded)?;
}
} }
Ok(()) Ok(())
} }

View File

@ -201,7 +201,7 @@ mod remote_coremgmt {
.await; .await;
match reply { match reply {
Ok(Packet::CoreMgmtAck) => { Ok(Packet::CoreMgmtReply { succeeded: true }) => {
write_i8(stream, Reply::Success as i8).await?; write_i8(stream, Reply::Success as i8).await?;
Ok(()) Ok(())
} }
@ -291,7 +291,7 @@ mod remote_coremgmt {
.await; .await;
match reply { match reply {
Ok(Packet::CoreMgmtAck) => { Ok(Packet::CoreMgmtReply { succeeded: true }) => {
write_i8(stream, Reply::Success as i8).await?; write_i8(stream, Reply::Success as i8).await?;
Ok(()) Ok(())
} }
@ -330,7 +330,7 @@ mod remote_coremgmt {
.await; .await;
match reply { match reply {
Ok(Packet::CoreMgmtAck) => { Ok(Packet::CoreMgmtReply { succeeded: true }) => {
write_i8(stream, Reply::Success as i8).await?; write_i8(stream, Reply::Success as i8).await?;
Ok(()) Ok(())
} }
@ -440,7 +440,7 @@ mod remote_coremgmt {
data: *slice, data: *slice,
}, },
|reply| match reply { |reply| match reply {
Packet::CoreMgmtAck => Ok(()), Packet::CoreMgmtReply { succeeded: true } => Ok(()),
packet => { packet => {
error!("received unexpected aux packet: {:?}", packet); error!("received unexpected aux packet: {:?}", packet);
Err(drtio::Error::UnexpectedReply) Err(drtio::Error::UnexpectedReply)
@ -490,7 +490,7 @@ mod remote_coremgmt {
.await; .await;
match reply { match reply {
Ok(Packet::CoreMgmtAck) => { Ok(Packet::CoreMgmtReply { succeeded: true }) => {
write_i8(stream, Reply::Success as i8).await?; write_i8(stream, Reply::Success as i8).await?;
Ok(()) Ok(())
} }
@ -527,7 +527,7 @@ mod remote_coremgmt {
.await; .await;
match reply { match reply {
Ok(Packet::CoreMgmtAck) => { Ok(Packet::CoreMgmtReply { succeeded: true }) => {
write_i8(stream, Reply::Success as i8).await?; write_i8(stream, Reply::Success as i8).await?;
Ok(()) Ok(())
} }
@ -565,7 +565,7 @@ mod remote_coremgmt {
.await; .await;
match reply { match reply {
Ok(Packet::CoreMgmtAck) => { Ok(Packet::CoreMgmtReply { succeeded: true }) => {
write_i8(stream, Reply::RebootImminent as i8).await?; write_i8(stream, Reply::RebootImminent as i8).await?;
Ok(()) Ok(())
} }
@ -602,7 +602,7 @@ mod remote_coremgmt {
.await; .await;
match reply { match reply {
Ok(Packet::CoreMgmtAck) => { Ok(Packet::CoreMgmtReply { succeeded: true }) => {
write_i8(stream, Reply::Success as i8).await?; write_i8(stream, Reply::Success as i8).await?;
Ok(()) Ok(())
} }

View File

@ -1056,7 +1056,7 @@ fn process_aux_packet(
timer timer
); );
mgmt::clear_log(); mgmt::clear_log();
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck) drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true })
} }
drtioaux::Packet::CoreMgmtSetLogLevelRequest { drtioaux::Packet::CoreMgmtSetLogLevelRequest {
destination: _destination, destination: _destination,
@ -1076,9 +1076,9 @@ fn process_aux_packet(
if let Ok(level_filter) = mgmt::byte_to_level_filter(log_level) { if let Ok(level_filter) = mgmt::byte_to_level_filter(log_level) {
info!("Changing log level to {}", level_filter); info!("Changing log level to {}", level_filter);
log::set_max_level(level_filter); log::set_max_level(level_filter);
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck) drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true })
} else { } else {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
} }
} }
drtioaux::Packet::CoreMgmtSetUartLogLevelRequest { drtioaux::Packet::CoreMgmtSetUartLogLevelRequest {
@ -1104,9 +1104,9 @@ fn process_aux_packet(
.unwrap() .unwrap()
.set_uart_log_level(level_filter); .set_uart_log_level(level_filter);
} }
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck) drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true })
} else { } else {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
} }
} }
drtioaux::Packet::CoreMgmtConfigReadRequest { drtioaux::Packet::CoreMgmtConfigReadRequest {
@ -1130,7 +1130,7 @@ fn process_aux_packet(
let key_slice = &key[..length as usize]; let key_slice = &key[..length as usize];
if !key_slice.is_ascii() { if !key_slice.is_ascii() {
error!("invalid key"); error!("invalid key");
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
} else { } else {
let key = core::str::from_utf8(key_slice).unwrap(); let key = core::str::from_utf8(key_slice).unwrap();
if core_manager.fetch_config_value(key).is_ok() { if core_manager.fetch_config_value(key).is_ok() {
@ -1144,7 +1144,7 @@ fn process_aux_packet(
}, },
) )
} else { } else {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
} }
} }
} }
@ -1198,11 +1198,7 @@ fn process_aux_packet(
core_manager.clear_data(); core_manager.clear_data();
} }
if succeeded { drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded })
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
} else {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
}
} }
drtioaux::Packet::CoreMgmtConfigRemoveRequest { drtioaux::Packet::CoreMgmtConfigRemoveRequest {
destination: _destination, destination: _destination,
@ -1223,14 +1219,11 @@ fn process_aux_packet(
let key_slice = &key[..length as usize]; let key_slice = &key[..length as usize];
if !key_slice.is_ascii() { if !key_slice.is_ascii() {
error!("invalid key"); error!("invalid key");
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
} else { } else {
let key = core::str::from_utf8(key_slice).unwrap(); let key = core::str::from_utf8(key_slice).unwrap();
if core_manager.remove_config(key).is_ok() { let succeeded = core_manager.remove_config(key).is_ok();
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck) drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded })
} else {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
}
} }
} }
drtioaux::Packet::CoreMgmtConfigEraseRequest { drtioaux::Packet::CoreMgmtConfigEraseRequest {
@ -1248,7 +1241,7 @@ fn process_aux_packet(
); );
error!("config erase not supported on zynq device"); error!("config erase not supported on zynq device");
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
} }
drtioaux::Packet::CoreMgmtRebootRequest { drtioaux::Packet::CoreMgmtRebootRequest {
destination: _destination, destination: _destination,
@ -1265,7 +1258,7 @@ fn process_aux_packet(
timer timer
); );
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)?; drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true })?;
info!("reboot imminent"); info!("reboot imminent");
slcr::reboot(); slcr::reboot();
Ok(()) Ok(())
@ -1285,7 +1278,7 @@ fn process_aux_packet(
); );
error!("debug allocator not supported on zynq device"); error!("debug allocator not supported on zynq device");
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
} }
p => { p => {