Adds a state for automatic connected PU detection

This commit is contained in:
Etienne Chassaing 2025-08-01 10:25:06 +02:00
parent 9102812a6f
commit 09f9e8feb2
2 changed files with 8 additions and 5 deletions

View File

@ -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:

12
main.py
View File

@ -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}"]