feat: enhance logging messages in ach_server.py and add experiments.py for protocol minimization

This commit is contained in:
2026-04-10 00:58:54 -04:00
committed by serversdown
parent 0358acb51d
commit 574d40027f
3 changed files with 649 additions and 14 deletions
+12 -12
View File
@@ -185,9 +185,9 @@ class AchSession:
from minimateplus.protocol import MiniMateProtocol
proto = MiniMateProtocol(transport, recv_timeout=self.timeout)
proto.startup()
log.info(" Startup OK pull protocol confirmed")
log.info(" [OK] Startup OK -- pull protocol confirmed")
except Exception as exc:
log.error(" Startup failed: %s", exc)
log.error(" [FAIL] Startup failed: %s", exc)
return
# ── Step 2: device info ───────────────────────────────────────────
@@ -196,16 +196,16 @@ class AchSession:
log.info("Step 2/3: reading device info")
try:
device_info = client.connect()
serial = device_info.serial_number
serial = device_info.serial
_save_json(session_dir / "device_info.json", _device_info_to_dict(device_info))
log.info(
" Device: serial=%s firmware=%s calibration=%s",
" [OK] Device: serial=%s firmware=%s calibration=%s",
serial,
device_info.firmware_version,
device_info.calibration_date,
)
except Exception as exc:
log.error(" Device info failed: %s", exc)
log.error(" [FAIL] Device info failed: %s", exc)
else:
log.info("Step 2/3: skipping device info (--events-only)")
@@ -221,12 +221,12 @@ class AchSession:
log.info(" Unit has %d stored event(s); last downloaded count: %d",
current_count, last_count)
except Exception as exc:
log.error(" count_events failed: %s", exc)
log.error(" [FAIL] count_events failed: %s", exc)
return
if current_count <= last_count:
log.info(" No new events since last call-home nothing to download")
log.info("Session complete (no new events) %s", session_dir)
log.info(" [OK] No new events since last call-home -- nothing to download")
log.info("Session complete (no new events) -> %s", session_dir)
return
new_event_count = current_count - last_count
@@ -252,7 +252,7 @@ class AchSession:
)
# Only the events beyond last_count are genuinely new
new_events = all_events[last_count:]
log.info(" Downloaded %d total event(s), %d new",
log.info(" [OK] Downloaded %d total event(s), %d new",
len(all_events), len(new_events))
_save_json(session_dir / "events.json", [_event_to_dict(e) for e in new_events])
@@ -280,13 +280,13 @@ class AchSession:
_save_state(self.state_path, state)
except Exception as exc:
log.error(" Event download failed: %s", exc, exc_info=True)
log.error(" [FAIL] Event download failed: %s", exc, exc_info=True)
finally:
raw_fh.close()
client.close() # closes transport / socket cleanly
log.info("Session complete %s", session_dir)
log.info("Session complete -> %s", session_dir)
log.info("="*60)
@@ -300,7 +300,7 @@ def _save_json(path: Path, obj: object) -> None:
def _device_info_to_dict(d: DeviceInfo) -> dict:
return {
"serial_number": d.serial_number,
"serial": d.serial,
"firmware_version": d.firmware_version,
"calibration_date": str(d.calibration_date) if d.calibration_date else None,
"aux_trigger": d.aux_trigger,