add all crates: domain, protocol, application, client, adapters, ESP32 firmware
Server: domain (entities, value objects, ports), protocol (postcard wire types), application (config service, data projection), adapters (config-memory, tcp-server), bootstrap (composition root with fake data). Client: client-domain (layout engine, render tree, HAL ports), client-application (message handling, repaint commands), adapters (tcp-client, display-terminal), client-desktop (end-to-end working). ESP32: client-esp32 firmware with ILI9341 display over SPI, WiFi networking. Display test verified on hardware — landscape orientation, text rendering works. 60 workspace tests, all passing.
This commit is contained in:
50
crates/client-esp32/src/tasks/network.rs
Normal file
50
crates/client-esp32/src/tasks/network.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
use client_domain::NetworkPort;
|
||||
use protocol::{ServerMessage, decode_server_message};
|
||||
use crate::config::{NET_THREAD_STACK_SIZE, NET_POLL_INTERVAL, NET_RECONNECT_DELAY};
|
||||
use crate::adapters::network::Esp32Network;
|
||||
use log::*;
|
||||
|
||||
pub fn spawn(server_addr: String, tx: mpsc::Sender<ServerMessage>) {
|
||||
thread::Builder::new()
|
||||
.stack_size(NET_THREAD_STACK_SIZE)
|
||||
.name("net".into())
|
||||
.spawn(move || run(server_addr, tx))
|
||||
.expect("failed to spawn network thread");
|
||||
}
|
||||
|
||||
fn run(server_addr: String, tx: mpsc::Sender<ServerMessage>) {
|
||||
let mut net = Esp32Network::new();
|
||||
|
||||
loop {
|
||||
if !net.is_connected() {
|
||||
info!("Connecting to server {server_addr}...");
|
||||
match net.connect(&server_addr) {
|
||||
Ok(()) => info!("Server connected"),
|
||||
Err(e) => {
|
||||
error!("Connection failed: {e}, retrying...");
|
||||
thread::sleep(NET_RECONNECT_DELAY);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match net.receive() {
|
||||
Ok(Some(payload)) => {
|
||||
match decode_server_message(&payload) {
|
||||
Ok(msg) => { let _ = tx.send(msg); }
|
||||
Err(e) => error!("Decode error: {e}"),
|
||||
}
|
||||
}
|
||||
Ok(None) => {
|
||||
thread::sleep(NET_POLL_INTERVAL);
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Receive error: {e}, reconnecting...");
|
||||
let _ = net.disconnect();
|
||||
thread::sleep(NET_RECONNECT_DELAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user