Real MQTT wiring for Bambu: connect, auto-detect v5/v3.1.1, request/reply
Removes GenericPrinter::receive (two disconnected fire-and-forget stubs that didn't actually give request/response) in favor of a real mechanism in the new src/printer/bambu_mqtt.rs: - BambuMqttSession wraps whichever rumqttc client a connection ended up using (v3.1.1's AsyncClient/EventLoop for BambuMQTT v1, v5's for BambuMQTT v2 - different types, different event/error shapes) behind one interface. `open()` respects ForceV1/ForceV2, and for Auto tries v5 first, falling back to v3.1.1 on any failure (see the module doc comment for why "any failure", not a precisely-matched version- rejection code - unverified against a live printer, no broker here to test against). - Reuses BambuTls::build_connector (now pub(crate)) for rumqttc's TLS transport via TlsConfiguration::NativeConnector, instead of a second, separate TLS trust story - hence rumqttc now pulls in use-native-tls instead of its default rustls stack, so there's one TLS implementation in the binary, not two. - request() publishes and waits (with a timeout) for a report whose sequence_id matches, correlated via a shared pending-request table that a spawned background task completes as reports arrive - the first real tokio::spawn in this crate, flagged as deferred since printer/mod.rs's very first doc comment; this is why it was deferred until now, and why it's needed now (polling the eventloop has to run continuously, independent of whatever call site is waiting). - publish()/publish_raw() are the fire-and-forget half, for commands like gcode_line that only get acknowledged implicitly. BambuPrinter::connect/send_gcode_line/publish now call the real session instead of printing what they would do. Verified against 192.0.2.1 (a reserved, never-routable test address): both AsyncClient/EventLoop pairs actually attempt a real TCP connection and fail gracefully (network timeout, not a panic) when nothing answers, and Auto genuinely attempts both while ForceV1 skips straight to v3.1.1. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MWQVtBGxHYLkVw2kBupd5g
This commit is contained in:
+1
-10
@@ -28,6 +28,7 @@
|
||||
|
||||
mod bambu;
|
||||
mod bambu_commands;
|
||||
mod bambu_mqtt;
|
||||
mod klipper;
|
||||
mod marlin_serial;
|
||||
mod prusa;
|
||||
@@ -73,7 +74,6 @@ pub trait GenericPrinter {
|
||||
|
||||
|
||||
async fn publish(&mut self, payload: String) -> Result<(), PrinterError>;
|
||||
async fn receive(&mut self, payload: String) -> Result<(), PrinterError>;
|
||||
|
||||
/// REQUIRED, no default body: `percent` is 0-100, but how it actually
|
||||
/// gets sent - an MQTT gcode-injection command, a REST call, raw bytes
|
||||
@@ -159,15 +159,6 @@ impl GenericPrinter for PrinterHandle {
|
||||
}
|
||||
}
|
||||
|
||||
async fn receive(&mut self, payload: String) -> Result<(), PrinterError> {
|
||||
match self {
|
||||
PrinterHandle::Bambu(p) => p.receive(payload).await,
|
||||
PrinterHandle::PrusaLink(p) => p.receive(payload).await,
|
||||
PrinterHandle::PrusaSerial(p) => p.receive(payload).await,
|
||||
PrinterHandle::Klipper(p) => p.receive(payload).await,
|
||||
}
|
||||
}
|
||||
|
||||
async fn set_fan_speed(&mut self, percent: u8) -> Result<(), PrinterError> {
|
||||
match self {
|
||||
PrinterHandle::Bambu(p) => p.set_fan_speed(percent).await,
|
||||
|
||||
Reference in New Issue
Block a user