Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions console_backend/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")]
Expand All @@ -24,8 +24,8 @@ pub struct CliOptions {
#[clap(long = "refresh-rate", validator(is_refresh_rate))]
pub refresh_rate: Option<u8>,

#[clap(long = "tab", validator(is_tab))]
pub tab: Option<String>,
#[clap(long = "tab")]
pub tab: Option<CliTabs>,
}

impl CliOptions {
Expand Down
1 change: 1 addition & 0 deletions console_backend/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use pyo3::types::PyBytes;

use async_logger_log::Logger;

use clap::Clap;
use std::{
io::{BufReader, Cursor},
str::FromStr,
Expand Down
46 changes: 31 additions & 15 deletions console_backend/src/types.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand All @@ -25,6 +25,7 @@ use std::{
hash::Hash,
net::TcpStream,
ops::Deref,
str::FromStr,
sync::{mpsc::Sender, Arc, Mutex},
thread,
thread::JoinHandle,
Expand Down Expand Up @@ -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.
Expand All @@ -430,9 +427,9 @@ impl std::str::FromStr for FlowControl {
/// - `sat_str`: The signal code.
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
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
Expand All @@ -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<Self, Self::Err> {
// TODO: add custom error handling
Ok(CliTabs(Tabs::from_str(s).map_err(|e| format!("{}", e))?))
}
}

Expand Down