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
2 changes: 1 addition & 1 deletion .github/workflows/auto-cancellation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ jobs:
steps:
- uses: fauguste/[email protected]
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
githubToken: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"console",
"swift"
]
}
}
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
members = [
"console_backend",
]

42 changes: 40 additions & 2 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ conda run -n $CONDA_ENV pylint --output-format=parseable $PYTHON_FILES
'''

[tasks.format-all]
dependencies = ["python-format-all", "qml-format", "rust-format"]
dependencies = ["python-format-all", "qml-format", "rust-format", "newline-format"]

[tasks.format]
alias = "format-all"

[tasks.format-check]
dependencies = ["python-format-check", "qml-format-check", "rust-format-check"]
dependencies = ["python-format-check", "qml-format-check", "rust-format-check", "newline-check"]

[tasks.lint]
dependencies = ["python-lint", "rust-lint", "format-check"]
Expand Down Expand Up @@ -343,3 +343,41 @@ script = '''
echo 'This is only used to validate locally.'
cd console_backend/tests && python ../../utils/bench_runner.py --frontend_mem --executable=../../main.dist/main && cd -
'''

[tasks.newline-terminator]
private = true
script_runner = "python"
script_extension = "py"
script = '''
import os
import sys
import subprocess
def raises_exc(func):
try: func()
except: return True
return False
dry_run = os.environ.get("NLT_DRY_RUN", "") == "1"
open_append = lambda fn: open(fn, "ta")
open_read = lambda fn: open(fn, "rb")
seek_end = lambda fp: (fp.seek(-1, 2), fp)[-1]
has_newline = lambda fn: seek_end(open_read(fn)).read(1) == b"\n"
append_newline = lambda fn: (open_append(fn).write("\n") if not dry_run else None, fn)[-1]
try_open_text = lambda fn: lambda: (open(fn, "ta"), open(fn, "tr").read(4096))
valid_file = lambda fn: os.path.getsize(fn) > 0 and not raises_exc(try_open_text(fn))
no_trailing_lf = lambda fn: valid_file(fn) and not has_newline(fn)
all_files = subprocess.check_output(["git", "ls-files"]).decode('utf8').splitlines()
no_newline = list(map(append_newline, filter(no_trailing_lf, all_files)))
footer = "*********************************************\n"
err = "ERROR: " if dry_run else "Fixing "
header = footer + "*** " + err + "files missing trailing newline ***\n" + footer
sys.stderr.write(header + str.join("\n", no_newline) + "\n" + footer) \
if no_newline else None
sys.exit(int(len(no_newline) > 0) if dry_run else 0)
'''

[tasks.newline-check]
env = { "NLT_DRY_RUN" = "1" }
run_task = "newline-terminator"

[tasks.newline-format]
run_task = "newline-terminator"
6 changes: 3 additions & 3 deletions console_backend/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ pub const GAL_E5X_STR: &str = "GAL E5a I+Q";
pub const GAL_E6B_STR: &str = "GAL E6 B";
pub const GAL_E6C_STR: &str = "GAL E6 C";
pub const GAL_E6X_STR: &str = "GAL E6 B+C";
pub const GAL_E8I_STR: &str = "GAL AltBOC";
pub const GAL_E8Q_STR: &str = "GAL AltBOC";
pub const GAL_E8X_STR: &str = "GAL AltBOC";
pub const GAL_E8I_STR: &str = "GAL E5ab I";
pub const GAL_E8Q_STR: &str = "GAL E5ab Q";
pub const GAL_E8X_STR: &str = "GAL E5ab I+Q";
pub const GAL_E7I_STR: &str = "GAL E5b I";
pub const GAL_E7Q_STR: &str = "GAL E5b Q";
pub const GAL_E7X_STR: &str = "GAL E5b I+Q";
Expand Down
105 changes: 89 additions & 16 deletions console_backend/src/date_conv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use chrono::{prelude::*, DateTime, Duration, Local, TimeZone, Utc};
use std::fmt::Display;

use crate::constants::{DECODED_THIS_SESSION, FACTORY_DEFAULT, NON_VOLATILE_MEMORY, UNKNOWN};
use crate::types::UtcDateTime;
Expand Down Expand Up @@ -44,26 +45,18 @@ pub fn utc_time(
.and_hms_nano(hours, minutes, seconds, nanoseconds)
}

/// Return Utc datetime as date and seconds.
/// Return generic datetime as date and seconds.
///
/// # Parameters
/// - `datetm`: The datetime to be converted into partial date and seconds strings.
///
/// # Returns:
/// - Partial datetime string and seconds/microseconds string.
pub fn utc_datetime_to_string_and_seconds(datetm: DateTime<Utc>) -> (String, f64) {
let seconds = datetm.second() as f64 + datetm.nanosecond() as f64 / 1e9_f64;
(datetm.format("%Y-%m-%d %H:%M").to_string(), seconds)
}

/// Return Local datetime as date and seconds.
///
/// # Parameters
/// - `datetm`: The datetime to be converted into partial date and seconds strings.
///
/// # Returns:
/// - Partial datetime string and seconds/microseconds string.
pub fn local_datetime_to_string_and_seconds(datetm: DateTime<Local>) -> (String, f64) {
pub fn datetime_to_string_and_seconds<T>(datetm: DateTime<T>) -> (String, f64)
where
T: TimeZone,
T::Offset: Display,
{
let seconds = datetm.second() as f64 + datetm.nanosecond() as f64 / 1e9_f64;
(datetm.format("%Y-%m-%d %H:%M").to_string(), seconds)
}
Expand All @@ -88,7 +81,7 @@ pub fn convert_gps_time_to_logging_format(
let t_gps = Utc.ymd(1980, 1, 6).and_hms(0, 0, 0)
+ Duration::weeks(wn as i64)
+ Duration::seconds(gnss_tow as i64);
let (t_gps_date_, t_gps_secs_) = utc_datetime_to_string_and_seconds(t_gps);
let (t_gps_date_, t_gps_secs_) = datetime_to_string_and_seconds(t_gps);
t_gps_date = Some(t_gps_date_);
t_gps_secs = Some(t_gps_secs_);
}
Expand All @@ -102,7 +95,7 @@ pub fn convert_gps_time_to_logging_format(
/// - Local Date string and Seconds float.
pub fn convert_local_time_to_logging_format() -> (String, f64) {
let local_t = Local::now();
let (t_local_date, t_local_secs) = local_datetime_to_string_and_seconds(local_t);
let (t_local_date, t_local_secs) = datetime_to_string_and_seconds(local_t);
(t_local_date, t_local_secs)
}

Expand All @@ -116,4 +109,84 @@ mod tests {
assert_eq!(utc_source(16_u8), String::from(DECODED_THIS_SESSION));
assert_eq!(utc_source(255_u8), String::from(UNKNOWN));
}

#[test]
fn utc_time_test() {
let year = 1337;
let month = 12;
let day = 13;
let hour = 11;
let minute = 14;
let second = 6;
let nanosecond = 1338;
assert_eq!(
utc_time(year, month, day, hour, minute, second, nanosecond).year(),
year
);
assert_eq!(
utc_time(year, month, day, hour, minute, second, nanosecond).month(),
month
);
assert_eq!(
utc_time(year, month, day, hour, minute, second, nanosecond).day(),
day
);
assert_eq!(
utc_time(year, month, day, hour, minute, second, nanosecond).hour(),
hour
);
assert_eq!(
utc_time(year, month, day, hour, minute, second, nanosecond).minute(),
minute
);
assert_eq!(
utc_time(year, month, day, hour, minute, second, nanosecond).second(),
second
);
assert_eq!(
utc_time(year, month, day, hour, minute, second, nanosecond).nanosecond(),
nanosecond
);
}

#[test]
fn datetime_to_string_and_seconds_test() {
let year = 1337;
let month = 12;
let day = 13;
let hour = 11;
let minute = 14;
let second = 6;
let nanosecond = 1338000;
let datetime = utc_time(year, month, day, hour, minute, second, nanosecond);
assert_eq!(
datetime_to_string_and_seconds(datetime),
(("1337-12-13 11:14").to_string(), 6.001338)
);
let datetime = Local::now();
let year = datetime.year();
let month = datetime.month();
let day = datetime.day();
let hour = datetime.hour();
let minute = datetime.minute();
let second = datetime.second();
let nanosecond = datetime.nanosecond();
assert_eq!(
datetime_to_string_and_seconds(datetime),
(
format!("{}-{:02}-{:02} {:02}:{:02}", year, month, day, hour, minute),
second as f64 + nanosecond as f64 / 1E9_f64
)
);
}

#[test]
fn convert_gps_time_to_logging_format_test() {
let week = Some(32);
let gnss_tow = 1337000_f64;
assert_eq!(
convert_gps_time_to_logging_format(week, gnss_tow),
(Some(("1980-09-01 11:23").to_string()), Some(20.0))
);
}
}
15 changes: 8 additions & 7 deletions console_backend/src/output.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde::Serialize;
use std::fs::File;

use crate::types::{PosLLHLog, Result, VelLog};
use crate::types::Result;
/// CsvSerializer for creating and writing to a csv.
/// Taken from ICBINS/src/output.rs.
#[derive(Debug)]
Expand All @@ -14,12 +15,12 @@ impl CsvSerializer {
writer: csv::Writer::from_path(filepath)?,
})
}
pub fn serialize_vel_log(&mut self, ds: &VelLog) -> Result<()> {
self.writer.serialize(ds)?;
self.writer.flush()?;
Ok(())
}
pub fn serialize_pos_llh_log(&mut self, ds: &PosLLHLog) -> Result<()> {
// TODO(john-michaelburke@) https://swift-nav.atlassian.net/browse/CPP-95
// Validate Solution Tab logging.
pub fn serialize<T>(&mut self, ds: &T) -> Result<()>
where
T: Serialize,
{
self.writer.serialize(ds)?;
self.writer.flush()?;
Ok(())
Expand Down
13 changes: 9 additions & 4 deletions console_backend/src/process_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ use crate::types::*;
///
/// # Returns:
/// - The filtered out Ok messages iterator.
fn log_errors(messages: impl Iterator<Item = sbp::Result<SBP>>) -> impl Iterator<Item = SBP> {
fn strip_errors_iter(
log_errors: bool,
messages: impl Iterator<Item = sbp::Result<SBP>>,
) -> impl Iterator<Item = SBP> {
messages
.inspect(|msg| {
.inspect(move |msg| {
if let Err(e) = msg {
eprintln!("error reading message: {}", e);
if log_errors {
eprintln!("error reading message: {}", e);
}
}
})
.filter_map(sbp::Result::ok)
Expand All @@ -28,7 +33,7 @@ pub fn process_messages(
client_send_clone: ClientSender,
) {
let mut main = MainTab::new(shared_state);
let messages = log_errors(messages);
let messages = strip_errors_iter(true, messages);
for message in messages {
match message {
SBP::MsgAgeCorrections(msg) => {
Expand Down
28 changes: 16 additions & 12 deletions console_backend/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,15 @@ impl Server {
)
.unwrap();
let message = message_reader.get_root::<m::message::Reader>().unwrap();
match message.which() {
Ok(m::message::Which::ConnectRequest(Ok(conn_req))) => {
let message = match message.which() {
Ok(msg) => msg,
Err(e) => {
eprintln!("error reading message: {}", e);
continue;
}
};
match message {
m::message::ConnectRequest(Ok(conn_req)) => {
let shared_state_clone = shared_state.clone();
if shared_state_clone.server_is_connected() {
println!("Already connected.");
Expand All @@ -178,7 +185,7 @@ impl Server {
connect_to_host(client_send_clone, shared_state_clone_, host_port);
});
}
Ok(m::message::Which::FileinRequest(Ok(file_in))) => {
m::message::FileinRequest(Ok(file_in)) => {
let shared_state_clone = shared_state.clone();
if shared_state_clone.server_is_connected() {
println!("Already connected.");
Expand All @@ -196,7 +203,7 @@ impl Server {
connect_to_file(&mut client_send_clone, shared_state_clone_, filename);
});
}
Ok(m::message::Which::TrackingSignalsStatusFront(Ok(cv_in))) => {
m::message::TrackingSignalsStatusFront(Ok(cv_in)) => {
let check_visibility =
cv_in.get_tracking_signals_check_visibility().unwrap();
let check_visibility: Vec<String> = check_visibility
Expand All @@ -210,21 +217,21 @@ impl Server {
check_visibility;
}
}
Ok(m::message::Which::SolutionVelocityStatusFront(Ok(cv_in))) => {
m::message::SolutionVelocityStatusFront(Ok(cv_in)) => {
let unit = cv_in.get_solution_velocity_unit().unwrap();
let shared_state_clone = shared_state.clone();
{
let mut shared_data = shared_state_clone.lock().unwrap();
(*shared_data).solution_tab.velocity_tab.unit = unit.to_string();
}
}
Ok(m::message::Which::SolutionPositionStatusUnitFront(Ok(cv_in))) => {
m::message::SolutionPositionStatusUnitFront(Ok(cv_in)) => {
let shared_state_clone = shared_state.clone();
let mut shared_data = shared_state_clone.lock().unwrap();
let unit = cv_in.get_solution_position_unit().unwrap();
(*shared_data).solution_tab.position_tab.unit = unit.to_string();
}
Ok(m::message::Which::SolutionPositionStatusButtonFront(Ok(cv_in))) => {
m::message::SolutionPositionStatusButtonFront(Ok(cv_in)) => {
let shared_state_clone = shared_state.clone();
let mut shared_data = shared_state_clone.lock().unwrap();
(*shared_data).solution_tab.position_tab.zoom =
Expand All @@ -236,11 +243,8 @@ impl Server {
(*shared_data).solution_tab.position_tab.pause =
cv_in.get_solution_position_pause();
}
Ok(_) => {
println!("something else");
}
Err(err) => {
println!("error: {}", err);
_ => {
eprintln!("unknown message from front-end");
}
}
} else {
Expand Down
Loading