feat(api): FastAPI bridge for pont bascule via serial + Tailscale access
- Add FastAPI service exposing /health, /last, /send/esclave, /send/dsd, /send/custom - Implement SerialBridge aligned with legacy Tkinter behavior (open delay 2s, post-write 0.5s, read in_waiting once) - Enforce single in-flight serial request (non-blocking lock, returns 409 BUSY) - Add environment-based serial configuration (.env + systemd EnvironmentFile) - Document installation, systemd service, and Tailscale usage (direct IP and tailscale serve)
This commit is contained in:
18
app/mock_bridge.py
Normal file
18
app/mock_bridge.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import threading
|
||||
import time
|
||||
|
||||
class MockBridge:
|
||||
def __init__(self):
|
||||
self._lock = threading.Lock()
|
||||
|
||||
def busy(self):
|
||||
return self._lock.locked()
|
||||
|
||||
def send_and_read_once(self, payload: bytes):
|
||||
if not self._lock.acquire(blocking=False):
|
||||
return {"busy": True, "error": "BUSY"}
|
||||
try:
|
||||
time.sleep(0.1)
|
||||
return {"ok": True, "response": "OK"}
|
||||
finally:
|
||||
self._lock.release()
|
||||
Reference in New Issue
Block a user