Skip to content

Commit

Permalink
ardupilot-manager: add initial version of REST API
Browse files Browse the repository at this point in the history
Initial version contains routes for getting, adding and deleting mavlink endpoints.
  • Loading branch information
rafaellehmkuhl committed Mar 22, 2021
1 parent 153cecd commit 1846a28
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions core/services/ardupilot_manager/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
#! /usr/bin/env python3
from typing import Any, Dict, List

import uvicorn
from fastapi import FastAPI

from ArduPilotManager import ArduPilotManager
from mavlink_proxy.Endpoint import Endpoint, EndpointType

app = FastAPI()
autopilot = ArduPilotManager()


@app.get("/available_endpoints", response_model=List[Dict[str, Any]])
def get_available_endpoints() -> Any:
return [endpoint.__dict__ for endpoint in autopilot.get_endpoints()]


@app.post("/endpoint", response_model=bool)
def create_new_endpoint(connection_type: EndpointType, place: str, argument: str = "") -> Any:
if autopilot.add_endpoint(Endpoint({"connType": connection_type, "place": place, "argument": argument})):
return True
return False


@app.delete("/endpoint", response_model=bool)
def remove_endpoint(connection_type: EndpointType, place: str, argument: str = "") -> Any:
if autopilot.remove_endpoint(Endpoint({"connType": connection_type, "place": place, "argument": argument})):
return True
return False


if __name__ == "__main__":
ardupilot_manager = ArduPilotManager()
ardupilot_manager.run()
autopilot.run()
uvicorn.run(app, host="0.0.0.0", port=8000)

0 comments on commit 1846a28

Please sign in to comment.