From a1eed373b07d54c534310a5a4cd69d77d3a54350 Mon Sep 17 00:00:00 2001 From: XaviDCR92 Date: Tue, 15 Jan 2019 00:21:22 +0100 Subject: requested_file is now also modified by send_file(). Packets smaller than 8 bytes are now also sent. --- src/app.rs | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) (limited to 'src/app.rs') diff --git a/src/app.rs b/src/app.rs index 3cea4ce..dfaf668 100644 --- a/src/app.rs +++ b/src/app.rs @@ -94,7 +94,7 @@ fn serial_comm(addr : Option<&String>, port_name : &String, baud_rate : Option<& TransferState::SendFile => transfer::send_file(&mut port, &folder, &mut sent_bytes, - &requested_file, + &mut requested_file, &mut file_data, &mut file_size), TransferState::Finished => break @@ -127,31 +127,25 @@ fn serial_init(addr : Option<&String>, port_name : &String, baud_rate : Option<& } }; - // This variable will be bound to a SystemPort - // instance if everything could be configured successfully. - let mut port_unwrapped; - match port { - Err(_) => { - return Err(Error::new(ErrorKind::NotFound, "Could not open serial device")); - }, - - Ok(p) => { - port_unwrapped = p; - } - }; - - let settings = - serial::PortSettings { - baud_rate: baud, - char_size: serial::Bits8, - parity: serial::ParityNone, - stop_bits: serial::Stop1, - flow_control: serial::FlowNone - }; - - port_unwrapped.configure(&settings)?; - - // Return SystemPort instance if successful. - Ok(port_unwrapped) + Err(_) => { + Err(Error::new(ErrorKind::NotFound, "Could not open serial device")) + }, + + Ok(mut p) => { + let settings = + serial::PortSettings { + baud_rate: baud, + char_size: serial::Bits8, + parity: serial::ParityNone, + stop_bits: serial::Stop1, + flow_control: serial::FlowNone + }; + + p.configure(&settings)?; + + // Return SystemPort instance if successful. + Ok(p) + } + } } -- cgit v1.2.3