code wiki / _hdl_build / nx_print_dispatch_gate.nx
nx_print_dispatch_gate.nx source
↩ module page · 100 lines · 5745 B
1// nx_print_dispatch_gate.nx -- GATE: the multi-material UNIFICATION. The SAME wall geometry, emitted in every
2// material via one dispatcher, each material-appropriate. T1 filament (HOT hotend + sub-mm decimal Z), T2
3// concrete (COLD, no hotend, whole-mm Z), T3 metal (arc + cooling dwell), T4 never-brick all three, T5 honest
4// refusal (clay/unknown have no emitter -> 0), T6 unification (3 distinct G-codes from one geometry+call).
5// license_tier: ORIGINAL
6import "nx_print_dispatch.nx"
7import "nx_print_material.nx"
8import "nx_food_science.nx"
9import "nx_seg_store.nx"
10import "nx_syscalls.nx"
11import "nx_gate_verdict.nx"
12
13const PD_PRINT: *u8 = "knowledge/store/print-"
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}
24func g_nobrick(g: *u8, n: i64) -> i64 {
25 if as_contains(g, n, "M997" as *u8) != 0 { return 0 }
26 if as_contains(g, n, "M500" as *u8) != 0 { return 0 }
27 if as_contains(g, n, "M502" as *u8) != 0 { return 0 }
28 return 1
29}
30func g_write(path: *u8, g: *u8, n: i64) -> i64 { let fd: i64 = sys_openat_wr(path, 420); if fd >= 0 { sys_write(fd, g, n); sys_close(fd) } return 0 }
31
32func main() -> i64 {
33 g_p("=== nx_print_dispatch_gate (multi-material UNIFICATION: same wall, any material) ===\n" as *u8)
34 pm_seed(PD_PRINT)
35
36 let gp: *u8 = sys_mmap(262144); let np: i64 = pd_emit(PD_PRINT, "pla" as *u8, 50, 50, 20, gp)
37 let gc: *u8 = sys_mmap(262144); let nc: i64 = pd_emit(PD_PRINT, "concrete" as *u8, 50, 50, 20, gc)
38 let gm: *u8 = sys_mmap(262144); let nm: i64 = pd_emit(PD_PRINT, "steel_waam" as *u8, 50, 50, 20, gm)
39 let gx: *u8 = sys_mmap(8192)
40 let nclay: i64 = pd_emit(PD_PRINT, "clay" as *u8, 50, 50, 20, gx)
41 let nunk: i64 = pd_emit(PD_PRINT, "unobtanium" as *u8, 50, 50, 20, gx)
42 g_p("dispatched: pla=" as *u8); g_i(np); g_p("B concrete=" as *u8); g_i(nc); g_p("B steel=" as *u8); g_i(nm); g_p("B clay=" as *u8); g_i(nclay); g_p(" unknown=" as *u8); g_i(nunk); g_p("\n" as *u8)
43
44 var pass: i64 = 0
45 var tot: i64 = 0
46
47 // T1 filament: HOT hotend + sub-mm decimal layer
48 tot = tot + 1
49 var ok1: i64 = 1
50 if np <= 0 { ok1 = 0 }
51 if as_contains(gp, np, "M104 S" as *u8) != 1 { ok1 = 0 }
52 if as_contains(gp, np, "M109 S" as *u8) != 1 { ok1 = 0 }
53 if as_contains(gp, np, "Z0.200" as *u8) != 1 { ok1 = 0 } // 200um filament layer, decimal mm
54 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 filament (hot hotend M104/M109 + sub-mm decimal layer Z0.200)\n" as *u8) } else { g_p("FAIL T1\n" as *u8) }
55
56 // T2 concrete: COLD (no hotend), whole-mm layer
57 tot = tot + 1
58 var ok2: i64 = 1
59 if nc <= 0 { ok2 = 0 }
60 if as_contains(gc, nc, "M104" as *u8) != 0 { ok2 = 0 } // cold paste -- no hotend
61 if as_contains(gc, nc, "G1 Z10 " as *u8) != 1 { ok2 = 0 }
62 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 concrete (cold -- no hotend; whole-mm layer Z10)\n" as *u8) } else { g_p("FAIL T2\n" as *u8) }
63
64 // T3 metal: arc + inter-layer cooling dwell
65 tot = tot + 1
66 var ok3: i64 = 1
67 if nm <= 0 { ok3 = 0 }
68 if as_contains(gm, nm, "M3 S" as *u8) != 1 { ok3 = 0 }
69 if as_contains(gm, nm, "G4 P" as *u8) != 1 { ok3 = 0 }
70 if ok3 == 1 { pass = pass + 1; g_p("PASS T3 metal (arc M3/M5 + inter-layer cooling dwell G4)\n" as *u8) } else { g_p("FAIL T3\n" as *u8) }
71
72 // T4 never-brick all three
73 tot = tot + 1
74 if g_nobrick(gp, np) == 1 { if g_nobrick(gc, nc) == 1 { if g_nobrick(gm, nm) == 1 { pass = pass + 1; g_p("PASS T4 never-brick across ALL materials (no firmware/EEPROM commands)\n" as *u8) } else { g_p("FAIL T4 metal\n" as *u8) } } else { g_p("FAIL T4 concrete\n" as *u8) } } else { g_p("FAIL T4 filament\n" as *u8) }
75
76 // T5 honest refusal of unsupported / unknown materials
77 tot = tot + 1
78 if nclay == 0 { if nunk == 0 { pass = pass + 1; g_p("PASS T5 honest refusal (clay/unknown have no emitter -> 0, never a wrong emit)\n" as *u8) } else { g_p("FAIL T5 unknown\n" as *u8) } } else { g_p("FAIL T5 clay\n" as *u8) }
79
80 // T6 unification: 3 distinct material-appropriate G-codes from ONE geometry + call
81 tot = tot + 1
82 if np > 0 { if nc > 0 { if nm > 0 { pass = pass + 1; g_p("PASS T6 unification: one geometry -> 3 material-appropriate G-codes via one dispatcher\n" as *u8) } else { g_p("FAIL T6\n" as *u8) } } else { g_p("FAIL T6\n" as *u8) } } else { g_p("FAIL T6\n" as *u8) }
83
84 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
85 sys_mkdir("knowledge/staging/print" as *u8, 0x1ed)
86 g_write("knowledge/staging/print/pla_wall.gcode" as *u8, gp, np)
87 g_write("knowledge/staging/print/concrete_wall.gcode" as *u8, gc, nc)
88 g_write("knowledge/staging/print/steel_waam_wall.gcode" as *u8, gm, nm)
89
90 g_p("nx_print_dispatch_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
91 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
92 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
93 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
94 let ctr__dry: *i64 = gv_ctr()
95 ctr__dry[0] = pass
96 ctr__dry[1] = tot
97 let rc__dry: i64 = gv_verdict("PRINT-DISPATCH-GATE" as *u8, ctr__dry, "3D printing in ALL materials, ONE entry point, never-brick)" as *u8)
98 sys_exit(rc__dry)
99 return rc__dry
100}