code wiki / _hdl_build / nx_home.nx
nx_home.nx
buildroot/runtime/_hdl_build/nx_home.nx
about
nx_home.nx -- SOVEREIGN home-control server (H0 of the IoT workstream). The brain a control surface (Roku
"Home" tab / web / phone) POSTs to; it holds the device registry + live state and applies commands. H0 uses a
SIM driver (a command just updates state) -- real IP-hub drivers (Matter/Hue/MQTT) plug in behind this later.
Sovereign socket HTTP server (no python/shell). REST:
GET /home/state -> {"devices":[{id,name,room,type,on,brightness},...]}
POST /home/cmd?id=<id>&on=<0|1>&bri=<0-100> -> the device's new state (404 if unknown id, 400 if no id)
POST /home/shutdown -> {"ok":1} then the server exits (managed teardown; auth-gate in prod)
Idempotent (#10), structured errors (#6), graceful (#14). Devices embedded for H0; H1 makes them data-driven
(#11, TSV/seg_store) + persisted. license_tier: ORIGINAL
nx_home <port>
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_itoa_lib.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 13 | const K_MAGIC_65536: i64 = 65536 |
| 14 | const K_MAGIC_16384: i64 = 16384 |
| 15 | const K_MAGIC_1024: i64 = 1024 |
| 16 | const K_MAGIC_131072: i64 = 131072 |
functions
| 18 | func h_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 23 | func h_n(v: i64) -> i64 { nxi_out(v); return 0 } |
| 24 | func h_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 25 | func h_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){ dst[off+i]=s[i]; i=i+1 } return off+i } |
| 26 | func h_catb(dst: *u8, off: i64, src: *u8, n: i64) -> i64 { var i: i64=0; while i<n { dst[off+i]=src[i]; i=i+1 } return off+n } called by 1: h_send |
| 27 | func h_catn(dst: *u8, off: i64, v: i64) -> i64 { var m: i64=v; 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 o: i64=off; var i: i64=0; while i<k{dst[o]=t[k-1-i];o=o+1;i=i+1} return o } |
| 28 | func h_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8){ if a[i]!=b[i]{return 0} i=i+1 } if b[i]!=(0 as u8){return 0} return 1 } called by 1: find_dev |
| 29 | func h_atoi(s: *u8) -> i64 { var v: i64=0; var i: i64=0; while s[i]!=(0 as u8){ let c: i64=s[i] as i64; if c>=48 { if c<=57 { v=v*10+(c-48) } } i=i+1 } return v } |
| 30 | func h_find(hay: *u8, n: i64, needle: *u8) -> i64 |
| 36 | func h_has(hay: *u8, n: i64, needle: *u8) -> i64 { if h_find(hay,n,needle)>=0 { return 1 } return 0 } |
| 37 | func h_extract(hay: *u8, n: i64, key: *u8, out: *u8, cap: i64) -> i64 |
| 47 | func h_sockaddr(buf: *u8, port: i64, a: i64, b: i64, c: i64, d: i64) -> i64 called by 1: h_bind_listen |
| 52 | func h_bind_listen(port: i64) -> i64 |
| 61 | func h_recv(cfd: i64, buf: *u8, cap: i64) -> i64 |
| 69 | func h_send(cfd: i64, status: *u8, body: *u8, blen: i64) -> i64 |
| 76 | func find_dev(ids: *i64, ndev: i64, id: *u8) -> i64 |
| 79 | func j_dev(buf: *u8, off: i64, ids: *i64, names: *i64, rooms: *i64, kinds: *i64, pwr: *i64, bri: *i64, i: i64) -> i64 |
| 89 | func handle(cfd: i64, req: *u8, n: i64, ids: *i64, names: *i64, rooms: *i64, kinds: *i64, pwr: *i64, bri: *i64, ndev: i64) -> i64 |
| 120 | func tsv_field(pool: *u8, pip: *i64, buf: *u8, s: i64, e: i64) -> i64 called by 1: load_tsv |
| 126 | func load_tsv(path: *u8, ids: *i64, names: *i64, rooms: *i64, kinds: *i64, pwr: *i64, bri: *i64) -> i64 |
| 155 | func check_auth(req: *u8, n: i64, token: *u8) -> i64 |
| 163 | func main(argc: i64, argv: *i64) -> i64 |