commit 4fead341993ebc5837a9c6940b89afcaf6e857a9
parent 721dbbf06b0678546b1e3a0365b9ada5dd5c5fa8
Author: Daniel Barlow <dan@telent.net>
Date: Mon, 5 Jan 2026 21:09:39 +0000
stop sending to peer if we haven't heard from it for 60s
this is udp so there is no way to test if it has closed the
connection - instead we expect it to periodically refresh
Diffstat:
1 file changed, 17 insertions(+), 12 deletions(-)
diff --git a/ecu-esp32/src/streamer.rs b/ecu-esp32/src/streamer.rs
@@ -3,7 +3,7 @@ use embassy_net::{
IpEndpoint,
Stack
};
-use embassy_time::{Duration, Timer};
+use embassy_time::{Duration, Instant, Timer};
use log::info;
@@ -18,7 +18,8 @@ enum SubscriptionKind {
struct Subscription {
kind : SubscriptionKind,
interval: Duration,
- subscriber: IpEndpoint
+ subscriber: IpEndpoint,
+ until: Instant
}
pub async fn loop_udp_thing(stack : Stack<'_>, ecu: &mut Ecu<'_>) {
@@ -51,21 +52,25 @@ pub async fn loop_udp_thing(stack : Stack<'_>, ecu: &mut Ecu<'_>) {
subscription = Some(Subscription {
kind: SubscriptionKind::Table(0x11, 0, 25),
interval: Duration::from_millis(500),
- subscriber: meta.endpoint
+ subscriber: meta.endpoint,
+ until: Instant::now() + Duration::from_secs(60),
})
}
}
if let Some(sub) = subscription {
- info!("got subscriber");
let mut buf = [0u8; 1024];
- match sub.kind {
- SubscriptionKind::Table(t, _s, _e) => {
- let tbl = ecu.fetch_table(t, &mut buf).await;
- info!("sending {}", tbl.len());
- let _ = sock.send_to(tbl, sub.subscriber).await;
- }
- }
- Timer::after(sub.interval).await;
+ if sub.until < Instant::now() {
+ subscription = None;
+ } else {
+ match sub.kind {
+ SubscriptionKind::Table(t, _s, _e) => {
+ let tbl = ecu.fetch_table(t, &mut buf).await;
+ let p = sock.send_to(tbl, sub.subscriber).await;
+ info!("sent {:?}", p);
+ }
+ }
+ Timer::after(sub.interval).await;
+ }
} else {
sock.wait_recv_ready().await;
}