diff --git a/classCAN.py b/classCAN.py index 1bb10ba..c215462 100644 --- a/classCAN.py +++ b/classCAN.py @@ -127,7 +127,6 @@ class CANBackend: "MV06": data[4], "MV07": data[5], "MV08": data[6], - "MV09": data[7], }) elif cob_id == 0x2AB and len(data) >= 1: diff --git a/main.py b/main.py index 8ce8360..626ad4a 100644 --- a/main.py +++ b/main.py @@ -51,6 +51,8 @@ latest_data: Dict[str, Any] = { "PatientSkid": {"QSkid": 0.0}, } +active_PUs : list[int] = [] + DEFAULT_FEED_VALVE = 0.0 # RECORDER @@ -213,6 +215,7 @@ def send_command(state: str, pu_number: int, ploop_setpoint: float = Query(...)) @app.get("/api/pu_status") def get_pu_status(): + global active_PUs states = { "PU1": can_backend.read_current_state(1), "PU2": can_backend.read_current_state(2), @@ -220,15 +223,16 @@ def get_pu_status(): } logging.info(f"[PU STATUS] {states}") + active_PUs = [pu for pu, status in states.items() if status != 'OFF'] + logging.info(f"[ACTIVE PU] {active_PUs}") + return JSONResponse(content=states) async def update_latest_data(): + global active_PUs while True: - for pu in [ - 1, - 2, - ]: # TODO: REPLACE THIS WITH CONNECTED PUs, IS GET PU STATUS SLOW? + for pu in active_PUs: # TODO: test data = can_backend.get_latest_data(pu_number=pu) latest_data[f"PU_{pu}"] = format_data(data) current_data = latest_data[f"PU_{pu}"]