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
1 change: 0 additions & 1 deletion console_backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub mod constants;
pub mod errors;
pub mod fft_monitor;
pub mod fileio;
pub mod formatters;
pub mod fusion_status_flags;
pub mod log_panel;
pub mod output;
Expand Down
2 changes: 1 addition & 1 deletion console_backend/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use serde::Serialize;
use serde_json::ser::CompactFormatter;

use crate::common_constants as cc;
use crate::formatters::*;
use crate::types::Result;
use crate::utils::formatters::*;
use crate::utils::OkOrLog;

pub type CsvLogging = cc::CsvLogging;
Expand Down
71 changes: 27 additions & 44 deletions console_backend/src/status_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,12 @@ impl HeartbeatInner {
}

pub fn check_heartbeat(&mut self) -> bool {
self.solid_connection = if (self.heartbeat_count == self.last_heartbeat_count
&& self.heartbeat_count != 0)
|| (self.data_rate <= f64::EPSILON)
{
false
} else {
self.solid_connection = (self.heartbeat_count != self.last_heartbeat_count
|| self.heartbeat_count == 0)
&& (self.data_rate > f64::EPSILON);
if self.solid_connection {
self.current_time = Instant::now();
true
};
}
self.last_heartbeat_count = self.heartbeat_count;
self.data_rate_update();
self.solid_connection
Expand Down Expand Up @@ -424,12 +421,10 @@ impl HeartbeatInner {
.is_none()
&& self.llh_is_rtk
{
self.baseline_display_mode =
if let Some(soln_mode) = rtk_mode_dict.get(&(self.llh_solution_mode as i32)) {
String::from(*soln_mode)
} else {
String::from(EMPTY_STR)
};
self.baseline_display_mode = rtk_mode_dict
.get(&(self.llh_solution_mode as i32))
.unwrap_or(&EMPTY_STR)
.to_string();
}
}

Expand All @@ -450,44 +445,32 @@ impl HeartbeatInner {
}
let ins_error = (self.ins_status_flags >> 4) & 0xF;
if ins_error != 0 {
self.ins_status_string =
if let Some(err_string) = ins_error_dict.get(&(ins_error as i32)) {
err_string.to_string()
} else {
UNKNOWN_ERROR.to_string()
};
self.ins_status_string = ins_error_dict
.get(&(ins_error as i32))
.unwrap_or(&UNKNOWN_ERROR)
.to_string();
} else {
let ins_type_string =
if let Some(type_string) = ins_type_dict.get(&(ins_type as i32)) {
String::from(*type_string)
} else {
format!("{}-", UNKNOWN_ERROR_SHORT)
};
let ins_mode_string =
if let Some(mode_string) = ins_mode_dict.get(&(ins_mode as i32)) {
mode_string
} else {
UNKNOWN_ERROR_SHORT
};
let mut odo_str = "";
if odo_status == 1 {
odo_str = ODO_POSTFIX;
}
self.ins_status_string =
format!("{}{}{}", ins_type_string, ins_mode_string, odo_str);
let ins_type_string = ins_type_dict
.get(&(ins_type as i32))
.map(|s| s.to_string())
.unwrap_or_else(|| format!("{UNKNOWN_ERROR_SHORT}-"));
let ins_mode_string = ins_mode_dict
.get(&(ins_mode as i32))
.unwrap_or(&UNKNOWN_ERROR_SHORT);
let odo_str = if odo_status == 1 { ODO_POSTFIX } else { "" };
self.ins_status_string = format!("{ins_type_string}{ins_mode_string}{odo_str}");
}
}
}
}

