Persist rover observation configuration and calibrate Insta360 panorama
This commit is contained in:
@@ -99,6 +99,58 @@ def board_layout_patch(vehicle_id: str, body: BoardLayoutChange, response: Respo
|
||||
raise HTTPException(500, "Не удалось сохранить раскладку аппарата.") from None
|
||||
|
||||
|
||||
class ObservationConfigurationChange(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
expected_revision: int = Field(ge=0, lt=2**53-1, strict=True)
|
||||
document: dict
|
||||
|
||||
|
||||
@router.get("/{vehicle_id}/observation-configuration")
|
||||
def observation_configuration_read(vehicle_id: str, response: Response,
|
||||
fleet: Annotated[FleetRegistry, Depends(local_operator)]):
|
||||
response.headers["Cache-Control"] = "no-store"
|
||||
try:
|
||||
with fleet.lock:
|
||||
row = fleet.find(vehicle_id)
|
||||
value = fleet.rover_configurations.view(row["node_id"])
|
||||
# A one-time draft may migrate only after reading the board's empty
|
||||
# configuration. It becomes durable solely through the normal PUT/ACK.
|
||||
if value["available"] and value["document"] is None:
|
||||
from k1link.fleet.observation_configuration import read
|
||||
value["draft"] = read(fleet.root, vehicle_id)["document"]
|
||||
return value
|
||||
except PairingError as error:
|
||||
raise HTTPException(404, str(error)) from None
|
||||
except (OSError, ValueError):
|
||||
raise HTTPException(500, "Не удалось прочитать настройки центра наблюдения.") from None
|
||||
|
||||
|
||||
@router.put("/{vehicle_id}/observation-configuration")
|
||||
def observation_configuration_write(vehicle_id: str, body: ObservationConfigurationChange,
|
||||
response: Response,
|
||||
fleet: Annotated[FleetRegistry, Depends(local_operator)]):
|
||||
from k1link.fleet.observation_configuration import RevisionConflict
|
||||
from k1link.fleet.rover_configuration import Unavailable
|
||||
response.headers["Cache-Control"] = "no-store"
|
||||
try:
|
||||
with fleet.lock:
|
||||
row = fleet.find(vehicle_id)
|
||||
if row["enrollment"] != "paired":
|
||||
raise Unavailable("Борт не подключён.")
|
||||
# Never hold the fleet lock while waiting for its authenticated heartbeat.
|
||||
return fleet.rover_configurations.update(row["node_id"], row["name"], body.document, body.expected_revision)
|
||||
except PairingError as error:
|
||||
raise HTTPException(404, str(error)) from None
|
||||
except RevisionConflict as error:
|
||||
raise HTTPException(409, str(error)) from None
|
||||
except Unavailable as error:
|
||||
raise HTTPException(503, str(error)) from None
|
||||
except ValueError:
|
||||
raise HTTPException(422, "Недопустимая конфигурация наблюдения.") from None
|
||||
except OSError:
|
||||
raise HTTPException(500, "Не удалось сохранить настройки центра наблюдения.") from None
|
||||
|
||||
|
||||
@router.get("/{vehicle_id}/monitor")
|
||||
def board_monitor(vehicle_id: str, response: Response,
|
||||
fleet: Annotated[FleetRegistry, Depends(local_operator)],
|
||||
|
||||
Reference in New Issue
Block a user