Skip to content

Commit 858e13f

Browse files
[CPP-155] SBP/ SBPJson/Solution Logging + LogBar (#64)
* 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.
1 parent 31d913e commit 858e13f

37 files changed

+1532
-255
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
with:
7878
path: |
7979
${{ env.RUST_CACHE_DIRS }}
80-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
80+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock', '**/console_backend.capnp') }}
8181

8282
- uses: davidB/rust-cargo-make@v1
8383
with:

Cargo.lock

Lines changed: 15 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

console_backend/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ chrono = { version = "0.4", features = ["serde"] }
1717
csv = "1"
1818
paste = "1"
1919
pyo3 = { version = "0.13", features = ["extension-module"] }
20-
sbp = { git = "https://github.com/swift-nav/libsbp.git", rev = "629974666b1aa5fdab9fdbd517e180a2aee3809b", features = ["swiftnav-rs"] }
20+
sbp = { git = "https://github.com/swift-nav/libsbp.git", rev = "a5c221684439f2124306a2daa44126aac5457c80", features = ["json", "swiftnav-rs"] }
2121
serde = { version = "1.0.123", features = ["derive"] }
2222
tempfile = "3.2.0"
2323
ordered-float = "2.0"
@@ -31,6 +31,7 @@ anyhow = { version = "1", features = ["backtrace"] }
3131
serde_yaml = "0.8.17"
3232
clap = "3.0.0-beta.2"
3333
indexmap = { version = "1.6.2", features = ["serde"] }
34+
serde_json = { version = "1" }
3435

3536
[target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies]
3637
serialport = "4.0.1"

console_backend/benches/cpu_benches.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,20 @@ fn run_process_messages(file_in_name: &str, failure: bool) {
5656
if failure {
5757
thread::sleep(time::Duration::from_millis(FAILURE_CASE_SLEEP_MILLIS));
5858
}
59-
let messages = sbp::iter_messages(Box::new(fs::File::open(file_in_name).unwrap()))
60-
.log_errors(log::Level::Debug)
61-
.with_rover_time();
6259
let shared_state = SharedState::new();
6360
let client_send = ClientSender {
6461
inner: client_send_,
6562
};
6663
shared_state.set_running(true, client_send.clone());
67-
process_messages::process_messages(messages, shared_state, client_send, RealtimeDelay::Off);
64+
match fs::File::open(file_in_name) {
65+
Ok(fileopen) => process_messages::process_messages(
66+
fileopen,
67+
shared_state,
68+
client_send,
69+
RealtimeDelay::Off,
70+
),
71+
Err(e) => panic!("unable to read file, {}.", e),
72+
}
6873
}
6974
recv_thread.join().expect("join should succeed");
7075
}

console_backend/src/cli_options.rs

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,56 @@
11
use clap::Clap;
2-
use std::{ops, path::PathBuf};
2+
use std::{
3+
ops::{Deref, Not},
4+
path::PathBuf,
5+
str::FromStr,
6+
};
7+
use strum::VariantNames;
38

9+
use crate::common_constants::{SbpLogging, Tabs};
410
use crate::constants::{AVAILABLE_BAUDRATES, AVAILABLE_REFRESH_RATES};
5-
use crate::types::{CliTabs, FlowControl};
11+
use crate::types::FlowControl;
12+
13+
#[derive(Debug)]
14+
pub struct CliTabs(Tabs);
15+
16+
impl Deref for CliTabs {
17+
type Target = Tabs;
18+
19+
fn deref(&self) -> &Self::Target {
20+
&self.0
21+
}
22+
}
23+
24+
impl FromStr for CliTabs {
25+
type Err = String;
26+
27+
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
28+
Ok(CliTabs(Tabs::from_str(s).map_err(|_| {
29+
format!("Must choose from available tabs {:?}", Tabs::VARIANTS)
30+
})?))
31+
}
32+
}
33+
34+
#[derive(Debug)]
35+
pub struct CliSbpLogging(SbpLogging);
36+
37+
impl Deref for CliSbpLogging {
38+
type Target = SbpLogging;
39+
40+
fn deref(&self) -> &Self::Target {
41+
&self.0
42+
}
43+
}
44+
45+
impl FromStr for CliSbpLogging {
46+
type Err = String;
47+
48+
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
49+
Ok(CliSbpLogging(SbpLogging::from_str(s).map_err(|_| {
50+
format!("Must choose from available tabs {:?}", SbpLogging::VARIANTS)
51+
})?))
52+
}
53+
}
654

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

