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
4 changes: 4 additions & 0 deletions console_backend/src/common_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ pub enum Keys {
NETWORK_INFO,
#[strum(serialize = "IP_ADDRESS")]
IP_ADDRESS,
#[strum(serialize = "RECOMMENDED_INS_SETTINGS")]
RECOMMENDED_INS_SETTINGS,
#[strum(serialize = "NEW_INS_CONFIRMATON")]
NEW_INS_CONFIRMATON,
#[strum(serialize = "ANTENNA_STATUS")]
ANTENNA_STATUS,
}
Expand Down
3 changes: 3 additions & 0 deletions console_backend/src/server_recv_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ pub fn server_recv_thread(
port,
})
}
m::message::ConfirmInsChange(Ok(_)) => {
shared_state_clone.set_settings_confirm_ins_change(true);
}
_ => {
error!("unknown message from front-end");
}
Expand Down
108 changes: 105 additions & 3 deletions console_backend/src/settings_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::path::Path;
use anyhow::anyhow;
use capnp::message::Builder;
use ini::Ini;
use lazy_static::lazy_static;
use log::{debug, error, warn};
use parking_lot::{MappedMutexGuard, Mutex, MutexGuard};
use sbp::link::Link;
Expand All @@ -20,6 +21,15 @@ use crate::utils::*;
const FIRMWARE_VERSION_SETTING_KEY: &str = "firmware_version";
const DGNSS_SOLUTION_MODE_SETTING_KEY: &str = "dgnss_solution_mode";

lazy_static! {
static ref RECOMMENDED_INS_SETTINGS: [(&'static str, &'static str, SettingValue); 4] = [
("imu", "imu_raw_output", SettingValue::Boolean(true)),
("imu", "gyro_range", SettingValue::String("125".to_string())),
("imu", "acc_range", SettingValue::String("8g".to_string())),
("imu", "imu_rate", SettingValue::String("100".to_string())),
];
}

pub struct SettingsTab<'link, S> {
client_sender: S,
shared_state: SharedState,
Expand Down Expand Up @@ -67,7 +77,7 @@ impl<'link, S: CapnProtoSender> SettingsTab<'link, S> {
};
}
if settings_state.reset {
if let Err(e) = self.reset() {
if let Err(e) = self.reset(true) {
error!("Issue resetting settings {}", e);
};
}
Expand All @@ -76,6 +86,11 @@ impl<'link, S: CapnProtoSender> SettingsTab<'link, S> {
error!("Issue saving settings, {}", e);
};
}
if settings_state.confirm_ins_change {
if let Err(e) = self.confirm_ins_change() {
error!("Issue confirming INS change, {}", e);
};
}
}

