kirby-ocpp 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +134 -95
  2. package/THIRD_PARTY_NOTICES.md +6 -2
  3. package/bin/kirby-ocpp.js +55 -0
  4. package/package.json +22 -44
  5. package/dist/cli.d.ts +0 -2
  6. package/dist/cli.js +0 -72
  7. package/dist/config.d.ts +0 -2
  8. package/dist/config.js +0 -53
  9. package/dist/ocpp/client.d.ts +0 -59
  10. package/dist/ocpp/client.js +0 -299
  11. package/dist/ocpp/schema-validator.d.ts +0 -15
  12. package/dist/ocpp/schema-validator.js +0 -75
  13. package/dist/ocpp/schemas/json/Authorize.json +0 -16
  14. package/dist/ocpp/schemas/json/AuthorizeResponse.json +0 -40
  15. package/dist/ocpp/schemas/json/BootNotification.json +0 -49
  16. package/dist/ocpp/schemas/json/BootNotificationResponse.json +0 -30
  17. package/dist/ocpp/schemas/json/CancelReservation.json +0 -15
  18. package/dist/ocpp/schemas/json/CancelReservationResponse.json +0 -20
  19. package/dist/ocpp/schemas/json/ChangeAvailability.json +0 -24
  20. package/dist/ocpp/schemas/json/ChangeAvailabilityResponse.json +0 -21
  21. package/dist/ocpp/schemas/json/ChangeConfiguration.json +0 -21
  22. package/dist/ocpp/schemas/json/ChangeConfigurationResponse.json +0 -22
  23. package/dist/ocpp/schemas/json/ClearCache.json +0 -8
  24. package/dist/ocpp/schemas/json/ClearCacheResponse.json +0 -20
  25. package/dist/ocpp/schemas/json/ClearChargingProfile.json +0 -27
  26. package/dist/ocpp/schemas/json/ClearChargingProfileResponse.json +0 -20
  27. package/dist/ocpp/schemas/json/DataTransfer.json +0 -23
  28. package/dist/ocpp/schemas/json/DataTransferResponse.json +0 -25
  29. package/dist/ocpp/schemas/json/DiagnosticsStatusNotification.json +0 -22
  30. package/dist/ocpp/schemas/json/DiagnosticsStatusNotificationResponse.json +0 -8
  31. package/dist/ocpp/schemas/json/FirmwareStatusNotification.json +0 -25
  32. package/dist/ocpp/schemas/json/FirmwareStatusNotificationResponse.json +0 -8
  33. package/dist/ocpp/schemas/json/GetCompositeSchedule.json +0 -27
  34. package/dist/ocpp/schemas/json/GetCompositeScheduleResponse.json +0 -79
  35. package/dist/ocpp/schemas/json/GetConfiguration.json +0 -16
  36. package/dist/ocpp/schemas/json/GetConfigurationResponse.json +0 -40
  37. package/dist/ocpp/schemas/json/GetDiagnostics.json +0 -30
  38. package/dist/ocpp/schemas/json/GetDiagnosticsResponse.json +0 -13
  39. package/dist/ocpp/schemas/json/GetLocalListVersion.json +0 -8
  40. package/dist/ocpp/schemas/json/GetLocalListVersionResponse.json +0 -15
  41. package/dist/ocpp/schemas/json/Heartbeat.json +0 -8
  42. package/dist/ocpp/schemas/json/HeartbeatResponse.json +0 -16
  43. package/dist/ocpp/schemas/json/MeterValues.json +0 -151
  44. package/dist/ocpp/schemas/json/MeterValuesResponse.json +0 -8
  45. package/dist/ocpp/schemas/json/RemoteStartTransaction.json +0 -127
  46. package/dist/ocpp/schemas/json/RemoteStartTransactionResponse.json +0 -20
  47. package/dist/ocpp/schemas/json/RemoteStopTransaction.json +0 -15
  48. package/dist/ocpp/schemas/json/RemoteStopTransactionResponse.json +0 -20
  49. package/dist/ocpp/schemas/json/ReserveNow.json +0 -33
  50. package/dist/ocpp/schemas/json/ReserveNowResponse.json +0 -23
  51. package/dist/ocpp/schemas/json/Reset.json +0 -20
  52. package/dist/ocpp/schemas/json/ResetResponse.json +0 -20
  53. package/dist/ocpp/schemas/json/SendLocalList.json +0 -68
  54. package/dist/ocpp/schemas/json/SendLocalListResponse.json +0 -22
  55. package/dist/ocpp/schemas/json/SetChargingProfile.json +0 -124
  56. package/dist/ocpp/schemas/json/SetChargingProfileResponse.json +0 -21
  57. package/dist/ocpp/schemas/json/StartTransaction.json +0 -32
  58. package/dist/ocpp/schemas/json/StartTransactionResponse.json +0 -44
  59. package/dist/ocpp/schemas/json/StatusNotification.json +0 -70
  60. package/dist/ocpp/schemas/json/StatusNotificationResponse.json +0 -8
  61. package/dist/ocpp/schemas/json/StopTransaction.json +0 -177
  62. package/dist/ocpp/schemas/json/StopTransactionResponse.json +0 -37
  63. package/dist/ocpp/schemas/json/TriggerMessage.json +0 -27
  64. package/dist/ocpp/schemas/json/TriggerMessageResponse.json +0 -21
  65. package/dist/ocpp/schemas/json/UnlockConnector.json +0 -15
  66. package/dist/ocpp/schemas/json/UnlockConnectorResponse.json +0 -21
  67. package/dist/ocpp/schemas/json/UpdateFirmware.json +0 -27
  68. package/dist/ocpp/schemas/json/UpdateFirmwareResponse.json +0 -8
  69. package/dist/ocpp/types.d.ts +0 -106
  70. package/dist/ocpp/types.js +0 -1
  71. package/dist/station/authorization.d.ts +0 -20
  72. package/dist/station/authorization.js +0 -78
  73. package/dist/station/charging-profile-registry.d.ts +0 -18
  74. package/dist/station/charging-profile-registry.js +0 -125
  75. package/dist/station/configuration-commands.d.ts +0 -11
  76. package/dist/station/configuration-commands.js +0 -29
  77. package/dist/station/configuration-registry.d.ts +0 -13
  78. package/dist/station/configuration-registry.js +0 -39
  79. package/dist/station/configuration.d.ts +0 -7
  80. package/dist/station/configuration.js +0 -88
  81. package/dist/station/connector-registry.d.ts +0 -25
  82. package/dist/station/connector-registry.js +0 -89
  83. package/dist/station/connector-status.d.ts +0 -7
  84. package/dist/station/connector-status.js +0 -66
  85. package/dist/station/local-auth-list.d.ts +0 -8
  86. package/dist/station/local-auth-list.js +0 -31
  87. package/dist/station/maintenance-lifecycle.d.ts +0 -25
  88. package/dist/station/maintenance-lifecycle.js +0 -110
  89. package/dist/station/meter-value-scheduler.d.ts +0 -21
  90. package/dist/station/meter-value-scheduler.js +0 -78
  91. package/dist/station/metering.d.ts +0 -15
  92. package/dist/station/metering.js +0 -138
  93. package/dist/station/ocpp-message.d.ts +0 -2
  94. package/dist/station/ocpp-message.js +0 -9
  95. package/dist/station/offline-transaction-sync.d.ts +0 -29
  96. package/dist/station/offline-transaction-sync.js +0 -99
  97. package/dist/station/payload.d.ts +0 -4
  98. package/dist/station/payload.js +0 -12
  99. package/dist/station/persistence.d.ts +0 -28
  100. package/dist/station/persistence.js +0 -206
  101. package/dist/station/reservation-rules.d.ts +0 -3
  102. package/dist/station/reservation-rules.js +0 -18
  103. package/dist/station/reservation-scheduler.d.ts +0 -11
  104. package/dist/station/reservation-scheduler.js +0 -33
  105. package/dist/station/smart-charging.d.ts +0 -45
  106. package/dist/station/smart-charging.js +0 -251
  107. package/dist/station/status-scheduler.d.ts +0 -16
  108. package/dist/station/status-scheduler.js +0 -58
  109. package/dist/station/transaction-message-retry.d.ts +0 -3
  110. package/dist/station/transaction-message-retry.js +0 -7
  111. package/dist/station/transaction-rules.d.ts +0 -7
  112. package/dist/station/transaction-rules.js +0 -34
  113. package/dist/station/trigger-message.d.ts +0 -2
  114. package/dist/station/trigger-message.js +0 -11
  115. package/dist/station-store.d.ts +0 -41
  116. package/dist/station-store.js +0 -104
  117. package/dist/station.d.ts +0 -113
  118. package/dist/station.js +0 -1204
  119. package/dist/tui.d.ts +0 -96
  120. package/dist/tui.js +0 -1618
  121. package/docs/OCPP_1.6J_CONFORMANCE.md +0 -61
