//! Run with: cargo run --example bambu_mapping_check -- //! //! **Read-only dry run of what a print would do.** Connects, reads the //! printer's state and loaded filament, downloads one project from the SD //! card root over FTPS, and prints the AMS mapping the production path would //! send - without sending it. Starts nothing, uploads nothing, deletes //! nothing. An optional third argument saves the downloaded copy locally. use std::time::Duration; use continuum_proxy::fleet; use continuum_proxy::printer::{GenericPrinter, PrinterHandle}; #[tokio::main] async fn main() -> anyhow::Result<()> { let mut args = std::env::args().skip(1); let (Some(target), Some(file)) = (args.next(), args.next()) else { anyhow::bail!("usage: cargo run --example bambu_mapping_check -- [save-to]"); }; let save_to = args.next(); let mut printers = fleet::load(std::path::Path::new("printers.toml"))?; let printer = printers .iter_mut() .find(|p| p.base().id == target) .ok_or_else(|| anyhow::anyhow!("no printer with id '{target}' in printers.toml"))?; let PrinterHandle::Bambu(bambu) = printer else { anyhow::bail!("'{target}' is not a Bambu printer"); }; tokio::time::timeout(Duration::from_secs(20), bambu.connect()) .await .map_err(|_| anyhow::anyhow!("connect timed out"))??; bambu.pushall().await.ok(); tokio::time::sleep(Duration::from_secs(4)).await; let report = bambu.print_status().await.ok_or_else(|| anyhow::anyhow!("no status yet"))?; println!("gcode_state: {:?}", report.gcode_state); println!("{:#?}", report.ams); let bytes = bambu.download_file(&format!("/{file}")).await?; println!("downloaded {} bytes", bytes.len()); if let Some(path) = save_to { std::fs::write(&path, &bytes)?; println!("saved a copy to {path}"); } for f in continuum_proxy::printer::plate_filaments(&bytes, 1)? { println!("project filament {}: {} {} #{}", f.index, f.filament_type, f.tray_info_idx, f.color); } if let Some(slot) = std::env::var("AMS_SLOT").ok().and_then(|v| v.parse::().ok()) { println!("(with AMS_SLOT={slot} chosen explicitly)"); bambu.set_ams_slot_override(Some(slot)); } match bambu.filament_source_for(&bytes, 1).await { Ok(source) => println!("mapping the production path would use: {source:?}"), Err(err) => println!("the production path would REFUSE: {err}"), } Ok(()) }