-
Notifications
You must be signed in to change notification settings - Fork 2
Headless runner for console[CPP-318][CPP-313]. #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| use console_backend::{ | ||
| cli_options::{handle_cli, CliOptions}, | ||
| connection::ConnectionState, | ||
| log_panel::setup_logging, | ||
| shared_state::{backend_recv_thread, SharedState}, | ||
| types::{ClientSender, Result}, | ||
| utils::{refresh_loggingbar, refresh_navbar}, | ||
| }; | ||
| use crossbeam::{channel, scope}; | ||
| fn main() -> Result<()> { | ||
| scope(|s| { | ||
| let (client_send_, client_recv) = channel::unbounded::<Vec<u8>>(); | ||
| let (_server_send, server_recv) = channel::unbounded::<Vec<u8>>(); | ||
| let client_send = ClientSender::new(client_send_); | ||
| setup_logging(client_send.clone(), true); | ||
| let opt = CliOptions::from_filtered_cli(); | ||
| let shared_state = SharedState::new(); | ||
| let connection_state = ConnectionState::new(client_send.clone(), shared_state.clone()); | ||
| if opt.input.is_none() { | ||
|
||
| eprintln!("\nRunning in headless mode only command line options work."); | ||
| eprintln!("Help:"); | ||
| eprintln!("\tcargo make headless-run -- --help"); | ||
|
||
| eprintln!("Usage:"); | ||
| eprintln!("\tcargo make headless-run -- tcp piksi-relay-bb9f2b10e53143f4a816a11884e679cf.ce.swiftnav.com --port=55555\n"); | ||
| } else { | ||
| handle_cli(opt, &connection_state, shared_state.clone()); | ||
| refresh_navbar(&mut client_send.clone(), shared_state.clone()); | ||
| refresh_loggingbar(&mut client_send.clone(), shared_state.clone()); | ||
| backend_recv_thread(connection_state, client_send, server_recv, shared_state); | ||
| s.spawn(move |_| { | ||
| loop { | ||
| if client_recv.recv().is_err() { | ||
|
||
| break; | ||
| } | ||
| } | ||
| }) | ||
| .join().unwrap(); | ||
|
||
| } | ||
| }).unwrap(); | ||
| Ok(()) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,11 +7,14 @@ use std::{ | |
| use strum::VariantNames; | ||
|
|
||
| use crate::constants::{AVAILABLE_BAUDRATES, AVAILABLE_REFRESH_RATES}; | ||
| use crate::errors::{CONVERT_TO_STR_FAILURE, SHARED_STATE_LOCK_MUTEX_FAILURE}; | ||
| use crate::log_panel::LogLevel; | ||
| use crate::types::FlowControl; | ||
| use crate::output::CsvLogging; | ||
| use crate::shared_state::SharedState; | ||
| use crate::types::{FlowControl, RealtimeDelay}; | ||
| use crate::{ | ||
| common_constants::{SbpLogging, Tabs}, | ||
| connection::Connection, | ||
| connection::{Connection, ConnectionState}, | ||
| }; | ||
|
|
||
| #[derive(Debug)] | ||
|
|
@@ -233,3 +236,48 @@ fn is_baudrate(br: &str) -> Result<(), String> { | |
| AVAILABLE_BAUDRATES | ||
| )) | ||
| } | ||
|
|
||
| /// Start connections based on CLI options. | ||
| /// | ||
| /// # Parameters | ||
| /// - `opt`: CLI Options to start specific connection type. | ||
| /// - `connection_state`: The Server state to start a specific connection. | ||
| /// - `client_send`: Client Sender channel for communication from backend to frontend. | ||
| /// - `shared_state`: The shared state for validating another connection is not already running. | ||
| pub fn handle_cli(opt: CliOptions, connection_state: &ConnectionState, shared_state: SharedState) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is simply moved out from server.rs, no other changes. |
||
| if let Some(opt_input) = opt.input { | ||
| match opt_input { | ||
| Input::Tcp { host, port } => { | ||
| connection_state.connect_to_host(host, port); | ||
| } | ||
| Input::File { file_in } => { | ||
| let filename = file_in.display().to_string(); | ||
| connection_state.connect_to_file(filename, RealtimeDelay::On, opt.exit_after); | ||
| } | ||
| Input::Serial { | ||
| serialport, | ||
| baudrate, | ||
| flow_control, | ||
| } => { | ||
| let serialport = serialport.display().to_string(); | ||
| connection_state.connect_to_serial(serialport, baudrate, flow_control); | ||
| } | ||
| } | ||
| } | ||
| if let Some(folder) = opt.dirname { | ||
| shared_state.set_logging_directory(PathBuf::from(folder)); | ||
| } | ||
| let log_level = if let Some(log_level_) = opt.log_level { | ||
| (*log_level_).clone() | ||
| } else { | ||
| LogLevel::INFO | ||
| }; | ||
| shared_state.set_log_level(log_level); | ||
| let mut shared_data = shared_state.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE); | ||
| (*shared_data).logging_bar.csv_logging = CsvLogging::from(opt.csv_log); | ||
| if let Some(sbp_log) = opt.sbp_log { | ||
| (*shared_data).logging_bar.sbp_logging = | ||
| SbpLogging::from_str(&sbp_log.to_string()).expect(CONVERT_TO_STR_FAILURE); | ||
| } | ||
| log::logger().flush(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ use capnp::message::Builder; | |
| use crate::common_constants as cc; | ||
| use crate::constants::LOG_WRITER_BUFFER_MESSAGE_COUNT; | ||
| use crate::errors::CONSOLE_LOG_JSON_TO_STRING_FAILURE; | ||
| use crate::types::*; | ||
| use crate::types::{CapnProtoSender, ClientSender}; | ||
| use crate::utils::serialize_capnproto_builder; | ||
|
|
||
| use async_logger::Writer; | ||
|
|
@@ -96,8 +96,8 @@ pub fn handle_log_msg(msg: MsgLog) { | |
| } | ||
| } | ||
|
|
||
| pub fn setup_logging(client_sender: ClientSender) { | ||
| let log_panel = LogPanelWriter::new(client_sender); | ||
| pub fn setup_logging(client_sender: ClientSender, debug: bool) { | ||
| let log_panel = LogPanelWriter::new(client_sender, debug); | ||
| let logger = Logger::builder() | ||
| .buf_size(LOG_WRITER_BUFFER_MESSAGE_COUNT) | ||
| .formatter(splitable_log_formatter) | ||
|
|
@@ -111,11 +111,15 @@ pub fn setup_logging(client_sender: ClientSender) { | |
| #[derive(Debug)] | ||
| pub struct LogPanelWriter<S: CapnProtoSender> { | ||
| pub client_sender: S, | ||
| pub debug: bool, | ||
| } | ||
|
|
||
| impl<S: CapnProtoSender> LogPanelWriter<S> { | ||
| pub fn new(client_sender: S) -> LogPanelWriter<S> { | ||
| LogPanelWriter { client_sender } | ||
| pub fn new(client_sender: S, debug: bool) -> LogPanelWriter<S> { | ||
| LogPanelWriter { | ||
| client_sender, | ||
| debug, | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -132,6 +136,9 @@ impl<S: CapnProtoSender> Writer<Box<String>> for LogPanelWriter<S> { | |
| let mut entries = log_update.init_entries(slice.len() as u32); | ||
|
|
||
| for (idx, item) in slice.iter().enumerate() { | ||
| if self.debug { | ||
| println!("{}", item); | ||
|
||
| } | ||
| let mut entry = entries.reborrow().get(idx as u32); | ||
|
|
||
| entry.set_line(&**item); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.