code wiki / _hdl_build / nx_print_dispatch_gate.nx
nx_print_dispatch_gate.nx source
↩ module page · 93 lines · 5342 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"
11
12const PD_PRINT: *u8 = "knowledge/store/print-"
13
14func 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 }
15func g_i(v: i64) -> i64 {
16 let bb: *u8 = sys_mmap(28); var m: i64 = v
17 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
18 let t: *u8 = sys_mmap(28); var k: i64 = 0
19 if m == 0 { t[0] = 48 as u8; k = 1 }
20 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
21 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
22}
23func g_nobrick(g: *u8, n: i64) -> i64 {
24 if as_contains(g, n, "M997" as *u8) != 0 { return 0 }
25 if as_contains(g, n, "M500" as *u8) != 0 { return 0 }
26 if as_contains(g, n, "M502" as *u8) != 0 { return 0 }
27 return 1
28}
29func 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 }
30
31func main() -> i64 {
32 g_p("=== nx_print_dispatch_gate (multi-material UNIFICATION: same wall, any material) ===\n" as *u8)
33 pm_seed(PD_PRINT)
34
35 let gp: *u8 = sys_mmap(262144); let np: i64 = pd_emit(PD_PRINT, "pla" as *u8, 50, 50, 20, gp)
36 let gc: *u8 = sys_mmap(262144); let nc: i64 = pd_emit(PD_PRINT, "concrete" as *u8, 50, 50, 20, gc)
37 let gm: *u8 = sys_mmap(262144); let nm: i64 = pd_emit(PD_PRINT, "steel_waam" as *u8, 50, 50, 20, gm)
38 let gx: *u8 = sys_mmap(8192)
39 let nclay: i64 = pd_emit(PD_PRINT, "clay" as *u8, 50, 50, 20, gx)
40 let nunk: i64 = pd_emit(PD_PRINT, "unobtanium" as *u8, 50, 50, 20, gx)
41 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)
42
43 var pass: i64 = 0
44 var tot: i64 = 0
45
46 // T1 filament: HOT hotend + sub-mm decimal layer
47 tot = tot + 1
48 var ok1: i64 = 1
49 if np <= 0 { ok1 = 0 }
50 if as_contains(gp, np, "M104 S" as *u8) != 1 { ok1 = 0 }
51 if as_contains(gp, np, "M109 S" as *u8) != 1 { ok1 = 0 }
52 if as_contains(gp, np, "Z0.200" as *u8) != 1 { ok1 = 0 } // 200um filament layer, decimal mm
53 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) }
54
55 // T2 concrete: COLD (no hotend), whole-mm layer
56 tot = tot + 1
57 var ok2: i64 = 1
58 if nc <= 0 { ok2 = 0 }
59 if as_contains(gc, nc, "M104" as *u8) != 0 { ok2 = 0 } // cold paste -- no hotend
60 if as_contains(gc, nc, "G1 Z10 " as *u8) != 1 { ok2 = 0 }
61 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) }
62
63 // T3 metal: arc + inter-layer cooling dwell
64 tot = tot + 1
65 var ok3: i64 = 1
66 if nm <= 0 { ok3 = 0 }
67 if as_contains(gm, nm, "M3 S" as *u8) != 1 { ok3 = 0 }
68 if as_contains(gm, nm, "G4 P" as *u8) != 1 { ok3 = 0 }
69 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) }
70
71 // T4 never-brick all three
72 tot = tot + 1
73 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) }
74
75 // T5 honest refusal of unsupported / unknown materials
76 tot = tot + 1
77 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) }
78
79 // T6 unification: 3 distinct material-appropriate G-codes from ONE geometry + call
80 tot = tot + 1
81 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) }
82
83 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
84 sys_mkdir("knowledge/staging/print" as *u8, 0x1ed)
85 g_write("knowledge/staging/print/pla_wall.gcode" as *u8, gp, np)
86 g_write("knowledge/staging/print/concrete_wall.gcode" as *u8, gc, nc)
87 g_write("knowledge/staging/print/steel_waam_wall.gcode" as *u8, gm, nm)
88
89 g_p("nx_print_dispatch_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
90 if pass == tot { g_p(" verdict=GREEN (3D printing in ALL materials, ONE entry point, never-brick)\n" as *u8); return 0 }
91 g_p(" verdict=RED\n" as *u8)
92 return 1
93}