A4: SECS-I transport (block protocol + E4 retry FSM)

Adds a complete IO-free SECS-I implementation:

  include/secsgem/secsi/header.hpp   10-byte block header (R/W/E bits)
  include/secsgem/secsi/block.hpp    length + header + body + checksum
  include/secsgem/secsi/protocol.hpp half-duplex FSM (ENQ/EOT/ACK/NAK)
  src/secsi/*                         implementations
  tests/test_secsi.cpp                header, block, multi-block split,
                                      back-to-back FSM drive, RTY,
                                      contention, T2 timeout

The protocol is event-driven (`Event` → `Action` queue), so wiring it
to an asio serial_port is a thin adapter — that lands in the next
commit so this one stays reviewable.

Key design points:
- Master/slave contention: slave yields on simultaneous ENQ (E4 §7.1.4).
- RTY exhaustion raises ActionRaiseError, clears the send queue, resets
  to Idle (no zombie state).
- Multi-block assembler validates contiguous 1..N numbering and exclusive
  E-bit-on-last invariants — rejects malformed sequences with nullopt.
- Block::checksum is exposed publicly for the receive path's verification.

Tests cover the happy path (back-to-back delivery), error paths
(checksum mismatch, short input, oversize body), retries (NAK chain to
exhaustion), and protocol corner cases (contention, T2 timeout).

secsgem-py implements SECS-I block framing but lacks the explicit RTY
state machine; this commit puts the C++ port ahead on transport
correctness.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-07 21:34:09 +02:00
parent ec478ac9cb
commit a400ef3160
9 changed files with 957 additions and 0 deletions
+4
View File
@@ -45,6 +45,9 @@ add_library(secsgem
src/secs2/codec.cpp
src/hsms/header.cpp
src/hsms/connection.cpp
src/secsi/header.cpp
src/secsi/block.cpp
src/secsi/protocol.cpp
src/gem/control_state.cpp
src/gem/communication_state.cpp
src/gem/process_job_state.cpp
@@ -81,6 +84,7 @@ add_executable(secsgem_tests
tests/test_secs2.cpp
tests/test_hsms.cpp
tests/test_hsms_connection.cpp
tests/test_secsi.cpp
tests/test_control_state.cpp
tests/test_communication_state.cpp
tests/test_data_model.cpp