E40 Process Jobs + E94 Control Jobs + E30 communication state

GEM300 layer: SEMI E40-0705 Process Job and E94-0705 Control Job
state machines, plus the E30 §6.1 communication-state machine that
sits between HSMS SELECT and full GEM communication. Data-driven
via data/process_job_state.yaml and data/control_job_state.yaml,
mirroring the existing control_state.yaml pattern.

Wire coverage:
  S14F9/F10   CreateObject (CJ)              host -> equipment
  S14F11/F12  DeleteObject (CJ)              host -> equipment
  S16F5/F6    PRJobCommand                   host -> equipment
  S16F9       PRJobAlert                     equipment -> host
  S16F11/F12  PRJobCreate (simplified body)  host -> equipment
  S16F13/F14  PRJobDequeue                   host -> equipment
  S16F27/F28  CJobCommand                    host -> equipment

Process Job FSM exposes 8 states matching PRJOBSTATE bytes (E40 §10.3.2);
HOQ is reorder-aware (move-to-head against an insertion-order vector);
Stop/Abort on a Queued PJ routes through ABORTING so the host observes
PRJOBSTATE=7 on the wire (§6.3); alert_enabled is settable per-PJ for
PRALERT control; FSM dispatches through ProcessJobStore::on_change_
dynamically so a late set_state_change_handler() reaches existing PJs.

Hardening: loader rejects NoState (sentinel) as initial/from/to and
rejects `on: created` rows; static_asserts pin enum values to wire
bytes; ProcessJobStore is non-movable to keep the per-PJ this-capture
safe.

Server simulator cascades the full CJ -> PJ lifecycle on CJSTART so
the wire trace exercises every legal state. CEIDs 400/401 fire on CJ
state changes via the existing event-report pipeline.

Tests: 60+ new assertions across test_process_jobs, test_control_jobs,
test_communication_state, test_hsms_connection, plus loader and
messages round-trip coverage.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-07 21:00:32 +02:00
parent 1f67aad985
commit 90c177b7ce
33 changed files with 3122 additions and 62 deletions
+67 -12
View File
@@ -107,21 +107,60 @@ void Connection::on_payload(std::error_code ec, std::size_t) {
close("read payload: " + ec.message());
return;
}
Frame frame;
try {
handle_frame(Frame::decode(payload_.data(), payload_.size()));
frame = Frame::decode(payload_.data(), payload_.size());
} catch (const std::exception& e) {
close(std::string("decode: ") + e.what());
return;
}
// E37 §7.7: a non-SECS-II PType must be rejected with Reject.req.
// Convention (matches the EntityNotSelected emission below): the
// offending header byte is echoed in byte2 and the reason code goes
// in byte3.
if (frame.header.ptype != kPTypeSecsII) {
log("!! unsupported PType=" + std::to_string(frame.header.ptype) +
"; emitting Reject.req");
send_frame(Frame(Header::control(
SType::RejectReq, frame.header.system_bytes, frame.header.session_id,
frame.header.ptype,
static_cast<uint8_t>(RejectReason::PtypeNotSupported))));
read_length();
return;
}
handle_frame(std::move(frame));
read_length();
}
void Connection::handle_frame(Frame frame) {
if (frame.header.stype == SType::Data) {
handle_data(frame);
} else {
handle_control(frame);
return;
}
// E37 §7.7: any SType the receiver does not implement must be answered
// with Reject.req (reason=StypeNotSupported). Defined SType values are
// {1,2,3,4,5,6,7,9}; anything else here is unsupported.
switch (frame.header.stype) {
case SType::SelectReq:
case SType::SelectRsp:
case SType::DeselectReq:
case SType::DeselectRsp:
case SType::LinktestReq:
case SType::LinktestRsp:
case SType::RejectReq:
case SType::SeparateReq:
handle_control(frame);
return;
case SType::Data:
return; // already handled above
}
const uint8_t bad_stype = static_cast<uint8_t>(frame.header.stype);
log("!! unsupported SType=" + std::to_string(bad_stype) +
"; emitting Reject.req");
send_frame(Frame(Header::control(
SType::RejectReq, frame.header.system_bytes, frame.header.session_id,
bad_stype,
static_cast<uint8_t>(RejectReason::StypeNotSupported))));
}
void Connection::handle_data(const Frame& frame) {
@@ -210,11 +249,19 @@ void Connection::handle_control(const Frame& frame) {
const Header& h = frame.header;
switch (h.stype) {
case SType::SelectReq: {
log("<- Select.req");
// E37 §7.2: a Select.req while already SELECTED is answered with
// SelectStatus::AlreadyActive; we do NOT transition (we're already
// there) and we do NOT call the selected handler twice.
const auto status = (state_ == State::Selected)
? SelectStatus::AlreadyActive
: SelectStatus::Ok;
log(std::string("<- Select.req") +
(status == SelectStatus::AlreadyActive ? " (already SELECTED)" : ""));
send_frame(Frame(Header::control(SType::SelectRsp, h.system_bytes, h.session_id, 0,
static_cast<uint8_t>(SelectStatus::Ok))));
log("-> Select.rsp (Ok)");
enter_selected();
static_cast<uint8_t>(status))));
log(std::string("-> Select.rsp (") +
(status == SelectStatus::Ok ? "Ok" : "AlreadyActive") + ")");
if (status == SelectStatus::Ok) enter_selected();
break;
}
case SType::SelectRsp: {
@@ -231,11 +278,19 @@ void Connection::handle_control(const Frame& frame) {
break;
}
case SType::DeselectReq: {
log("<- Deselect.req");
// E37 §7.4: Deselect.req while NOT_SELECTED returns NotEstablished
// and leaves state untouched.
const auto status = (state_ == State::Selected)
? DeselectStatus::Ok
: DeselectStatus::NotEstablished;
log(std::string("<- Deselect.req") +
(status == DeselectStatus::NotEstablished ? " (not SELECTED)" : ""));
send_frame(Frame(Header::control(SType::DeselectRsp, h.system_bytes, h.session_id, 0,
static_cast<uint8_t>(DeselectStatus::Ok))));
state_ = State::NotSelected;
arm_t7();
static_cast<uint8_t>(status))));
if (status == DeselectStatus::Ok) {
state_ = State::NotSelected;
arm_t7();
}
break;
}
case SType::DeselectRsp: {
@@ -268,7 +323,7 @@ void Connection::handle_control(const Frame& frame) {
break;
}
case SType::Data:
break; // unreachable
break; // unreachable: SType::Data is dispatched to handle_data
}
}