Skip to content

Commit

Permalink
Remaining Update Tab Functionality + Nag messages[CPP-312][CPP-306][C…
Browse files Browse the repository at this point in the history
…PP-302][CPP-305][CPP-304][CPP-172] (#124)

* More update WIP.

* Update console_backend/src/update_tab.rs

Co-authored-by: Steven Meyer <[email protected]>

* Update resources/UpdateTab.qml

Co-authored-by: Jason Mobarak <[email protected]>

* Update resources/UpdateTab.qml

Co-authored-by: Jason Mobarak <[email protected]>

* Update resources/UpdateTab.qml

Co-authored-by: Jason Mobarak <[email protected]>

* Respond to review requests.

* Clean up formatting and name variables, remove unneeded comments.

Co-authored-by: Steven Meyer <[email protected]>
Co-authored-by: Jason Mobarak <[email protected]>
  • Loading branch information
3 people authored Sep 19, 2021
1 parent e1786a3 commit 9d06aad
Show file tree
Hide file tree
Showing 24 changed files with 1,248 additions and 141 deletions.
2 changes: 1 addition & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ args = [
[tasks.store-version]
script_runner = "@shell"
script = '''
echo $(git describe --tags) > console_backend/src/version.txt
git describe --tags --always > console_backend/src/version.txt
'''

[tasks.install-backend]
Expand Down
12 changes: 12 additions & 0 deletions console_backend/src/common_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ pub enum Keys {
TITLE,
#[strum(serialize = "IMPORT_STATUS")]
IMPORT_STATUS,
#[strum(serialize = "FW_OUTDATED")]
FW_OUTDATED,
#[strum(serialize = "FW_V2_OUTDATED")]
FW_V2_OUTDATED,
#[strum(serialize = "SERIAL_PROMPT")]
SERIAL_PROMPT,
#[strum(serialize = "CONSOLE_OUTDATED")]
CONSOLE_OUTDATED,
#[strum(serialize = "CONSOLE_VERSION_CURRENT")]
CONSOLE_VERSION_CURRENT,
#[strum(serialize = "CONSOLE_VERSION_LATEST")]
CONSOLE_VERSION_LATEST,
}

#[derive(Clone, Debug, Display, EnumString, EnumVariantNames, Eq, Hash, PartialEq)]
Expand Down
3 changes: 3 additions & 0 deletions console_backend/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ impl Connection {
pub fn settings_enabled(&self) -> bool {
matches!(self, Connection::Tcp(_) | Connection::Serial(_))
}
pub fn is_serial(&self) -> bool {
matches!(self, Connection::Serial(_))
}
pub fn try_connect(
&self,
shared_state: Option<SharedState>,
Expand Down
2 changes: 2 additions & 0 deletions console_backend/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ pub(crate) const SERVER_STATE_DISCONNECT_FAILURE: &str = "server state disconnec
pub(crate) const CONSOLE_LOG_JSON_TO_STRING_FAILURE: &str = "unable to convert json to string";
pub(crate) const CROSSBEAM_SCOPE_UNWRAP_FAILURE: &str = "unable to unwrap crossbeam scope";
pub(crate) const UNABLE_TO_CLONE_UPDATE_SHARED: &str = "unable to clone update shared";
pub(crate) const FILEIO_CHANNEL_SEND_FAILURE: &str =
"failure attempting to send via fileio channel";
30 changes: 19 additions & 11 deletions console_backend/src/fileio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use sbp::messages::{
SBP,
};

use crate::errors::FILEIO_CHANNEL_SEND_FAILURE;
use crate::types::{MsgSender, Result};

const MAX_RETRIES: usize = 20;
Expand Down Expand Up @@ -88,7 +89,9 @@ impl<'a> Fileio<'a> {
backoff.snooze();
}
send_msg(sequence, offset)?;
req_tx.send((sequence, ReadReq::new(offset))).unwrap();
req_tx
.send((sequence, ReadReq::new(offset)))
.expect(FILEIO_CHANNEL_SEND_FAILURE);
offset += READ_CHUNK_SIZE as u32;
sequence += 1;
open_requests.fetch_add(1);
Expand All @@ -98,7 +101,7 @@ impl<'a> Fileio<'a> {
});

let key = self.link.register(move |msg: MsgFileioReadResp| {
res_tx.send(msg).unwrap();
res_tx.send(msg).expect(FILEIO_CHANNEL_SEND_FAILURE);
});

loop {
Expand Down Expand Up @@ -127,7 +130,7 @@ impl<'a> Fileio<'a> {
open_requests.fetch_sub(1);
if !last_sent && bytes_read != READ_CHUNK_SIZE as usize {
last_sent = true;
stop_req_tx.send(true).unwrap();
stop_req_tx.send(true).expect(FILEIO_CHANNEL_SEND_FAILURE);
}
if last_sent && open_requests.load() == 0 {
break
Expand Down Expand Up @@ -230,7 +233,9 @@ impl<'a> Fileio<'a> {
let chunk_len = std::cmp::min(state.chunk_size, data_len - slice_offset);
let req = WriteReq::new(slice_offset, end_offset, chunk_len < state.chunk_size);
send_msg(&state, &req)?;
req_tx.send((state.clone(), req)).unwrap();
req_tx
.send((state.clone(), req))
.expect(FILEIO_CHANNEL_SEND_FAILURE);
state.update(chunk_len);
slice_offset += chunk_len;
open_requests.fetch_add(1);
Expand All @@ -240,7 +245,7 @@ impl<'a> Fileio<'a> {
});

let key = self.link.register(move |msg: MsgFileioWriteResp| {
res_tx.send(msg).unwrap();
res_tx.send(msg).expect(FILEIO_CHANNEL_SEND_FAILURE);
});

let mut pending: HashMap<u32, (WriteState, WriteReq)> = HashMap::new();
Expand Down Expand Up @@ -294,7 +299,7 @@ impl<'a> Fileio<'a> {
let (tx, rx) = channel::unbounded();

let key = self.link.register(move |msg: MsgFileioReadDirResp| {
tx.send(msg).unwrap();
tx.send(msg).expect(FILEIO_CHANNEL_SEND_FAILURE);
});

self.sender.send(SBP::from(MsgFileioReadDirReq {
Expand Down Expand Up @@ -358,10 +363,11 @@ impl<'a> Fileio<'a> {
let sequence = new_sequence();
let (stop_tx, stop_rx) = channel::bounded(0);
let (tx, rx) = channel::bounded(1);

let stop_tx_clone = stop_tx.clone();
let key = self.link.register(move |msg: MsgFileioConfigResp| {
tx.send(FileioConfig::new(msg)).unwrap();
stop_tx.send(true).unwrap();
tx.send(FileioConfig::new(msg))
.expect(FILEIO_CHANNEL_SEND_FAILURE);
stop_tx_clone.send(true).expect(FILEIO_CHANNEL_SEND_FAILURE);
});

let sender = &self.sender;
Expand All @@ -376,10 +382,12 @@ impl<'a> Fileio<'a> {
}
});

match rx.recv_timeout(CONFIG_REQ_TIMEOUT) {
let res = match rx.recv_timeout(CONFIG_REQ_TIMEOUT) {
Ok(config) => config,
Err(_) => Default::default(),
}
};
stop_tx.send(true).expect(FILEIO_CHANNEL_SEND_FAILURE);
res
})
.unwrap();

Expand Down
10 changes: 5 additions & 5 deletions console_backend/src/process_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ where
.lock()
.expect(UNABLE_TO_CLONE_UPDATE_SHARED)
.clone_update_tab_context();
update_tab_context.set_serial_prompt(conn.is_serial());
let client_send_clone = client_send.clone();
let (update_tab_tx, update_tab_rx) = tabs.update.lock().unwrap().clone_channel();
let settings_parker = Parker::new();
Expand All @@ -237,11 +238,12 @@ where
settings_parker.park();
}
});
let handle = scope.spawn(|_| {
scope.spawn(|_| {
update_tab::update_tab_thread(
update_tab_tx.clone(),
update_tab_rx,
update_tab_context,
shared_state.clone(),
client_send_clone,
source.stateless_link(),
msg_sender.clone(),
Expand Down Expand Up @@ -284,10 +286,8 @@ where
}
log::logger().flush();
}
if update_tab_tx.send(None).is_ok() {
if let Err(err) = handle.join() {
error!("Error joining update tab, {:?}", err);
}
if let Err(err) = update_tab_tx.send(None) {
error!("Issue stopping update tab: {}", err);
}
if conn.close_when_done() {
shared_state.set_running(false, client_send.clone());
Expand Down
26 changes: 14 additions & 12 deletions console_backend/src/server_recv_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ pub fn server_recv_thread(
let download_latest_firmware = cv_in.get_download_latest_firmware();
let update_firmware = cv_in.get_update_firmware();
let send_file_to_device = cv_in.get_send_file_to_device();
let serial_prompt_confirm = cv_in.get_serial_prompt_confirm();
let firmware_directory = match cv_in.get_download_directory().which() {
Ok(m::update_tab_status_front::download_directory::Directory(
Ok(directory),
Expand Down Expand Up @@ -254,18 +255,19 @@ pub fn server_recv_thread(
}
_ => None,
};
update_tab_sender
.send(Some(UpdateTabUpdate {
download_latest_firmware,
update_firmware,
send_file_to_device,
firmware_directory,
firmware_local_filepath,
firmware_local_filename,
fileio_local_filepath,
fileio_destination_filepath,
}))
.unwrap();
if let Err(err) = update_tab_sender.send(Some(UpdateTabUpdate {
download_latest_firmware,
update_firmware,
send_file_to_device,
firmware_directory,
firmware_local_filepath,
firmware_local_filename,
fileio_local_filepath,
fileio_destination_filepath,
serial_prompt_confirm,
})) {
error!("{}", err);
}
}
}
m::message::SettingsRefreshRequest(Ok(_)) => {
Expand Down
10 changes: 10 additions & 0 deletions console_backend/src/settings_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ use crate::shared_state::SharedState;
use crate::types::{CapnProtoSender, Error, MsgSender, Result};
use crate::utils::*;

const FIRMWARE_VERSION_SETTING_KEY: &str = "firmware_version";
const DGNSS_SOLUTION_MODE_SETTING_KEY: &str = "dgnss_solution_mode";

pub struct SettingsTab<'link, S> {
client_sender: S,
shared_state: SharedState,
Expand Down Expand Up @@ -203,6 +206,13 @@ impl<'link, S: CapnProtoSender> SettingsTab<'link, S> {
continue;
}
};
if FIRMWARE_VERSION_SETTING_KEY == setting.name {
self.shared_state
.set_firmware_version(setting.clone().value);
}
if DGNSS_SOLUTION_MODE_SETTING_KEY == setting.name {
self.shared_state.set_dgnss_enabled(setting.clone().value);
}

// update possible enum values with the possible values returned by the device
if !setting.fmt_type.is_empty() && current_setting.setting.kind == SettingKind::Enum {
Expand Down
26 changes: 26 additions & 0 deletions console_backend/src/shared_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,26 @@ impl SharedState {
let mut shared_data = self.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
shared_data.settings_tab.write = setting;
}
pub fn console_version(&self) -> String {
let shared_data = self.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
(*shared_data).console_version.clone()
}
pub fn set_firmware_version(&self, firmware_version: String) {
let mut shared_data = self.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
shared_data.firmware_version = Some(firmware_version);
}
pub fn firmware_version(&self) -> Option<String> {
let mut shared_data = self.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
shared_data.firmware_version.take()
}
pub fn dgnss_enabled(&self) -> bool {
let shared_data = self.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
shared_data.dgnss_enabled
}
pub fn set_dgnss_enabled(&self, dgnss_solution_mode: String) {
let mut shared_data = self.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
shared_data.dgnss_enabled = dgnss_solution_mode != "No DGNSS";
}
}

impl Deref for SharedState {
Expand Down Expand Up @@ -298,6 +318,9 @@ pub struct SharedStateInner {
pub(crate) advanced_spectrum_analyzer_tab: AdvancedSpectrumAnalyzerTabState,
pub(crate) update_tab_sender: Option<Sender<Option<UpdateTabUpdate>>>,
pub(crate) settings_tab: SettingsTabState,
pub(crate) console_version: String,
pub(crate) firmware_version: Option<String>,
pub(crate) dgnss_enabled: bool,
}
impl SharedStateInner {
pub fn new() -> SharedStateInner {
Expand All @@ -318,6 +341,9 @@ impl SharedStateInner {
advanced_spectrum_analyzer_tab: AdvancedSpectrumAnalyzerTabState::new(),
update_tab_sender: None,
settings_tab: SettingsTabState::new(),
console_version: String::from(include_str!("version.txt").trim()),
firmware_version: None,
dgnss_enabled: false,
}
}
}
Expand Down
33 changes: 20 additions & 13 deletions console_backend/src/status_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,18 @@ impl<S: CapnProtoSender> StatusBar<S> {
pub fn new(shared_state: SharedState, client_sender: S) -> StatusBar<S> {
let heartbeat_data = Heartbeat::new();
let is_running = ArcBool::new();
let version = String::from(include_str!("version.txt").trim());
let version = shared_state.console_version();
StatusBar {
client_sender,
shared_state: shared_state.clone(),
heartbeat_data: heartbeat_data.clone(),
port: shared_state.current_connection(),
version,
heartbeat_handler: StatusBar::<S>::heartbeat_thread(is_running.clone(), heartbeat_data),
heartbeat_handler: StatusBar::<S>::heartbeat_thread(
is_running.clone(),
heartbeat_data,
shared_state,
),
is_running,
}
}
Expand All @@ -89,14 +93,19 @@ impl<S: CapnProtoSender> StatusBar<S> {
/// # Parameters:
/// - `client_send`: Client Sender channel for communication from backend to frontend.
/// - `shared_state`: The shared state for communicating between frontend/backend/other backend tabs.
fn heartbeat_thread(is_running: ArcBool, heartbeat_data: Heartbeat) -> JoinHandle<()> {
fn heartbeat_thread(
is_running: ArcBool,
heartbeat_data: Heartbeat,
shared_state: SharedState,
) -> JoinHandle<()> {
is_running.set(true);
let mut last_time = Instant::now();
spawn(move || loop {
if !is_running.get() {
break;
}
heartbeat_data.heartbeat();
let dgnss_enabled = shared_state.dgnss_enabled();
heartbeat_data.heartbeat(dgnss_enabled);
let new_time = Instant::now();
let time_diff = (new_time - last_time).as_secs_f64();
let delay_time = UPDATE_TOLERANCE_SECONDS - time_diff;
Expand Down Expand Up @@ -144,10 +153,7 @@ impl<S: CapnProtoSender> StatusBar<S> {
status_bar_status.set_ins(&sb_update.ins_status);
status_bar_status.set_data_rate(&sb_update.data_rate);
status_bar_status.set_solid_connection(sb_update.solid_connection);
status_bar_status.set_title(&format!(
"{}(###) Swift Console {}",
self.port, self.version
));
status_bar_status.set_title(&format!("{} Swift Console {}", self.port, self.version));

self.client_sender
.send_data(serialize_capnproto_builder(builder));
Expand Down Expand Up @@ -374,10 +380,11 @@ impl HeartbeatInner {
}
}

pub fn baseline_ned_update(&mut self) {
pub fn baseline_ned_update(&mut self, dgnss_enabled: bool) {
if let Some(last_btime_update) = self.last_btime_update {
//TODO(@john-michaelburke) [CPP-172] Add missing dgnss_enabled logic.
if (self.current_time - last_btime_update).as_secs_f64() < UPDATE_TOLERANCE_SECONDS {
if dgnss_enabled
&& (self.current_time - last_btime_update).as_secs_f64() < UPDATE_TOLERANCE_SECONDS
{
self.baseline_display_mode = if let Some(bsoln_mode) =
rtk_mode_dict.get(&(self.baseline_solution_mode as i32))
{
Expand Down Expand Up @@ -486,12 +493,12 @@ impl Heartbeat {
pub fn new() -> Heartbeat {
Heartbeat(Arc::new(Mutex::new(HeartbeatInner::default())))
}
pub fn heartbeat(&self) {
pub fn heartbeat(&self, dgnss_enabled: bool) {
let mut shared_data = self.lock().expect(SHARED_STATE_LOCK_MUTEX_FAILURE);
let good_heartbeat: bool = (*shared_data).check_heartbeat();
if good_heartbeat {
(*shared_data).pos_llh_update();
(*shared_data).baseline_ned_update();
(*shared_data).baseline_ned_update(dgnss_enabled);
(*shared_data).ins_update();
(*shared_data).age_of_corrections_update();
(*shared_data).prepare_update_packet();
Expand Down
12 changes: 12 additions & 0 deletions console_backend/src/update_downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use std::{
const INDEX_URL: &str =
"https://s3-us-west-1.amazonaws.com/downloads.swiftnav.com/index_https.json";

const V2_LINK: &str =
"https://www.swiftnav.com/resource-files/Piksi%20Multi/v2.0.0/Firmware/PiksiMulti-v2.0.0.bin";

#[derive(Clone, Debug, Deserialize, Serialize)]
struct PiksiMultiDataConsole {
version: String,
Expand Down Expand Up @@ -69,6 +72,15 @@ impl UpdateDownloader {
}
}

pub fn download_multi_v2_firmware(
&mut self,
directory: PathBuf,
update_shared: Option<UpdateTabContext>,
) -> anyhow::Result<PathBuf> {
let filepath_url = String::from(V2_LINK);
self.download_file_from_url(filepath_url, directory, update_shared)
}

pub fn download_multi_firmware(
&mut self,
directory: PathBuf,
Expand Down
Loading

0 comments on commit 9d06aad

Please sign in to comment.