Skip to main content

Crate ecr17_protocol

Crate ecr17_protocol 

Source
Expand description

§ecr17-protocol

A pure-Rust implementation of the Italian ECR17 payment protocol used by Nexi Group POS terminals over a local LAN connection.

The crate is layered so the protocol logic is trivially testable and free of I/O (modules are added incrementally per docs/PLAN.md):

  • lrc — LRC checksum and LrcMode framing selector
  • codec — STX/ETX/LRC framing (encode/decode)
  • types — request/result/enum data model (serde)
  • protocol — message builders (one per ECR17 command)
  • response — response parsers
  • retry — money-safety retry policy (a financial command is never blindly replayed)
  • session — ACK/NAK, retransmit, timeout orchestration over a Transport
  • client — the async Ecr17Client API

I/O lives behind the async Transport trait; the real tokio TCP transport is available under the tokio-transport feature.

💰 Money-critical: this drives a terminal that charges real cards. Financial commands are never blindly re-sent after a reconnect — recover a lost response via send_last_result() (spec command G).

Protocol reference (public): https://developer.nexigroup.com/traditionalpos/en-EU/docs/

Re-exports§

pub use client::Ecr17Client;
pub use codec::DecodedPacket;
pub use codec::PacketCodec;
pub use codec::PacketType;
pub use error::Ecr17Error;
pub use error::Result;
pub use lrc::LrcMode;
pub use retry::should_retry_after_reconnect;
pub use session::Ecr17Session;
pub use session::SessionConfig;
pub use transport::FakeTransport;
pub use transport::Transport;
pub use types::*;

Modules§

client
Ecr17Client — the high-level async API: builds requests, drives the Ecr17Session, parses/maps responses to the typed crate::types results, and applies the money-safe auto-reconnect policy. Port of the reference C++ HybridEcr17Client.
codec
ECR17 packet framing: encode/decode STX payload ETX LRC application frames, SOH message EOT progress updates (no LRC), and ACK/NAK control frames.
error
Crate error type.
lrc
LRC checksum and the LrcMode framing selector.
protocol
ECR17 application-message builders — the bytes that go between STX and ETX.
response
Parsers for ECR17 terminal response application messages.
retry
Money-safety retry policy.
session
Ecr17Session — drives one ECR17 request/response exchange over a Transport.
transport
The async Transport abstraction and an in-memory FakeTransport for tests.
types
Request/result/config data model (serde), mirroring the reference types/client.ts field-for-field. Enums serialize to the same JSON string unions as the TS API and struct fields use camelCase, so the model maps cleanly onto the Tauri IPC. Absent optional fields deserialize to None; a None serializes as JSON null (the TS side treats null/absent equivalently for these optional fields).