diff --git a/console_backend/src/cli_options.rs b/console_backend/src/cli_options.rs index d8139dfac..9f5b908dd 100644 --- a/console_backend/src/cli_options.rs +++ b/console_backend/src/cli_options.rs @@ -3,7 +3,7 @@ use std::{ops, path::PathBuf, str::FromStr}; use crate::common_constants::Tabs; use crate::constants::{AVAILABLE_BAUDRATES, AVAILABLE_REFRESH_RATES, TAB_LIST}; -use crate::types::FlowControl; +use crate::types::{CliTabs, FlowControl}; #[derive(Clap, Debug)] #[clap(name = "swift_navigation_console", about = "Swift Navigation Console.")] @@ -24,8 +24,8 @@ pub struct CliOptions { #[clap(long = "refresh-rate", validator(is_refresh_rate))] pub refresh_rate: Option, - #[clap(long = "tab", validator(is_tab))] - pub tab: Option, + #[clap(long = "tab")] + pub tab: Option, } impl CliOptions { diff --git a/console_backend/src/server.rs b/console_backend/src/server.rs index bb7bff498..fc391f345 100644 --- a/console_backend/src/server.rs +++ b/console_backend/src/server.rs @@ -6,6 +6,7 @@ use pyo3::types::PyBytes; use async_logger_log::Logger; +use clap::Clap; use std::{ io::{BufReader, Cursor}, str::FromStr, diff --git a/console_backend/src/types.rs b/console_backend/src/types.rs index 45a88b1cc..d7d4483df 100644 --- a/console_backend/src/types.rs +++ b/console_backend/src/types.rs @@ -1,4 +1,4 @@ -use crate::common_constants as cc; +use crate::common_constants::{self as cc, Tabs}; use crate::constants::*; use crate::formatters::*; use crate::piksi_tools_constants::*; @@ -25,6 +25,7 @@ use std::{ hash::Hash, net::TcpStream, ops::Deref, + str::FromStr, sync::{mpsc::Sender, Arc, Mutex}, thread, thread::JoinHandle, @@ -414,13 +415,9 @@ pub enum RealtimeDelay { // NavBar Types. // Enum wrapping around various Vel NED Message types. #[derive(Debug)] -pub enum FlowControl { - None, - Software, - Hardware, -} +pub struct FlowControl(SPFlowControl); -impl std::str::FromStr for FlowControl { +impl FromStr for FlowControl { type Err = String; /// Convert flow control string slice to expected serialport FlowControl variant. @@ -430,9 +427,9 @@ impl std::str::FromStr for FlowControl { /// - `sat_str`: The signal code. fn from_str(s: &str) -> std::result::Result { match s { - FLOW_CONTROL_NONE => Ok(FlowControl::None), - FLOW_CONTROL_SOFTWARE => Ok(FlowControl::Software), - FLOW_CONTROL_HARDWARE => Ok(FlowControl::Hardware), + FLOW_CONTROL_NONE => Ok(FlowControl(SPFlowControl::None)), + FLOW_CONTROL_SOFTWARE => Ok(FlowControl(SPFlowControl::Software)), + FLOW_CONTROL_HARDWARE => Ok(FlowControl(SPFlowControl::Hardware)), _ => Err(format!( "Not a valid flow control option. Choose from [\"{}\", \"{}\", \"{}\"]", FLOW_CONTROL_NONE, FLOW_CONTROL_SOFTWARE, FLOW_CONTROL_HARDWARE @@ -442,13 +439,32 @@ impl std::str::FromStr for FlowControl { } impl Deref for FlowControl { + type Target = SPFlowControl; + fn deref(&self) -> &Self::Target { - match self { - FlowControl::None => &SPFlowControl::None, - FlowControl::Software => &SPFlowControl::Software, - FlowControl::Hardware => &SPFlowControl::Hardware, - } + &self.0 + } +} + +#[derive(Debug)] +pub struct CliTabs(Tabs); + +impl Deref for CliTabs { + + type Target = Tabs; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl FromStr for CliTabs { + type Err = String; + + fn from_str(s: &str) -> std::result::Result { + // TODO: add custom error handling + Ok(CliTabs(Tabs::from_str(s).map_err(|e| format!("{}", e))?)) } }