plc-checkweigher 1.33.0 → 1.33.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -698,20 +698,23 @@ console-passwd)
698
698
 
699
699
  # ─────────────────────────────────────────────────────────────────────────────
700
700
  # FIX — auto-detect and repair common issues
701
- # Usage: fix [-wifi] [-health] [-programs] [-errors] (no flags = run all)
701
+ # Usage: fix [-wifi] [-health] [-programs] [-errors] [-registers] (no flags = all but registers)
702
702
  # ─────────────────────────────────────────────────────────────────────────────
703
703
  fix)
704
- FIX_WIFI=0; FIX_HEALTH=0; FIX_PROGRAMS=0; FIX_ERRORS=0
704
+ FIX_WIFI=0; FIX_HEALTH=0; FIX_PROGRAMS=0; FIX_ERRORS=0; FIX_REGISTERS=0
705
705
  if [[ $# -eq 0 ]]; then
706
+ # -registers is opt-in only: it talks to the PLC and may rewrite the
707
+ # register map, so it is excluded from the default "fix everything" run.
706
708
  FIX_WIFI=1; FIX_HEALTH=1; FIX_PROGRAMS=1; FIX_ERRORS=1
707
709
  else
708
710
  for _flag in "$@"; do
709
711
  case "$_flag" in
710
- -wifi) FIX_WIFI=1 ;;
711
- -health) FIX_HEALTH=1 ;;
712
- -programs) FIX_PROGRAMS=1 ;;
713
- -errors) FIX_ERRORS=1 ;;
714
- *) warn "Unknown flag: $_flag (valid: -wifi -health -programs -errors)" ;;
712
+ -wifi) FIX_WIFI=1 ;;
713
+ -health) FIX_HEALTH=1 ;;
714
+ -programs) FIX_PROGRAMS=1 ;;
715
+ -errors) FIX_ERRORS=1 ;;
716
+ -registers) FIX_REGISTERS=1 ;;
717
+ *) warn "Unknown flag: $_flag (valid: -wifi -health -programs -errors -registers)" ;;
715
718
  esac
716
719
  done
717
720
  fi
@@ -720,10 +723,11 @@ fix)
720
723
  mkdir -p "$LOG_DIR" 2>/dev/null || true
721
724
  # Build mode tag: "all" or hyphen-joined active scopes
722
725
  _LOG_MODES=""
723
- [[ $FIX_WIFI -eq 1 ]] && _LOG_MODES="${_LOG_MODES:+${_LOG_MODES}-}wifi"
724
- [[ $FIX_HEALTH -eq 1 ]] && _LOG_MODES="${_LOG_MODES:+${_LOG_MODES}-}health"
725
- [[ $FIX_PROGRAMS -eq 1 ]] && _LOG_MODES="${_LOG_MODES:+${_LOG_MODES}-}programs"
726
- [[ $FIX_ERRORS -eq 1 ]] && _LOG_MODES="${_LOG_MODES:+${_LOG_MODES}-}errors"
726
+ [[ $FIX_WIFI -eq 1 ]] && _LOG_MODES="${_LOG_MODES:+${_LOG_MODES}-}wifi"
727
+ [[ $FIX_HEALTH -eq 1 ]] && _LOG_MODES="${_LOG_MODES:+${_LOG_MODES}-}health"
728
+ [[ $FIX_PROGRAMS -eq 1 ]] && _LOG_MODES="${_LOG_MODES:+${_LOG_MODES}-}programs"
729
+ [[ $FIX_ERRORS -eq 1 ]] && _LOG_MODES="${_LOG_MODES:+${_LOG_MODES}-}errors"
730
+ [[ $FIX_REGISTERS -eq 1 ]] && _LOG_MODES="${_LOG_MODES:+${_LOG_MODES}-}registers"
727
731
  [[ "$_LOG_MODES" == "wifi-health-programs-errors" ]] && _LOG_MODES="all"
728
732
  LOG_FILE="${LOG_DIR}/fix_${_LOG_MODES}_$(date '+%Y%m%d_%H%M%S').log"
729
733
  flog() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" >> "$LOG_FILE"; }
@@ -733,7 +737,7 @@ fix)
733
737
  ffix_err() { spin_err "$*"; flog "ERROR : $*"; }
734
738
 
735
739
  FIX_COUNT=0
736
- flog "=== Run started | wifi=${FIX_WIFI} health=${FIX_HEALTH} programs=${FIX_PROGRAMS} errors=${FIX_ERRORS} ==="
740
+ flog "=== Run started | wifi=${FIX_WIFI} health=${FIX_HEALTH} programs=${FIX_PROGRAMS} errors=${FIX_ERRORS} registers=${FIX_REGISTERS} ==="
737
741
 
738
742
  banner "Auto Fix"
739
743
  echo ""
@@ -1238,6 +1242,37 @@ SMBC
1238
1242
  echo ""
1239
1243
  fi
1240
1244
 
1245
+ # ─────────────────────────────────────────────────────────────────────────
1246
+ # REGISTERS — confirm the live PLC register layout and auto-correct the map
1247
+ # ─────────────────────────────────────────────────────────────────────────
1248
+ if [[ $FIX_REGISTERS -eq 1 ]]; then
1249
+ echo -e " ${B}▸ PLC Registers${NC}"; hr; echo ""
1250
+ flog "=== Register scan ==="
1251
+ # The scanner connects to the PLC, decodes known + candidate registers,
1252
+ # and — if the read weight reads 0 while an item is on the scale —
1253
+ # detects the real register and writes data/register_map.json so the
1254
+ # code self-corrects without a source edit.
1255
+ _REG_OUT=$("${PYTHON}" -c "
1256
+ import sys; sys.path.insert(0, '${INSTALL_DIR}')
1257
+ import regmap
1258
+ changed, _ = regmap.scan(write=True)
1259
+ sys.exit(10 if changed else 0)
1260
+ " 2>&1)
1261
+ _REG_RC=$?
1262
+ echo "$_REG_OUT"
1263
+ while IFS= read -r _rl; do flog "REG: $_rl"; done <<< "$_REG_OUT"
1264
+ echo ""
1265
+ if [[ $_REG_RC -eq 10 ]]; then
1266
+ ffix_ok "Register map auto-corrected — read weight remapped"
1267
+ # New map takes effect on the reader's next item; restart to apply now.
1268
+ sudo systemctl restart plc_watcher 2>/dev/null || true
1269
+ ffix_info "plc_watcher restarted to apply the new register map"
1270
+ else
1271
+ ffix_info "Register scan complete — no remap needed"
1272
+ fi
1273
+ echo ""
1274
+ fi
1275
+
1241
1276
  # ── Summary ───────────────────────────────────────────────────────────────
1242
1277
  flog "=== Complete: ${FIX_COUNT} fix(es) applied ==="
1243
1278
  hr
@@ -1961,6 +1996,7 @@ help|--help|-h)
1961
1996
  echo " fix -health Fix disk, memory, time, dirs"
1962
1997
  echo " fix -programs Fix services, packages, queue, unit files"
1963
1998
  echo " fix -errors Scan journal, verify RT/permissions/PLC/config"
1999
+ echo " fix -registers Confirm live PLC register layout + auto-correct map"
1964
2000
  echo " logs Stream live logs (plc_watcher + plc_web)"
1965
2001
  echo " queue Show SMB pending queue and delivery ledger"
1966
2002
  echo " selfheal status Self-healing daemon state + unresolved problems"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plc-checkweigher",
3
- "version": "1.33.0",
3
+ "version": "1.33.2",
4
4
  "description": "One-command installer for the PLC Check-Weigher system on Raspberry Pi (PREEMPT_RT kernel, Python stack, WiFi, SMB, systemd RT services)",
5
5
  "scripts": {
6
6
  "postinstall": "node bin/cli.js"