diff --git a/sw/deployer/src/debug.rs b/sw/deployer/src/debug.rs index 4124745..cfa69d1 100644 --- a/sw/deployer/src/debug.rs +++ b/sw/deployer/src/debug.rs @@ -116,10 +116,67 @@ impl TryFrom> for ScreenshotMetadata { } impl Handler { - pub fn process_user_input(&self) { + pub fn process_user_input(&self) -> Option { if let Ok(line) = self.line_rx.try_recv() { - print!("Line: {line}"); + if line.len() == 0 { + return None; + } + let mut data: Vec = Vec::new(); + if line.matches("@").count() != 2 { + data.append(&mut line.as_bytes().to_vec()); + data.append(&mut [b'\0'].to_vec()); + return Some(sc64::DebugPacket { + datatype: DataType::Text.into(), + data, + }); + } else { + let start = line.find("@").unwrap(); + let end = line.rfind("@").unwrap(); + let path = &line[start + 1..end]; + if path.len() == 0 { + println!("Invalid path provided"); + return None; + } + let mut file = match File::open(path) { + Ok(file) => file, + Err(error) => { + println!("Couldn't open file: {error}"); + return None; + } + }; + let length = match file.metadata() { + Ok(metadata) => metadata.len(), + Err(error) => { + println!("Couldn't get file length: {error}"); + return None; + } + }; + let mut data = vec![0u8; length as usize]; + if let Err(error) = file.read_exact(&mut data) { + println!("Couldn't read file contents: {error}"); + return None; + } + if line.starts_with("@") && line.ends_with("@") { + return Some(sc64::DebugPacket { + datatype: DataType::RawBinary.into(), + data, + }); + } else { + let mut combined_data: Vec = Vec::new(); + combined_data.append(&mut line[0..start].as_bytes().to_vec()); + combined_data.append(&mut [b'@'].to_vec()); + combined_data.append(&mut format!("{length}").into_bytes()); + combined_data.append(&mut [b'@'].to_vec()); + combined_data.append(&mut data); + combined_data.append(&mut [b'\0'].to_vec()); + return Some(sc64::DebugPacket { + datatype: DataType::Text.into(), + data: combined_data, + }); + } + } } + None } pub fn handle_debug_packet(&mut self, debug_packet: sc64::DebugPacket) { diff --git a/sw/deployer/src/main.rs b/sw/deployer/src/main.rs index 5b0ae5c..42201b7 100644 --- a/sw/deployer/src/main.rs +++ b/sw/deployer/src/main.rs @@ -311,6 +311,8 @@ fn handle_64dd_command(sn: Option, args: &_64DDArgs) -> Result<(), sc64: // TODO: handle 64DD stuff + // TODO: print BIG warning to not use this mode together with real 64DD + println!("{}", "Sorry nothing".yellow()); Ok(()) @@ -366,8 +368,9 @@ fn handle_debug_command(sn: Option, args: &DebugArgs) -> Result<(), sc64 } } else if let Some(gdb_packet) = debug_handler.receive_gdb_packet() { sc64.send_debug_packet(gdb_packet)?; + } else if let Some(debug_packet) = debug_handler.process_user_input() { + sc64.send_debug_packet(debug_packet)?; } else { - debug_handler.process_user_input(); thread::sleep(Duration::from_millis(1)); } }