code wiki / (root) / nx_ac_monitor_page_gate.nx

nx_ac_monitor_page_gate.nx source

↩ module page · 113 lines · 4112 B

1// nx_ac_monitor_page_gate.nx -- gate for the hubless browser monitoring page. 2// 3// Runs the product brain end-to-end, renders the page, and proves it is a 4// self-contained, responsive, ZERO-JS dashboard that reflects the verdict: 5// - valid doctype ... </html>, ZERO <script> (cross-browser by construction) 6// - responsive viewport meta (phone + desktop) 7// - the hubless promise ("no hub required") 8// - the alert badge + plain-language message track the actual fault 9// - the liar-killer trust verdict is shown; an untrusted reading -> UNVERIFIED 10// 11// expect_exit: 0 12// license_tier: ORIGINAL 13 14import "nx_ac_monitor_page.nx" 15 16func slen(s: *u8) -> i64 { 17 var n: i64 = 0 18 while s[n] != 0 as u8 { n = n + 1 } 19 return n 20} 21func has(h: *u8, len: i64, pat: *u8) -> i64 { 22 if mp_find(h, len, pat, slen(pat)) < 0 { return 0 } 23 return 1 24} 25 26func g_reset_rd(r: *AcReading) -> i64 { 27 r.mode = NX_HVAC_MODE_COOL 28 r.t_supply_mC = 12000 29 r.rh_supply_pm = 900 30 r.t_return_mC = 24000 31 r.rh_return_pm = 500 32 r.airflow_cfm = 1200 33 r.rho_gm3 = 1200 34 r.t_suction_mC = 13000 35 r.t_sat_evap_mC = 5000 36 r.t_liquid_mC = 39000 37 r.t_sat_cond_mC = 44000 38 r.t_outdoor_mC = 35000 39 r.p_elec_w = 3000 40 r.t_return_b_mC = NX_ACV_ABSENT 41 r.return_a_src = 1 42 r.return_b_src = 0 43 r.return_tol_mC = 500 44 return 0 45} 46func g_reset_th(t: *FddThresh) -> i64 { 47 t.target_superheat_mC = 8333 48 t.superheat_band_mC = 2778 49 t.target_subcool_mC = 5556 50 t.subcool_band_mC = 2778 51 t.split_ceiling_mC = 13889 52 t.cond_over_ambient_ceiling_mC = 25000 53 t.cfm_per_ton_floor = 350 54 t.max_cph_x10 = 35 55 t.freeze_suction_sat_mC = 0 56 return 0 57} 58 59func main() -> i64 { 60 let r: *AcReading = sys_mmap(256) as *AcReading 61 let av: *AcVerify = sys_mmap(128) as *AcVerify 62 let fin: *FddInput = sys_mmap(128) as *FddInput 63 let th: *FddThresh = sys_mmap(128) as *FddThresh 64 let fout: *FddOut = sys_mmap(64) as *FddOut 65 let res: *MonitorResult = sys_mmap(64) as *MonitorResult 66 let h: *u8 = sys_mmap(MP_CAP) 67 g_reset_th(th) 68 69 // ===== undercharge reading -> WARN page ========================= 70 g_reset_rd(r) 71 r.t_suction_mC = 20000 72 r.t_sat_evap_mC = 3000 73 r.t_liquid_mC = 42000 74 r.t_sat_cond_mC = 44000 75 nx_ac_monitor(r, av, fin, th, fout, 360, 150, 80, res) 76 if res.fdd_verdict != NX_FDD_UNDERCHARGE { return 5 } 77 let n1: i64 = mp_page(h, "Living Room AC" as *u8, res) 78 79 // structural: self-contained, responsive, ZERO JS 80 if has(h, n1, "<!doctype html>" as *u8) != 1 { return 10 } 81 if has(h, n1, "</html>" as *u8) != 1 { return 11 } 82 if has(h, n1, "<script" as *u8) != 0 { return 12 } // ZERO js 83 if has(h, n1, "width=device-width" as *u8) != 1 { return 13 } 84 if has(h, n1, "no hub required" as *u8) != 1 { return 14 } 85 if has(h, n1, "Living Room AC" as *u8) != 1 { return 15 } 86 // verdict-driven content 87 if has(h, n1, "SERVICE SOON" as *u8) != 1 { return 16 } 88 if has(h, n1, "Low refrigerant charge" as *u8) != 1 { return 17 } 89 if has(h, n1, "COP" as *u8) != 1 { return 18 } 90 if has(h, n1, "plausible" as *u8) != 1 { return 19 } 91 92 // ===== frozen coil -> CRITICAL page ============================= 93 g_reset_rd(r) 94 r.t_sat_evap_mC = -2000 95 nx_ac_monitor(r, av, fin, th, fout, 360, 150, 80, res) 96 if res.alert_level != NX_ALERT_CRITICAL { return 20 } 97 let n2: i64 = mp_page(h, "Attic Unit" as *u8, res) 98 if has(h, n2, "CRITICAL" as *u8) != 1 { return 21 } 99 if has(h, n2, "freezing" as *u8) != 1 { return 22 } 100 if has(h, n2, "<script" as *u8) != 0 { return 23 } 101 102 // ===== impossible reading -> UNVERIFIED page (liar-killer) ====== 103 g_reset_rd(r) 104 r.rh_return_pm = 1500 105 nx_ac_monitor(r, av, fin, th, fout, 360, 150, 80, res) 106 if res.alert_level != NX_ALERT_UNTRUSTED { return 30 } 107 let n3: i64 = mp_page(h, "Bedroom AC" as *u8, res) 108 if has(h, n3, "UNVERIFIED" as *u8) != 1 { return 31 } 109 if has(h, n3, "liar-killer" as *u8) != 1 { return 32 } 110 if has(h, n3, "false alarm" as *u8) != 1 { return 33 } 111 112 return 0 113}