summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXavier Del Campo <xavi92psx@gmail.com>2018-12-30 18:21:35 +0100
committerXavier Del Campo <xavi92psx@gmail.com>2018-12-30 18:21:35 +0100
commitb47361f283777f266970f9c082782ebac6c04aef (patch)
treec575bd7d024e6092a144869d3b59229d9740842b /src
parent344e0963112081ca5d4e25762bbe0b8e73d2dda5 (diff)
Added some comments
Diffstat (limited to 'src')
-rw-r--r--src/app.rs24
-rw-r--r--src/cmdline.rs8
-rw-r--r--src/main.rs1
3 files changed, 23 insertions, 10 deletions
diff --git a/src/app.rs b/src/app.rs
index c520b27..360cbe4 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -53,14 +53,18 @@ fn setup_tcp(tcp_addr : &String) -> io::Result<()> {
}
fn serial_comm(addr : Option<&String>, port_name : &String, baud_rate : Option<&String>) -> io::Result<()> {
- serial_init(addr, port_name, baud_rate).unwrap();
+ let port = serial_init(addr, port_name, baud_rate).unwrap();
Ok(())
}
+/// This function initializes a serial device.
+/// Command line parameters are extracted and parsed here.
fn serial_init(addr : Option<&String>, port_name : &String, baud_rate : Option<&String>) -> io::Result<serial::SystemPort> {
use serial::SerialPort;
+ // Try to open the serial device. If opened,
+ // a SystemPort instance will be returned.
let port = serial::open(port_name);
let mut port_unwrapped;
@@ -70,7 +74,7 @@ fn serial_init(addr : Option<&String>, port_name : &String, baud_rate : Option<&
Some(b) => {
match b.parse() {
Ok(s) => serial::BaudRate::from_speed(s),
- Err(_) | Ok(_) => return Err(io::Error::new(io::ErrorKind::Other, "Invalid baudrate")),
+ Err(_) => return Err(io::Error::new(io::ErrorKind::Other, "Invalid baudrate")),
}
}
};
@@ -86,15 +90,17 @@ fn serial_init(addr : Option<&String>, port_name : &String, baud_rate : Option<&
}
};
- let settings : serial::PortSettings = serial::PortSettings {
- baud_rate: baud,
- char_size: serial::Bits8,
- parity: serial::ParityOdd,
- stop_bits: serial::Stop1,
- flow_control: serial::FlowNone
- };
+ let settings =
+ serial::PortSettings {
+ baud_rate: baud,
+ char_size: serial::Bits8,
+ parity: serial::ParityOdd,
+ stop_bits: serial::Stop1,
+ flow_control: serial::FlowNone
+ };
port_unwrapped.configure(&settings)?;
+ // Return SystemPort instance if successful.
Ok(port_unwrapped)
}
diff --git a/src/cmdline.rs b/src/cmdline.rs
index c3278df..6405301 100644
--- a/src/cmdline.rs
+++ b/src/cmdline.rs
@@ -1,5 +1,9 @@
use std::{string::String, env, collections::HashMap};
+/// This structure defines a command line
+/// argument and its low-level parameters.
+/// An array of CmdLineArg instances,
+/// called CMD_LINE_ARGS, is defined.
pub struct CmdLineArg {
pub arg_str : &'static str,
pub param_str : Option<&'static str>,
@@ -7,7 +11,11 @@ pub struct CmdLineArg {
explanation : &'static str
}
+/// This parameter allows defining serial port name.
pub const PORT_NAME_ARG : &'static str = "--port-name";
+
+/// This parameter disables sending any information
+/// coming from the console to stdout.
pub const DISABLE_OUTPUT_ARG : &'static str = "--disable-output";
pub const BAUDRATE_ARG : &'static str = "--baudrate";
pub const TCP_ARG : &'static str = "--tcp";
diff --git a/src/main.rs b/src/main.rs
index 71870ec..c65130a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,4 @@
extern crate serial;
-
mod cmdline;
mod app;