Add print.rs (AmsState/AmsUnit/AmsTray/XcamSettings), fix print vs pushing

Mirrors continuum-schemas' schemas/bambulab/ restructuring: PushallResponse
removed (it never existed on the wire — pushall's request goes to
"pushing", but the state-push stream it triggers arrives under "print",
a different root key, not a direct reply). BambuReport::Pushing(...) ->
BambuReport::Print(PrintReport).

AmsTray is an untagged enum (Empty/Loaded) rather than one struct full of
Option<T> fields, matching the JSON Schema's oneOf for the same slot -
#[serde(deny_unknown_fields)] on EmptyTray is load-bearing: untagged enums
try variants in order, and a loaded tray (superset of Empty's one field)
would otherwise incorrectly match Empty first.

Verified against the full real ams/xcam example from the conversation via
examples/bambu_commands_demo.rs - both the empty and loaded tray in that
payload deserialize to the correct enum variant.
This commit is contained in:
2026-08-28 23:19:20 +00:00
parent 4eef52714b
commit 1583f531fa
5 changed files with 144 additions and 25 deletions
+22 -2
View File
@@ -5,7 +5,7 @@
//! matches byte for byte, same as the proto-based version did, with none
//! of the build.rs ceremony.
use continuum_proxy::printer::{CommandEnvelope, GetVersionRequest, GetVersionResponse, PushallRequest};
use continuum_proxy::printer::{CommandEnvelope, GetVersionRequest, GetVersionResponse, PrintReport, PushallRequest};
fn main() {
// --- get_version request ---
@@ -31,5 +31,25 @@ fn main() {
let actual = serde_json::to_string(&pushall).unwrap();
let expected = r#"{"sequence_id":"0","command":"pushall","version":1,"push_target":1}"#;
println!("pushall request: {actual}");
println!("matches Bambu's shape: {}", actual == expected);
println!("matches Bambu's shape: {}\n", actual == expected);
// --- print report: arrives under "print", NOT "pushing" (pushall
// triggers this stream, it isn't a direct reply to it) — includes the
// full ams/xcam example, with one empty tray and one loaded tray, to
// exercise the untagged Empty/Loaded split.
let real_print_report = r#"{
"ams": {"ams": [{"humidity":"4","id":"0","temp":"22.7","tray":[
{"id":"0"},
{"bed_temp":"0","bed_temp_type":"0","cols":["000000FF"],"drying_temp":"0","drying_time":"0","id":"1","nozzle_temp_max":"240","nozzle_temp_min":"190","remain":0,"tag_uid":"0000000000000000","tray_color":"000000FF","tray_diameter":"0.00","tray_id_name":"","tray_info_idx":"GFA00","tray_sub_brands":"","tray_type":"PLA","tray_uuid":"00000000000000000000000000000000","tray_weight":"0","xcam_info":"000000000000000000000000"}
]}]},
"ams_exist_bits": "1",
"insert_flag": true,
"power_on_flag": false,
"tray_exist_bits": "e",
"tray_is_bbl_bits": "e",
"xcam": {"allow_skip_parts":false,"buildplate_marker_detector":false,"first_layer_inspector":true,"halt_print_sensitivity":"medium","print_halt":true,"printing_monitor":true,"spaghetti_detector":true},
"xcam_status": "0"
}"#;
let parsed: PrintReport = serde_json::from_str(real_print_report).unwrap();
println!("print report parsed fine, empty + loaded tray both matched correctly:\n{parsed:#?}");
}