package/README.md CHANGED
@@ -1,130 +1,169 @@
1
1
  # kirby-ocpp
2
2
 
3
- Terminal OCPP 1.6J charge point emulator for local and staging CSMS testing.
3
+ Terminal OCPP 1.6J charge point emulator for local and staging CSMS testing, written in Rust.
4
4
 
5
- It runs as an interactive TUI, speaks OCPP 1.6 JSON over WebSocket, validates payloads against bundled OCPP 1.6J JSON schemas, and can persist station state per charge point id.
5
+ It speaks OCPP 1.6 JSON over WebSocket (`ws://` and `wss://`, including mutual TLS), validates every payload against the bundled official OCPP 1.6J JSON schemas, persists station state per charge point id, and can be used three ways:
6
+
7
+ - an interactive terminal UI (default when stdout is a terminal);
8
+ - a headless event logger (`--no-tui`, `--json`);
9
+ - a scripted scenario runner for CI (`kirby-ocpp run --scenario ...`).
6
10
 
7
11
  ## Install
8
12
 
9
- Run without installing:
13
+ With Node.js (no Rust needed; installs the prebuilt binary for your platform):
10
14
 
11
15
  ```bash
12
16
  npx kirby-ocpp --url ws://localhost:9000/ocpp --id CP-001
13
- ```
14
-
15
- Or install globally:
16
-
17
- ```bash
18
17
  npm install -g kirby-ocpp
19
- kirby-ocpp --url ws://localhost:9000/ocpp --id CP-001
20
18
  ```
21
19
 
22
- ## Usage
20
+ With Cargo (Rust 1.88 or newer):
23
21
 
24
22
  ```bash
25
- kirby-ocpp --url ws://localhost:9000/ocpp --id CP-001
23
+ cargo install kirby-ocpp
26
24
  ```
27
25
 
