Simplify boilerplate for learning: drop real protocol code, minimal main.rs
Removed adapters/ (rumqttc MQTT, suppaftp FTPS, reqwest HTTP), plate_changer/ (tokio-serial), discovery/, and cache.rs (rusqlite) — src/printer/ already covers 'talk to a printer' as simple stubs, so keeping a second, more complex version alongside it was redundant. main.rs goes from 6 concurrent tasks to 2 (uplink + go2rtc). uplink/ drops channels, jitter, and Send-bound futures. Verified with cargo build + cargo run --example printer_polymorphism.
This commit is contained in:
@@ -1,51 +1,52 @@
|
||||
# continuum-proxy
|
||||
|
||||
Edge gateway daemon for the Continuum print farm platform. Runs on a Linux SBC
|
||||
on-site, discovers and talks to printers over the LAN, and maintains a
|
||||
resilient uplink to the cloud control plane (`continuum-backend`).
|
||||
Edge gateway daemon for the Continuum print farm platform. Runs on a Linux
|
||||
SBC on-site, talks to printers over the LAN, and keeps a connection to the
|
||||
cloud control plane (`continuum-backend`).
|
||||
|
||||
## Responsibilities
|
||||
## This is a learning-stage boilerplate
|
||||
|
||||
- **Uplink** (`src/uplink/`): persistent WebSocket connection to
|
||||
`wss://api.domain.com/ws/edge/v1` with exponential-backoff reconnects,
|
||||
heartbeat ping/pong, and inbound task dispatch.
|
||||
- **Printer adapters** (`src/adapters/`): protocol clients per printer vendor —
|
||||
Bambu Lab (MQTT 8883 + FTPS 990), PrusaLink (REST), Klipper (Moonraker WS).
|
||||
- **Plate changer** (`src/plate_changer/`): mechanical cycle execution and
|
||||
sensor validation over GPIO/serial for automated plate-swap hardware.
|
||||
- **Local cache** (`rusqlite`): buffers telemetry and job state through
|
||||
connectivity gaps so nothing is lost if the uplink drops.
|
||||
- **go2rtc watchdog**: supervises the bundled `go2rtc` process for camera
|
||||
restreaming (RTSP/USB → WebRTC).
|
||||
This repo is deliberately minimal right now — real printer protocol clients
|
||||
(Bambu MQTT+FTPS, PrusaLink REST, Klipper/Moonraker WebSocket) are **not**
|
||||
implemented yet. Each vendor is a stub that just prints what it would do
|
||||
(`src/printer/bambu.rs`, `prusa.rs`, `klipper.rs`). The idea is to learn
|
||||
Rust's polymorphism pattern (trait + enum, since Rust has no class
|
||||
inheritance) on something simple before adding real networking on top.
|
||||
|
||||
## Getting started
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
cargo run
|
||||
cargo run # the daemon: cloud uplink + go2rtc watchdog
|
||||
cargo run --example printer_polymorphism # standalone demo, no network/env needed
|
||||
```
|
||||
|
||||
## Structure
|
||||
|
||||
```
|
||||
src/
|
||||
main.rs Multi-threaded async engine: uplink, discovery, go2rtc watchdog
|
||||
uplink/ Cloud WebSocket client (reconnect, heartbeat, dispatch)
|
||||
adapters/ bambu.rs, prusalink.rs, moonraker.rs — wire-protocol clients
|
||||
printer/ Domain model: Printer trait + PrinterBase + PrinterHandle enum
|
||||
plate_changer/ Mechanical cycle control + sensor validation
|
||||
discovery/ LAN printer discovery (SSDP / mDNS / static config)
|
||||
main.rs Runs the uplink and the go2rtc watchdog side by side
|
||||
config.rs Loads settings from environment variables
|
||||
uplink/ WebSocket client to continuum-backend: connect, heartbeat, reconnect on drop
|
||||
printer/ Printer trait + PrinterBase + PrinterHandle enum + one stub per vendor
|
||||
go2rtc.rs Restarts the go2rtc camera-restreaming process if it dies
|
||||
examples/
|
||||
printer_polymorphism.rs Runs all three printer stubs through one `connect()` call site
|
||||
```
|
||||
|
||||
`src/adapters/` talks the raw wire protocols (MQTT, FTPS, HTTP, WS).
|
||||
`src/printer/` is the vendor-agnostic domain model layered on top: a
|
||||
`Printer` trait plus one struct per vendor (`BambuPrinter`, `PrusaPrinter`,
|
||||
`KlipperPrinter`) wrapped in a closed `PrinterHandle` enum. Rust has no class
|
||||
inheritance, so this trait+enum combo is what stands in for a
|
||||
`GenericPrinter -> BambuPrinter` hierarchy — composition for shared fields,
|
||||
a trait for shared/overridable behavior, an enum for the closed set of
|
||||
vendors. See `examples/printer_polymorphism.rs`:
|
||||
`src/printer/` is where the "inheritance" question lives — see that
|
||||
module's doc comment for the trait+enum pattern this project uses instead
|
||||
of class inheritance, and run the example above to see it work.
|
||||
|
||||
```bash
|
||||
cargo run --example printer_polymorphism
|
||||
```
|
||||
## What's not here yet (on purpose)
|
||||
|
||||
- Real MQTT/FTPS/HTTP/WebSocket printer clients — `src/printer/*.rs` has a
|
||||
`println!` where each of these will go.
|
||||
- Local SQLite buffering for telemetry across connectivity gaps.
|
||||
- LAN printer discovery (SSDP/mDNS).
|
||||
- The mechanical plate-changer interface (serial/GPIO).
|
||||
|
||||
Add these back in one at a time as you get comfortable with the Rust
|
||||
underneath them — each is its own small lesson (async I/O, a new crate's
|
||||
API, error handling for a real protocol) rather than something to absorb
|
||||
all at once.
|
||||
|
||||
Reference in New Issue
Block a user