refactor: use idiomatic way to store IP instead of tuple

This commit is contained in:
Youwen Wu 2024-03-16 12:04:07 -07:00
parent ac89c7c966
commit a12647ee86
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3
3 changed files with 8 additions and 11 deletions

View file

@ -1,6 +1,8 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!! // Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use std::net::Ipv4Addr;
use tauri::Manager; use tauri::Manager;
mod telemetry; mod telemetry;
use tracing_subscriber::FmtSubscriber; use tracing_subscriber::FmtSubscriber;
@ -12,7 +14,7 @@ struct Payload {
message: String, 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; const NTABLE_PORT: u16 = 5810;
fn main() { fn main() {

View file

@ -13,15 +13,12 @@ use tokio::time::{sleep, Duration};
/// `telemetry_status` event with the payload `"disconnected"` instead. /// `telemetry_status` event with the payload `"disconnected"` instead.
pub async fn create_client( pub async fn create_client(
app_handle: &AppHandle, app_handle: &AppHandle,
ntable_ip: &(u8, u8, u8, u8), ntable_ip: &Ipv4Addr,
ntable_port: &u16, ntable_port: &u16,
) -> Client { ) -> Client {
loop { loop {
let client_attempt = Client::try_new_w_config( let client_attempt = Client::try_new_w_config(
SocketAddrV4::new( SocketAddrV4::new(*ntable_ip, *ntable_port),
Ipv4Addr::new(ntable_ip.0, ntable_ip.1, ntable_ip.2, ntable_ip.3),
*ntable_port,
),
Config { Config {
..Default::default() ..Default::default()
}, },

View file

@ -1,3 +1,5 @@
use std::net::Ipv4Addr;
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};
@ -16,11 +18,7 @@ use create_subscription::create_subscription;
/// to all connected frontends using the "telemetry_data" event. /// to all connected frontends using the "telemetry_data" event.
/// ///
/// The function loops forever, retrying connection every 3 seconds, reconnecting if the client disconnects. /// The function loops forever, retrying connection every 3 seconds, reconnecting if the client disconnects.
pub async fn subscribe_topics( pub async fn subscribe_topics(app_handle: AppHandle, ntable_ip: Ipv4Addr, ntable_port: u16) {
app_handle: AppHandle,
ntable_ip: (u8, u8, u8, u8),
ntable_port: u16,
) {
let mut previous_gpws: bool = false; let mut previous_gpws: bool = false;
loop { loop {