From a642c832032721e847026ede770e3f23ab5fa8bb Mon Sep 17 00:00:00 2001 From: Sachymetsu Date: Sat, 10 Jan 2026 08:39:29 +0100 Subject: [PATCH] TCP connection drop handling, blip size config --- config.example.kdl | 1 + src/detector.rs | 4 ++-- src/net.rs | 12 +++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/config.example.kdl b/config.example.kdl index 10142ca..dcdcb08 100644 --- a/config.example.kdl +++ b/config.example.kdl @@ -8,4 +8,5 @@ constants { BLOCK_SIZE "usize" "512" HOST_PORT "u16" "6125" BLIP_THRESHOLD "u16" "12" + BLIP_SIZE "usize" "2" } diff --git a/src/detector.rs b/src/detector.rs index 378d165..7b5f9af 100644 --- a/src/detector.rs +++ b/src/detector.rs @@ -16,7 +16,7 @@ use embassy_time::{Duration, Instant, Ticker, Timer}; use crate::{ adc::AdcDriver, - constants::BLOCK_SIZE, + constants::{BLIP_SIZE, BLOCK_SIZE}, pwm::PwmDriver, rtc::GlobalRtc, updates::UpdateConnection, @@ -165,7 +165,7 @@ impl Detector<'_> { let blips = peaks.len(); - if blips > 0 { + if blips >= BLIP_SIZE { self.state .strikes .update(|strike| strike.saturating_add(32)); diff --git a/src/net.rs b/src/net.rs index 8ca3382..fd4fead 100644 --- a/src/net.rs +++ b/src/net.rs @@ -6,7 +6,7 @@ use embassy_net::{ udp::{PacketMetadata, UdpSocket}, }; use embassy_time::{Duration, Timer, WithTimeout}; -use sachy_fmt::{error, unwrap}; +use sachy_fmt::{error, info, unwrap}; use sachy_mdns::{ GROUP_ADDR_V4, GROUP_SOCK_V4, MDNS_PORT, service::{MdnsService, Service}, @@ -141,11 +141,19 @@ async fn data_loop<'connection>(tcp: &mut TcpSocket<'connection>, net_data: &Net continue; } + info!("Connected!"); UpdateConnection::connect(); 'inner: loop { let data = net_data.receive().await; + if !tcp.may_send() { + // Clear backlog, no point in keeping the updates + // if there is nothing to send the updates to + net_data.clear(); + break 'inner; + } + if tcp .write_with(|buf| { let written = unwrap!(postcard::to_slice( @@ -165,5 +173,7 @@ async fn data_loop<'connection>(tcp: &mut TcpSocket<'connection>, net_data: &Net break 'inner; } } + + info!("DISCONNECT"); } } -- 2.51.2