28
- Common options:
29
-
30
- ```bash
31
- kirby-ocpp \
32
- --url ws://localhost:9000/ocpp \
33
- --id CP-001 \
34
- --vendor Kirby \
35
- --model TUI-16 \
36
- --connector 1 \
37
- --connectors 2 \
38
- --heartbeat 30
39
- ```
26
+ Or download a prebuilt binary for Linux, macOS or Windows from the [GitHub releases](https://github.com/archhaze24/kirby-ocpp/releases). To build from a checkout: `cargo install --path crates/kirby-ocpp`.
40
27
 
41
- WSS/TLS options:
28
+ ## Quick start
42
29
 
43
30
  ```bash
44
- kirby-ocpp \
45
- --url wss://csms.example.com/ocpp \
46
- --id CP-001 \
47
- --tls-ca ./ca.pem \
48
- --tls-cert ./client-cert.pem \
49
- --tls-key ./client-key.pem
31
+ kirby-ocpp --url ws://localhost:9000/ocpp --id CP-001 # TUI
32
+ kirby-ocpp --url ws://localhost:9000/ocpp --no-tui --json # headless, JSON lines
33
+ kirby-ocpp --url ws://localhost:9000/ocpp run --scenario charge-session
50
34
  ```
51
35
 
52
- Useful runtime flags:
53
-
54
- - `--no-persist`: run an ephemeral station.
55
- - `--state-dir <path>`: choose where station state is stored.
56
- - `--ws-subprotocol <protocol>`: defaults to `ocpp1.6`.
57
- - `--ws-ping <seconds>`: WebSocket ping interval, `0` disables pings.
58
- - `--no-reconnect`: disable automatic reconnect.
59
- - `--reconnect-initial-ms <ms>`, `--reconnect-max-ms <ms>`, `--reconnect-max-attempts <count>`: reconnect backoff.
60
- - `--call-timeout-ms <ms>`: OCPP CALL response timeout.
61
- - `--tls-server-name <name>` and `--tls-skip-verify`: local/self-signed WSS testing.
62
-
63
- Environment variables mirror the main flags: `OCPP_URL`, `OCPP_CHARGE_POINT_ID`, `OCPP_VENDOR`, `OCPP_MODEL`, `OCPP_WS_SUBPROTOCOL`, `OCPP_WS_PING_INTERVAL`, `OCPP_RECONNECT`, `OCPP_RECONNECT_INITIAL_MS`, `OCPP_RECONNECT_MAX_MS`, `OCPP_RECONNECT_MAX_ATTEMPTS`, `OCPP_CALL_TIMEOUT_MS`, `OCPP_TLS_CA_FILE`, `OCPP_TLS_CERT_FILE`, `OCPP_TLS_KEY_FILE`, `OCPP_TLS_SERVER_NAME`, and `OCPP_TLS_SKIP_VERIFY`.
64
-
65
- ## TUI
66
-
67
- The interface is organized into tabs. Use `1`-`7` or `Tab` / `Shift+Tab` to switch tabs, `Up` / `Down` to select an action, and `Enter` to run it.
36
+ `--url` (or `OCPP_URL`) is the only required option. Precedence is flag, then environment variable, then default. Booleans accept `true/false/yes/no/y/n/on/off/1/0`.
68
37
 
69
- - `1` Station
70
- - `2` Connector
71
- - `3` Transaction
72
- - `4` Maintenance
73
- - `5` Data
74
- - `6` Logs
75
- - `7` Scenarios
76
-
77
- Global shortcuts:
78
-
79
- - `/`: command palette.
80
- - `[` / `]`: previous/next connector.
81
- - `+`: add connector.
82
- - `j` / `k`: scroll logs.
83
- - `G`: jump logs to bottom.
84
- - `F`: cycle log filter.
85
- - `l`: full-screen plain log view.
86
- - `y`: copy current log buffer.
87
- - `?`: help.
88
- - `q`: quit.
89
-
90
- Forms prompt for values such as `idTag`, connector id, measurands, and `DataTransfer` payloads. There is no built-in default RFID/idTag.
91
- On the Connector tab, `s` cycles the selected connector status and `S` opens a list of all OCPP connector statuses.
92
-
93
- ## Persistence
94
-
95
- State is persisted by default per `chargePointId`. This includes mutable configuration, local auth lists/cache, charging profiles, connector meter values, reservations, and pending offline transactions.
96
-
97
- ```bash
98
- kirby-ocpp --url ws://localhost:9000/ocpp --id CP-001 --no-persist
99
- kirby-ocpp --url ws://localhost:9000/ocpp --id CP-001 --state-dir ./station-state
38
+ ## Options
39
+
40
+ | Flag | Env | Default | Meaning |
41
+ | --- | --- | --- | --- |
42
+ | `-u, --url` | `OCPP_URL` | required | CSMS WebSocket URL (`ws://` or `wss://`) |
43
+ | `-i, --id` | `OCPP_CHARGE_POINT_ID` | `CP-001` | Charge point id |
44
+ | `--vendor` | `OCPP_VENDOR` | `archhaze24` | BootNotification vendor |
45
+ | `--model` | `OCPP_MODEL` | `KIRBY` | BootNotification model |
46
+ | `--serial` | `OCPP_SERIAL` | none | Serial number (max 25 chars) |
47
+ | `--firmware-version` | `OCPP_FIRMWARE_VERSION` | none | Firmware version (max 50 chars) |
48
+ | `-c, --connector` | | `1` | Initial connector |
49
+ | `--connectors` | | `1` | Number of connectors |
50
+ | `--heartbeat` | | `30` | Fallback heartbeat interval (s) |
51
+ | `--ws-subprotocol` | `OCPP_WS_SUBPROTOCOL` | `ocpp1.6` | Requested subprotocol |
52
+ | `--ws-ping` | `OCPP_WS_PING_INTERVAL` | `30` | WebSocket ping interval (s), `0` disables |
53
+ | `--reconnect <BOOL>` | `OCPP_RECONNECT` | `true` | Auto-reconnect after unexpected disconnect |
54
+ | `--no-reconnect` | | | Disable auto-reconnect (wins over `--reconnect`) |
55
+ | `--reconnect-initial-ms` | `OCPP_RECONNECT_INITIAL_MS` | `1000` | Initial backoff |
56
+ | `--reconnect-max-ms` | `OCPP_RECONNECT_MAX_MS` | `30000` | Maximum backoff |
57
+ | `--reconnect-max-attempts` | `OCPP_RECONNECT_MAX_ATTEMPTS` | `0` | `0` = unlimited |
58
+ | `--call-timeout-ms` | `OCPP_CALL_TIMEOUT_MS` | `30000` | CALL response timeout |
59
+ | `--tls-ca` | `OCPP_TLS_CA_FILE` | system roots | CA bundle (PEM) |
60
+ | `--tls-cert`, `--tls-key` | `OCPP_TLS_CERT_FILE`, `OCPP_TLS_KEY_FILE` | | Client certificate and key for mTLS (both or neither) |
61
+ | `--tls-server-name` | `OCPP_TLS_SERVER_NAME` | URL host | SNI / verification name override |
62
+ | `--tls-skip-verify` | `OCPP_TLS_SKIP_VERIFY` | off | Skip certificate verification (testing only) |
63
+ | `--no-persist` | `KIRBY_OCPP_NO_PERSIST` | off | Do not load or save station state |
64
+ | `--state-dir` | `KIRBY_OCPP_STATE_DIR` | `~/.kirby-ocpp/stations` | State directory (`%USERPROFILE%` on Windows) |
65
+ | `--print-config` | | | Print the effective configuration as JSON and exit |
66
+ | `--no-tui` | | | Never start the TUI; log to stdout |
67
+ | `--json` | | | JSON lines instead of text (events and the `run` report) |
68
+ | `--log-file` | | | Also append the headless event log to a file |
69
+ | `--licenses` | | | Print licence notices and exit |
70
+ | `-V, --version`, `-h, --help` | | | |
71
+
72
+ Options are global and may be placed before or after a subcommand.
73
+
74
+ ## TLS
75
+
76
+ `wss://` uses rustls. Without `--tls-ca` the operating system trust store is used. Use `--tls-ca` for a private CA, `--tls-cert`/`--tls-key` for client authentication, `--tls-server-name` when the URL host differs from the certificate name, and `--tls-skip-verify` only against local self-signed servers.
77
+
78
+ ## State persistence
79
+
80
+ Per charge point id, one JSON file `<state dir>/<id>.station.json` holds the local authorization list and its version, authorization cache, charging profiles, writable configuration values, availability, connector count and per-connector state (status, meter, reservation, transaction) and the offline transaction queue. Files are versioned and written atomically (temp file plus rename); a corrupt file or one belonging to another charge point is moved to `<file>.bak` and the station starts clean. `--no-persist` disables both loading and saving.
81
+
82
+ ## Terminal UI
83
+
84
+ Seven tabs, switched with `1`-`7` or `Tab`/`Shift-Tab`: Station, Connector, Transaction, Maintenance, Data, Logs, Scenarios. Panes: connectors, actions, log (move focus with Left/Right).
85
+
86
+ | Key | Action |
87
+ | --- | --- |
88
+ | `Up/Down`, `j/k`, `PageUp/PageDown` | Move in the focused pane |
89
+ | `[` `]` | Previous / next connector |
90
+ | `Enter` | Run the selected action / open the selected log row |
91
+ | letters | Accelerators of the current tab's actions (shown in the list) |
92
+ | `/` or `:` or `Ctrl-P` | Command palette (fuzzy search over all actions); `/` searches the log when the log pane is focused on the Logs tab |
93
+ | `Esc` | Close dialog / clear log search |
94
+ | `?` | Help |
95
+ | `q`, `Ctrl-C` | Quit |
96
+
97
+ Actions: connect/disconnect/reconnect, BootNotification, Heartbeat, add connector; plug/unplug, set status, StatusNotification, fault toggle; Authorize, StartTransaction, StopTransaction (with reason), MeterValues; set diagnostics/firmware outcome and send their status notifications; DataTransfer, vendor ping and raw CALLs.
98
+
99
+ Log view (Logs tab): CALL/RESULT/ERROR correlation, filters (all, calls, errors, station, csms; `f`), search (`s`), pause/follow (`p`), jump to newest (`G`), detail view with scroll (`Enter`; `c`/`y` copies), copy row (`y`) or visible rows (`Y`), export as JSONL (`e`, default `./kirby-ocpp-<id>-<timestamp>.jsonl`), clear with confirmation (`c`). The buffer keeps the last 2000 entries. Copying tries external clipboard tools first and falls back to the terminal's OSC 52 sequence.
100
+
101
+ Scenarios tab: one `Run: <name>` action per built-in scenario (keys `o`, `w`, `s`, `i` for the first four) and `l` to load a scenario file, `x` to cancel the running one.
102
+
103
+ ## Headless mode and exit codes
104
+
105
+ Without a TTY (or with `--no-tui`) the tool connects and prints events until SIGINT/SIGTERM, then closes the WebSocket cleanly. With `--json` each line is one JSON object; frames carry a `payload` field.
106
+
107
+ `kirby-ocpp run --scenario <name|file.toml> [--report report.json] [--timeout 60] [--id-tag TAG]` connects, waits for an accepted BootNotification, runs the scenario and prints a PASS/FAIL/SKIP report (a JSON object with `"type": "report"` under `--json`).
108
+
109
+ | Code | Meaning |
110
+ | --- | --- |
111
+ | 0 | Success (scenario passed, normal shutdown) |
112
+ | 1 | Scenario failed or timed out, or a runtime error |
113
+ | 2 | Usage or configuration error |
114
+
115
+ ## Scenarios
116
+
117
+ `kirby-ocpp scenarios list` lists the built-in scenarios (`charge-session`, `fault-recovery`, `finish-session`, `offline-sync`); `kirby-ocpp scenarios show <name>` prints one as TOML. Built-ins target connector 1 unless `--connector` is given.
118
+
119
+ ```toml
120
+ name = "my-session"
121
+ description = "Plug in, start, meter, stop"
122
+
123
+ [[steps]]
124
+ action = "plug"
125
+ connector = 1
126
+
127
+ [[steps]]
128
+ action = "start_tx"
129
+ connector = 1
130
+ id_tag = "KIRBY-TAG" # implicitly expects status Accepted
131
+
132
+ [[steps]]
133
+ action = "meter"
134
+ connector = 1
135
+ wh_delta = 1000
136
+
137
+ [[steps]]
138
+ action = "expect_call" # a CALL seen since the last matched expect_call
139
+ call = "MeterValues"
140
+ timeout_ms = 3000
141
+
142
+ [[steps]]
143
+ action = "stop_tx"
144
+ connector = 1
145
+ reason = "Local"
146
+ expect = { status = "Accepted" }
100
147
  ```
101
148
 
102
- ## Scope
149
+ Actions: `connect`, `disconnect`, `reconnect`, `boot`, `heartbeat`, `plug`, `unplug`, `authorize`, `start_tx`, `stop_tx`, `meter`, `status`, `fault`, `clear_fault`, `sleep`, `wait_for`, `expect_call` (`call`, optional `direction`, `match` payload subset), `send_raw` (`call`, `payload`, `validate`), `data_transfer`. Every step may have `name` and `expect` (`status`, `payload` subset, `error = true`). `wait_for` takes `condition = { kind = ... }` with kinds `connected`, `disconnected`, `registration`, `connector_status`, `tx_active`, `tx_idle`, `no_pending_messages`, and `timeout_ms` (default 5000). Unknown fields are rejected.
103
150
 
104
- kirby-ocpp targets OCPP 1.6J. It supports common Charge Point calls and Central System commands for booting, authorization, transactions, metering, local auth lists, reservations, availability, reset, diagnostics, firmware, smart charging, trigger messages, and data transfer.
151
+ ## Testing against a mock
105
152
 
106
- Detailed coverage is tracked in [docs/OCPP_1.6J_CONFORMANCE.md](docs/OCPP_1.6J_CONFORMANCE.md).
153
+ `crates/kirby-ocpp-testkit` is a dev-only scripted mock CSMS (plain and TLS) used by the integration tests; it is not published. Use it from tests of your own, or point `kirby-ocpp` at any real or local CSMS.
107
154
 
108
155
  ## Development
109
156
 
110
- ```bash
111
- npm install
112
- npm run dev -- --url ws://localhost:9000/ocpp --id CP-001
113
- ```
114
-
115
- Before publishing:
157
+ Workspace crates: `kirby-ocpp-core` (protocol, station state machine, scenarios, WebSocket/TLS; no terminal code), `kirby-ocpp-tui` (ratatui UI), `kirby-ocpp` (binary: CLI and headless runner), `kirby-ocpp-testkit` (mock CSMS, not published).
116
158
 
117
159
  ```bash
118
- npm run typecheck
119
- npm test
120
- npm run smoke
121
- npm run pack:check
160
+ cargo fmt --all --check
161
+ cargo clippy --workspace --all-targets -- -D warnings
162
+ cargo test --workspace # includes doc tests and process-level CLI tests
122
163
  ```
123
164
 
124
- `npm run pack:check` builds the package, installs the generated tarball into a temporary directory, and verifies the installed CLI and bundled schemas.
125
-
126
- ## Third-Party Materials
165
+ Protocol coverage is documented in [docs/OCPP_1.6J_CONFORMANCE.md](docs/OCPP_1.6J_CONFORMANCE.md).
127
166
 
128
- This project is MIT licensed. Bundled OCPP 1.6J JSON schemas are sourced from the official Open Charge Alliance OCPP 1.6 download package and are included for validation/conformance. They are not owned by this project and are not covered by this project's MIT license.
167
+ ## License
129
168
 
130
- See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
169
+ MIT, see [LICENSE](LICENSE). The bundled OCPP JSON schemas belong to the Open Charge Alliance; see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) or run `kirby-ocpp --licenses`. Crate licences are recorded in `Cargo.lock` and the crates' metadata.
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## OCPP 1.6J JSON schemas
4
4
 
