code wiki / (root) / nx_battery_research_fetch.nx

nx_battery_research_fetch.nx source

↩ module page · 123 lines · 10866 B

1// nx_battery_research_fetch.nx -- the Nishi RESEARCHER expanded into LITHIUM-ION BATTERY RECLAMATION as a SAFE 2// BUSINESS (operator: "based on the Instructables Recovering-Lithium-Ion-Batteries + other things, use the nishi 3// researcher and lets get a business plan building from the hardware rung up ... so people can get their lithium 4// ion batteries back to top capabilities like an ego battery while having a safe business where lion fires cant 5// happen like halo fire so it can act like a laundromat"). Grounds the whole ladder: the CELLS we reclaim, the 6// FIRE-SAFETY/thermal-runaway-prevention spine (the #26 never-brick analog = NEVER IGNITE), the 7// reclaim/recondition/recycle/repair process, capacity/state-of-health testing (EGO-grade restore), and the 8// laundromat-style self-service retail business model. Mirrors the proven nx_perma_research_fetch / 9// nx_fin_research_fetch pattern: own TLS-1.3 (nx_https_fetch_follow) + Mozilla CA store, idempotent have-skip, 10// saving each cited source to knowledge/fetched/batt_*.raw so the corpus COMPOUNDS. 100% sovereign (own TLS, 11// nx_cc->nxasm, no curl/wget/gcc). Wikipedia = orientation points per [[feedback-researcher-depth-is-dynamic-not-hardcoded]]; 12// dynamic depth via SREACH is the growth rung. z1 = the operator's explicit Instructables seed (may not fetch 13// over sovereign TLS; logged honestly either way). COVERAGE: 43 sources. expect_exit: 0 license_tier: ORIGINAL 14import "nx_syscalls.nx" 15import "nx_x509_trust_store.nx" 16import "nx_trust_store_load_from_certdata.nx" 17import "nx_https_fetch_follow.nx" 18const K_MAGIC_4194304: i64 = 4194304 19const K_MAGIC_8388608: i64 = 8388608 20 21func ff_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 22func ff_putn(v: i64) -> i64 { 23 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 24 var m: i64 = v 25 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 26 let d: *u8 = sys_mmap(24); var k: i64 = 0 27 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 28 var j: i64 = k - 1 29 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 } 30 return 0 31} 32func have_file(path: *u8) -> i64 { 33 let fd: i64 = sys_openat_rd(path) 34 if fd < 0 { return 0 } 35 sys_close(fd) 36 return 1 37} 38func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 { 39 if have_file(opath) == 1 { ff_puts(opath); ff_puts(" [have-skip]\n" as *u8); return 1 } 40 let status: *i64 = sys_mmap(8) as *i64 41 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status) 42 ff_puts(url); ff_puts(" status=" as *u8); ff_putn(status[0]); ff_puts(" bytes=" as *u8); ff_putn(n) 43 if n <= 0 { ff_puts(" FETCH-FAIL\n" as *u8); return 0 } 44 var gz: i64 = 0 45 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } } 46 if gz == 1 { ff_puts(" [GZIP-skip]\n" as *u8); return 0 } 47 let fd: i64 = sys_openat_wr(opath, 0x1a4) 48 if fd < 0 { ff_puts(" SAVE-FAIL\n" as *u8); return 0 } 49 sys_write(fd, out, n) 50 sys_close(fd) 51 ff_puts(" SAVED\n" as *u8) 52 return 1 53} 54 55func main() -> i64 { 56 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 57 if r <= 0 { ff_puts("BATT: certdata load failed\n" as *u8); return 1 } 58 let store: *TrustStore = r as *TrustStore 59 ff_puts("CA roots=" as *u8); ff_putn(trust_store_count(store)); ff_puts("\n" as *u8) 60 let cap: i64 = K_MAGIC_8388608 61 let out: *u8 = sys_mmap(cap) 62 var ok: i64 = 0 63 64 ff_puts("== A. LI-ION CELLS & CHEMISTRY (what we reclaim) ==\n" as *u8) 65 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Lithium-ion_battery" as *u8, "knowledge/fetched/batt_a1_liion.raw" as *u8, store, out, cap) 66 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Lithium_polymer_battery" as *u8, "knowledge/fetched/batt_a2_lipo.raw" as *u8, store, out, cap) 67 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Lithium_iron_phosphate_battery" as *u8, "knowledge/fetched/batt_a3_lifepo4.raw" as *u8, store, out, cap) 68 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Battery_pack" as *u8, "knowledge/fetched/batt_a4_battery_pack.raw" as *u8, store, out, cap) 69 ok = ok + fetch_save("https://en.wikipedia.org/wiki/List_of_battery_sizes" as *u8, "knowledge/fetched/batt_a5_battery_sizes.raw" as *u8, store, out, cap) 70 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Rechargeable_battery" as *u8, "knowledge/fetched/batt_a6_rechargeable.raw" as *u8, store, out, cap) 71 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Electric_battery" as *u8, "knowledge/fetched/batt_a7_electric_battery.raw" as *u8, store, out, cap) 72 73 ff_puts("== B. FIRE SAFETY & THERMAL-RUNAWAY PREVENTION (the NEVER-IGNITE spine) ==\n" as *u8) 74 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Thermal_runaway" as *u8, "knowledge/fetched/batt_b1_thermal_runaway.raw" as *u8, store, out, cap) 75 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Battery_management_system" as *u8, "knowledge/fetched/batt_b2_bms.raw" as *u8, store, out, cap) 76 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Fire_class" as *u8, "knowledge/fetched/batt_b3_fire_class.raw" as *u8, store, out, cap) 77 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Fire_suppression_system" as *u8, "knowledge/fetched/batt_b4_fire_suppression.raw" as *u8, store, out, cap) 78 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Gaseous_fire_suppression" as *u8, "knowledge/fetched/batt_b5_gaseous_suppression.raw" as *u8, store, out, cap) 79 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Fire_extinguisher" as *u8, "knowledge/fetched/batt_b6_fire_extinguisher.raw" as *u8, store, out, cap) 80 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Dangerous_goods" as *u8, "knowledge/fetched/batt_b7_dangerous_goods.raw" as *u8, store, out, cap) 81 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Safety_data_sheet" as *u8, "knowledge/fetched/batt_b8_sds.raw" as *u8, store, out, cap) 82 ok = ok + fetch_save("https://en.wikipedia.org/wiki/National_Fire_Protection_Association" as *u8, "knowledge/fetched/batt_b9_nfpa.raw" as *u8, store, out, cap) 83 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Combustion" as *u8, "knowledge/fetched/batt_b10_combustion.raw" as *u8, store, out, cap) 84 85 ff_puts("== C. RECLAIM / RECONDITION / RECYCLE / REPAIR (the core process) ==\n" as *u8) 86 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Battery_recycling" as *u8, "knowledge/fetched/batt_c1_battery_recycling.raw" as *u8, store, out, cap) 87 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Battery_charger" as *u8, "knowledge/fetched/batt_c2_battery_charger.raw" as *u8, store, out, cap) 88 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Battery_balancing" as *u8, "knowledge/fetched/batt_c3_battery_balancing.raw" as *u8, store, out, cap) 89 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Remanufacturing" as *u8, "knowledge/fetched/batt_c4_remanufacturing.raw" as *u8, store, out, cap) 90 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Refurbishment" as *u8, "knowledge/fetched/batt_c5_refurbishment.raw" as *u8, store, out, cap) 91 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Right_to_repair" as *u8, "knowledge/fetched/batt_c6_right_to_repair.raw" as *u8, store, out, cap) 92 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Electronic_waste" as *u8, "knowledge/fetched/batt_c7_ewaste.raw" as *u8, store, out, cap) 93 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Extended_producer_responsibility" as *u8, "knowledge/fetched/batt_c8_epr.raw" as *u8, store, out, cap) 94 95 ff_puts("== D. CAPACITY / SoC / SoH / TESTING (EGO-grade restore) ==\n" as *u8) 96 ok = ok + fetch_save("https://en.wikipedia.org/wiki/State_of_charge" as *u8, "knowledge/fetched/batt_d1_soc.raw" as *u8, store, out, cap) 97 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Charge_cycle" as *u8, "knowledge/fetched/batt_d2_charge_cycle.raw" as *u8, store, out, cap) 98 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Self-discharge" as *u8, "knowledge/fetched/batt_d3_self_discharge.raw" as *u8, store, out, cap) 99 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Internal_resistance" as *u8, "knowledge/fetched/batt_d4_internal_resistance.raw" as *u8, store, out, cap) 100 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Ampere-hour" as *u8, "knowledge/fetched/batt_d5_amp_hour.raw" as *u8, store, out, cap) 101 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Energy_density" as *u8, "knowledge/fetched/batt_d6_energy_density.raw" as *u8, store, out, cap) 102 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Multimeter" as *u8, "knowledge/fetched/batt_d7_multimeter.raw" as *u8, store, out, cap) 103 104 ff_puts("== E. BUSINESS / RETAIL MODEL (laundromat-style self-service + community) ==\n" as *u8) 105 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Self-service_laundry" as *u8, "knowledge/fetched/batt_e1_laundromat.raw" as *u8, store, out, cap) 106 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Business_plan" as *u8, "knowledge/fetched/batt_e2_business_plan.raw" as *u8, store, out, cap) 107 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Franchising" as *u8, "knowledge/fetched/batt_e3_franchising.raw" as *u8, store, out, cap) 108 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Small_business" as *u8, "knowledge/fetched/batt_e4_small_business.raw" as *u8, store, out, cap) 109 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Vending_machine" as *u8, "knowledge/fetched/batt_e5_vending_machine.raw" as *u8, store, out, cap) 110 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Hackerspace" as *u8, "knowledge/fetched/batt_e6_hackerspace.raw" as *u8, store, out, cap) 111 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Core_charge" as *u8, "knowledge/fetched/batt_e7_core_charge.raw" as *u8, store, out, cap) 112 113 ff_puts("== F. VALUE-PROP ANCHOR (power tools / e-bikes = the fire-risk market) ==\n" as *u8) 114 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Power_tool" as *u8, "knowledge/fetched/batt_f1_power_tool.raw" as *u8, store, out, cap) 115 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Electric_bicycle" as *u8, "knowledge/fetched/batt_f2_ebike.raw" as *u8, store, out, cap) 116 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Electric_vehicle_battery" as *u8, "knowledge/fetched/batt_f3_ev_battery.raw" as *u8, store, out, cap) 117 118 ff_puts("== Z. OPERATOR SEED (explicit orientation point) ==\n" as *u8) 119 ok = ok + fetch_save("https://www.instructables.com/Recovering-Lithium-Ion-Batteries/" as *u8, "knowledge/fetched/batt_z1_instructables_seed.raw" as *u8, store, out, cap) 120 121 ff_puts("READABLE SOURCES SAVED THIS PASS+HAVE: " as *u8); ff_putn(ok); ff_puts(" / 43\n" as *u8) 122 return 0 123}