nx_print_send.nx source
↩ module page · 64 lines · 3210 B
1// nx_print_send.nx -- PHYSICAL Print-Job: submit the sovereign .urf artifact to the real Brother and
2// print a page. This is OUTWARD-FACING + consumes paper/toner -> run ONLY on explicit operator consent.
3// Reads knowledge/fetched/nishi_test.urf, builds a Print-Job (image/urf), POSTs it, reports job-id/state.
4// Still never-brick (#26): it submits a normal print job; it writes no firmware/NVRAM. license_tier: ORIGINAL
5
6import "nx_syscalls.nx"
7import "nx_ipp_codec.nx"
8import "nx_ipp_transport.nx"
9import "nx_ipp_submit.nx"
10const K_MAGIC_4096: i64 = 4096
11const K_MAGIC_131072: i64 = 131072
12
13func p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
14func pn(v: i64) -> i64 {
15 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
16 var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
17 let t: *u8 = sys_mmap(24); var k: i64 = 0
18 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
19 let b: *u8 = sys_mmap(24); var i: i64 = 0
20 while i < k { b[i] = t[k - 1 - i]; i = i + 1 }
21 sys_write(1, b, k); return 0
22}
23func phex16(v: i64) -> i64 {
24 let hx: *u8 = "0123456789abcdef"; var sh: i64 = 12
25 while sh >= 0 { sys_write(1, ((hx as i64) + ((v >> sh) & 0xf)) as *u8, 1); sh = sh - 4 }
26 return 0
27}
28
29func main() -> i64 {
30 let a: i64 = 192
31 let b: i64 = 168
32 let c: i64 = 8
33 let d: i64 = 127
34 p("=== PHYSICAL PRINT-JOB -> Brother DCP-L2540DW (consumes paper/toner) ===\n")
35
36 let lenp: *i64 = sys_mmap(8) as *i64
37 let doc: *u8 = sys_read_file("knowledge/fetched/nishi_test.urf\x00" as *u8, lenp)
38 if doc == (0 as *u8) { p("no nishi_test.urf -- run nx_urf_make first\n"); sys_exit(1); return 1 }
39 let doclen: i64 = lenp[0]
40 p("doc bytes="); pn(doclen); p("\n")
41
42 // build Print-Job header, then append the URF document into one payload buffer
43 let pay: *u8 = sys_mmap(doclen + K_MAGIC_4096)
44 let hlen: i64 = nx_ipp_build_print_job(pay, a, b, c, d, "/ipp/print", "nishi", "nishi-urf-page", "image/urf")
45 var i: i64 = 0
46 while i < doclen { pay[hlen + i] = doc[i]; i = i + 1 }
47 let total: i64 = hlen + doclen
48
49 let resp: *u8 = sys_mmap(K_MAGIC_131072)
50 let body: *u8 = sys_mmap(K_MAGIC_131072)
51 let out2: *i64 = sys_mmap(16) as *i64
52 let v: i64 = nx_ipt_post_ipp(a, b, c, d, 631, "/ipp/print", pay, total, resp, K_MAGIC_131072, body, K_MAGIC_131072, 12, out2)
53 p("transport="); p(nx_ipt_verdict_name(v)); p(" http="); pn(out2[0]); p(" ipp_body="); pn(out2[1]); p("\n")
54 if v != NX_IPT_OK { p("submit failed (reported, not swallowed)\n"); sys_exit(1); return 1 }
55 let st: i64 = nx_ipp_status(body)
56 p("ipp_status=0x"); phex16(st); p("\n")
57 let sc: *i64 = sys_mmap(64) as *i64
58 let jid: *i64 = sys_mmap(8) as *i64
59 if nx_ipp_get_enum(body, out2[1], "job-id", sc, jid) == NX_IPP_OK { p("job-id="); pn(jid[0]); p("\n") }
60 let jst: *i64 = sys_mmap(8) as *i64
61 if nx_ipp_get_enum(body, out2[1], "job-state", sc, jst) == NX_IPP_OK { p("job-state="); pn(jst[0]); p(" (3=pending 4=held 5=processing 6=stopped 9=completed)\n") }
62 if st == NX_IPP_STATUS_OK { p("RESULT: job accepted by the printer.\n") }
63 sys_exit(0); return 0
64}