eculocate

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 9dc22f2a86a8d58b2f5db1607932b92e519c8d87
parent 2b4563d544a07d9ef1a94223d3ca57f6a82c4a3a
Author: Daniel Barlow <dan@telent.net>
Date:   Mon, 29 Dec 2025 12:02:17 +0000

move may_recv() and advertise() to MdnsResponder

Diffstat:
Mecu-esp32/src/wifi.rs | 21++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/ecu-esp32/src/wifi.rs b/ecu-esp32/src/wifi.rs @@ -2,7 +2,7 @@ //! //! This gets an ip address via DHCP and advertises it with mdns -use alloc::vec; +// use alloc::vec; use alloc::vec::Vec; use alloc::string::String; use alloc::collections::BTreeSet; @@ -79,7 +79,6 @@ impl<'a> MdnsResponder<'a> { tx_buffer : &'a mut [u8], my_address: [u8;4]) -> MdnsResponder<'a> { - let mut sock = UdpSocket::new( stack, rx_meta, @@ -99,6 +98,16 @@ impl<'a> MdnsResponder<'a> { database: DnsDatabase::create(&my_address), } } + + async fn advertise(&self) { + let db = &self.database; + send_response(&self.sock, 0, MDNS_ENDPOINT, db, None, db.advertised()).await; + } + + fn may_recv(&self) -> bool { + self.sock.may_recv() + } + fn sock(&self) -> &UdpSocket<'a> { &self.sock } @@ -296,8 +305,6 @@ async fn send_response(sock: &UdpSocket<'_>, None => &mut [][..] }; - // log::info!("can send {:?} {:?}", - // r.name, r.ty); let mut flags = Flags::new(); @@ -335,7 +342,7 @@ async fn send_response(sock: &UdpSocket<'_>, // Serialize the message into the buffer assert!(message.space_needed() <= data_buf.len()); - // info!("ready to send to {:?}", endpoint); + info!("ready to send to {:?}", endpoint); match message.write(&mut data_buf) { Result::Ok(len) => { @@ -451,10 +458,10 @@ pub async fn start_wifi(spawner: &Spawner, let dns_db = &mdns_responder.database; let sock = mdns_responder.sock(); - send_response(&sock, 0, MDNS_ENDPOINT, dns_db, None, dns_db.advertised()).await; + mdns_responder.advertise().await; loop { - if sock.may_recv() { + if mdns_responder.may_recv() { let mut questions = [Question::default(); 64]; let mut answers = [ResourceRecord::default(); 64]; let mut authorities = [ResourceRecord::default(); 64];