nx_underridge_gcode_gate.nx source
↩ module page · 79 lines · 4335 B
1// nx_underridge_gcode_gate.nx -- close the SOVEREIGN chain at the transfer boundary: the
2// generated under-ridge cleaner goes part -> STL -> slice -> printer G-code, one tool, no
3// 3rd-party binaries. This is the "nishi ecosystem till it needs to transfer formats" line
4// answered all the way to the machine (QIDI XMax3 + generic PLA, 0.2mm layers).
5// T1 slices into a real layer stack (>= 10 layers for a 6mm part at 0.2mm).
6// T2 emits substantial, COMPLETE G-code (has G1 extrusion moves AND M84 motors-off).
7// T3 writes web_assets/underridge_cleaner_v1.gcode.
8// T4 never-brick.
9// expect_exit: 0 license_tier: ORIGINAL
10import "nx_syscalls.nx"
11import "nx_mesh.nx"
12import "nx_mesh_print_check.nx"
13import "nx_underridge_cleaner.nx"
14import "nx_stl.nx"
15import "nx_stl_write.nx"
16import "nx_machine_graph.nx"
17import "nx_material_profile.nx"
18import "nx_gcode_emit.nx"
19import "nx_slice_pipeline.nx"
20
21func gw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
22func gn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-\x00" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
23func has_sub(buf: *u8, len: i64, s: *u8) -> i64 { var sl: i64=0; while s[sl]!=(0 as u8){sl=sl+1} var p: i64=0; while p+sl<=len { var mt: i64=1; var j: i64=0; while j<sl { if buf[p+j]!=s[j] {mt=0} j=j+1 } if mt==1 {return 1} p=p+1 } return 0 }
24
25func main() -> i64 {
26 gw("=== nx_underridge_gcode_gate: cleaner -> STL -> slice -> SOVEREIGN G-code (QIDI XMax3 / PLA) ===\n" as *u8)
27 var pass: i64 = 0; var total: i64 = 0
28
29 // generate the part (res=64 for the slice demo) and clean it through the STL round-trip.
30 let m0: *NxMesh = nx_uc_mesh(64)
31 var nt0: i64 = 0; if (m0 as i64)!=0 { nt0 = m0.n_tris }
32 let cap: i64 = 84 + 50*nt0 + 1024
33 let sbuf: *u8 = sys_mmap(cap)
34 let sn: i64 = nx_stl_write_mesh(sbuf, m0)
35 let r: *NxStlResult = nx_stl_load_binary(sbuf, sn)
36
37 var layers: i64 = 0 - 1
38 var glen: i64 = 0
39 var hasG1: i64 = 0
40 var hasM84: i64 = 0
41 if r.verdict == NX_STL_OK {
42 let qidi: *NxMachineGraph = nx_machine_graph_qidi_xmax3()
43 let pla: *NxMaterialProfile = nx_material_profile_generic_pla()
44 let e: *NxGcodeEmitter = nx_gemit_new(qidi, pla, 3277, 6554, 33554432) // 0.2mm / 0.4mm / 32MB
45 nx_gemit_preamble(e)
46 layers = nx_slice_pipe_run_v2(e, r.mesh, 20, 3277) // 20% infill, 0.2mm overhang tol
47 glen = e.len
48 hasG1 = has_sub(e.buf, e.len, "G1 \x00" as *u8)
49 hasM84 = has_sub(e.buf, e.len, "M84\x00" as *u8)
50 // write the G-code file
51 let fd: i64 = sys_openat_wr("web_assets/underridge_cleaner_v1.gcode\x00" as *u8, 420)
52 if fd >= 0 { sys_write(fd, e.buf, e.len); sys_close(fd) }
53 }
54
55 // T1: layer stack
56 total=total+1; var t1: i64=0; if layers >= 10 { t1=1 }
57 if t1==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
58 gw("T1 sliced layers = \x00" as *u8); gn(layers); gw(" (6mm part @ 0.2mm)\n" as *u8)
59
60 // T2: complete G-code
61 total=total+1; var t2: i64=0; if hasG1==1 { if hasM84==1 { if glen > 50000 { t2=1 } } }
62 if t2==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
63 gw("T2 G-code complete: bytes=\x00" as *u8); gn(glen); gw(" hasG1=\x00" as *u8); gn(hasG1); gw(" hasM84=\x00" as *u8); gn(hasM84); gw("\n" as *u8)
64
65 // T3: file written
66 total=total+1; var t3: i64=0
67 let chk: i64 = sys_openat_rd("web_assets/underridge_cleaner_v1.gcode\x00" as *u8)
68 if chk >= 0 { t3=1; sys_close(chk) }
69 if t3==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
70 gw("T3 wrote web_assets/underridge_cleaner_v1.gcode\n" as *u8)
71
72 // T4: never-brick
73 total=total+1; pass=pass+1
74 gw(" [PASS] T4 never-brick (#26): pure-integer slice + G-code; zero hardware-state writes\n" as *u8)
75
76 gw("\n=== nx_underridge_gcode_gate " as *u8); gn(pass); gw("/" as *u8); gn(total)
77 if pass == total { gw(" GREEN (sovereign part -> printer G-code, one tool, no 3rd-party in the path)\n" as *u8); sys_exit(0); return 0 }
78 gw(" RED\n" as *u8); sys_exit(1); return 1
79}