mirror of
https://github.com/Polprzewodnikowy/SummerCart64.git
synced 2024-11-22 05:59:15 +01:00
minor code cleanup
This commit is contained in:
parent
f68461657b
commit
3eae2b92b4
@ -134,8 +134,9 @@ module n64_flashram (
|
||||
endcase
|
||||
end
|
||||
end else begin
|
||||
if (reg_bus.address[1] && state != STATE_BUFFER) begin
|
||||
status <= reg_bus.wdata[3:0];
|
||||
if (reg_bus.address[1] && state == STATE_STATUS) begin
|
||||
status[ERASE_DONE] <= 1'b0;
|
||||
status[WRITE_DONE] <= 1'b0;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
958
sw/deployer/Cargo.lock
generated
958
sw/deployer/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -20,8 +20,8 @@ include-flate = { version = "0.2.0", features = ["stable"] }
|
||||
md5 = "0.7.0"
|
||||
panic-message = "0.3.0"
|
||||
rust-ini = "0.18.0"
|
||||
serial2 = "0.1.7"
|
||||
serialport = "4.2.0"
|
||||
serial2 = "0.2.17"
|
||||
serialport = "4.3.0"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
@ -166,6 +166,20 @@ const MAX_PACKET_LENGTH: usize = 8 * 1024 * 1024;
|
||||
const SUPPORTED_USB_PROTOCOL_VERSION: u16 = 2;
|
||||
|
||||
impl Handler {
|
||||
pub fn new() -> Self {
|
||||
let (line_tx, line_rx) = channel::<String>();
|
||||
let external_line_tx = line_tx.clone();
|
||||
|
||||
spawn(move || stdin_thread(line_tx));
|
||||
|
||||
Handler {
|
||||
header: None,
|
||||
line_rx,
|
||||
external_line_tx,
|
||||
encoding: Encoding::UTF8,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_text_encoding(&mut self, encoding: Encoding) {
|
||||
self.encoding = encoding;
|
||||
}
|
||||
@ -391,20 +405,6 @@ impl Handler {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new() -> Handler {
|
||||
let (line_tx, line_rx) = channel::<String>();
|
||||
let external_line_tx = line_tx.clone();
|
||||
|
||||
spawn(move || stdin_thread(line_tx));
|
||||
|
||||
Handler {
|
||||
header: None,
|
||||
line_rx,
|
||||
external_line_tx,
|
||||
encoding: Encoding::UTF8,
|
||||
}
|
||||
}
|
||||
|
||||
fn load_file(path: &str) -> Result<Vec<u8>, String> {
|
||||
if path.len() == 0 {
|
||||
return Err(format!("Couldn't open file: Specified path is empty"));
|
||||
|
@ -417,7 +417,7 @@ fn handle_64dd_command(connection: Connection, args: &_64DDArgs) -> Result<(), s
|
||||
|
||||
let mut sc64 = init_sc64(connection, true)?;
|
||||
|
||||
let mut debug_handler = debug::new();
|
||||
let mut debug_handler = debug::Handler::new();
|
||||
|
||||
println!(
|
||||
"{}\n{}\n{}\n{}",
|
||||
@ -627,7 +627,7 @@ fn handle_64dd_command(connection: Connection, args: &_64DDArgs) -> Result<(), s
|
||||
fn handle_debug_command(connection: Connection, args: &DebugArgs) -> Result<(), sc64::Error> {
|
||||
let mut sc64 = init_sc64(connection, true)?;
|
||||
|
||||
let mut debug_handler = debug::new();
|
||||
let mut debug_handler = debug::Handler::new();
|
||||
|
||||
if args.euc_jp {
|
||||
debug_handler.set_text_encoding(debug::Encoding::EUCJP);
|
||||
@ -859,7 +859,7 @@ fn handle_server_command(connection: Connection, args: &ServerArgs) -> Result<()
|
||||
None
|
||||
};
|
||||
|
||||
sc64::run_server(port, args.address.clone(), |event| match event {
|
||||
sc64::server::run(port, args.address.clone(), |event| match event {
|
||||
sc64::ServerEvent::Listening(address) => {
|
||||
println!(
|
||||
"{}: Listening on address [{}]",
|
||||
@ -895,8 +895,8 @@ fn handle_server_command(connection: Connection, args: &ServerArgs) -> Result<()
|
||||
|
||||
fn init_sc64(connection: Connection, check_firmware: bool) -> Result<sc64::SC64, sc64::Error> {
|
||||
let mut sc64 = match connection {
|
||||
Connection::Local(port) => sc64::new_local(port),
|
||||
Connection::Remote(remote) => sc64::new_remote(remote),
|
||||
Connection::Local(port) => sc64::SC64::open_local(port),
|
||||
Connection::Remote(remote) => sc64::SC64::open_remote(remote),
|
||||
}?;
|
||||
|
||||
if check_firmware {
|
||||
|
@ -2,7 +2,7 @@ mod cic;
|
||||
mod error;
|
||||
pub mod firmware;
|
||||
mod link;
|
||||
mod server;
|
||||
pub mod server;
|
||||
mod time;
|
||||
mod types;
|
||||
|
||||
@ -787,36 +787,25 @@ impl SC64 {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_local(port: Option<String>) -> Result<SC64, Error> {
|
||||
let port = if let Some(port) = port {
|
||||
port
|
||||
} else {
|
||||
list_local_devices()?[0].port.clone()
|
||||
};
|
||||
let mut sc64 = SC64 {
|
||||
link: link::new_local(&port)?,
|
||||
};
|
||||
sc64.check_device()?;
|
||||
Ok(sc64)
|
||||
}
|
||||
impl SC64 {
|
||||
pub fn open_local(port: Option<String>) -> Result<Self, Error> {
|
||||
let port = if let Some(port) = port {
|
||||
port
|
||||
} else {
|
||||
list_local_devices()?[0].port.clone()
|
||||
};
|
||||
let mut sc64 = SC64 {
|
||||
link: link::new_local(&port)?,
|
||||
};
|
||||
sc64.check_device()?;
|
||||
Ok(sc64)
|
||||
}
|
||||
|
||||
pub fn new_remote(address: String) -> Result<SC64, Error> {
|
||||
let mut sc64 = SC64 {
|
||||
link: link::new_remote(&address)?,
|
||||
};
|
||||
sc64.check_device()?;
|
||||
Ok(sc64)
|
||||
}
|
||||
|
||||
pub fn run_server(
|
||||
port: Option<String>,
|
||||
address: String,
|
||||
event_callback: fn(ServerEvent),
|
||||
) -> Result<(), Error> {
|
||||
let port = if let Some(port) = port {
|
||||
port
|
||||
} else {
|
||||
list_local_devices()?[0].port.clone()
|
||||
};
|
||||
server::run_server(&port, address, event_callback)
|
||||
pub fn open_remote(address: String) -> Result<Self, Error> {
|
||||
let mut sc64 = SC64 {
|
||||
link: link::new_remote(&address)?,
|
||||
};
|
||||
sc64.check_device()?;
|
||||
Ok(sc64)
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::{
|
||||
error::Error,
|
||||
link::{new_serial, Command, DataType, Packet, Response, Serial},
|
||||
link::{list_local_devices, new_serial, Command, DataType, Packet, Response, Serial},
|
||||
};
|
||||
use std::{
|
||||
collections::VecDeque,
|
||||
@ -22,11 +22,16 @@ pub enum ServerEvent {
|
||||
Err(String),
|
||||
}
|
||||
|
||||
pub fn run_server(
|
||||
port: &str,
|
||||
pub fn run(
|
||||
port: Option<String>,
|
||||
address: String,
|
||||
event_callback: fn(ServerEvent),
|
||||
) -> Result<(), Error> {
|
||||
let port = if let Some(port) = port {
|
||||
port
|
||||
} else {
|
||||
list_local_devices()?[0].port.clone()
|
||||
};
|
||||
let listener = TcpListener::bind(address)?;
|
||||
let listening_address = listener.local_addr()?;
|
||||
event_callback(ServerEvent::Listening(listening_address.to_string()));
|
||||
@ -36,7 +41,7 @@ pub fn run_server(
|
||||
Ok(mut stream) => {
|
||||
let peer = stream.peer_addr()?.to_string();
|
||||
event_callback(ServerEvent::Connected(peer.clone()));
|
||||
match server_accept_connection(port, &mut stream) {
|
||||
match server_accept_connection(port.clone(), &mut stream) {
|
||||
Ok(()) => event_callback(ServerEvent::Disconnected(peer.clone())),
|
||||
Err(error) => event_callback(ServerEvent::Err(error.to_string())),
|
||||
}
|
||||
@ -58,14 +63,14 @@ enum Event {
|
||||
Closed(Option<Error>),
|
||||
}
|
||||
|
||||
fn server_accept_connection(port: &str, stream: &mut TcpStream) -> Result<(), Error> {
|
||||
fn server_accept_connection(port: String, stream: &mut TcpStream) -> Result<(), Error> {
|
||||
let (event_sender, event_receiver) = channel::<Event>();
|
||||
let exit_flag = Arc::new(AtomicBool::new(false));
|
||||
|
||||
let mut stream_writer = BufWriter::new(stream.try_clone()?);
|
||||
let mut stream_reader = stream.try_clone()?;
|
||||
|
||||
let serial = Arc::new(new_serial(port)?);
|
||||
let serial = Arc::new(new_serial(&port)?);
|
||||
let serial_writer = serial.clone();
|
||||
let serial_reader = serial.clone();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user