created a separate patient skid file
This commit is contained in:
parent
cf82c3f6ec
commit
c8d892ced3
41
main.py
41
main.py
|
|
@ -21,6 +21,7 @@ import numpy as np
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import httpx
|
import httpx
|
||||||
import time
|
import time
|
||||||
|
from patient_skid_functions import handle_patient_skid_for_idle, set_patient_skid_users
|
||||||
|
|
||||||
from serial_manager import SerialConfig, SerialStore, SerialReader
|
from serial_manager import SerialConfig, SerialStore, SerialReader
|
||||||
from protocol_decoder import decode_frames
|
from protocol_decoder import decode_frames
|
||||||
|
|
@ -288,20 +289,6 @@ def expand_pu_number(pu_number: int) -> list[int]:
|
||||||
return [pu_number] if pu_number != 3 else [1, 2]
|
return [pu_number] if pu_number != 3 else [1, 2]
|
||||||
|
|
||||||
|
|
||||||
def handle_patient_skid_for_idle() -> None:
|
|
||||||
"""Send the special commands to patient skid when entering IDLE."""
|
|
||||||
try:
|
|
||||||
url = "http://192.168.1.28:8000/stop_test"
|
|
||||||
response = httpx.get(url, timeout=1.0)
|
|
||||||
logging.info(f"Stopping test on Patient Skid: {response.status_code}")
|
|
||||||
|
|
||||||
url = "http://192.168.1.28:8000/close_valves"
|
|
||||||
response = httpx.get(url, timeout=1.0)
|
|
||||||
logging.info(f"Closing valves on Patient Skid: {response.status_code}")
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"Error handling patient skid for IDLE: {e}")
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
def send_command_to_pu(
|
def send_command_to_pu(
|
||||||
pu: int, state: str, ploop_setpoint: float, qperm_setpoint: float
|
pu: int, state: str, ploop_setpoint: float, qperm_setpoint: float
|
||||||
|
|
@ -623,32 +610,6 @@ async def update_latest_flow():
|
||||||
logging.error(f"Error fetching flow: {e}")
|
logging.error(f"Error fetching flow: {e}")
|
||||||
await asyncio.sleep(1.0)
|
await asyncio.sleep(1.0)
|
||||||
|
|
||||||
def stop_patient_skid():
|
|
||||||
try:
|
|
||||||
url = f"http://192.168.1.28:8000/stop_test"
|
|
||||||
response = httpx.get(url, timeout=5.0)
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
|
||||||
return {"status": "success", "detail": response.json()}
|
|
||||||
else:
|
|
||||||
raise HTTPException(status_code=502, detail=f"Remote server error: {response.text}")
|
|
||||||
except httpx.RequestError as e:
|
|
||||||
raise HTTPException(status_code=500, detail=f"Request to external server failed: {str(e)}")
|
|
||||||
|
|
||||||
def set_patient_skid_users(count: int = 0):
|
|
||||||
try:
|
|
||||||
url = f"http://192.168.1.28:8000/set_users/{count}"
|
|
||||||
response = httpx.get(url, timeout=5.0)
|
|
||||||
|
|
||||||
response_2 = httpx.get("http://192.168.1.28:8000/start_defined_test", timeout=5.0)
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
|
||||||
return {"status": "success", "detail": response.json()}
|
|
||||||
else:
|
|
||||||
raise HTTPException(status_code=502, detail=f"Remote server error: {response.text}")
|
|
||||||
except httpx.RequestError as e:
|
|
||||||
raise HTTPException(status_code=500, detail=f"Request to external server failed: {str(e)}")
|
|
||||||
|
|
||||||
app.include_router(router)
|
app.include_router(router)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
30
patient_skid_functions.py
Normal file
30
patient_skid_functions.py
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
import httpx
|
||||||
|
import logging
|
||||||
|
|
||||||
|
def handle_patient_skid_for_idle() -> None:
|
||||||
|
"""Send the special commands to patient skid when entering IDLE."""
|
||||||
|
try:
|
||||||
|
url = "http://192.168.1.28:8000/stop_test"
|
||||||
|
response = httpx.get(url, timeout=1.0)
|
||||||
|
logging.info(f"Stopping test on Patient Skid: {response.status_code}")
|
||||||
|
|
||||||
|
url = "http://192.168.1.28:8000/close_valves"
|
||||||
|
response = httpx.get(url, timeout=1.0)
|
||||||
|
logging.info(f"Closing valves on Patient Skid: {response.status_code}")
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Error handling patient skid for IDLE: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
def set_patient_skid_users(count: int = 0):
|
||||||
|
try:
|
||||||
|
url = f"http://192.168.1.28:8000/set_users/{count}"
|
||||||
|
response = httpx.get(url, timeout=5.0)
|
||||||
|
|
||||||
|
response_2 = httpx.get("http://192.168.1.28:8000/start_defined_test", timeout=5.0)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
return {"status": "success", "detail": response.json()}
|
||||||
|
else:
|
||||||
|
raise HTTPException(status_code=502, detail=f"Remote server error: {response.text}")
|
||||||
|
except httpx.RequestError as e:
|
||||||
|
raise HTTPException(status_code=500, detail=f"Request to external server failed: {str(e)}")
|
||||||
Loading…
Reference in New Issue
Block a user