feature/9128_change_radio_endpoints #3
@ -1,5 +1,6 @@
|
|||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
|
import routes
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import requests
|
import requests
|
||||||
@ -18,7 +19,7 @@ swag = Swagger(app)
|
|||||||
radios = {}
|
radios = {}
|
||||||
|
|
||||||
|
|
||||||
@app.route("/report")
|
@app.route(routes.endpoint_routes["b"])
|
||||||
def report():
|
def report():
|
||||||
"""Get streams report from the RTSP relay.
|
"""Get streams report from the RTSP relay.
|
||||||
---
|
---
|
||||||
@ -40,7 +41,7 @@ def report():
|
|||||||
return _error_message_json(e.message), 500
|
return _error_message_json(e.message), 500
|
||||||
|
|
||||||
|
|
||||||
@app.route("/radio/report")
|
@app.route(routes.endpoint_routes["a"])
|
||||||
def radio_report():
|
def radio_report():
|
||||||
"""List radio devices available to the system.
|
"""List radio devices available to the system.
|
||||||
---
|
---
|
||||||
@ -53,7 +54,6 @@ def radio_report():
|
|||||||
return jsonify(devices)
|
return jsonify(devices)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/radio/<radio>/connect")
|
|
||||||
|
|
|||||||
def connect(radio):
|
def connect(radio):
|
||||||
"""Connect to a radio device, by driver name or serial number.
|
"""Connect to a radio device, by driver name or serial number.
|
||||||
---
|
---
|
||||||
@ -87,7 +87,7 @@ def connect(radio):
|
|||||||
return "Radio device not found", 400
|
return "Radio device not found", 400
|
||||||
|
|
||||||
|
|
||||||
@app.route("/radio/<radio>/disconnect")
|
@app.route(routes.endpoint_routes["f"])
|
||||||
def disconnect(radio):
|
def disconnect(radio):
|
||||||
"""Disconnect from a radio device.
|
"""Disconnect from a radio device.
|
||||||
---
|
---
|
||||||
@ -112,8 +112,9 @@ def disconnect(radio):
|
|||||||
return _error_message_json("Radio not connected"), 400
|
return _error_message_json("Radio not connected"), 400
|
||||||
|
|
||||||
|
|
||||||
@app.route("/radio/<radio>/configure/<frequency>")
|
# TODO: add post parameters...
|
||||||
def configure(radio, frequency):
|
@app.route(routes.endpoint_routes["c"])
|
||||||
|
def configure():
|
||||||
"""Tune the radio to a frequency.
|
"""Tune the radio to a frequency.
|
||||||
You must connect to the radio before attempting to configure it.
|
You must connect to the radio before attempting to configure it.
|
||||||
The radio must be configured before streaming can be started.
|
The radio must be configured before streaming can be started.
|
||||||
@ -141,7 +142,7 @@ def configure(radio, frequency):
|
|||||||
return _error_message_json("Radio not connected"), 400
|
return _error_message_json("Radio not connected"), 400
|
||||||
|
|
||||||
|
|
||||||
@app.route("/radio/<radio>/start")
|
@app.route(routes.endpoint_routes["d"])
|
||||||
def start_stream(radio):
|
def start_stream(radio):
|
||||||
"""Start the radio stream.
|
"""Start the radio stream.
|
||||||
Once the stream has been started, connect to the stream at:
|
Once the stream has been started, connect to the stream at:
|
||||||
@ -159,14 +160,17 @@ def start_stream(radio):
|
|||||||
400:
|
400:
|
||||||
description: JSON with error message.
|
description: JSON with error message.
|
||||||
"""
|
"""
|
||||||
try:
|
if id is not None:
|
||||||
radios[radio].start_stream()
|
_start_tuuube_stream(id)
|
||||||
return jsonify("message", "successfully started radio stream"), 200
|
else:
|
||||||
except Exception as e:
|
try:
|
||||||
return _error_message_json(e.message), 400
|
radios[radio].start_stream()
|
||||||
|
return jsonify("message", "successfully started radio stream"), 200
|
||||||
|
except Exception as e:
|
||||||
|
return _error_message_json(e.message), 400
|
||||||
|
|
||||||
|
|
||||||
@app.route("/radio/<radio>/end")
|
@app.route(routes.endpoint_routes["e"])
|
||||||
def end_stream(radio):
|
def end_stream(radio):
|
||||||
"""Terminate the radio stream.
|
"""Terminate the radio stream.
|
||||||
---
|
---
|
||||||
@ -182,15 +186,17 @@ def end_stream(radio):
|
|||||||
400:
|
400:
|
||||||
description: JSON with error message.
|
description: JSON with error message.
|
||||||
"""
|
"""
|
||||||
try:
|
if id is not None:
|
||||||
radios[radio].end_stream()
|
_end_tuuube_stream(id)
|
||||||
return jsonify("message", "successfully ended radio stream"), 200
|
else:
|
||||||
except Exception as e:
|
try:
|
||||||
error_message = {"error_message": e.message}
|
radios[radio].end_stream()
|
||||||
return _error_message_json(e.message), 400
|
return jsonify("message", "successfully ended radio stream"), 200
|
||||||
|
except Exception as e:
|
||||||
|
return _error_message_json(e.message), 400
|
||||||
|
|
||||||
|
|
||||||
@app.route("/radio/<radio>/info")
|
@app.route(routes.endpoint_routes["g"])
|
||||||
def radio_info(radio):
|
def radio_info(radio):
|
||||||
"""Get information about a radio.
|
"""Get information about a radio.
|
||||||
---
|
---
|
||||||
@ -215,8 +221,7 @@ def radio_info(radio):
|
|||||||
tubes = {}
|
tubes = {}
|
||||||
|
|
||||||
|
|
||||||
@app.route("/tuuube/<id>/start")
|
def _start_tuuube_stream(id):
|
||||||
def start_tuuube_stream(id):
|
|
||||||
"""Start streaming from a youtube source.
|
"""Start streaming from a youtube source.
|
||||||
Once the stream has been started, connect to the stream at:
|
Once the stream has been started, connect to the stream at:
|
||||||
rtsp://[host]:8554/tuuube/[id]
|
rtsp://[host]:8554/tuuube/[id]
|
||||||
@ -249,8 +254,7 @@ def start_tuuube_stream(id):
|
|||||||
return _error_message_json(e.message), 400
|
return _error_message_json(e.message), 400
|
||||||
|
|
||||||
|
|
||||||
@app.route("/tuuube/<id>/end")
|
def _end_tuuube_stream(id):
|
||||||
def end_tuuube_stream(id):
|
|
||||||
"""Terminate the youtube stream.
|
"""Terminate the youtube stream.
|
||||||
---
|
---
|
||||||
parameters:
|
parameters:
|
||||||
|
|||||||
10
routes.py
Normal file
10
routes.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
endpoint_routes = {
|
||||||
|
jono
commented
Expand this to have default routes so that the program can function without the data being supplied. I think the correct way to do this is:
That way we can actually use the microservice outside of the SDE, but if we are inside the SDE with the actual path details (supplied with the config file) then we can interact with the rest of the system. Expand this to have default routes so that the program can function without the data being supplied. I think the correct way to do this is:
- Give these useful paths, even if it dummy data. So route 'a' would be `route_path_a` instead of the empty string
- However, if a file `<filename>.[json|yml|whatever]` exists in the current directory, then:
- Load the contents of that file
- Overwrite the paths with the specified paths
That way we can actually use the microservice outside of the SDE, but if we are inside the SDE with the actual path details (supplied with the config file) then we can interact with the rest of the system.
|
|||||||
|
"a": "",
|
||||||
|
"b": "",
|
||||||
|
"c": "",
|
||||||
|
"d": "",
|
||||||
|
"e": "",
|
||||||
|
"f":"",
|
||||||
|
"g":""
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user
Don't remove this endpoint until the rest of the code handles connecting automatically to connected USB devices. We can add that feature and then remove this route in the same PR (different from this one).