code wiki / _hdl_build / nx_home.nx

nx_home.nx

buildroot/runtime/_hdl_build/nx_home.nx

12709 B206 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic home
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_itoa_lib.nx nx_home.nx

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

main h_p sys_write sys_exit h_atoi sys_mmap load_tsv sys_mmap ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close tsv_field sys_read_file ↻ h_bind_listen sys_socket sys_mmap ↻ sys_setsockopt h_sockaddr sys_bind sys_close ↻ sys_listen h_n nxi_out nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap sys_accept h_recv sys_read ↻ h_find h_strlen check_auth h_find ↻ h_send sys_mmap ↻

structs

none

consts

13const K_MAGIC_65536: i64 = 65536
14const K_MAGIC_16384: i64 = 16384
15const K_MAGIC_1024: i64 = 1024
16const K_MAGIC_131072: i64 = 131072

functions

18func 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 }
called by 1: main calls 1: sys_write
23func h_n(v: i64) -> i64 { nxi_out(v); return 0 }
called by 1: main calls 1: nxi_out
24func h_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 3: h_findhandlemain
25func 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 }
called by 3: h_sendj_devhandle
26func 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
27func 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 }
called by 2: h_sendj_dev calls 1: sys_mmap
28func 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
29func 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 }
called by 2: handlemain
30func h_find(hay: *u8, n: i64, needle: *u8) -> i64
36func h_has(hay: *u8, n: i64, needle: *u8) -> i64 { if h_find(hay,n,needle)>=0 { return 1 } return 0 }
called by 1: handle calls 1: h_find
37func h_extract(hay: *u8, n: i64, key: *u8, out: *u8, cap: i64) -> i64
called by 1: handle calls 1: h_find
47func h_sockaddr(buf: *u8, port: i64, a: i64, b: i64, c: i64, d: i64) -> i64
called by 1: h_bind_listen
52func h_bind_listen(port: i64) -> i64
61func h_recv(cfd: i64, buf: *u8, cap: i64) -> i64
called by 1: main calls 2: sys_readh_find
69func h_send(cfd: i64, status: *u8, body: *u8, blen: i64) -> i64
76func find_dev(ids: *i64, ndev: i64, id: *u8) -> i64
called by 1: handle calls 1: h_streq
79func j_dev(buf: *u8, off: i64, ids: *i64, names: *i64, rooms: *i64, kinds: *i64, pwr: *i64, bri: *i64, i: i64) -> i64
called by 1: handle calls 2: h_cath_catn
89func handle(cfd: i64, req: *u8, n: i64, ids: *i64, names: *i64, rooms: *i64, kinds: *i64, pwr: *i64, bri: *i64, ndev: i64) -> i64
120func tsv_field(pool: *u8, pip: *i64, buf: *u8, s: i64, e: i64) -> i64
called by 1: load_tsv
126func load_tsv(path: *u8, ids: *i64, names: *i64, rooms: *i64, kinds: *i64, pwr: *i64, bri: *i64) -> i64
called by 1: main calls 3: sys_mmapsys_read_filetsv_field
155func check_auth(req: *u8, n: i64, token: *u8) -> i64
called by 1: main calls 1: h_find
163func main(argc: i64, argv: *i64) -> i64