First start on getting a microservice together
This commit is contained in:
parent
53ffbb8afe
commit
b3dece82f2
101
microservice.py
Executable file
101
microservice.py
Executable file
@ -0,0 +1,101 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
import SoapySDR as soapy
|
||||
|
||||
from flask import Flask, request, jsonify
|
||||
from flasgger import Swagger
|
||||
|
||||
app = Flask(__name__)
|
||||
swag = Swagger(app)
|
||||
|
||||
sdrs = {}
|
||||
|
||||
@app.route('/radio/report')
|
||||
def report():
|
||||
"""List radio devices available to the system.
|
||||
---
|
||||
responses:
|
||||
200:
|
||||
description: A list of radio devices.
|
||||
"""
|
||||
|
||||
devices = [dict(device) for device in soapy.Device.enumerate()]
|
||||
return jsonify(devices)
|
||||
|
||||
@app.route('/radio/<radio>/connect')
|
||||
def connect(radio):
|
||||
"""Connect to a radio device, by driver name or serial number.
|
||||
---
|
||||
parameters:
|
||||
- name: radio
|
||||
description: Radio device driver name, or serial number.
|
||||
in: path
|
||||
type: string
|
||||
required: true
|
||||
responses:
|
||||
200:
|
||||
description: Successfully connected to a radio.
|
||||
400:
|
||||
description: No radio device by that name is available.
|
||||
500:
|
||||
description: Failed to connect to radio.
|
||||
"""
|
||||
if radio in sdrs:
|
||||
return "Radio device already connected", 400
|
||||
|
||||
devices = [dict(device) for device in soapy.Device.enumerate()]
|
||||
for device in devices:
|
||||
if radio in device.values():
|
||||
sdrs[radio] = {'device': soapy.Device(device)}
|
||||
|
||||
if sdrs[radio]['device'] is None:
|
||||
sdrs.pop(radio)
|
||||
return "Failed to open device", 500
|
||||
else:
|
||||
return "", 200
|
||||
|
||||
return "Radio device not found", 400
|
||||
|
||||
@app.route('/radio/<radio>/disconnect')
|
||||
def disconnect(radio):
|
||||
"""Disconnect from a radio device.
|
||||
---
|
||||
parameters:
|
||||
- name: radio
|
||||
description: Radio device driver name, or serial number.
|
||||
in: path
|
||||
type: string
|
||||
required: true
|
||||
responses:
|
||||
200:
|
||||
description: Successfully connected to a radio.
|
||||
400:
|
||||
description: No radio device by that name is available.
|
||||
500:
|
||||
description: An unknown error occurred.
|
||||
"""
|
||||
if radio in sdrs:
|
||||
if 'stream' in sdrs[radio] and sdrs[radio]['stream'] is not None:
|
||||
return "Radio is currently streaming, cannot disconnect", 400
|
||||
else:
|
||||
sdrs.pop(radio)
|
||||
return "", 200
|
||||
else:
|
||||
return "Radio not connected", 400
|
||||
|
||||
'''
|
||||
@app.route('/radio/<radio>/configure/<frequency>')
|
||||
def configure(radio):
|
||||
pass
|
||||
|
||||
@app.route('/radio/<radio>/start')
|
||||
def start_stream(radio):
|
||||
pass
|
||||
|
||||
@app.route('/radio/<radio>/end')
|
||||
def end_stream(radio):
|
||||
pass
|
||||
'''
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
@ -1,3 +1,5 @@
|
||||
colorama==0.4.3
|
||||
numpy==1.17.4
|
||||
prefixed==0.7.0
|
||||
flask==2.2.3
|
||||
flasgger==0.9.5
|
||||
|
||||
Loading…
Reference in New Issue
Block a user