ocpp/protocol

OCPP protocol state machines — a pure, sans-IO layer above the message models in ocpp.

The ocpp/* modules answer “what do OCPP payloads look like?”; this layer answers “what happens next on a connection?”. It implements the OCPP-J RPC rules from part 4 of the spec (one CALL in flight per direction, FIFO queueing, correlation of anonymous CALLRESULTs, call timeouts, SEND exemption, CALLRESULTERROR matching) as plain functions over plain data, with no processes, sockets, or clocks. One generic machine serves OCPP 1.6, 2.0.1 and 2.1 alike: version specifics enter only as injected codec functions taken from the per-version dispatch modules.

Shape of a machine

Every machine follows the same discipline:

Because everything is a value, transitions are trivially unit-testable and adapter-agnostic: the same machine can be embedded in an OTP actor, a JavaScript event loop, or a replay/simulation harness.

Modules

Dependencies

The layer is deliberately small, but not stdlib-only: it depends on gleam_stdlib, on gleam_json (frames are built and serialized as gleam/json values, and the injected codecs traffic in Json, matching the dispatch modules’ signatures), and on the ocpp package (ocpp/rpc, ocpp/transport/json/frame, and the per-version dispatch codecs). If this layer is extracted as its own package, gleam_json — already a transitive dependency via ocpp — must be a direct dependency too.

Types

How a CSMS answered a station’s boot notification — the boot vocabulary shared by the two role machines. The station machine reads it out of the responses to its own boot CALLs (ocpp/protocol/station); the CSMS machine reads it out of the application’s replies to inbound boot CALLs (ocpp/protocol/csms). It lives here so neither role module has to import the other.

pub type BootStatus {
  BootAccepted
  BootPending
  BootRejected
}

Constructors

  • BootAccepted

    The station is registered and may operate normally.

  • BootPending

    The CSMS is not yet ready; the station boots again after the returned interval.

  • BootRejected

    The CSMS refuses registration; the station boots again after the returned interval.

Values

pub fn earliest(
  deadlines: List(option.Option(Int)),
) -> option.Option(Int)

Merge the next_deadline values of stacked machines (or of a machine and the application’s own deadlines) into the single earliest instant to aim the one timer at. None entries mean “nothing to wake up for” and are ignored; the result is None only when every entry is.

Search Document