-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ardupilot-manager: add initial version of REST API
Initial version contains routes for getting, adding and deleting mavlink endpoints.
- Loading branch information
1 parent
153cecd
commit 1846a28
Showing
1 changed file
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |