feat: add gpws trigger code
This commit is contained in:
parent
832083ac48
commit
9c4cf32b73
2 changed files with 43 additions and 1 deletions
24
client/src-tauri/src/telemetry/check_triggers.rs
Normal file
24
client/src-tauri/src/telemetry/check_triggers.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
use tauri::{AppHandle, Manager};
|
||||||
|
|
||||||
|
pub fn check_triggers(
|
||||||
|
app_handle: &AppHandle,
|
||||||
|
topic_name: &str,
|
||||||
|
data: &network_tables::Value,
|
||||||
|
previous_gpws: &bool,
|
||||||
|
) {
|
||||||
|
if topic_name == "gpws" {
|
||||||
|
match data {
|
||||||
|
network_tables::Value::Boolean(b) => {
|
||||||
|
if *b != *previous_gpws {
|
||||||
|
if cfg!(debug_assertions) {
|
||||||
|
println!("gpws changed from {} to {}", previous_gpws, b);
|
||||||
|
}
|
||||||
|
app_handle
|
||||||
|
.emit_all("telemetry_gpws", b)
|
||||||
|
.expect("Failed to emit telemetry_gpws event");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,12 @@
|
||||||
use network_tables::v4::MessageData;
|
use network_tables::v4::MessageData;
|
||||||
use serde_json::to_string;
|
use serde_json::to_string;
|
||||||
use tauri::{AppHandle, Manager};
|
use tauri::{AppHandle, Manager};
|
||||||
|
mod check_triggers;
|
||||||
mod create_client;
|
mod create_client;
|
||||||
mod create_subscription;
|
mod create_subscription;
|
||||||
|
|
||||||
use crate::telemetry::create_client::create_client;
|
use check_triggers::check_triggers;
|
||||||
|
use create_client::create_client;
|
||||||
use create_subscription::create_subscription;
|
use create_subscription::create_subscription;
|
||||||
|
|
||||||
/// Attempts to subscribe to NetworkTables topics and send the data to the frontend.
|
/// Attempts to subscribe to NetworkTables topics and send the data to the frontend.
|
||||||
|
@ -19,6 +21,8 @@ pub async fn subscribe_topics(
|
||||||
ntable_ip: (u8, u8, u8, u8),
|
ntable_ip: (u8, u8, u8, u8),
|
||||||
ntable_port: u16,
|
ntable_port: u16,
|
||||||
) {
|
) {
|
||||||
|
let mut previous_gpws: bool = false;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// I hope this doesn't lead to a catastrophic infinite loop failure
|
// I hope this doesn't lead to a catastrophic infinite loop failure
|
||||||
let client = create_client(&app_handle, &ntable_ip, &ntable_port).await;
|
let client = create_client(&app_handle, &ntable_ip, &ntable_port).await;
|
||||||
|
@ -33,6 +37,20 @@ pub async fn subscribe_topics(
|
||||||
.emit_all("telemetry_data", json_message.clone())
|
.emit_all("telemetry_data", json_message.clone())
|
||||||
.expect("Failed to send telemetry message");
|
.expect("Failed to send telemetry message");
|
||||||
|
|
||||||
|
check_triggers(
|
||||||
|
&app_handle,
|
||||||
|
&message.topic_name,
|
||||||
|
&message.data,
|
||||||
|
&previous_gpws,
|
||||||
|
);
|
||||||
|
|
||||||
|
if message.topic_name == "gpws" {
|
||||||
|
previous_gpws = match message.data {
|
||||||
|
network_tables::Value::Boolean(b) => b,
|
||||||
|
_ => previous_gpws,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
println!("{}", json_message);
|
println!("{}", json_message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue