code wiki / _hdl_build / nx_batt_recondition.nx

nx_batt_recondition.nx source

↩ module page · 43 lines · 2570 B

1// nx_batt_recondition.nx -- R2 RECLAIM / RECONDITION WORKFLOW. Given a triage verdict (R1 nx_batt_intake), drives 2// the staged restore and ROUTES EVERY charge step through the never-ignite spine (R0 nx_battery_safety): a step that 3// would exceed the safety envelope (rate / voltage / thermal) is REFUSED and the workflow aborts SAFE -- it can NEVER 4// drive an unsafe charge. UNSAFE-REJECT / RETIRE-RECYCLE packs are routed to recycle and NEVER charged (safety 5// screened first = the #26 NEVER-IGNITE priority). Composes R0 + R1; this is the rung that makes "EGO-grade restore" 6// real AND safe. license_tier: ORIGINAL 7import "nx_intent.nx" 8import "nx_battery_safety.nx" 9import "nx_batt_intake.nx" 10 11const NX_RW_DONE_RESTORED: i64 = 0 // workflow finished, pack restored to service 12const NX_RW_DONE_RETIRED: i64 = 1 // routed to safe recycle (zero charge commands issued) 13const NX_RW_REFUSED_UNSAFE: i64 = 2 // a step hit the safety wall -> aborted safe (never-ignite) 14const NX_RW_BAD_VERDICT: i64 = 3 15 16// Drive the restore for `verdict`. Each charge step is validated by nx_battery_validate_command against `env`; 17// out_steps[0] = number of steps actually completed (0 for retire/reject/healthy, or the count before a refusal). 18func nx_recondition_run(verdict: i64, env: *NxBatterySafetyEnvelope, log: *NxBatteryCommandLog, 19 charge_ma: i64, voltage_mv: i64, now_us: i64, out_steps: *i64) -> i64 { 20 out_steps[0] = 0 21 // NEVER charge a reject/retire -- safety screened before any energy is applied. 22 if verdict == NX_BI_UNSAFE_REJECT { return NX_RW_DONE_RETIRED } 23 if verdict == NX_BI_RETIRE_RECYCLE { return NX_RW_DONE_RETIRED } 24 if verdict == NX_BI_PASS_HEALTHY { return NX_RW_DONE_RESTORED } // nothing to do 25 26 var nsteps: i64 = 0 27 if verdict == NX_BI_BMS_RESET { nsteps = 1 } // one low-current wake pulse 28 if verdict == NX_BI_RECONDITION { nsteps = 4 } // balance-charge cycles 29 if verdict == NX_BI_RECELL { nsteps = 6 } // post-recell condition + capacity-verify 30 if nsteps == 0 { return NX_RW_BAD_VERDICT } 31 32 var i: i64 = 0 33 while i < nsteps { 34 let v: i64 = nx_battery_validate_command(env, NX_INTENT_DEFENSIVE, NX_BC_CHARGE, charge_ma, voltage_mv, log, now_us + i*100) 35 if v != NX_BS_OK { 36 out_steps[0] = i // steps completed before the safety wall 37 return NX_RW_REFUSED_UNSAFE // the spine refused -> workflow aborts safe 38 } 39 i = i + 1 40 } 41 out_steps[0] = nsteps 42 return NX_RW_DONE_RESTORED 43}