nx_vessel_gcode_test.nx source
↩ module page · 42 lines · 1391 B
1// nx_vessel_gcode_test.nx -- smoke for nx_vessel_gcode (C2).
2//
3// Proves the vessel solid slices to real, structurally-valid G-code via the
4// nx_vessel_to_gcode organ (res 32 resolves the wall):
5// - the emitter allocates and emits a sensible amount of G-code (1-2)
6// - it carries thousands of extrusion moves (3)
7// Exit code = failed assertion number; 0 = all pass.
8
9import "nx_syscalls.nx"
10import "nx_gcode_emit.nx"
11import "nx_vessel_gcode.nx"
12
13func smoke_count(buf: *u8, len: i64, needle: *u8) -> i64 {
14 var nlen: i64 = 0
15 while needle[nlen] != (0 as u8) { nlen = nlen + 1 }
16 if len < nlen { return 0 }
17 var count: i64 = 0
18 var i: i64 = 0
19 let last: i64 = len - nlen
20 while i <= last {
21 var j: i64 = 0
22 var matched: i64 = 1
23 while j < nlen {
24 if buf[i + j] != needle[j] { matched = 0; j = nlen }
25 j = j + 1
26 }
27 if matched == 1 { count = count + 1 }
28 i = i + 1
29 }
30 return count
31}
32
33func main() -> i64 {
34 // small demonstrator: 30 mm radius, 3 mm wall, 40 mm tall, 4 mm base,
35 // res 32, 0.3 mm layers, 0.4 mm lines, 15% infill, 8 MB buffer
36 let e: *NxGcodeEmitter = nx_vessel_to_gcode(30, 3, 40, 4, 32, 4915, 6554, 15, 8388608)
37 if (e as i64) == 0 { return 1 }
38 if e.len < 10000 { return 2 }
39 if smoke_count(e.buf, e.len, "G1 X" as *u8) < 200 { return 3 }
40
41 return 0
42}