diff --git a/src/libboard_artiq/src/drtioaux_proto.rs b/src/libboard_artiq/src/drtioaux_proto.rs index cc04838..c15448c 100644 --- a/src/libboard_artiq/src/drtioaux_proto.rs +++ b/src/libboard_artiq/src/drtioaux_proto.rs @@ -297,11 +297,6 @@ pub enum Packet { destination: u8, clear: bool, }, - CoreMgmtGetLogReply { - last: bool, - length: u16, - data: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE], - }, CoreMgmtClearLogRequest { destination: u8, }, @@ -321,12 +316,6 @@ pub enum Packet { CoreMgmtConfigReadContinue { destination: u8, }, - CoreMgmtConfigReadReply { - succeeded: bool, - length: u16, - last: bool, - value: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE], - }, CoreMgmtConfigWriteRequest { destination: u8, length: u16, @@ -347,9 +336,18 @@ pub enum Packet { CoreMgmtAllocatorDebugRequest { destination: u8, }, - CoreMgmtAck { - succeeded: bool, + CoreMgmtGetLogReply { + last: bool, + length: u16, + data: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE], }, + CoreMgmtConfigReadReply { + length: u16, + last: bool, + value: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE], + }, + CoreMgmtAck, + CoreMgmtNack, } impl Packet { @@ -630,29 +628,18 @@ impl Packet { destination: reader.read_u8()?, clear: reader.read_bool()?, }, - 0xd1 => { - let last = reader.read_bool()?; - let length = reader.read_u16()?; - let mut data: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE]; - reader.read_exact(&mut data[0..length as usize])?; - Packet::CoreMgmtGetLogReply { - last: last, - length: length, - data: data, - } - } - 0xd2 => Packet::CoreMgmtClearLogRequest { + 0xd1 => Packet::CoreMgmtClearLogRequest { destination: reader.read_u8()?, }, - 0xd5 => Packet::CoreMgmtSetLogLevelRequest { + 0xd2 => Packet::CoreMgmtSetLogLevelRequest { destination: reader.read_u8()?, log_level: reader.read_u8()?, }, - 0xd6 => Packet::CoreMgmtSetUartLogLevelRequest { + 0xd3 => Packet::CoreMgmtSetUartLogLevelRequest { destination: reader.read_u8()?, log_level: reader.read_u8()?, }, - 0xd7 => { + 0xd4 => { let destination = reader.read_u8()?; let length = reader.read_u16()?; let mut key: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE]; @@ -663,20 +650,10 @@ impl Packet { key: key, } } - 0xd8 => { - let succeeded = reader.read_bool()?; - let length = reader.read_u16()?; - let last = reader.read_bool()?; - let mut value: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE]; - reader.read_exact(&mut value[0..length as usize])?; - Packet::CoreMgmtConfigReadReply { - succeeded: succeeded, - length: length, - last: last, - value: value, - } - } - 0xd9 => { + 0xd5 => Packet::CoreMgmtConfigReadContinue { + destination: reader.read_u8()?, + }, + 0xd6 => { let destination = reader.read_u8()?; let length = reader.read_u16()?; let last = reader.read_bool()?; @@ -689,7 +666,7 @@ impl Packet { data: data, } } - 0xda => { + 0xd7 => { let destination = reader.read_u8()?; let length = reader.read_u16()?; let mut key: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE]; @@ -700,21 +677,39 @@ impl Packet { key: key, } } - 0xdb => Packet::CoreMgmtConfigEraseRequest { + 0xd8 => Packet::CoreMgmtConfigEraseRequest { destination: reader.read_u8()?, }, - 0xdc => Packet::CoreMgmtRebootRequest { + 0xd9 => Packet::CoreMgmtRebootRequest { destination: reader.read_u8()?, }, - 0xdd => Packet::CoreMgmtAllocatorDebugRequest { + 0xda => Packet::CoreMgmtAllocatorDebugRequest { destination: reader.read_u8()?, }, - 0xde => Packet::CoreMgmtAck { - succeeded: reader.read_bool()?, + 0xdb => { + let last = reader.read_bool()?; + let length = reader.read_u16()?; + let mut data: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE]; + reader.read_exact(&mut data[0..length as usize])?; + Packet::CoreMgmtGetLogReply { + last: last, + length: length, + data: data, + } }, - 0xdf => Packet::CoreMgmtConfigReadContinue { - destination: reader.read_u8()?, + 0xdc => { + let length = reader.read_u16()?; + let last = reader.read_bool()?; + let mut value: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE]; + reader.read_exact(&mut value[0..length as usize])?; + Packet::CoreMgmtConfigReadReply { + length: length, + last: last, + value: value, + } }, + 0xdd => Packet::CoreMgmtAck, + 0xde => Packet::CoreMgmtNack, ty => return Err(Error::UnknownPacket(ty)), }) @@ -1091,28 +1086,23 @@ impl Packet { writer.write_u8(0xcc)?; writer.write_u8(destination)?; } + Packet::CoreMgmtGetLogRequest { destination, clear } => { writer.write_u8(0xd0)?; writer.write_u8(destination)?; writer.write_bool(clear)?; } - Packet::CoreMgmtGetLogReply { last, length, data } => { - writer.write_u8(0xd1)?; - writer.write_bool(last)?; - writer.write_u16(length)?; - writer.write_all(&data[0..length as usize])?; - } Packet::CoreMgmtClearLogRequest { destination } => { - writer.write_u8(0xd2)?; + writer.write_u8(0xd1)?; writer.write_u8(destination)?; } Packet::CoreMgmtSetLogLevelRequest { destination, log_level } => { - writer.write_u8(0xd5)?; + writer.write_u8(0xd2)?; writer.write_u8(destination)?; writer.write_u8(log_level)?; } Packet::CoreMgmtSetUartLogLevelRequest { destination, log_level } => { - writer.write_u8(0xd6)?; + writer.write_u8(0xd3)?; writer.write_u8(destination)?; writer.write_u8(log_level)?; } @@ -1121,22 +1111,14 @@ impl Packet { length, key, } => { - writer.write_u8(0xd7)?; + writer.write_u8(0xd4)?; writer.write_u8(destination)?; writer.write_u16(length)?; writer.write_all(&key[0..length as usize])?; } - Packet::CoreMgmtConfigReadReply { - succeeded, - length, - last, - value, - } => { - writer.write_u8(0xd8)?; - writer.write_bool(succeeded)?; - writer.write_u16(length)?; - writer.write_bool(last)?; - writer.write_all(&value[0..length as usize])?; + Packet::CoreMgmtConfigReadContinue { destination } => { + writer.write_u8(0xd5)?; + writer.write_u8(destination)?; } Packet::CoreMgmtConfigWriteRequest { destination, @@ -1144,7 +1126,7 @@ impl Packet { last, data, } => { - writer.write_u8(0xd9)?; + writer.write_u8(0xd6)?; writer.write_u8(destination)?; writer.write_u16(length)?; writer.write_bool(last)?; @@ -1155,31 +1137,41 @@ impl Packet { length, key, } => { - writer.write_u8(0xda)?; + writer.write_u8(0xd7)?; writer.write_u8(destination)?; writer.write_u16(length)?; writer.write_all(&key[0..length as usize])?; } Packet::CoreMgmtConfigEraseRequest { destination } => { - writer.write_u8(0xdb)?; + writer.write_u8(0xd8)?; writer.write_u8(destination)?; } Packet::CoreMgmtRebootRequest { destination } => { - writer.write_u8(0xdc)?; + writer.write_u8(0xd9)?; writer.write_u8(destination)?; } Packet::CoreMgmtAllocatorDebugRequest { destination } => { - writer.write_u8(0xdd)?; + writer.write_u8(0xda)?; writer.write_u8(destination)?; } - Packet::CoreMgmtAck { succeeded } => { - writer.write_u8(0xde)?; - writer.write_bool(succeeded)?; + Packet::CoreMgmtGetLogReply { last, length, data } => { + writer.write_u8(0xdb)?; + writer.write_bool(last)?; + writer.write_u16(length)?; + writer.write_all(&data[0..length as usize])?; } - Packet::CoreMgmtConfigReadContinue { destination } => { - writer.write_u8(0xdf)?; - writer.write_u8(destination)?; + Packet::CoreMgmtConfigReadReply { + length, + last, + value, + } => { + writer.write_u8(0xdc)?; + writer.write_u16(length)?; + writer.write_bool(last)?; + writer.write_all(&value[0..length as usize])?; } + Packet::CoreMgmtAck => writer.write_u8(0xdd)?, + Packet::CoreMgmtNack => writer.write_u8(0xde)?, } Ok(()) } diff --git a/src/runtime/src/mgmt.rs b/src/runtime/src/mgmt.rs index 5c7effb..545b102 100644 --- a/src/runtime/src/mgmt.rs +++ b/src/runtime/src/mgmt.rs @@ -200,7 +200,7 @@ mod remote_coremgmt { .await?; match reply { - Packet::CoreMgmtAck { succeeded: true } => { + Packet::CoreMgmtAck => { write_i8(stream, Reply::Success as i8).await?; Ok(()) } @@ -277,7 +277,7 @@ mod remote_coremgmt { .await?; match reply { - Packet::CoreMgmtAck { succeeded: true } => { + Packet::CoreMgmtAck => { write_i8(stream, Reply::Success as i8).await?; Ok(()) } @@ -310,7 +310,7 @@ mod remote_coremgmt { .await?; match reply { - Packet::CoreMgmtAck { succeeded: true } => { + Packet::CoreMgmtAck => { write_i8(stream, Reply::Success as i8).await?; Ok(()) } @@ -352,7 +352,6 @@ mod remote_coremgmt { loop { match reply { Packet::CoreMgmtConfigReadReply { - succeeded: true, length, last, value, @@ -413,7 +412,7 @@ mod remote_coremgmt { data: *slice, }, |reply| match reply { - Packet::CoreMgmtAck { succeeded: true } => Ok(()), + Packet::CoreMgmtAck => Ok(()), _ => { error!("received unknown packet"); Err(drtio::Error::UnexpectedReply.into()) @@ -461,7 +460,7 @@ mod remote_coremgmt { .await?; match reply { - Packet::CoreMgmtAck { succeeded: true } => { + Packet::CoreMgmtAck => { write_i8(stream, Reply::Success as i8).await?; Ok(()) } @@ -492,7 +491,7 @@ mod remote_coremgmt { .await?; match reply { - Packet::CoreMgmtAck { succeeded: true } => { + Packet::CoreMgmtAck => { write_i8(stream, Reply::Success as i8).await?; Ok(()) } @@ -524,7 +523,7 @@ mod remote_coremgmt { .await?; match reply { - Packet::CoreMgmtAck { succeeded: true } => { + Packet::CoreMgmtAck => { write_i8(stream, Reply::RebootImminent as i8).await?; Ok(()) } @@ -556,7 +555,7 @@ mod remote_coremgmt { .await?; match reply { - Packet::CoreMgmtAck { succeeded: true } => { + Packet::CoreMgmtAck => { write_i8(stream, Reply::Success as i8).await?; Ok(()) } diff --git a/src/satman/src/main.rs b/src/satman/src/main.rs index fd3bdc6..3e5ac28 100644 --- a/src/satman/src/main.rs +++ b/src/satman/src/main.rs @@ -1058,7 +1058,7 @@ fn process_aux_packet( timer ); mgmt::clear_log(); - drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded: true }) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck) } drtioaux::Packet::CoreMgmtSetLogLevelRequest { destination: _destination, @@ -1078,9 +1078,9 @@ fn process_aux_packet( if let Ok(level_filter) = mgmt::byte_to_level_filter(log_level) { info!("Changing log level to {}", log_level); log::set_max_level(level_filter); - drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded: true }) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck) } else { - drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded: false }) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) } } drtioaux::Packet::CoreMgmtSetUartLogLevelRequest { @@ -1106,9 +1106,9 @@ fn process_aux_packet( .unwrap() .set_uart_log_level(level_filter); } - drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded: true }) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck) } else { - drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded: false }) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) } } drtioaux::Packet::CoreMgmtConfigReadRequest { @@ -1134,12 +1134,7 @@ fn process_aux_packet( error!("invalid key"); drtioaux::send( 0, - &drtioaux::Packet::CoreMgmtConfigReadReply { - succeeded: false, - length: 0, - last: true, - value: value_slice, - }, + &drtioaux::Packet::CoreMgmtNack, ) } else { let key = core::str::from_utf8(key_slice).unwrap(); @@ -1148,7 +1143,6 @@ fn process_aux_packet( drtioaux::send( 0, &drtioaux::Packet::CoreMgmtConfigReadReply { - succeeded: true, length: meta.len as u16, last: meta.status.is_last(), value: value_slice, @@ -1157,12 +1151,7 @@ fn process_aux_packet( } else { drtioaux::send( 0, - &drtioaux::Packet::CoreMgmtConfigReadReply { - succeeded: false, - length: 0, - last: true, - value: value_slice, - }, + &drtioaux::Packet::CoreMgmtNack, ) } } @@ -1186,7 +1175,6 @@ fn process_aux_packet( drtioaux::send( 0, &drtioaux::Packet::CoreMgmtConfigReadReply { - succeeded: true, length: meta.len as u16, last: meta.status.is_last(), value: value_slice, @@ -1218,7 +1206,11 @@ fn process_aux_packet( core_manager.clear_data(); } - drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded: succeeded }) + if succeeded { + drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck) + } else { + drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) + } } drtioaux::Packet::CoreMgmtConfigRemoveRequest { destination: _destination, @@ -1239,11 +1231,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::CoreMgmtAck { succeeded: false }) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) } else { let key = core::str::from_utf8(key_slice).unwrap(); let succeeded = core_manager.remove_config(key).is_ok(); - drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded }) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck) } } drtioaux::Packet::CoreMgmtConfigEraseRequest { @@ -1278,7 +1270,7 @@ fn process_aux_packet( timer ); - drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded: true })?; + drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)?; info!("reboot imminent"); slcr::reboot(); Ok(())