Skip to content

Commit

Permalink
[CPP-155] SBP/ SBPJson/Solution Logging + LogBar (#64)
Browse files Browse the repository at this point in the history
* Initial commit.

* Not working.

* SBP/Csv Logging.

* Increasing expected time (likely due to the performance drop in the logging mechanism).

* Respond to review requests.

* Reduce height of top level tabs.

* Respond to review requests.

* CLI args better UI behavior.

* Adding a few unittests.

* Fix lint.

* Hardcode windows cc/cxx paths for GA.

* Remove extra CC env vars.
  • Loading branch information
john-michaelburke authored May 29, 2021
1 parent 31d913e commit 858e13f
Show file tree
Hide file tree
Showing 37 changed files with 1,532 additions and 255 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
with:
path: |
${{ env.RUST_CACHE_DIRS }}
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock', '**/console_backend.capnp') }}

- uses: davidB/rust-cargo-make@v1
with:
Expand Down
20 changes: 15 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion console_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ chrono = { version = "0.4", features = ["serde"] }
csv = "1"
paste = "1"
pyo3 = { version = "0.13", features = ["extension-module"] }
sbp = { git = "https://github.com/swift-nav/libsbp.git", rev = "629974666b1aa5fdab9fdbd517e180a2aee3809b", features = ["swiftnav-rs"] }
sbp = { git = "https://github.com/swift-nav/libsbp.git", rev = "a5c221684439f2124306a2daa44126aac5457c80", features = ["json", "swiftnav-rs"] }
serde = { version = "1.0.123", features = ["derive"] }
tempfile = "3.2.0"
ordered-float = "2.0"
Expand All @@ -31,6 +31,7 @@ anyhow = { version = "1", features = ["backtrace"] }
serde_yaml = "0.8.17"
clap = "3.0.0-beta.2"
indexmap = { version = "1.6.2", features = ["serde"] }
serde_json = { version = "1" }

[target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies]
serialport = "4.0.1"
Expand Down
13 changes: 9 additions & 4 deletions console_backend/benches/cpu_benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,20 @@ fn run_process_messages(file_in_name: &str, failure: bool) {
if failure {
thread::sleep(time::Duration::from_millis(FAILURE_CASE_SLEEP_MILLIS));
}
let messages = sbp::iter_messages(Box::new(fs::File::open(file_in_name).unwrap()))
.log_errors(log::Level::Debug)
.with_rover_time();
let shared_state = SharedState::new();
let client_send = ClientSender {
inner: client_send_,
};
shared_state.set_running(true, client_send.clone());
process_messages::process_messages(messages, shared_state, client_send, RealtimeDelay::Off);
match fs::File::open(file_in_name) {
Ok(fileopen) => process_messages::process_messages(
fileopen,
shared_state,
client_send,
RealtimeDelay::Off,
),
Err(e) => panic!("unable to read file, {}.", e),
}
}
recv_thread.join().expect("join should succeed");
}
Expand Down
75 changes: 70 additions & 5 deletions console_backend/src/cli_options.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,56 @@
use clap::Clap;
use std::{ops, path::PathBuf};
use std::{
ops::{Deref, Not},
path::PathBuf,
str::FromStr,
};
use strum::VariantNames;

use crate::common_constants::{SbpLogging, Tabs};
use crate::constants::{AVAILABLE_BAUDRATES, AVAILABLE_REFRESH_RATES};
use crate::types::{CliTabs, FlowControl};
use crate::types::FlowControl;

#[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> {
Ok(CliTabs(Tabs::from_str(s).map_err(|_| {
format!("Must choose from available tabs {:?}", Tabs::VARIANTS)
})?))
}
}

#[derive(Debug)]
pub struct CliSbpLogging(SbpLogging);

impl Deref for CliSbpLogging {
type Target = SbpLogging;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl FromStr for CliSbpLogging {
type Err = String;

fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
Ok(CliSbpLogging(SbpLogging::from_str(s).map_err(|_| {
format!("Must choose from available tabs {:?}", SbpLogging::VARIANTS)
})?))
}
}

#[derive(Clap, Debug)]
#[clap(name = "swift_navigation_console", about = "Swift Navigation Console.")]
Expand All @@ -14,17 +62,34 @@ pub struct CliOptions {
#[clap(long = "exit-after")]
pub exit_after: bool,

// // Frontend Options
/// Enable CSV logging.
#[clap(long = "csv-log")]
pub csv_log: bool,

/// Enable SBP-JSON or SBP logging.
#[clap(long = "sbp-log")]
pub sbp_log: Option<CliSbpLogging>,

/// Set log directory.
#[clap(long = "log-dirname")]
pub dirname: Option<String>,

// Frontend Options
/// Don't use opengl in plots.
#[clap(long = "no-opengl", parse(from_flag = ops::Not::not))]
#[clap(long = "no-opengl", parse(from_flag = Not::not))]
pub no_opengl: bool,

/// Don't use opengl in plots.
/// Change the refresh rate of the plots.
#[clap(long = "refresh-rate", validator(is_refresh_rate))]
pub refresh_rate: Option<u8>,

/// Start console from specific tab.
#[clap(long = "tab")]
pub tab: Option<CliTabs>,

/// Show CSV logging button.
#[clap(long = "show-csv-log")]
pub show_csv_log: bool,
}