17-
// // Frontend Options
65+
/// Enable CSV logging.
66+
#[clap(long = "csv-log")]
67+
pub csv_log: bool,
68+
69+
/// Enable SBP-JSON or SBP logging.
70+
#[clap(long = "sbp-log")]
71+
pub sbp_log: Option<CliSbpLogging>,
72+
73+
/// Set log directory.
74+
#[clap(long = "log-dirname")]
75+
pub dirname: Option<String>,
76+
77+
// Frontend Options
1878
/// Don't use opengl in plots.
19-
#[clap(long = "no-opengl", parse(from_flag = ops::Not::not))]
79+
#[clap(long = "no-opengl", parse(from_flag = Not::not))]
2080
pub no_opengl: bool,
2181

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

86+
/// Start console from specific tab.
2687
#[clap(long = "tab")]
2788
pub tab: Option<CliTabs>,
89+
90+
/// Show CSV logging button.
91+
#[clap(long = "show-csv-log")]
92+
pub show_csv_log: bool,
2893
}
2994

3095
impl CliOptions {

console_backend/src/common_constants.rs

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,38 @@ pub enum Tabs {
3434
ADVANCED,
3535
}
3636

37+
#[derive(Clone, Debug, Display, EnumString, EnumVariantNames, Eq, Hash, PartialEq)]
38+
pub enum SbpLogging {
39+
#[strum(serialize = "OFF")]
40+
OFF,
41+
#[strum(serialize = "SBP_JSON")]
42+
SBP_JSON,
43+
#[strum(serialize = "SBP")]
44+
SBP,
45+
}
46+
47+
#[derive(Clone, Debug, Display, EnumString, EnumVariantNames, Eq, Hash, PartialEq)]
48+
pub enum CsvLogging {
49+
#[strum(serialize = "OFF")]
50+
OFF,
51+
#[strum(serialize = "ON")]
52+
ON,
53+
}
54+
55+
#[derive(Clone, Debug, Display, EnumString, EnumVariantNames, Eq, Hash, PartialEq)]
56+
pub enum LogLevel {
57+
#[strum(serialize = "ERROR")]
58+
ERROR,
59+
#[strum(serialize = "WARNING")]
60+
WARNING,
61+
#[strum(serialize = "NOTICE")]
62+
NOTICE,
63+
#[strum(serialize = "INFO")]
64+
INFO,
65+
#[strum(serialize = "DEBUG")]
66+
DEBUG,
67+
}
68+
3769
#[derive(Clone, Debug, Display, EnumString, EnumVariantNames, Eq, Hash, PartialEq)]
3870
pub enum Keys {
3971
#[strum(serialize = "POINTS")]
@@ -78,8 +110,40 @@ pub enum Keys {
78110
WEEK,
79111
#[strum(serialize = "ROWS")]
80112
ROWS,
113+
#[strum(serialize = "PREVIOUS_HOSTS")]
114+
PREVIOUS_HOSTS,
115+
#[strum(serialize = "PREVIOUS_PORTS")]
116+
PREVIOUS_PORTS,
117+
#[strum(serialize = "PREVIOUS_FILES")]
118+
PREVIOUS_FILES,
81119
#[strum(serialize = "CONNECTED")]
82120
CONNECTED,
121+
#[strum(serialize = "PORT")]
122+
PORT,
123+
#[strum(serialize = "POS")]
124+
POS,
125+
#[strum(serialize = "RTK")]
126+
RTK,
127+
#[strum(serialize = "SATS")]
128+
SATS,
129+
#[strum(serialize = "CORR_AGE")]
130+
CORR_AGE,
131+
#[strum(serialize = "INS")]
132+
INS,
133+
#[strum(serialize = "DATA_RATE")]
134+
DATA_RATE,
135+
#[strum(serialize = "SOLID_CONNECTION")]
136+
SOLID_CONNECTION,
137+
#[strum(serialize = "PREVIOUS_FOLDERS")]
138+
PREVIOUS_FOLDERS,
139+
#[strum(serialize = "SBP_LOGGING")]
140+
SBP_LOGGING,
141+
#[strum(serialize = "CSV_LOGGING")]
142+
CSV_LOGGING,
143+
#[strum(serialize = "SBP_LOGGING_LABELS")]
144+
SBP_LOGGING_LABELS,
145+
#[strum(serialize = "LOG_LEVEL_LABELS")]
146+
LOG_LEVEL_LABELS,
83147
}
84148

85149
#[derive(Clone, Debug, Display, EnumString, EnumVariantNames, Eq, Hash, PartialEq)]
@@ -96,10 +160,10 @@ pub enum ApplicationStates {
96160
pub enum MessageKeys {
97161
#[strum(serialize = "status")]
98162
STATUS,
99-
#[strum(serialize = "connectedStatus")]
100-
CONNECTED_STATUS,
101-
#[strum(serialize = "bottomNavbarStatus")]
102-
BOTTOM_NAVBAR_STATUS,
163+
#[strum(serialize = "statusBarStatus")]
164+
STATUS_BAR_STATUS,
165+
#[strum(serialize = "navBarStatus")]
166+
NAV_BAR_STATUS,
103167
#[strum(serialize = "solutionPositionStatus")]
104168
SOLUTION_POSITION_STATUS,
105169
#[strum(serialize = "solutionTableStatus")]
@@ -134,6 +198,10 @@ pub enum MessageKeys {
134198
SOLUTION_POSITION_STATUS_BUTTON_FRONT,
135199
#[strum(serialize = "logAppend")]
136200
LOG_APPEND,
201+
#[strum(serialize = "loggingBarFront")]
202+
LOGGING_BAR_FRONT,
203+
#[strum(serialize = "loggingBarStatus")]
204+
LOGGING_BAR_STATUS,
137205
}
138206

139207
#[derive(Clone, Debug, Display, EnumString, EnumVariantNames, Eq, Hash, PartialEq)]

console_backend/src/constants.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ pub const PAUSE_LOOP_SLEEP_DURATION_MS: u64 = 100;
2929
// Logging constants
3030
pub const LOG_WRITER_BUFFER_MESSAGE_COUNT: usize = 50;
3131

32+
// Main Tab constants.
33+
pub const VEL_TIME_STR_FILEPATH: &str = "velocity_log_%Y%m%d-%H%M%S.csv";
34+
pub const POS_LLH_TIME_STR_FILEPATH: &str = "position_log_%Y%m%d-%H%M%S.csv";
35+
pub const SBP_FILEPATH: &str = "swift-gnss-%Y%m%d-%H%M%S.sbp";
36+
pub const SBP_JSON_FILEPATH: &str = "swift-gnss-%Y%m%d-%H%M%S.sbp.json";
37+
pub const DEFAULT_LOG_DIRECTORY: &str = "SwiftNav";
38+
3239
// Common constants.
3340
pub const NUM_POINTS: usize = 200;
3441

console_backend/src/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
pub const HEARTBEAT_LOCK_MUTEX_FAILURE: &str = "unable to lock heartbeat mutex";
22
pub const SHARED_STATE_LOCK_MUTEX_FAILURE: &str = "unable to lock shared_state mutex";
33
pub const CAP_N_PROTO_SERIALIZATION_FAILURE: &str = "unable to serialize capnproto message";
4+
pub const CAP_N_PROTO_DESERIALIZATION_FAILURE: &str = "unable to deserialize capnproto message";
5+
pub const CONVERT_TO_STR_FAILURE: &str = "error converting to str";

0 commit comments

Comments
 (0)