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

This commit is contained in:
occheung 2024-09-04 10:00:48 +08:00
parent 2bc4ff2c9b
commit 13e4b2c40c
3 changed files with 79 additions and 38 deletions

View File

@ -331,6 +331,16 @@ pub enum Packet {
CoreMgmtAllocatorDebugRequest {
destination: u8,
},
CoreMgmtFlashRequest {
destination: u8,
last: bool,
length: u16,
data: [u8; MASTER_PAYLOAD_MAX_SIZE],
},
CoreMgmtDropLinkAck {
destination: u8,
},
CoreMgmtDropLink,
CoreMgmtGetLogReply {
last: bool,
length: u16,
@ -341,8 +351,9 @@ pub enum Packet {
length: u16,
value: [u8; SAT_PAYLOAD_MAX_SIZE],
},
CoreMgmtAck,
CoreMgmtNack,
CoreMgmtReply {
succeeded: bool,
},
}
impl Packet {
@ -682,6 +693,23 @@ impl Packet {
destination: reader.read_u8()?,
},
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 length = reader.read_u16()?;
let mut data: [u8; SAT_PAYLOAD_MAX_SIZE] = [0; SAT_PAYLOAD_MAX_SIZE];
@ -692,7 +720,7 @@ impl Packet {
data: data,
}
}
0xdc => {
0xdf => {
let last = reader.read_bool()?;
let length = reader.read_u16()?;
let mut value: [u8; SAT_PAYLOAD_MAX_SIZE] = [0; SAT_PAYLOAD_MAX_SIZE];
@ -703,8 +731,9 @@ impl Packet {
value: value,
}
}
0xdd => Packet::CoreMgmtAck,
0xde => Packet::CoreMgmtNack,
0xe0 => Packet::CoreMgmtReply {
succeeded: reader.read_bool()?,
},
ty => return Err(Error::UnknownPacket(ty)),
})
@ -1149,20 +1178,39 @@ impl Packet {
writer.write_u8(0xda)?;
writer.write_u8(destination)?;
}
Packet::CoreMgmtGetLogReply { last, length, data } => {
Packet::CoreMgmtFlashRequest {
destination,
last,
length,
data,
} => {
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_u16(length)?;
writer.write_all(&data[0..length as usize])?;
}
Packet::CoreMgmtConfigReadReply { last, length, value } => {
writer.write_u8(0xdc)?;
writer.write_u8(0xdf)?;
writer.write_bool(last)?;
writer.write_u16(length)?;
writer.write_all(&value[0..length as usize])?;
}
Packet::CoreMgmtAck => writer.write_u8(0xdd)?,
Packet::CoreMgmtNack => writer.write_u8(0xde)?,
Packet::CoreMgmtReply { succeeded } => {
writer.write_u8(0xe0)?;
writer.write_bool(succeeded)?;
}
}
Ok(())
}

View File

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

View File

@ -1055,7 +1055,7 @@ fn process_aux_packet(
timer
);
mgmt::clear_log();
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true })
}
drtioaux::Packet::CoreMgmtSetLogLevelRequest {
destination: _destination,
@ -1075,9 +1075,9 @@ fn process_aux_packet(
if let Ok(level_filter) = mgmt::byte_to_level_filter(log_level) {
info!("Changing log level to {}", level_filter);
log::set_max_level(level_filter);
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true })
} else {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
}
}
drtioaux::Packet::CoreMgmtSetUartLogLevelRequest {
@ -1103,9 +1103,9 @@ fn process_aux_packet(
.unwrap()
.set_uart_log_level(level_filter);
}
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true })
} else {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
}
}
drtioaux::Packet::CoreMgmtConfigReadRequest {
@ -1129,7 +1129,7 @@ fn process_aux_packet(
let key_slice = &key[..length as usize];
if !key_slice.is_ascii() {
error!("invalid key");
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
} else {
let key = core::str::from_utf8(key_slice).unwrap();
if core_manager.fetch_config_value(key).is_ok() {
@ -1143,7 +1143,7 @@ fn process_aux_packet(
},
)
} else {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
}
}
}
@ -1197,11 +1197,7 @@ fn process_aux_packet(
core_manager.clear_data();
}
if succeeded {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
} else {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
}
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded })
}
drtioaux::Packet::CoreMgmtConfigRemoveRequest {
destination: _destination,
@ -1222,14 +1218,11 @@ fn process_aux_packet(
let key_slice = &key[..length as usize];
if !key_slice.is_ascii() {
error!("invalid key");
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
} else {
let key = core::str::from_utf8(key_slice).unwrap();
if core_manager.remove_config(key).is_ok() {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
} else {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
}
let succeeded = core_manager.remove_config(key).is_ok();
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded })
}
}
drtioaux::Packet::CoreMgmtConfigEraseRequest {
@ -1247,7 +1240,7 @@ fn process_aux_packet(
);
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 {
destination: _destination,
@ -1264,7 +1257,7 @@ fn process_aux_packet(
timer
);
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)?;
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true })?;
info!("reboot imminent");
slcr::reboot();
Ok(())
@ -1284,7 +1277,7 @@ fn process_aux_packet(
);
error!("debug allocator not supported on zynq device");
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
}
p => {