Robot event triggers (#22)
* feat: add gpws trigger code * feat: add gpws detection * refactor: use allegedly more performant codium fix * chore: remove unused functions and imports * feat: break out of subscription creation loop after 50 attempts * fix: refactor telemetry to use new method * refactor: rename `unlistenGpws` to `unlistenGPWS` * refactor: use tracing and attributes for debugging * refactor: remove redundant debug checks from tracing * chore: add .env to gitignore * fix: revert .env file * feat: add wallpaper * fix: detect connectivity properly * fix: gracefully handle JSON serialization errors --------- Co-authored-by: Ananth Venkatesh <46249765+quantum9Innovation@users.noreply.github.com>
This commit is contained in:
parent
186100e311
commit
8e62f32e66
11 changed files with 67 additions and 36 deletions
2
client/src-tauri/.gitignore
vendored
2
client/src-tauri/.gitignore
vendored
|
@ -1,3 +1,3 @@
|
||||||
# Generated by Cargo
|
# Generated by Cargo
|
||||||
# will have compiled files and executables
|
# will have compiled files and executables
|
||||||
/target/
|
/target/
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
use tauri::Manager;
|
use tauri::Manager;
|
||||||
mod telemetry;
|
mod telemetry;
|
||||||
|
use tracing_subscriber::FmtSubscriber;
|
||||||
|
|
||||||
#[derive(Clone, serde::Serialize)]
|
#[derive(Clone, serde::Serialize)]
|
||||||
struct Payload {
|
struct Payload {
|
||||||
|
@ -15,6 +16,12 @@ const NTABLE_PORT: u16 = 5810;
|
||||||
fn main() {
|
fn main() {
|
||||||
let rt = tokio::runtime::Runtime::new().expect("Failed to create Tokio runtime");
|
let rt = tokio::runtime::Runtime::new().expect("Failed to create Tokio runtime");
|
||||||
|
|
||||||
|
// set the environment variable RUST_LOG to debug in order to see debug messages
|
||||||
|
let subscriber = FmtSubscriber::builder()
|
||||||
|
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
||||||
|
.finish();
|
||||||
|
tracing::subscriber::set_global_default(subscriber).unwrap();
|
||||||
|
|
||||||
rt.block_on(async {
|
rt.block_on(async {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
|
|
23
client/src-tauri/src/telemetry/check_triggers.rs
Normal file
23
client/src-tauri/src/telemetry/check_triggers.rs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
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 {
|
||||||
|
tracing::debug!("gpws: {}", b);
|
||||||
|
|
||||||
|
app_handle
|
||||||
|
.emit_all("telemetry_gpws", b)
|
||||||
|
.expect("Failed to emit telemetry_gpws event");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,9 +37,11 @@ pub async fn create_client(
|
||||||
break client; // Exit the loop if the client is successfully created
|
break client; // Exit the loop if the client is successfully created
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if cfg!(debug_assertions) {
|
tracing::debug!(
|
||||||
println!("Failed to create client: {}. Retrying in 3 seconds...", e);
|
message = "Failed to create client. Retrying in 3 seconds...",
|
||||||
}
|
error = %e,
|
||||||
|
rate_limit = "3s",
|
||||||
|
);
|
||||||
app_handle
|
app_handle
|
||||||
.emit_all("telemetry_status", "disconnected")
|
.emit_all("telemetry_status", "disconnected")
|
||||||
.expect("Failed to emit telemetry_status disconnected event");
|
.expect("Failed to emit telemetry_status disconnected event");
|
||||||
|
|
|
@ -32,9 +32,7 @@ pub async fn create_subscription(client: &Client) -> Result<Subscription, networ
|
||||||
match subscription_attempt {
|
match subscription_attempt {
|
||||||
Ok(subscription) => break Ok(subscription),
|
Ok(subscription) => break Ok(subscription),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if cfg!(debug_assertions) {
|
tracing::debug!("Failed to create subscription: {:?}", e);
|
||||||
println!("Failed to create subscription: {}", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if attempts >= 50 {
|
if attempts >= 50 {
|
||||||
break Err(e);
|
break Err(e);
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
use network_tables::v4::{MessageData, Subscription};
|
use network_tables::v4::{MessageData, Subscription};
|
||||||
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;
|
||||||
|
@ -41,7 +45,11 @@ pub async fn subscribe_topics(
|
||||||
while let Some(mut message) = subscription.next().await {
|
while let Some(mut message) = subscription.next().await {
|
||||||
process_message(&mut message);
|
process_message(&mut message);
|
||||||
|
|
||||||
let json_message = to_string(&message).expect("Failed to serialize message");
|
let json_message = match to_string(&message) {
|
||||||
|
Ok(json) => json,
|
||||||
|
Err(_) => continue,
|
||||||
|
};
|
||||||
|
|
||||||
app_handle
|
app_handle
|
||||||
.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");
|
||||||
|
|
|
@ -76,17 +76,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.infotainment-container {
|
.infotainment-container {
|
||||||
background: #2c3e50; /* fallback for old browsers */
|
background-image: url('./assets/wallpaper.jpg');
|
||||||
background: -webkit-linear-gradient(
|
background-repeat: no-repeat;
|
||||||
to right,
|
background-size: cover;
|
||||||
#2c3e50,
|
|
||||||
#fd746c
|
|
||||||
); /* Chrome 10-25, Safari 5.1-6 */
|
|
||||||
background: linear-gradient(
|
|
||||||
to right,
|
|
||||||
#2c3e50,
|
|
||||||
#fd746c
|
|
||||||
); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
|
|
||||||
/* hide scrollbar */
|
/* hide scrollbar */
|
||||||
-ms-overflow-style: none;
|
-ms-overflow-style: none;
|
||||||
scrollbar-width: none;
|
scrollbar-width: none;
|
||||||
|
|
BIN
client/src/assets/wallpaper.jpg
Normal file
BIN
client/src/assets/wallpaper.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 453 KiB |
|
@ -1,7 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { blur } from "svelte/transition";
|
import { blur } from 'svelte/transition'
|
||||||
|
|
||||||
import SvelteLogo from "./SvelteLogo.svelte";
|
import SvelteLogo from './SvelteLogo.svelte'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
@ -15,16 +15,8 @@
|
||||||
|
|
||||||
<style lang="postcss">
|
<style lang="postcss">
|
||||||
.bg {
|
.bg {
|
||||||
background: #2c3e50; /* fallback for old browsers */
|
background-image: url('../../assets/wallpaper.jpg');
|
||||||
background: -webkit-linear-gradient(
|
background-repeat: no-repeat;
|
||||||
to right,
|
background-size: cover;
|
||||||
#2c3e50,
|
|
||||||
#fd746c
|
|
||||||
); /* Chrome 10-25, Safari 5.1-6 */
|
|
||||||
background: linear-gradient(
|
|
||||||
to right,
|
|
||||||
#2c3e50,
|
|
||||||
#fd746c
|
|
||||||
); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -430,3 +430,13 @@ export const modeLudicrousSequence = async () => {
|
||||||
|
|
||||||
Notifications.playAudio(getVoicePath('set-acceleration-profile-ludicrous'))
|
Notifications.playAudio(getVoicePath('set-acceleration-profile-ludicrous'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const gpwsTriggeredSequence = async () => {
|
||||||
|
if (get(settingsStore).disableAnnoyances) return
|
||||||
|
await tick()
|
||||||
|
|
||||||
|
Notifications.error('Terrain, pull up!', {
|
||||||
|
withAudio: true,
|
||||||
|
src: getVoicePath('terrain-pull-up'),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { gpwsTriggeredSequence } from '../Sequences/sequences'
|
||||||
import { telemetryStore } from '../stores/telemetryStore'
|
import { telemetryStore } from '../stores/telemetryStore'
|
||||||
import { listen } from '@tauri-apps/api/event'
|
import { listen } from '@tauri-apps/api/event'
|
||||||
|
|
||||||
|
@ -24,8 +25,6 @@ export const initializeTelemetry = async () => {
|
||||||
telemetryStore.set(data['topic_name'], data['data'])
|
telemetryStore.set(data['topic_name'], data['data'])
|
||||||
})
|
})
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
const unlistenGPWS = await listen('telemetry_gpws', event => {
|
const unlistenGPWS = await listen('telemetry_gpws', event => {
|
||||||
const data = JSON.parse(event.payload as string) as boolean
|
const data = JSON.parse(event.payload as string) as boolean
|
||||||
if (data) {
|
if (data) {
|
||||||
|
@ -33,10 +32,10 @@ export const initializeTelemetry = async () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
>>>>>>> cffa594 (fix: detect connectivity properly)
|
|
||||||
const unlistenAll = () => {
|
const unlistenAll = () => {
|
||||||
unlistenStatus()
|
unlistenStatus()
|
||||||
unlistenTelemetry()
|
unlistenTelemetry()
|
||||||
|
unlistenGPWS()
|
||||||
}
|
}
|
||||||
|
|
||||||
return unlistenAll
|
return unlistenAll
|
||||||
|
|
Loading…
Reference in a new issue