5
- This package bundles the OCPP 1.6J JSON schemas under `dist/ocpp/schemas/json` for local protocol validation.
5
+ `kirby-ocpp` bundles the OCPP 1.6J JSON schemas (`crates/kirby-ocpp-core/schemas`) and embeds them in the binary for local protocol validation.
6
6
 
7
7
  The schemas are sourced from the official Open Charge Alliance OCPP 1.6 download package:
8
8
 
@@ -12,4 +12,8 @@ The OCPP 1.6J specification package references Creative Commons Attribution-NoDe
12
12
 
13
13
  - https://creativecommons.org/licenses/by-nd/4.0/legalcode
14
14
 
15
- The bundled schemas are included for compatibility/conformance validation and are not owned by this project. The project license in `LICENSE` applies to this project's own source code, not to Open Charge Alliance materials. Open Charge Alliance does not sponsor or endorse this package.
15
+ The bundled schemas are included, unmodified, for compatibility and conformance validation and are not owned by this project. The project license in `LICENSE` applies to this project's own source code, not to Open Charge Alliance materials. Open Charge Alliance does not sponsor or endorse this project.
16
+
17
+ ## Rust dependencies
18
+
19
+ `kirby-ocpp` is statically linked from open-source Rust crates (tokio, rustls, ring, ratatui, crossterm, clap, serde and others), each under its own licence (MIT, Apache-2.0, ISC, BSD and similar permissive licences). Their names, versions and licences are recorded in `Cargo.lock` and each crate's own metadata; run `cargo install cargo-license && cargo license` in a source checkout, or inspect the dependency tree with `cargo tree`, for the exact list. Binary distributions must keep this notice together with the licence texts of those crates.
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+ // Launcher: runs the native kirby-ocpp binary shipped by the matching platform package.
3
+ "use strict";
4
+
5
+ const { spawnSync } = require("node:child_process");
6
+ const path = require("node:path");
7
+
8
+ const PLATFORMS = {
9
+ "linux-x64": "@archhaze24/kirby-ocpp-linux-x64",
10
+ "linux-arm64": "@archhaze24/kirby-ocpp-linux-arm64",
11
+ "darwin-x64": "@archhaze24/kirby-ocpp-darwin-x64",
12
+ "darwin-arm64": "@archhaze24/kirby-ocpp-darwin-arm64",
13
+ "win32-x64": "@archhaze24/kirby-ocpp-win32-x64",
14
+ };
15
+
16
+ function binaryPath() {
17
+ const key = `${process.platform}-${process.arch}`;
18
+ const pkg = PLATFORMS[key];
19
+ if (!pkg) {
20
+ throw new Error(
21
+ `kirby-ocpp has no prebuilt binary for ${key}. Supported: ${Object.keys(PLATFORMS).join(", ")}. ` +
22
+ "Build from source instead: cargo install kirby-ocpp",
23
+ );
24
+ }
25
+ let manifest;
26
+ try {
27
+ manifest = require.resolve(`${pkg}/package.json`);
28
+ } catch {
29
+ throw new Error(
30
+ `The platform package ${pkg} is not installed (npm skipped the optional dependency). ` +
31
+ "Reinstall without --omit=optional, or run: cargo install kirby-ocpp",
32
+ );
33
+ }
34
+ const exe = process.platform === "win32" ? "kirby-ocpp.exe" : "kirby-ocpp";
35
+ return path.join(path.dirname(manifest), "bin", exe);
36
+ }
37
+
38
+ let binary;
39
+ try {
40
+ binary = binaryPath();
41
+ } catch (error) {
42
+ console.error(`kirby-ocpp: ${error.message}`);
43
+ process.exit(1);
44
+ }
45
+
46
+ const result = spawnSync(binary, process.argv.slice(2), { stdio: "inherit" });
47
+ if (result.error) {
48
+ console.error(`kirby-ocpp: could not run ${binary}: ${result.error.message}`);
49
+ process.exit(1);
50
+ }
51
+ if (result.signal) {
52
+ process.kill(process.pid, result.signal);
53
+ } else {
54
+ process.exit(result.status ?? 1);
55
+ }
package/package.json CHANGED
@@ -1,62 +1,40 @@
1
1
  {
2
2
  "name": "kirby-ocpp",
3
- "version": "0.1.1",
4
- "description": "A terminal OCPP charge point emulator.",
5
- "type": "module",
6
- "author": "archhaze24",
7
- "bin": {
8
- "kirby-ocpp": "dist/cli.js"
9
- },
10
- "files": [
11
- "dist",
12
- "docs",
13
- "README.md",
14
- "THIRD_PARTY_NOTICES.md",
15
- "LICENSE"
16
- ],
17
- "scripts": {
18
- "build": "tsc -p tsconfig.json && node scripts/copy-schemas.mjs",
19
- "dev": "tsx src/cli.ts",
20
- "pack:check": "node scripts/check-packed-install.mjs",
21
- "prepack": "npm run build",
22
- "smoke": "npm run build && node scripts/smoke-ocpp.mjs",
23
- "start": "node dist/cli.js",
24
- "test": "npm run build && node --test tests/*.test.mjs",
25
- "typecheck": "tsc -p tsconfig.json --noEmit"
26
- },
3
+ "version": "0.2.0",
4
+ "description": "Terminal OCPP 1.6J charge point emulator for testing a CSMS (TUI, headless and scenarios)",
27
5
  "keywords": [
28
6
  "ocpp",
29
7
  "ocpp16",
8
+ "ev",
30
9
  "charge-point",
31
10
  "emulator",
32
- "tui",
33
- "cli"
11
+ "csms",
12
+ "tui"
34
13
  ],
35
14
  "license": "MIT",
15
+ "author": "archhaze24",
36
16
  "repository": {
37
17
  "type": "git",
38
18
  "url": "git+https://github.com/archhaze24/kirby-ocpp.git"
39
19
  },
40
- "bugs": {
41
- "url": "https://github.com/archhaze24/kirby-ocpp/issues"
42
- },
43
20
  "homepage": "https://github.com/archhaze24/kirby-ocpp#readme",
44
- "engines": {
45
- "node": ">=20"
21
+ "bin": {
22
+ "kirby-ocpp": "bin/kirby-ocpp.js"
46
23
  },
47
- "dependencies": {
48
- "blessed": "^0.1.81",
49
- "commander": "^12.1.0",
50
- "jsonschema": "^1.5.0",
51
- "nanoid": "^5.0.7",
52
- "ws": "^8.18.0",
53
- "zod": "^3.23.8"
24
+ "files": [
25
+ "bin",
26
+ "README.md",
27
+ "LICENSE",
28
+ "THIRD_PARTY_NOTICES.md"
29
+ ],
30
+ "engines": {
31
+ "node": ">=18"
54
32
  },
55
- "devDependencies": {
56
- "@types/blessed": "^0.1.25",
57
- "@types/node": "^22.10.2",
58
- "@types/ws": "^8.5.13",
59
- "tsx": "^4.19.2",
60
- "typescript": "^5.7.2"
33
+ "optionalDependencies": {
34
+ "@archhaze24/kirby-ocpp-linux-x64": "0.2.0",
35
+ "@archhaze24/kirby-ocpp-linux-arm64": "0.2.0",
36
+ "@archhaze24/kirby-ocpp-darwin-x64": "0.2.0",
37
+ "@archhaze24/kirby-ocpp-darwin-arm64": "0.2.0",
38
+ "@archhaze24/kirby-ocpp-win32-x64": "0.2.0"
61
39
  }
62
40
  }
package/dist/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/dist/cli.js DELETED
@@ -1,72 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Command } from "commander";
3
- import { createRequire } from "node:module";
4
- import { ZodError } from "zod";
5
- import { parseConfig } from "./config.js";
6
- import { Station } from "./station.js";
7
- import { Tui } from "./tui.js";
8
- const program = new Command();
9
- const require = createRequire(import.meta.url);
10
- const packageJson = require("../package.json");
11
- program
12
- .name("kirby-ocpp")
13
- .description("Terminal OCPP charge point emulator")
14
- .version(packageJson.version ?? "0.1.0")
15
- .option("-u, --url <url>", "Central System WebSocket URL, e.g. ws://localhost:9000/ocpp")
16
- .option("-i, --id <id>", "charge point id", process.env.OCPP_CHARGE_POINT_ID ?? "CP-001")
17
- .option("--vendor <vendor>", "charge point vendor", process.env.OCPP_VENDOR ?? "archhaze24")
18
- .option("--model <model>", "charge point model", process.env.OCPP_MODEL ?? "KIRBY")
19
- .option("-c, --connector <id>", "initial connector id", "1")
20
- .option("--connectors <count>", "number of station connectors", "1")
21
- .option("--heartbeat <seconds>", "fallback heartbeat interval in seconds", "30")
22
- .option("--no-persist", "do not save station state such as local auth list and charging profiles")
23
- .option("--state-dir <path>", "directory for persisted station state")
24
- .option("--ws-subprotocol <protocol>", "WebSocket subprotocol to request", "ocpp1.6")
25
- .option("--ws-ping <seconds>", "WebSocket ping interval in seconds, 0 disables pings", "30")
26
- .option("--no-reconnect", "do not automatically reconnect after an unexpected WebSocket disconnect")
27
- .option("--reconnect-initial-ms <milliseconds>", "initial automatic reconnect delay in milliseconds", "1000")
28
- .option("--reconnect-max-ms <milliseconds>", "maximum automatic reconnect delay in milliseconds", "30000")
29
- .option("--reconnect-max-attempts <attempts>", "maximum automatic reconnect attempts, 0 means unlimited", "0")
30
- .option("--call-timeout-ms <milliseconds>", "OCPP CALL response timeout in milliseconds", "30000")
31
- .option("--tls-ca <path>", "CA certificate bundle for wss:// connections")
32
- .option("--tls-cert <path>", "client certificate for wss:// mutual TLS")
33
- .option("--tls-key <path>", "client private key for wss:// mutual TLS")
34
- .option("--tls-server-name <name>", "TLS server name override for wss:// connections")
35
- .option("--tls-skip-verify", "disable TLS certificate verification for local/self-signed wss:// testing")
36
- .parse();
37
- const options = program.opts();
38
- try {
39
- const config = parseConfig({
40
- centralSystemUrl: options.url,
41
- chargePointId: options.id,
42
- vendor: options.vendor,
43
- model: options.model,
44
- connectorId: options.connector,
45
- connectorCount: Math.max(Number.parseInt(options.connectors, 10), Number.parseInt(options.connector, 10)),
46
- heartbeatIntervalSeconds: options.heartbeat,
47
- persistState: options.persist,
48
- stateDirectory: options.stateDir,
49
- webSocketSubprotocol: options.wsSubprotocol,
50
- webSocketPingIntervalSeconds: options.wsPing,
51
- webSocketReconnectEnabled: options.reconnect,
52
- webSocketReconnectInitialDelayMs: options.reconnectInitialMs,
53
- webSocketReconnectMaxDelayMs: options.reconnectMaxMs,
54
- webSocketReconnectMaxAttempts: options.reconnectMaxAttempts,
55
- callTimeoutMs: options.callTimeoutMs,
56
- tlsRejectUnauthorized: !options.tlsSkipVerify,
57
- tlsCaFile: options.tlsCa,
58
- tlsCertFile: options.tlsCert,
59
- tlsKeyFile: options.tlsKey,
60
- tlsServerName: options.tlsServerName
61
- });
62
- const station = new Station(config);
63
- const tui = new Tui(station);
64
- tui.start();
65
- }
66
- catch (error) {
67
- if (error instanceof ZodError) {
68
- console.error(error.errors.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join("\n"));
69
- process.exit(1);
70
- }
71
- throw error;
72
- }
package/dist/config.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { StationConfig } from "./ocpp/types.js";
2
- export declare function parseConfig(input: Partial<Record<keyof StationConfig, unknown>>): StationConfig;
package/dist/config.js DELETED
@@ -1,53 +0,0 @@
1
- import { z } from "zod";
2
- const configSchema = z.object({
3
- centralSystemUrl: z
4
- .string({
5
- required_error: "Use --url or OCPP_URL to set the Central System WebSocket URL"
6
- })
7
- .url(),
8
- chargePointId: z.string().min(1),
9
- vendor: z.string().min(1),
10
- model: z.string().min(1),
11
- connectorId: z.coerce.number().int().positive(),
12
- connectorCount: z.coerce.number().int().positive(),
13
- heartbeatIntervalSeconds: z.coerce.number().int().positive(),
14
- persistState: z.coerce.boolean(),
15
- stateDirectory: z.string().min(1).optional(),
16
- webSocketSubprotocol: z.string().min(1),
17
- webSocketPingIntervalSeconds: z.coerce.number().int().nonnegative(),
18
- webSocketReconnectEnabled: z.coerce.boolean(),
19
- webSocketReconnectInitialDelayMs: z.coerce.number().int().nonnegative(),
20
- webSocketReconnectMaxDelayMs: z.coerce.number().int().nonnegative(),
21
- webSocketReconnectMaxAttempts: z.coerce.number().int().nonnegative(),
22
- callTimeoutMs: z.coerce.number().int().positive(),
23
- tlsRejectUnauthorized: z.coerce.boolean(),
24
- tlsCaFile: z.string().min(1).optional(),
25
- tlsCertFile: z.string().min(1).optional(),
26
- tlsKeyFile: z.string().min(1).optional(),
27
- tlsServerName: z.string().min(1).optional()
28
- });
29
- export function parseConfig(input) {
30
- return configSchema.parse({
31
- centralSystemUrl: input.centralSystemUrl ?? process.env.OCPP_URL,
32
- chargePointId: input.chargePointId ?? process.env.OCPP_CHARGE_POINT_ID ?? "CP-001",
33
- vendor: input.vendor ?? process.env.OCPP_VENDOR ?? "archhaze24",
34
- model: input.model ?? process.env.OCPP_MODEL ?? "KIRBY",
35
- connectorId: input.connectorId ?? 1,
36
- connectorCount: input.connectorCount ?? input.connectorId ?? 1,
37
- heartbeatIntervalSeconds: input.heartbeatIntervalSeconds ?? 30,
38
- persistState: input.persistState ?? process.env.KIRBY_OCPP_NO_PERSIST !== "1",
39
- stateDirectory: input.stateDirectory ?? process.env.KIRBY_OCPP_STATE_DIR,
40
- webSocketSubprotocol: input.webSocketSubprotocol ?? process.env.OCPP_WS_SUBPROTOCOL ?? "ocpp1.6",
41
- webSocketPingIntervalSeconds: input.webSocketPingIntervalSeconds ?? process.env.OCPP_WS_PING_INTERVAL ?? 30,
42
- webSocketReconnectEnabled: input.webSocketReconnectEnabled ?? process.env.OCPP_RECONNECT !== "0",
43
- webSocketReconnectInitialDelayMs: input.webSocketReconnectInitialDelayMs ?? process.env.OCPP_RECONNECT_INITIAL_MS ?? 1_000,
44
- webSocketReconnectMaxDelayMs: input.webSocketReconnectMaxDelayMs ?? process.env.OCPP_RECONNECT_MAX_MS ?? 30_000,
45
- webSocketReconnectMaxAttempts: input.webSocketReconnectMaxAttempts ?? process.env.OCPP_RECONNECT_MAX_ATTEMPTS ?? 0,
46
- callTimeoutMs: input.callTimeoutMs ?? process.env.OCPP_CALL_TIMEOUT_MS ?? 30_000,
47
- tlsRejectUnauthorized: input.tlsRejectUnauthorized ?? process.env.OCPP_TLS_SKIP_VERIFY !== "1",
48
- tlsCaFile: input.tlsCaFile ?? process.env.OCPP_TLS_CA_FILE,
49
- tlsCertFile: input.tlsCertFile ?? process.env.OCPP_TLS_CERT_FILE,
50
- tlsKeyFile: input.tlsKeyFile ?? process.env.OCPP_TLS_KEY_FILE,
51
- tlsServerName: input.tlsServerName ?? process.env.OCPP_TLS_SERVER_NAME
52
- });
53
- }
@@ -1,59 +0,0 @@
1
- import EventEmitter from "node:events";
2
- import type { CallResponse, OcppMessage } from "./types.js";
3
- interface OcppClientEvents {
4
- connected: [];
5
- disconnected: [code?: number, reason?: string];
6
- error: [error: Error];
7
- log: [direction: "in" | "out", message: OcppMessage];
8
- call: [messageId: string, action: string, payload: Record<string, unknown>];
9
- }
10
- export interface OcppClientOptions {
11
- subprotocol?: string;
12
- pingIntervalSeconds?: number;
13
- tlsRejectUnauthorized?: boolean;
14
- tlsCaFile?: string;
15
- tlsCertFile?: string;
16
- tlsKeyFile?: string;
17
- tlsServerName?: string;
18
- }
19
- export declare interface OcppClient {
20
- on<K extends keyof OcppClientEvents>(event: K, listener: (...args: OcppClientEvents[K]) => void): this;
21
- emit<K extends keyof OcppClientEvents>(event: K, ...args: OcppClientEvents[K]): boolean;
22
- }
23
- export declare class OcppClient extends EventEmitter {
24
- private readonly centralSystemUrl;
25
- private readonly chargePointId;
26
- private readonly options;
27
- private socket?;
28
- private pingTimer?;
29
- private awaitingPong;
30
- private readonly pending;
31
- private readonly incomingCalls;
32
- private readonly schemaValidator;
33
- constructor(centralSystemUrl: string, chargePointId: string, options?: OcppClientOptions);
34
- get isConnected(): boolean;
35
- connect(): void;
36
- close(): void;
37
- call(action: string, payload: Record<string, unknown>, timeoutMs?: number): Promise<CallResponse>;
38
- reply(messageId: string, payload: Record<string, unknown>): void;
39
- replyError(messageId: string, code: string, description: string, details?: Record<string, unknown>): void;
40
- private send;
41
- private handleMessage;
42
- private resolveCall;
43
- private rejectCall;
44
- private rejectPending;
45
- private toError;
46
- private assertValidRequest;
47
- private assertValidResponse;
48
- private validationErrorCode;
49
- private isValidCall;
50
- private isValidCallResult;
51
- private isValidCallError;
52
- private isObjectPayload;
53
- private readMessageId;
54
- private startPingTimer;
55
- private stopPingTimer;
56
- private buildChargePointUrl;
57
- private buildWebSocketOptions;
58
- }
59
- export {};