pub fn age_of_corrections_update(&mut self) {
self.age_of_corrections = 0.0;
if let Some(age_corr) = self.age_corrections {
if let Some(last_age_corr_time) = self.last_age_corr_receipt_time {
if (self.current_time - last_age_corr_time).as_secs_f64() < UPDATE_TOLERANCE_SECONDS
{
self.age_of_corrections = age_corr;
}
if let (Some(age_corr), Some(last_age_corr_time)) =
(self.age_corrections, self.last_age_corr_receipt_time)
{
if (self.current_time - last_age_corr_time).as_secs_f64() < UPDATE_TOLERANCE_SECONDS {
self.age_of_corrections = age_corr;
}
}
}
Expand Down
81 changes: 34 additions & 47 deletions console_backend/src/tabs/settings_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const NTRIP_ENABLE_SETTING_KEY: &str = "enable";

const SETTINGS_READ_WRITE_TIMEOUT: Duration = Duration::from_millis(1000);

// Timeout used to read all settings
const GLOBAL_TIMEOUT: Duration = Duration::from_secs(15);

lazy_static! {
static ref RECOMMENDED_INS_SETTINGS: [(&'static str, &'static str, SettingValue); 4] = [
("imu", "imu_raw_output", SettingValue::Boolean(true)),
Expand Down Expand Up @@ -277,27 +280,14 @@ impl SettingsTab {
}

fn import_success(&self) {
let mut builder = Builder::new_default();
let msg = builder.init_root::<crate::console_backend_capnp::message::Builder>();
let mut import_response = msg.init_settings_import_response();
import_response.set_status("success");
self.client_sender
.send_data(serialize_capnproto_builder(builder));
send_settings_import_response(&self.client_sender, "success");
}

fn import_err(&self, err: &Error, group: &str, name: &str, value: &str) {
let mut builder = Builder::new_default();
let msg = builder.init_root::<crate::console_backend_capnp::message::Builder>();
let mut import_response = msg.init_settings_import_response();
import_response.set_status(&format!(
"{err}\n\nWhile writing \"{value}\" to {group} -> {name}",
err = err,
group = group,
name = name,
value = value,
));
self.client_sender
.send_data(serialize_capnproto_builder(builder));
send_settings_import_response(
&self.client_sender,
&format!("{err}\n\nWhile writing \"{value}\" to {group} -> {name}"),
)
}

pub fn reset(&self, reset_settings: bool) -> Result<()> {
Expand Down Expand Up @@ -345,8 +335,8 @@ impl SettingsTab {
let ins_on = ins_mode != SettingValue::String("Disabled".to_string());
if ins_on {
let recommended_settings = self.get_recommended_ins_setting_changes()?;
for recommendation in recommended_settings {
self.write_setting(&recommendation.0, &recommendation.1, &recommendation.3)?;
for (group, name, _, value) in recommended_settings {
self.write_setting(&group, &name, &value)?;
}
}
self.save()?;
Expand All @@ -357,19 +347,19 @@ impl SettingsTab {
fn get_recommended_ins_setting_changes(&self) -> Result<Vec<(String, String, String, String)>> {
let mut recommended_changes = vec![];

for setting in RECOMMENDED_INS_SETTINGS.iter() {
for &(group, name, ref recommended_value) in RECOMMENDED_INS_SETTINGS.iter() {
let value = self
.sbp_client
.lock()
.read_setting_with_timeout(setting.0, setting.1, SETTINGS_READ_WRITE_TIMEOUT)?
.read_setting_with_timeout(group, name, SETTINGS_READ_WRITE_TIMEOUT)?
.ok_or_else(|| anyhow!("setting not found"))?
.value;
if value.as_ref() != Some(&setting.2) {
if value.as_ref() != Some(recommended_value) {
recommended_changes.push((
setting.0.to_string(),
setting.1.to_string(),
group.to_owned(),
name.to_owned(),
value.map_or_else(String::new, |v| v.to_string()),
setting.2.to_string(),
recommended_value.to_string(),
));
}
}
Expand All @@ -388,12 +378,12 @@ impl SettingsTab {
.reborrow()
.init_recommended_settings(recommendations.len() as u32);

for (i, recommendation) in recommendations.iter().enumerate() {
for (i, (group, name, curr_val, rec_val)) in recommendations.iter().enumerate() {
let mut entry = recommended_entries.reborrow().get(i as u32);
entry.set_setting_group(&recommendation.0);
entry.set_setting_name(&recommendation.1);
entry.set_current_value(&recommendation.2);
entry.set_recommended_value(&recommendation.3);
entry.set_setting_group(group);
entry.set_setting_name(name);
entry.set_current_value(curr_val);
entry.set_recommended_value(rec_val);
}
}

Expand Down Expand Up @@ -451,8 +441,6 @@ impl SettingsTab {
}

fn read_all_settings(&self) {
const GLOBAL_TIMEOUT: Duration = Duration::from_secs(15);

let (ctx, handle) = Context::with_timeout(SETTINGS_READ_WRITE_TIMEOUT);

let mut conn = self.shared_state.watch_connection();
Expand Down Expand Up @@ -482,14 +470,13 @@ impl SettingsTab {
let mut product_id = None;
for entry in settings {
if let Some(ref value) = entry.value {
if FIRMWARE_VERSION_SETTING_KEY == entry.setting.name {
firmware_version = Some(value.to_string());
}
if PRODUCT_ID_SETTING_KEY == entry.setting.name {
product_id = Some(value.to_string());
}
if DGNSS_SOLUTION_MODE_SETTING_KEY == entry.setting.name {
self.shared_state.set_dgnss_enabled(value.to_string());
match entry.setting.name.as_str() {
FIRMWARE_VERSION_SETTING_KEY => firmware_version = Some(value.to_string()),
PRODUCT_ID_SETTING_KEY => product_id = Some(value.to_string()),
DGNSS_SOLUTION_MODE_SETTING_KEY => {
self.shared_state.set_dgnss_enabled(value.to_string())
}
_ => {}
}
}
self.settings.lock().insert(entry);
Expand Down Expand Up @@ -658,11 +645,11 @@ impl SettingsTab {
fn sort_import_groups(conf: &Ini) -> Vec<(&str, &ini::Properties)> {
let mut groups: Vec<_> = conf
.iter()
.flat_map(|(section, props)| section.map(|s| (s, props)))
.flat_map(|(section, props)| section.zip(Some(props)))
.collect();
if let Some(idx) = groups
.iter()
.position(|(s, _)| *s == ETHERNET_SETTING_GROUP)
.position(|&(s, _)| s == ETHERNET_SETTING_GROUP)
{
let ethernet = groups.remove(idx);
groups.push(ethernet);
Expand All @@ -680,20 +667,20 @@ fn sort_import_group<'a>(
) -> Box<dyn Iterator<Item = (&'a str, &'a str)> + 'a> {
match group {
NTRIP_SETTING_GROUP => {
let enable = prop.iter().find(|(n, _)| *n == NTRIP_ENABLE_SETTING_KEY);
let enable = prop.iter().find(|&(n, _)| n == NTRIP_ENABLE_SETTING_KEY);
Box::new(
prop.iter()
.filter(|(n, _)| *n != NTRIP_ENABLE_SETTING_KEY)
.filter(|&(n, _)| n != NTRIP_ENABLE_SETTING_KEY)
.chain(enable),
)
}
ETHERNET_SETTING_GROUP => {
let interface_mode = prop
.iter()
.find(|(n, _)| *n == ETHERNET_INTERFACE_MODE_SETTING_KEY);
.find(|&(n, _)| n == ETHERNET_INTERFACE_MODE_SETTING_KEY);
Box::new(
prop.iter()
.filter(|(n, _)| *n != ETHERNET_INTERFACE_MODE_SETTING_KEY)
.filter(|&(n, _)| n != ETHERNET_INTERFACE_MODE_SETTING_KEY)
.chain(interface_mode),
)
}
Expand Down
9 changes: 9 additions & 0 deletions console_backend/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::shared_state::{ConnectionState, SerialConfig, SharedState};
use crate::types::SignalCodes;

pub mod date_conv;
pub mod formatters;

/// Formats DOPS field into string, used in SolutionPositionTab
pub fn dops_into_string(field: u16) -> String {
Expand Down Expand Up @@ -258,6 +259,14 @@ pub fn refresh_loggingbar_recording(
client_sender.send_data(serialize_capnproto_builder(builder));
}

pub fn send_settings_import_response(client_sender: &BoxedClientSender, status: &str) {
let mut builder = Builder::new_default();
let msg = builder.init_root::<crate::console_backend_capnp::message::Builder>();
let mut import_response = msg.init_settings_import_response();
import_response.set_status(status);
client_sender.send_data(serialize_capnproto_builder(builder));
}

pub fn signal_key_label(
key: (SignalCodes, i16),
extra: Option<&HashMap<i16, i16>>,
Expand Down