Expand description
Host-side implementation of Marlin’s Binary File Transfer Mark II protocol.
Uploads G-code files to a 3D printer’s SD card over serial, with framing checksums, sync acknowledgement, retransmit on timeout, and optional heatshrink payload compression.
§Crate layout
The core (codec, session, file_transfer) is sans-I/O:
callers feed bytes in and pull events out, plumbing them through any
transport. Optional adapter modules wrap the core for the common cases:
adapters::blocking— synchronous loop over astd::io::Read+std::io::Writetransport. Behind theblockingfeature.adapters::tokio— async loop over atokio::io::AsyncRead+tokio::io::AsyncWrite+Unpintransport. Behind thetokiofeature.adapters::serialport— convenience helpers for opening aserialport::SerialPort, which already implementsRead + Writeand so plugs into the blocking adapter directly. Behind theserialfeature (impliesblocking).
Heatshrink payload compression is gated behind the heatshrink feature
and exposed via compression.
§Quickstart
use marlin_binary_transfer::adapters::blocking::{upload, UploadOptions};
use marlin_binary_transfer::adapters::serialport;
use marlin_binary_transfer::file_transfer::Compression;
let mut port = serialport::open("/dev/ttyUSB0", 250_000)?;
let file = std::fs::File::open("model.gco")?;
let stats = upload(&mut *port, file, UploadOptions {
dest_filename: "model.gco".into(),
compression: Compression::Auto,
..UploadOptions::default()
})?;
println!("uploaded {} bytes in {} chunks", stats.bytes_sent, stats.chunks_sent);See the README for the tokio quickstart, sans-I/O usage, and a complete description of what the upload helpers handle on your behalf (binary-mode enter/exit, retransmit, error classification).
§Protocol reference
https://github.com/MarlinFirmware/Marlin/pull/14817
§Status
Pre-1.0. The Marlin protocol is documented as experimental upstream and may evolve. Public API follows semver within 0.x — pin a minor version.
Modules§
- adapters
blockingortokioorserial - Optional I/O adapters that wrap the sans-I/O core into convenience APIs.
- codec
- Layer 1: packet encoding, decoding, and Fletcher-16 checksum.
- compression
- Optional heatshrink payload compression.
- file_
transfer - Layer 3: file-transfer state machine.
- session
- Layer 2: sans-I/O session state machine.