Windows discovery tool / windows (push) Successful in 1m35s
On the first real dispatch the proxy froze about 4.5 minutes in: pushall was published at QoS 1 from two tasks while holding the fleet lock, and once the in-flight window filled every publish blocked forever, stalling telemetry, heartbeats and the uplink. Publishes now time out after 10 s and pushall is QoS 0. Also adds an optional ams_slot to start_print so a job can choose its AMS slot (single-filament projects, same material type only).
60 lines
2.5 KiB
Rust
60 lines
2.5 KiB
Rust
//! Run with: cargo run --example bambu_mapping_check -- <printer-id> <file-on-card>
|
|
//!
|
|
//! **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 -- <printer-id> <file-on-card> [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::<u8>().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(())
|
|
}
|