feat(fleet): preserve operator VESC integration before final driver merge
This commit is contained in:
@@ -6,12 +6,12 @@ import asyncio
|
||||
import ipaddress
|
||||
import json
|
||||
from contextlib import suppress
|
||||
from typing import Annotated
|
||||
from typing import Annotated, Literal
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, Response
|
||||
from fastapi.responses import StreamingResponse
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
from pydantic import BaseModel, ConfigDict, Field, StrictBool
|
||||
|
||||
from k1link.fleet.registry import FleetRegistry
|
||||
from k1link.fleet.trust import PairingError
|
||||
@@ -51,6 +51,42 @@ class AddRequest(BaseModel):
|
||||
router = APIRouter(prefix="/api/v1/fleet", tags=["fleet"])
|
||||
|
||||
|
||||
class BoardLayoutChange(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
section: Literal["computer", "settings", "devices"]
|
||||
open: StrictBool
|
||||
|
||||
|
||||
@router.get("/{vehicle_id}/board-layout")
|
||||
def board_layout_read(vehicle_id: str, response: Response,
|
||||
fleet: Annotated[FleetRegistry, Depends(local_operator)]):
|
||||
from k1link.fleet.board_layout import read
|
||||
response.headers["Cache-Control"] = "no-store"
|
||||
try:
|
||||
with fleet.lock:
|
||||
fleet.find(vehicle_id)
|
||||
return read(fleet.root, vehicle_id)
|
||||
except PairingError as error:
|
||||
raise HTTPException(404, str(error)) from None
|
||||
except (OSError, ValueError):
|
||||
raise HTTPException(500, "Не удалось прочитать раскладку аппарата.") from None
|
||||
|
||||
|
||||
@router.patch("/{vehicle_id}/board-layout")
|
||||
def board_layout_patch(vehicle_id: str, body: BoardLayoutChange, response: Response,
|
||||
fleet: Annotated[FleetRegistry, Depends(local_operator)]):
|
||||
from k1link.fleet.board_layout import update
|
||||
response.headers["Cache-Control"] = "no-store"
|
||||
try:
|
||||
with fleet.lock:
|
||||
fleet.find(vehicle_id)
|
||||
return update(fleet.root, vehicle_id, body.section, body.open)
|
||||
except PairingError as error:
|
||||
raise HTTPException(404, str(error)) from None
|
||||
except (OSError, ValueError):
|
||||
raise HTTPException(500, "Не удалось сохранить раскладку аппарата.") from None
|
||||
|
||||
|
||||
@router.get("/{vehicle_id}/monitor")
|
||||
def board_monitor(vehicle_id: str, response: Response,
|
||||
fleet: Annotated[FleetRegistry, Depends(local_operator)],
|
||||
@@ -141,6 +177,30 @@ def sensor_command(
|
||||
raise HTTPException(409, str(error)) from None
|
||||
|
||||
|
||||
@router.get("/{vehicle_id}/devices/{device_id}/configurations")
|
||||
def vesc_configurations(vehicle_id: str, device_id: str, response: Response,
|
||||
fleet: Annotated[FleetRegistry, Depends(local_operator)], before: int = 0):
|
||||
response.headers["Cache-Control"] = "no-store"
|
||||
try:
|
||||
with fleet.lock:
|
||||
node = fleet.find(vehicle_id)["node_id"]
|
||||
return fleet.vesc_archive.listing(node, device_id, before)
|
||||
except (PairingError, ValueError):
|
||||
raise HTTPException(404, "История конфигураций недоступна.") from None
|
||||
|
||||
|
||||
@router.get("/{vehicle_id}/devices/{device_id}/configurations/{version_id}")
|
||||
def vesc_configuration(vehicle_id: str, device_id: str, version_id: str, response: Response,
|
||||
fleet: Annotated[FleetRegistry, Depends(local_operator)]):
|
||||
response.headers["Cache-Control"] = "no-store"
|
||||
try:
|
||||
with fleet.lock:
|
||||
node = fleet.find(vehicle_id)["node_id"]
|
||||
return fleet.vesc_archive.read(node, device_id, version_id)
|
||||
except (PairingError, ValueError):
|
||||
raise HTTPException(404, "Версия конфигурации не найдена.") from None
|
||||
|
||||
|
||||
@router.get("/{vehicle_id}/devices/operations/{operation_id}")
|
||||
def sensor_operation(
|
||||
vehicle_id: str, operation_id: str, fleet: Annotated[FleetRegistry, Depends(local_operator)]
|
||||
|
||||
Reference in New Issue
Block a user