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) => {
|
Ok(client) => {
|
||||||
println!("Client created");
|
println!("Client created");
|
||||||
app_handle
|
app_handle
|
||||||
.emit_all("telemetry_connected", "connected")
|
.emit_all("telemetry_status", "connected")
|
||||||
.expect("Failed to emit telemetry_status connected event");
|
.expect("Failed to emit telemetry_status connected event");
|
||||||
break client; // Exit the loop if the client is successfully created
|
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 client = create_client(&app_handle, &ntable_ip, &ntable_port).await;
|
||||||
|
|
||||||
let mut subscription: Subscription = match create_subscription(&client).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(_) => {
|
Err(_) => {
|
||||||
app_handle
|
app_handle
|
||||||
.emit_all("telemetry_status", "disconnected")
|
.emit_all("telemetry_status", "disconnected")
|
||||||
|
@ -41,13 +46,28 @@ 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");
|
||||||
|
|
||||||
if cfg!(debug_assertions) {
|
app_handle
|
||||||
println!("{}", json_message);
|
.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
|
app_handle
|
||||||
.emit_all("telemetry_status", "disconnected")
|
.emit_all("telemetry_status", "disconnected")
|
||||||
.expect("Failed to emit telemetry_disconnected event");
|
.expect("Failed to emit telemetry_disconnected event");
|
||||||
|
|
|
@ -10,7 +10,8 @@ import { listen } from '@tauri-apps/api/event'
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const initializeTelemetry = async () => {
|
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') {
|
if (event.payload === 'connected') {
|
||||||
telemetryStore.set('connected', true)
|
telemetryStore.set('connected', true)
|
||||||
} else if (event.payload === 'disconnected') {
|
} 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)
|
const data = JSON.parse(event.payload as string)
|
||||||
telemetryStore.set(data['topic_name'], data['data'])
|
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 = () => {
|
const unlistenAll = () => {
|
||||||
unlistenStatus()
|
unlistenStatus()
|
||||||
unlistenTelemetry()
|
unlistenTelemetry()
|
||||||
|
|
Loading…
Reference in a new issue