Prefix generated sequence_id instead of offsetting it
A printer's own free-running counter for unsolicited messages is always
a plain numeric string, so a non-numeric prefix ("cxproxy-") rules out
collision with it outright, rather than a large numeric starting offset
merely making collision improbable. Confirmed sequence_id need not be
numeric (live test, ISO-timestamp-prefixed value round-tripped fine) and
re-verified the new prefixed IDs round-trip through get_version on both
P1P (v1) and H2C (v2).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -86,6 +86,20 @@ const REQUEST_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
/// 1MB has real headroom for that.
|
||||
const MAX_PACKET_SIZE: usize = 1024 * 1024;
|
||||
|
||||
/// Every `sequence_id` this crate generates gets this prefix - a printer
|
||||
/// runs its own independent counter for unsolicited messages (confirmed
|
||||
/// live: `print.push_status`'s was already in the 500s at the start of a
|
||||
/// session, climbing steadily), and that counter has only ever been
|
||||
/// observed as a plain unprefixed integer string. An earlier version of
|
||||
/// this just started our own counter from a large offset instead of
|
||||
/// prefixing it, to dodge the same range a printer's counter climbs
|
||||
/// through - confirmed live (with an ISO-timestamp-prefixed sequence_id)
|
||||
/// that `sequence_id` isn't required to be numeric at all, so a
|
||||
/// non-numeric prefix rules out collision outright instead of merely
|
||||
/// making it improbable, and the counter itself can go back to starting
|
||||
/// at 1 each session.
|
||||
const SEQUENCE_ID_PREFIX: &str = "cxproxy-";
|
||||
|
||||
enum BambuMqttClient {
|
||||
V1(rumqttc::AsyncClient),
|
||||
V2(rumqttc::v5::AsyncClient),
|
||||
@@ -292,7 +306,10 @@ impl BambuMqttSession {
|
||||
/// `PrintStatusCache`. Not for a command with no reply at all either,
|
||||
/// like `gcode_line` - use `publish` (fire-and-forget) for those.
|
||||
pub async fn request(&self, category: &str, mut body: Value) -> Result<Value, PrinterError> {
|
||||
let sequence_id = self.next_sequence_id.fetch_add(1, Ordering::Relaxed).to_string();
|
||||
let sequence_id = format!(
|
||||
"{SEQUENCE_ID_PREFIX}{}",
|
||||
self.next_sequence_id.fetch_add(1, Ordering::Relaxed)
|
||||
);
|
||||
body["sequence_id"] = Value::String(sequence_id.clone());
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
Reference in New Issue
Block a user