pub fn refresh(&mut self) {
Expand Down Expand Up @@ -138,10 +153,12 @@ impl<'link, S: CapnProtoSender> SettingsTab<'link, S> {
.send_data(serialize_capnproto_builder(builder));
}

pub fn reset(&self) -> Result<()> {
pub fn reset(&self, reset_settings: bool) -> Result<()> {
let flags = if reset_settings { 1 } else { 0 };

self.msg_sender.send(
MsgReset {
flags: 1,
Copy link
Collaborator

@john-michaelburke john-michaelburke Oct 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when flags are 0 and a MsgReset is sent? Just reset the device but not the settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just reset the device but not the settings?

Yep, exactly

flags,
sender_id: None,
}
.into(),
Expand All @@ -155,6 +172,87 @@ impl<'link, S: CapnProtoSender> SettingsTab<'link, S> {
Ok(())
}

pub fn confirm_ins_change(&mut self) -> Result<()> {
let ins_mode = self
.settings
.get("ins", "output_mode")?
.value
.as_ref()
.ok_or_else(|| anyhow!("setting not found"))?;

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 {
// todo(DEVINFRA-570): Remove below line when libsettings-rs
// returns "True"/"False" for bools
let value = if &recommendation.3 == "true" {
"True"
} else {
&recommendation.3
};
self.write_setting(&recommendation.0, &recommendation.1, value)?;
}
}

self.save()?;
self.reset(false)?;

Ok(())
}

pub fn get_recommended_ins_setting_changes(
&self,
) -> Result<Vec<(String, String, String, String)>> {
let client = self.client();

let mut recommended_changes = vec![];

for setting in RECOMMENDED_INS_SETTINGS.iter() {
let value = client
.read_setting(setting.0, setting.1)
.ok_or_else(|| anyhow!("setting not found"))??;
if value != setting.2 {
recommended_changes.push((
setting.0.to_string(),
setting.1.to_string(),
value.to_string(),
setting.2.to_string(),
));
}
}

Ok(recommended_changes)
}

pub fn send_ins_change_response(&mut self, output_mode: &str) -> Result<()> {
let mut builder = Builder::new_default();
let msg = builder.init_root::<crate::console_backend_capnp::message::Builder>();
let mut ins_resp = msg.init_ins_settings_change_response();

if output_mode != "Disabled" {
let recommendations = self.get_recommended_ins_setting_changes()?;
let mut recommended_entries = ins_resp
.reborrow()
.init_recommended_settings(recommendations.len() as u32);

for (i, recommendation) 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);
}
}

self.client_sender
.send_data(serialize_capnproto_builder(builder));

Ok(())
}

pub fn write_setting(&mut self, group: &str, name: &str, value: &str) -> Result<()> {
let setting = self.settings.get(group, name)?;

Expand All @@ -181,6 +279,10 @@ impl<'link, S: CapnProtoSender> SettingsTab<'link, S> {
.set(group, name, SettingValue::String(value.to_string()))?;
}

if group == "ins" && name == "output_mode" {
self.send_ins_change_response(value)?;
}

self.send_table_data();

Ok(())
Expand Down
6 changes: 6 additions & 0 deletions console_backend/src/shared_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ impl SharedState {
let mut shared_data = self.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
shared_data.settings_tab.reset = set_to;
}
pub fn set_settings_confirm_ins_change(&self, set_to: bool) {
let mut shared_data = self.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
shared_data.settings_tab.confirm_ins_change = set_to;
}
pub fn set_export_settings(&self, path: Option<PathBuf>) {
let mut shared_data = self.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
shared_data.settings_tab.export = path;
Expand Down Expand Up @@ -546,6 +550,7 @@ pub struct SettingsTabState {
pub refresh: bool,
pub reset: bool,
pub save: bool,
pub confirm_ins_change: bool,
pub export: Option<PathBuf>,
pub import: Option<PathBuf>,
pub write: Option<settings_tab::SaveRequest>,
Expand All @@ -564,6 +569,7 @@ impl SettingsTabState {
self.refresh
|| self.reset
|| self.save
|| self.confirm_ins_change
|| self.export.is_some()
|| self.import.is_some()
|| self.write.is_some()
Expand Down
8 changes: 8 additions & 0 deletions resources/Constants/Constants.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ QtObject {
property QtObject baselineTable
property QtObject settingsTab
property QtObject settingsTable
property QtObject insSettingsPopup
property QtObject solutionPosition
property QtObject solutionTable
property QtObject solutionVelocity
Expand Down Expand Up @@ -514,4 +515,11 @@ QtObject {
readonly property string zoomAllButtonUrl: "qrc:///zoom-all.svg"
}

insSettingsPopup: QtObject {
readonly property var columnHeaders: ["Name", "Current Value", "Recommended Value"]
readonly property int dialogWidth: 550
readonly property int columnSpacing: 10
readonly property int tableHeight: 150
}

}
9 changes: 9 additions & 0 deletions resources/SettingsTab.qml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ Item {
}
settings_tab_model.clear_import_status(settingsTabData);
}
if (settingsTabData.new_ins_confirmation) {
insSettingsPopup.settings = settingsTabData.recommended_ins_settings;
insSettingsPopup.insPopup.open();
settings_tab_model.clear_new_ins_confirmation(settingsTabData);
}
}
}

Expand Down Expand Up @@ -111,6 +116,10 @@ Item {
onYes: data_model.settings_save_request()
}

SettingsTabComponents.InsSettingsPopup {
id: insSettingsPopup
}

MessageDialog {
id: importFailure

Expand Down
Loading