Merge pull request #2 from couscousdude/refactor-rust
refactor: use idiomatic way to store IP instead of tuple
This commit is contained in:
commit
6d5ef6809a
3 changed files with 8 additions and 11 deletions
|
@ -1,6 +1,8 @@
|
|||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
use tauri::Manager;
|
||||
mod telemetry;
|
||||
use tracing_subscriber::FmtSubscriber;
|
||||
|
@ -12,7 +14,7 @@ struct Payload {
|
|||
message: String,
|
||||
}
|
||||
|
||||
const NTABLE_IP: (u8, u8, u8, u8) = (10, 12, 80, 2);
|
||||
const NTABLE_IP: Ipv4Addr = Ipv4Addr::new(10, 12, 80, 2);
|
||||
const NTABLE_PORT: u16 = 5810;
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -13,15 +13,12 @@ use tokio::time::{sleep, Duration};
|
|||
/// `telemetry_status` event with the payload `"disconnected"` instead.
|
||||
pub async fn create_client(
|
||||
app_handle: &AppHandle,
|
||||
ntable_ip: &(u8, u8, u8, u8),
|
||||
ntable_ip: &Ipv4Addr,
|
||||
ntable_port: &u16,
|
||||
) -> Client {
|
||||
loop {
|
||||
let client_attempt = Client::try_new_w_config(
|
||||
SocketAddrV4::new(
|
||||
Ipv4Addr::new(ntable_ip.0, ntable_ip.1, ntable_ip.2, ntable_ip.3),
|
||||
*ntable_port,
|
||||
),
|
||||
SocketAddrV4::new(*ntable_ip, *ntable_port),
|
||||
Config {
|
||||
..Default::default()
|
||||
},
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::net::Ipv4Addr;
|
||||
|
||||
use network_tables::v4::{MessageData, Subscription};
|
||||
use serde_json::to_string;
|
||||
use tauri::{AppHandle, Manager};
|
||||
|
@ -16,11 +18,7 @@ use create_subscription::create_subscription;
|
|||
/// to all connected frontends using the "telemetry_data" event.
|
||||
///
|
||||
/// The function loops forever, retrying connection every 3 seconds, reconnecting if the client disconnects.
|
||||
pub async fn subscribe_topics(
|
||||
app_handle: AppHandle,
|
||||
ntable_ip: (u8, u8, u8, u8),
|
||||
ntable_port: u16,
|
||||
) {
|
||||
pub async fn subscribe_topics(app_handle: AppHandle, ntable_ip: Ipv4Addr, ntable_port: u16) {
|
||||
let mut previous_gpws: bool = false;
|
||||
|
||||
loop {
|
||||
|
|
Loading…
Reference in a new issue