|
@@ -32,6 +32,18 @@ class AppGpsHandler(BaseHandler):
|
|
|
self._tool_timeout_s = 8
|
|
self._tool_timeout_s = 8
|
|
|
self._nav_db = NavDB.default()
|
|
self._nav_db = NavDB.default()
|
|
|
|
|
|
|
|
|
|
+ async def _attach_recent_alert(self, device_id: str, payload: dict | None) -> dict | None:
|
|
|
|
|
+ if payload is None:
|
|
|
|
|
+ return None
|
|
|
|
|
+ merged = dict(payload)
|
|
|
|
|
+ try:
|
|
|
|
|
+ recent_alert = await self.ws_server.get_recent_device_alert(device_id)
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ recent_alert = None
|
|
|
|
|
+ if recent_alert is not None:
|
|
|
|
|
+ merged["risk_alert_event"] = recent_alert
|
|
|
|
|
+ return merged
|
|
|
|
|
+
|
|
|
async def _resolve_conn(self, request):
|
|
async def _resolve_conn(self, request):
|
|
|
requested_device_id = request.query.get("device_id")
|
|
requested_device_id = request.query.get("device_id")
|
|
|
conn = await self.ws_server.get_connection(device_id=requested_device_id)
|
|
conn = await self.ws_server.get_connection(device_id=requested_device_id)
|
|
@@ -136,7 +148,12 @@ class AppGpsHandler(BaseHandler):
|
|
|
"coord_type": "WGS84",
|
|
"coord_type": "WGS84",
|
|
|
"source": "device_mcp_gnss",
|
|
"source": "device_mcp_gnss",
|
|
|
}
|
|
}
|
|
|
- self._latest_payloads[self._device_key(conn)] = (time.monotonic(), payload)
|
|
|
|
|
|
|
+ device_key = self._device_key(conn)
|
|
|
|
|
+ self._latest_payloads[device_key] = (time.monotonic(), payload)
|
|
|
|
|
+ try:
|
|
|
|
|
+ await self.ws_server.update_device_gps(device_key, payload)
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ pass
|
|
|
return payload
|
|
return payload
|
|
|
|
|
|
|
|
async def _get_or_start_inflight(self, device_key: str, conn, tool_name: str):
|
|
async def _get_or_start_inflight(self, device_key: str, conn, tool_name: str):
|
|
@@ -221,6 +238,9 @@ class AppGpsHandler(BaseHandler):
|
|
|
},
|
|
},
|
|
|
status=503,
|
|
status=503,
|
|
|
)
|
|
)
|
|
|
|
|
+ conn, _ = await self._resolve_conn(request)
|
|
|
|
|
+ if conn is not None:
|
|
|
|
|
+ payload = await self._attach_recent_alert(self._device_key(conn), payload)
|
|
|
return self._json_response(payload)
|
|
return self._json_response(payload)
|
|
|
|
|
|
|
|
async def handle_get_risk_alerts(self, request):
|
|
async def handle_get_risk_alerts(self, request):
|
|
@@ -368,7 +388,12 @@ class AppGpsHandler(BaseHandler):
|
|
|
subscribed_device_key, max_age_s=3.0, allow_stale=True
|
|
subscribed_device_key, max_age_s=3.0, allow_stale=True
|
|
|
)
|
|
)
|
|
|
if current_payload is not None:
|
|
if current_payload is not None:
|
|
|
- await ws.send_json(current_payload)
|
|
|
|
|
|
|
+ await ws.send_json(
|
|
|
|
|
+ await self._attach_recent_alert(
|
|
|
|
|
+ subscribed_device_key,
|
|
|
|
|
+ current_payload,
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
else:
|
|
else:
|
|
|
payload, error_code = await self._get_fix_payload(request)
|
|
payload, error_code = await self._get_fix_payload(request)
|
|
|
if error_code:
|
|
if error_code:
|
|
@@ -380,11 +405,21 @@ class AppGpsHandler(BaseHandler):
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
else:
|
|
else:
|
|
|
- await ws.send_json(payload)
|
|
|
|
|
|
|
+ await ws.send_json(
|
|
|
|
|
+ await self._attach_recent_alert(
|
|
|
|
|
+ subscribed_device_key,
|
|
|
|
|
+ payload,
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
payload = await asyncio.wait_for(gps_queue.get(), timeout=30.0)
|
|
payload = await asyncio.wait_for(gps_queue.get(), timeout=30.0)
|
|
|
- await ws.send_json(payload)
|
|
|
|
|
|
|
+ await ws.send_json(
|
|
|
|
|
+ await self._attach_recent_alert(
|
|
|
|
|
+ subscribed_device_key,
|
|
|
|
|
+ payload,
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
except asyncio.TimeoutError:
|
|
except asyncio.TimeoutError:
|
|
|
payload, error_code = await self._get_fix_payload(request)
|
|
payload, error_code = await self._get_fix_payload(request)
|
|
|
if error_code:
|
|
if error_code:
|
|
@@ -401,7 +436,12 @@ class AppGpsHandler(BaseHandler):
|
|
|
subscribed_device_key = None
|
|
subscribed_device_key = None
|
|
|
await asyncio.sleep(interval_s)
|
|
await asyncio.sleep(interval_s)
|
|
|
else:
|
|
else:
|
|
|
- await ws.send_json(payload)
|
|
|
|
|
|
|
+ await ws.send_json(
|
|
|
|
|
+ await self._attach_recent_alert(
|
|
|
|
|
+ subscribed_device_key,
|
|
|
|
|
+ payload,
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
except asyncio.CancelledError:
|
|
except asyncio.CancelledError:
|
|
|
raise
|
|
raise
|