fix: detect connectivity properly
This commit is contained in:
parent
b0d075bbfd
commit
13399fcd93
3 changed files with 40 additions and 9 deletions
|
@ -32,7 +32,7 @@ pub async fn create_client(
|
|||
Ok(client) => {
|
||||
println!("Client created");
|
||||
app_handle
|
||||
.emit_all("telemetry_connected", "connected")
|
||||
.emit_all("telemetry_status", "connected")
|
||||
.expect("Failed to emit telemetry_status connected event");
|
||||
break client; // Exit the loop if the client is successfully created
|
||||
}
|
||||
|
|
|
@ -24,7 +24,12 @@ pub async fn subscribe_topics(
|
|||
let client = create_client(&app_handle, &ntable_ip, &ntable_port).await;
|
||||
|
||||
let mut subscription: Subscription = match create_subscription(&client).await {
|
||||
Ok(subscription) => subscription,
|
||||
Ok(subscription) => {
|
||||
app_handle
|
||||
.emit_all("telemetry_status", "connected")
|
||||
.expect("Failed to emit telemetry_connected event");
|
||||
subscription
|
||||
}
|
||||
Err(_) => {
|
||||
app_handle
|
||||
.emit_all("telemetry_status", "disconnected")
|
||||
|
@ -41,13 +46,28 @@ pub async fn subscribe_topics(
|
|||
.emit_all("telemetry_data", json_message.clone())
|
||||
.expect("Failed to send telemetry message");
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
println!("{}", json_message);
|
||||
app_handle
|
||||
.emit_all("telemetry_status", "connected")
|
||||
.expect("Failed to emit telemetry_connected event");
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
tracing::debug!("{}", json_message);
|
||||
}
|
||||
if cfg!(debug_assertions) {
|
||||
println!("disconnected");
|
||||
}
|
||||
|
||||
tracing::debug!("disconnected");
|
||||
app_handle
|
||||
.emit_all("telemetry_status", "disconnected")
|
||||
.expect("Failed to emit telemetry_disconnected event");
|
||||
|
|
|
@ -10,7 +10,8 @@ import { listen } from '@tauri-apps/api/event'
|
|||
*/
|
||||
|
||||
export const initializeTelemetry = async () => {
|
||||
const unlistenStatus = await listen('telemetry_status', (event) => {
|
||||
const unlistenStatus = await listen('telemetry_status', event => {
|
||||
console.log(event)
|
||||
if (event.payload === 'connected') {
|
||||
telemetryStore.set('connected', true)
|
||||
} else if (event.payload === 'disconnected') {
|
||||
|
@ -18,11 +19,21 @@ export const initializeTelemetry = async () => {
|
|||
}
|
||||
})
|
||||
|
||||
const unlistenTelemetry = await listen('telemetry_data', (event) => {
|
||||
const unlistenTelemetry = await listen('telemetry_data', event => {
|
||||
const data = JSON.parse(event.payload as string)
|
||||
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) {
|
||||
gpwsTriggeredSequence()
|
||||
}
|
||||
})
|
||||
|
||||
>>>>>>> cffa594 (fix: detect connectivity properly)
|
||||
const unlistenAll = () => {
|
||||
unlistenStatus()
|
||||
unlistenTelemetry()
|
||||
|
|
Loading…
Reference in a new issue