nx_klipper_gcode_validator.nx
buildroot/runtime/nx_klipper_gcode_validator.nx
about
nx_klipper_gcode_validator.nx -- Phase B1 of S-class hardening.
Real-input validation that the substrate's emitted G-code parses
as syntactically valid Klipper commands. Walks the emitted byte
stream + verifies every non-comment line follows G/M/T + space-
separated letter+number parameters.
Per [[feedback-no-false-ok-substrate-honesty-audit]] + the
S-class honest audit: emitted G-code MUST be parseable by Klipper
before we send it to the Qidi. If our slicer emits something
Klipper rejects mid-job, that's a half-print failure (operator's
"spaghetti or where it prints halfway" failure class). This
validator is the substrate-side guarantee that emitted bytes ARE
valid before any filament moves.
Validates:
- Non-empty + non-comment lines must start with G/M/T
- Command (after G/M/T) must be a decimal number
- Parameters: letter (A-Z) followed by signed numeric value
- No control bytes (< 0x09) outside CR/LF/TAB
- F (feedrate) parameter, when present, must be positive
Does NOT validate:
- Command semantics (G99 wouldn't be flagged even though Klipper
might reject it; substrate trusts caller's command set)
- Numeric ranges (axes within build volume = simulator's job)
- Klipper extended commands (SET_*, BED_MESH_*, etc.)
license_tier: ORIGINAL
dependencies 1 imports · 3 importers
imports: nx_syscalls.nx
imported by: nx_christus_integration_test.nxnx_klipper_gcode_validator_test.nxnx_mushroom_overhang_test.nx
structs
| none |
consts
| 33 | const NX_KGV_OK: i64 = 0 |
| 34 | const NX_KGV_BAD_LINE: i64 = 1 |
| 35 | const NX_KGV_BAD_PARAM: i64 = 2 |
| 36 | const NX_KGV_BAD_CONTROL_CHAR: i64 = 3 |
| 37 | const NX_KGV_BAD_FEEDRATE: i64 = 4 |
| 38 | const NX_KGV_BAD_INPUT: i64 = 5 |
| 39 | const NX_KGV_N: i64 = 6 |
functions
| 41 | func nx_kgv_is_valid(v: i64) -> i64 |
| 48 | func kgv_is_digit(b: i64) -> i64 called by 1: kgv_validate_line |
| 55 | func kgv_is_upper(b: i64) -> i64 called by 1: kgv_validate_line |
| 63 | func kgv_validate_line(buf: *u8, start: i64, end: i64) -> i64 |
| 235 | func nx_klipper_gcode_validate(buf: *u8, len: i64, |