From b5f37d24cf9384615b3a721af3d90723ef09a31f Mon Sep 17 00:00:00 2001
From: Sam Mauldin <sam@mauldin.me>
Date: Thu, 11 Jan 2024 21:00:23 +0000
Subject: [PATCH] Remove requirement for felinet

---
 src/config.rs |  2 +-
 src/main.rs   | 61 ++++++++++++++++++++++++++++++---------------------
 2 files changed, 37 insertions(+), 26 deletions(-)

diff --git a/src/config.rs b/src/config.rs
index d8c2f94..45161db 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -31,7 +31,7 @@ pub struct Config {
     pub ssid: u8,
     #[serde(default)]
     pub icon: u16,
-    pub felinet: FelinetConfig,
+    pub felinet: Option<FelinetConfig>,
     pub beacon: BeaconConfig,
 }
 
diff --git a/src/main.rs b/src/main.rs
index a9e89aa..3a67e9a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -129,12 +129,21 @@ async fn gate_forever(
         temperature_mutex,
     )?;
 
-    let endpoint = Endpoint::from_str(&config.felinet.address)?
-        .keep_alive_while_idle(true)
-        .keep_alive_timeout(Duration::from_secs(5))
-        .http2_keep_alive_interval(Duration::from_secs(5))
-        .tcp_keepalive(Some(Duration::from_secs(5)));
-    let client = HandlerClient::connect(endpoint).await?;
+    let client = if let Some(felinet_config) = &config.felinet {
+        let endpoint = Endpoint::from_str(&felinet_config.address)?
+            .keep_alive_while_idle(true)
+            .keep_alive_timeout(Duration::from_secs(5))
+            .http2_keep_alive_interval(Duration::from_secs(5))
+            .tcp_keepalive(Some(Duration::from_secs(5)));
+
+        Some(HandlerClient::connect(endpoint).await?)
+    } else {
+        eprintln!(
+            "No FELINET section specified in configuration. Received packets will not be uploaded!"
+        );
+        None
+    };
+
     let callsign = config.callsign.clone();
 
     {
@@ -159,28 +168,30 @@ async fn gate_forever(
         });
     }
 
-    {
-        let client = client.clone();
-        tokio::task::spawn(async {
-            felinet_send_forever(client, tx).await;
-        });
-    }
+    if let Some(client) = client {
+        {
+            let client = client.clone();
+            tokio::task::spawn(async {
+                felinet_send_forever(client, tx).await;
+            });
+        }
 
-    {
-        let mut client = client.clone();
-        tokio::task::spawn(async move {
-            loop {
-                client
-                    .ping(Request::new(PingRequest { uuid: uuid.into() }))
-                    .await
-                    .ok();
+        {
+            let mut client = client.clone();
+            tokio::task::spawn(async move {
+                loop {
+                    client
+                        .ping(Request::new(PingRequest { uuid: uuid.into() }))
+                        .await
+                        .ok();
+
+                    tokio::time::sleep(Duration::from_secs(600)).await;
+                }
+            });
+        }
 
-                tokio::time::sleep(Duration::from_secs(600)).await;
-            }
-        });
+        felinet_receive_forever(client, packet_send, &callsign, config.ssid, uuid).await;
     }
 
-    felinet_receive_forever(client, packet_send, &callsign, config.ssid, uuid).await;
-
     Ok(())
 }
-- 
GitLab