code wiki / _hdl_build / nx_paste_gcode_gate.nx
nx_paste_gcode_gate.nx source
↩ module page · 91 lines · 5037 B
1// nx_paste_gcode_gate.nx -- GATE: 3D-printing workstream R2. The concrete/paste G-code emitter for the R-ECO
2// cistern. Proves: T1 valid construction G-code structure (cold paste -- NO hotend), T2 correct layer count
3// from the material profile, T3 CARDINAL-26 NEVER-BRICK (no firmware/EEPROM commands), T4 material-profile-
4// driven layer height, T5 extrusion accumulates, T6 sovereign provenance. Writes the printable .gcode.
5// license_tier: ORIGINAL
6import "nx_paste_gcode.nx"
7import "nx_print_material.nx"
8import "nx_food_science.nx"
9import "nx_seg_store.nx"
10import "nx_syscalls.nx"
11
12const PG_PRINT: *u8 = "knowledge/store/print-"
13const PG_OUT: *u8 = "knowledge/staging/print/cistern.gcode"
14
15func g_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
16func g_i(v: i64) -> i64 {
17 let bb: *u8 = sys_mmap(28); var m: i64 = v
18 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
19 let t: *u8 = sys_mmap(28); var k: i64 = 0
20 if m == 0 { t[0] = 48 as u8; k = 1 }
21 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
22 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
23}
24
25func main() -> i64 {
26 g_p("=== nx_paste_gcode_gate (3D-printing R2: concrete G-code for the R-ECO cistern) ===\n" as *u8)
27 pm_seed(PG_PRINT)
28
29 let g: *u8 = sys_mmap(262144)
30 let n: i64 = pg_emit(PG_PRINT, 4000, 4000, 2000, g) // 4m x 4m footprint, 2m tall wall
31 g_p("emitted " as *u8); g_i(n); g_p(" bytes of construction G-code; wall concrete = " as *u8); g_i(pg_concrete_cm3(PG_PRINT, 4000, 4000, 2000)); g_p(" cm3\n" as *u8)
32
33 var pass: i64 = 0
34 var tot: i64 = 0
35
36 // T1 valid cold-paste construction G-code
37 tot = tot + 1
38 var ok1: i64 = 1
39 if as_contains(g, n, "G21" as *u8) != 1 { ok1 = 0 }
40 if as_contains(g, n, "G90" as *u8) != 1 { ok1 = 0 }
41 if as_contains(g, n, "G28" as *u8) != 1 { ok1 = 0 }
42 if as_contains(g, n, "G1 Z" as *u8) != 1 { ok1 = 0 }
43 if as_contains(g, n, "G1 X" as *u8) != 1 { ok1 = 0 }
44 if as_contains(g, n, "M84" as *u8) != 1 { ok1 = 0 }
45 if as_contains(g, n, "M104" as *u8) != 0 { ok1 = 0 } // COLD paste: no hotend
46 if as_contains(g, n, "M109" as *u8) != 0 { ok1 = 0 }
47 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 valid construction G-code (cold paste -- no hotend M104/M109)\n" as *u8) } else { g_p("FAIL T1\n" as *u8) }
48
49 // T2 layer count from the profile (2000mm / 10mm = 200 layers, indices 0..199)
50 tot = tot + 1
51 var ok2: i64 = 1
52 if as_contains(g, n, ";LAYER:0" as *u8) != 1 { ok2 = 0 }
53 if as_contains(g, n, ";LAYER:199" as *u8) != 1 { ok2 = 0 }
54 if as_contains(g, n, ";LAYER:200" as *u8) != 0 { ok2 = 0 }
55 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 200 layers (height / profile layer-height), indexed 0..199\n" as *u8) } else { g_p("FAIL T2\n" as *u8) }
56
57 // T3 CARDINAL 26 never-brick: no firmware/EEPROM commands
58 tot = tot + 1
59 var ok3: i64 = 1
60 if as_contains(g, n, "M997" as *u8) != 0 { ok3 = 0 } // firmware update -- THE brick command
61 if as_contains(g, n, "M500" as *u8) != 0 { ok3 = 0 } // save settings to EEPROM
62 if as_contains(g, n, "M502" as *u8) != 0 { ok3 = 0 } // reset EEPROM
63 if ok3 == 1 { pass = pass + 1; g_p("PASS T3 never-brick: no M997 (firmware flash), no M500/M502 (EEPROM) -- emit-only\n" as *u8) } else { g_p("FAIL T3\n" as *u8) }
64
65 // T4 material-profile-driven layer height (concrete profile = 10mm layers)
66 tot = tot + 1
67 var ok4: i64 = 1
68 if as_contains(g, n, "G1 Z10 " as *u8) != 1 { ok4 = 0 } // first layer at 10mm
69 if as_contains(g, n, "G1 Z2000 " as *u8) != 1 { ok4 = 0 } // last layer at 2000mm
70 if ok4 == 1 { pass = pass + 1; g_p("PASS T4 layer height driven by the concrete material profile (10mm)\n" as *u8) } else { g_p("FAIL T4\n" as *u8) }
71
72 // T5 extrusion accumulates (final E = 200 layers x 16000mm perimeter)
73 tot = tot + 1
74 if as_contains(g, n, "E3200000" as *u8) == 1 { pass = pass + 1; g_p("PASS T5 extrusion accumulates to E3200000 (pump volume over the whole print)\n" as *u8) } else { g_p("FAIL T5\n" as *u8) }
75
76 // T6 sovereign provenance
77 tot = tot + 1
78 var ok6: i64 = 1
79 if as_contains(g, n, "Nishi" as *u8) != 1 { ok6 = 0 }
80 if as_contains(g, n, "NEVER-BRICK" as *u8) != 1 { ok6 = 0 }
81 if ok6 == 1 { pass = pass + 1; g_p("PASS T6 sovereign provenance header (Nishi + never-brick note, firmware-ignored comment)\n" as *u8) } else { g_p("FAIL T6\n" as *u8) }
82
83 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
84 sys_mkdir("knowledge/staging/print" as *u8, 0x1ed)
85 let fd: i64 = sys_openat_wr(PG_OUT, 420); if fd >= 0 { sys_write(fd, g, n); sys_close(fd); g_p("wrote " as *u8); g_p(PG_OUT); g_p("\n" as *u8) }
86
87 g_p("nx_paste_gcode_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
88 if pass == tot { g_p(" verdict=GREEN (the ladder grew into CONCRETE: printable cistern G-code, never-brick)\n" as *u8); return 0 }
89 g_p(" verdict=RED\n" as *u8)
90 return 1
91}