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
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
/target/
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
use tauri::Manager;
|
||||
mod telemetry;
|
||||
use tracing_subscriber::FmtSubscriber;
|
||||
|
||||
#[derive(Clone, serde::Serialize)]
|
||||
struct Payload {
|
||||
|
@ -15,6 +16,12 @@ const NTABLE_PORT: u16 = 5810;
|
|||
fn main() {
|
||||
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 {
|
||||
tauri::Builder::default()
|
||||
.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
|
||||
}
|
||||
Err(e) => {
|
||||
if cfg!(debug_assertions) {
|
||||
println!("Failed to create client: {}. Retrying in 3 seconds...", e);
|
||||
}
|
||||
tracing::debug!(
|
||||
message = "Failed to create client. Retrying in 3 seconds...",
|
||||
error = %e,
|
||||
rate_limit = "3s",
|
||||
);
|
||||
app_handle
|
||||
.emit_all("telemetry_status", "disconnected")
|
||||
.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 {
|
||||
Ok(subscription) => break Ok(subscription),
|
||||
Err(e) => {
|
||||
if cfg!(debug_assertions) {
|
||||
println!("Failed to create subscription: {}", e);
|
||||
}
|
||||
tracing::debug!("Failed to create subscription: {:?}", e);
|
||||
|
||||
if attempts >= 50 {
|
||||
break Err(e);
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
use network_tables::v4::{MessageData, Subscription};
|
||||
use serde_json::to_string;
|
||||
use tauri::{AppHandle, Manager};
|
||||
mod check_triggers;
|
||||
mod create_client;
|
||||
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;
|
||||
|
||||
/// 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_port: u16,
|
||||
) {
|
||||
let mut previous_gpws: bool = false;
|
||||
|
||||
loop {
|
||||
// I hope this doesn't lead to a catastrophic infinite loop failure
|
||||
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 {
|
||||
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
|
||||
.emit_all("telemetry_data", json_message.clone())
|
||||
.expect("Failed to send telemetry message");
|
||||
|
|
|
@ -76,17 +76,9 @@
|
|||
}
|
||||
|
||||
.infotainment-container {
|
||||
background: #2c3e50; /* fallback for old browsers */
|
||||
background: -webkit-linear-gradient(
|
||||
to right,
|
||||
#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+ */
|
||||
background-image: url('./assets/wallpaper.jpg');
|
||||
background-repeat: no-repeat;
|
||||
background-size: cover;
|
||||
/* hide scrollbar */
|
||||
-ms-overflow-style: 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">
|
||||
import { blur } from "svelte/transition";
|
||||
import { blur } from 'svelte/transition'
|
||||
|
||||
import SvelteLogo from "./SvelteLogo.svelte";
|
||||
import SvelteLogo from './SvelteLogo.svelte'
|
||||
</script>
|
||||
|
||||
<div
|
||||
|
@ -15,16 +15,8 @@
|
|||
|
||||
<style lang="postcss">
|
||||
.bg {
|
||||
background: #2c3e50; /* fallback for old browsers */
|
||||
background: -webkit-linear-gradient(
|
||||
to right,
|
||||
#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+ */
|
||||
background-image: url('../../assets/wallpaper.jpg');
|
||||
background-repeat: no-repeat;
|
||||
background-size: cover;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -430,3 +430,13 @@ export const modeLudicrousSequence = async () => {
|
|||
|
||||
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 { listen } from '@tauri-apps/api/event'
|
||||
|
||||
|
@ -24,8 +25,6 @@ export const initializeTelemetry = async () => {
|
|||
telemetryStore.set(data['topic_name'], data['data'])
|
||||
})
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
const unlistenGPWS = await listen('telemetry_gpws', event => {
|
||||
const data = JSON.parse(event.payload as string) as boolean
|
||||
if (data) {
|
||||
|
@ -33,10 +32,10 @@ export const initializeTelemetry = async () => {
|
|||
}
|
||||
})
|
||||
|
||||
>>>>>>> cffa594 (fix: detect connectivity properly)
|
||||
const unlistenAll = () => {
|
||||
unlistenStatus()
|
||||
unlistenTelemetry()
|
||||
unlistenGPWS()
|
||||
}
|
||||
|
||||
return unlistenAll
|
||||
|
|
Loading…
Reference in a new issue