Skip to content

Commit

Permalink
add mock_uss endpoint for telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
mickmis committed Dec 22, 2023
1 parent 9a19121 commit 8dcd4dc
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion monitoring/mock_uss/f3548v21/routes_scd.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from typing import Optional

import flask

from monitoring.mock_uss.f3548v21.flight_planning import op_intent_from_flightrecord
from monitoring.monitorlib import scd
from monitoring.mock_uss import webapp
from monitoring.mock_uss.auth import requires_scope
from monitoring.mock_uss.flights.database import db
from monitoring.mock_uss.flights.database import db, FlightRecord
from uas_standards.astm.f3548.v21.api import (
ErrorResponse,
GetOperationalIntentDetailsResponse,
GetOperationalIntentTelemetryResponse,
OperationalIntentState,
)


Expand Down Expand Up @@ -44,6 +48,58 @@ def scdsc_get_operational_intent_details(entityid: str):
return flask.jsonify(response), 200


@webapp.route(
"/mock/scd/uss/v1/operational_intents/<entityid>/telemetry", methods=["GET"]
)
@requires_scope(scd.SCOPE_CM_SA)
def scdsc_get_operational_intent_telemetry(entityid: str):
"""Implements getOperationalIntentTelemetry in ASTM SCD API."""

# Look up entityid in database
tx = db.value
flight: Optional[FlightRecord] = None
for f in tx.flights.values():
if f and f.op_intent.reference.id == entityid:
flight = f
break

# If requested operational intent doesn't exist, return 404
if flight is None:
return (
flask.jsonify(
ErrorResponse(
message="Operational intent {} not known by this USS".format(
entityid
)
)
),
404,
)

elif flight.op_intent.reference.state not in {
OperationalIntentState.Contingent,
OperationalIntentState.Nonconforming,
}:
return (
flask.jsonify(
ErrorResponse(
message=f"Operational intent {entityid} is not in a state that provides telemetry ({flight.op_intent.reference.state})"
)
),
409,
)

# TODO: implement support for telemetry
return (
flask.jsonify(
ErrorResponse(
message=f"Operational intent {entityid} has no telemetry data available."
)
),
412,
)


@webapp.route("/mock/scd/uss/v1/operational_intents", methods=["POST"])
@requires_scope(scd.SCOPE_SC)
def scdsc_notify_operational_intent_details_changed():
Expand Down

0 comments on commit 8dcd4dc

Please sign in to comment.