impl CliOptions {
Expand Down
76 changes: 72 additions & 4 deletions console_backend/src/common_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,38 @@ pub enum Tabs {
ADVANCED,
}

#[derive(Clone, Debug, Display, EnumString, EnumVariantNames, Eq, Hash, PartialEq)]
pub enum SbpLogging {
#[strum(serialize = "OFF")]
OFF,
#[strum(serialize = "SBP_JSON")]
SBP_JSON,
#[strum(serialize = "SBP")]
SBP,
}

#[derive(Clone, Debug, Display, EnumString, EnumVariantNames, Eq, Hash, PartialEq)]
pub enum CsvLogging {
#[strum(serialize = "OFF")]
OFF,
#[strum(serialize = "ON")]
ON,
}

#[derive(Clone, Debug, Display, EnumString, EnumVariantNames, Eq, Hash, PartialEq)]
pub enum LogLevel {
#[strum(serialize = "ERROR")]
ERROR,
#[strum(serialize = "WARNING")]
WARNING,
#[strum(serialize = "NOTICE")]
NOTICE,
#[strum(serialize = "INFO")]
INFO,
#[strum(serialize = "DEBUG")]
DEBUG,
}

#[derive(Clone, Debug, Display, EnumString, EnumVariantNames, Eq, Hash, PartialEq)]
pub enum Keys {
#[strum(serialize = "POINTS")]
Expand Down Expand Up @@ -78,8 +110,40 @@ pub enum Keys {
WEEK,
#[strum(serialize = "ROWS")]
ROWS,
#[strum(serialize = "PREVIOUS_HOSTS")]
PREVIOUS_HOSTS,
#[strum(serialize = "PREVIOUS_PORTS")]
PREVIOUS_PORTS,
#[strum(serialize = "PREVIOUS_FILES")]
PREVIOUS_FILES,
#[strum(serialize = "CONNECTED")]
CONNECTED,
#[strum(serialize = "PORT")]
PORT,
#[strum(serialize = "POS")]
POS,
#[strum(serialize = "RTK")]
RTK,
#[strum(serialize = "SATS")]
SATS,
#[strum(serialize = "CORR_AGE")]
CORR_AGE,
#[strum(serialize = "INS")]
INS,
#[strum(serialize = "DATA_RATE")]
DATA_RATE,
#[strum(serialize = "SOLID_CONNECTION")]
SOLID_CONNECTION,
#[strum(serialize = "PREVIOUS_FOLDERS")]
PREVIOUS_FOLDERS,
#[strum(serialize = "SBP_LOGGING")]
SBP_LOGGING,
#[strum(serialize = "CSV_LOGGING")]
CSV_LOGGING,
#[strum(serialize = "SBP_LOGGING_LABELS")]
SBP_LOGGING_LABELS,
#[strum(serialize = "LOG_LEVEL_LABELS")]
LOG_LEVEL_LABELS,
}

#[derive(Clone, Debug, Display, EnumString, EnumVariantNames, Eq, Hash, PartialEq)]
Expand All @@ -96,10 +160,10 @@ pub enum ApplicationStates {
pub enum MessageKeys {
#[strum(serialize = "status")]
STATUS,
#[strum(serialize = "connectedStatus")]
CONNECTED_STATUS,
#[strum(serialize = "bottomNavbarStatus")]
BOTTOM_NAVBAR_STATUS,
#[strum(serialize = "statusBarStatus")]
STATUS_BAR_STATUS,
#[strum(serialize = "navBarStatus")]
NAV_BAR_STATUS,
#[strum(serialize = "solutionPositionStatus")]
SOLUTION_POSITION_STATUS,
#[strum(serialize = "solutionTableStatus")]
Expand Down Expand Up @@ -134,6 +198,10 @@ pub enum MessageKeys {
SOLUTION_POSITION_STATUS_BUTTON_FRONT,
#[strum(serialize = "logAppend")]
LOG_APPEND,
#[strum(serialize = "loggingBarFront")]
LOGGING_BAR_FRONT,
#[strum(serialize = "loggingBarStatus")]
LOGGING_BAR_STATUS,
}

#[derive(Clone, Debug, Display, EnumString, EnumVariantNames, Eq, Hash, PartialEq)]
Expand Down
7 changes: 7 additions & 0 deletions console_backend/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ pub const PAUSE_LOOP_SLEEP_DURATION_MS: u64 = 100;
// Logging constants
pub const LOG_WRITER_BUFFER_MESSAGE_COUNT: usize = 50;

// Main Tab constants.
pub const VEL_TIME_STR_FILEPATH: &str = "velocity_log_%Y%m%d-%H%M%S.csv";
pub const POS_LLH_TIME_STR_FILEPATH: &str = "position_log_%Y%m%d-%H%M%S.csv";
pub const SBP_FILEPATH: &str = "swift-gnss-%Y%m%d-%H%M%S.sbp";
pub const SBP_JSON_FILEPATH: &str = "swift-gnss-%Y%m%d-%H%M%S.sbp.json";
pub const DEFAULT_LOG_DIRECTORY: &str = "SwiftNav";

// Common constants.
pub const NUM_POINTS: usize = 200;

Expand Down
2 changes: 2 additions & 0 deletions console_backend/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub const HEARTBEAT_LOCK_MUTEX_FAILURE: &str = "unable to lock heartbeat mutex";
pub const SHARED_STATE_LOCK_MUTEX_FAILURE: &str = "unable to lock shared_state mutex";
pub const CAP_N_PROTO_SERIALIZATION_FAILURE: &str = "unable to serialize capnproto message";
pub const CAP_N_PROTO_DESERIALIZATION_FAILURE: &str = "unable to deserialize capnproto message";
pub const CONVERT_TO_STR_FAILURE: &str = "error converting to str";
Loading

0 comments on commit 858e13f

Please sign in to comment.