mirror of
https://github.com/Polprzewodnikowy/SummerCart64.git
synced 2024-11-22 05:59:15 +01:00
little cleanup
This commit is contained in:
parent
d630315058
commit
dc0b0495e4
@ -373,7 +373,7 @@ fn handle_list_command() -> Result<(), sc64::Error> {
|
|||||||
fn handle_upload_command(connection: Connection, args: &UploadArgs) -> Result<(), sc64::Error> {
|
fn handle_upload_command(connection: Connection, args: &UploadArgs) -> Result<(), sc64::Error> {
|
||||||
let mut sc64 = init_sc64(connection, true)?;
|
let mut sc64 = init_sc64(connection, true)?;
|
||||||
|
|
||||||
if args.reboot && !sc64.aux_try_notify(sc64::AuxMessage::Halt)? {
|
if args.reboot && !sc64.try_notify_via_aux(sc64::AuxMessage::Halt)? {
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
"Warning: no response for [Halt] AUX message".bright_yellow()
|
"Warning: no response for [Halt] AUX message".bright_yellow()
|
||||||
@ -425,7 +425,7 @@ fn handle_upload_command(connection: Connection, args: &UploadArgs) -> Result<()
|
|||||||
|
|
||||||
sc64.calculate_cic_parameters(args.cic_seed)?;
|
sc64.calculate_cic_parameters(args.cic_seed)?;
|
||||||
|
|
||||||
if args.reboot && !sc64.aux_try_notify(sc64::AuxMessage::Reboot)? {
|
if args.reboot && !sc64.try_notify_via_aux(sc64::AuxMessage::Reboot)? {
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
"Warning: no response for [Reboot] AUX message".bright_yellow()
|
"Warning: no response for [Reboot] AUX message".bright_yellow()
|
||||||
@ -470,7 +470,7 @@ fn handle_64dd_command(connection: Connection, args: &_64DDArgs) -> Result<(), s
|
|||||||
.bright_green()
|
.bright_green()
|
||||||
);
|
);
|
||||||
|
|
||||||
if args.reboot && !sc64.aux_try_notify(sc64::AuxMessage::Halt)? {
|
if args.reboot && !sc64.try_notify_via_aux(sc64::AuxMessage::Halt)? {
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
"Warning: no response for [Halt] AUX message".bright_yellow()
|
"Warning: no response for [Halt] AUX message".bright_yellow()
|
||||||
@ -587,7 +587,7 @@ fn handle_64dd_command(connection: Connection, args: &_64DDArgs) -> Result<(), s
|
|||||||
|
|
||||||
sc64.set_save_writeback(true)?;
|
sc64.set_save_writeback(true)?;
|
||||||
|
|
||||||
if args.reboot && !sc64.aux_try_notify(sc64::AuxMessage::Reboot)? {
|
if args.reboot && !sc64.try_notify_via_aux(sc64::AuxMessage::Reboot)? {
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
"Warning: no response for [Reboot] AUX message".bright_yellow()
|
"Warning: no response for [Reboot] AUX message".bright_yellow()
|
||||||
|
@ -571,16 +571,16 @@ impl SC64 {
|
|||||||
self.command_usb_write(debug_packet.datatype, &debug_packet.data)
|
self.command_usb_write(debug_packet.datatype, &debug_packet.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn aux_send(&mut self, data: u32) -> Result<(), Error> {
|
pub fn send_aux_packet(&mut self, data: AuxMessage) -> Result<(), Error> {
|
||||||
self.command_aux_write(data)
|
self.command_aux_write(data.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn aux_send_and_receive(
|
pub fn send_and_receive_aux_packet(
|
||||||
&mut self,
|
&mut self,
|
||||||
data: u32,
|
data: AuxMessage,
|
||||||
timeout: std::time::Duration,
|
timeout: std::time::Duration,
|
||||||
) -> Result<Option<u32>, Error> {
|
) -> Result<Option<AuxMessage>, Error> {
|
||||||
self.aux_send(data)?;
|
self.send_aux_packet(data)?;
|
||||||
let reply_timeout = std::time::Instant::now();
|
let reply_timeout = std::time::Instant::now();
|
||||||
loop {
|
loop {
|
||||||
match self.receive_data_packet()? {
|
match self.receive_data_packet()? {
|
||||||
@ -598,11 +598,10 @@ impl SC64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn aux_try_notify(&mut self, message: AuxMessage) -> Result<bool, Error> {
|
pub fn try_notify_via_aux(&mut self, message: AuxMessage) -> Result<bool, Error> {
|
||||||
let value: u32 = message.into();
|
|
||||||
let timeout = std::time::Duration::from_millis(500);
|
let timeout = std::time::Duration::from_millis(500);
|
||||||
if let Some(response) = self.aux_send_and_receive(value, timeout)? {
|
if let Some(response) = self.send_and_receive_aux_packet(message, timeout)? {
|
||||||
return Ok(value == response);
|
return Ok(message == response);
|
||||||
}
|
}
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
@ -614,7 +614,7 @@ impl From<Setting> for [u32; 2] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub enum DataPacket {
|
pub enum DataPacket {
|
||||||
AuxData(u32),
|
AuxData(AuxMessage),
|
||||||
Button,
|
Button,
|
||||||
DataFlushed,
|
DataFlushed,
|
||||||
DebugData(DebugPacket),
|
DebugData(DebugPacket),
|
||||||
@ -628,32 +628,25 @@ impl TryFrom<AsynchronousPacket> for DataPacket {
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
fn try_from(value: AsynchronousPacket) -> Result<Self, Self::Error> {
|
fn try_from(value: AsynchronousPacket) -> Result<Self, Self::Error> {
|
||||||
Ok(match value.id {
|
Ok(match value.id {
|
||||||
b'X' => Self::AuxData(u32::from_be_bytes(value.data[0..4].try_into().unwrap())),
|
b'X' => Self::AuxData(value.data.try_into()?),
|
||||||
b'B' => Self::Button,
|
b'B' => Self::Button,
|
||||||
b'G' => Self::DataFlushed,
|
b'G' => Self::DataFlushed,
|
||||||
b'U' => Self::DebugData(value.data.try_into()?),
|
b'U' => Self::DebugData(value.data.try_into()?),
|
||||||
b'D' => Self::DiskRequest(value.data.try_into()?),
|
b'D' => Self::DiskRequest(value.data.try_into()?),
|
||||||
b'I' => Self::IsViewer64(value.data),
|
b'I' => Self::IsViewer64(value.data),
|
||||||
b'S' => Self::SaveWriteback(value.data.try_into()?),
|
b'S' => Self::SaveWriteback(value.data.try_into()?),
|
||||||
b'F' => {
|
b'F' => Self::UpdateStatus(value.data.try_into()?),
|
||||||
if value.data.len() != 4 {
|
|
||||||
return Err(Error::new(
|
|
||||||
"Incorrect data length for update status data packet",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
Self::UpdateStatus(
|
|
||||||
u32::from_be_bytes(value.data[0..4].try_into().unwrap()).try_into()?,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
_ => return Err(Error::new("Unknown data packet code")),
|
_ => return Err(Error::new("Unknown data packet code")),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum AuxMessage {
|
pub enum AuxMessage {
|
||||||
Ping,
|
Ping,
|
||||||
Halt,
|
Halt,
|
||||||
Reboot,
|
Reboot,
|
||||||
|
Other(u32),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<AuxMessage> for u32 {
|
impl From<AuxMessage> for u32 {
|
||||||
@ -662,10 +655,26 @@ impl From<AuxMessage> for u32 {
|
|||||||
AuxMessage::Ping => 0xFF000000,
|
AuxMessage::Ping => 0xFF000000,
|
||||||
AuxMessage::Halt => 0xFF000001,
|
AuxMessage::Halt => 0xFF000001,
|
||||||
AuxMessage::Reboot => 0xFF000002,
|
AuxMessage::Reboot => 0xFF000002,
|
||||||
|
AuxMessage::Other(message) => message,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TryFrom<Vec<u8>> for AuxMessage {
|
||||||
|
type Error = Error;
|
||||||
|
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
|
||||||
|
if value.len() != 4 {
|
||||||
|
return Err(Error::new("Invalid data length for AUX data packet"));
|
||||||
|
}
|
||||||
|
Ok(match u32::from_be_bytes(value[0..4].try_into().unwrap()) {
|
||||||
|
0xFF000000 => AuxMessage::Ping,
|
||||||
|
0xFF000001 => AuxMessage::Halt,
|
||||||
|
0xFF000002 => AuxMessage::Reboot,
|
||||||
|
message => AuxMessage::Other(message),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct DebugPacket {
|
pub struct DebugPacket {
|
||||||
pub datatype: u8,
|
pub datatype: u8,
|
||||||
pub data: Vec<u8>,
|
pub data: Vec<u8>,
|
||||||
@ -821,10 +830,15 @@ impl Display for UpdateStatus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<u32> for UpdateStatus {
|
impl TryFrom<Vec<u8>> for UpdateStatus {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
|
||||||
Ok(match value {
|
if value.len() != 4 {
|
||||||
|
return Err(Error::new(
|
||||||
|
"Incorrect data length for update status data packet",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(match u32::from_be_bytes(value[0..4].try_into().unwrap()) {
|
||||||
1 => Self::MCU,
|
1 => Self::MCU,
|
||||||
2 => Self::FPGA,
|
2 => Self::FPGA,
|
||||||
3 => Self::Bootloader,
|
3 => Self::Bootloader,
|
||||||
|
Loading…
Reference in New Issue
Block a user