added method for sending commands

This commit is contained in:
micha 2021-11-12 09:09:02 +01:00
parent 9b004c8043
commit 23dd1298ca

View File

@ -9,6 +9,7 @@ app = Flask(__name__)
serial_port = '/dev/ttyUSB0'
baud = 19200
'''
bands = {
'6': '0',
'10': '1',
@ -22,6 +23,7 @@ bands = {
'80': '9',
'160': '10'
}
'''
vlcd = {
'STA': '-',
@ -34,12 +36,14 @@ vlcd = {
'TMP': '-'
}
'''
keying_methods = {
"off" : "0",
"ptt" : "1",
"cor" : "2",
"qrp" : "3"
}
'''
def get_serial(port, baud):
try:
@ -50,13 +54,13 @@ def get_serial(port, baud):
print(e)
sys.exit(2)
# sends a command and an optional parameter to the
# sends a command to the
# Hardrock-50 via the serial interface
def send_command(cmd, param):
def send_cmd_via_serial(cmd):
ser = get_serial(serial_port, baud)
res = None
try:
command = cmd + param + ';'
command = cmd + ';'
ser.write(str.encode(command))
res = ser.readline().decode("utf-8").rstrip()
except Exception as e:
@ -103,7 +107,19 @@ def get_status():
return jsonify(vlcd)
@app.route('/tune', methods=['POST'])
def set_tune():
return '', 204
@app.route('/', methods=['GET'])
def send_command():
try:
cmd = request.args.get('cmd', default="", type=str)
data = send_cmd_via_serial(cmd)
return jsonify(isError= False,
message= "Success",
statusCode= 200,
data= data), 200
except Exception as e:
return jsonify(isError= True,
message= "Error",
statusCode= 200,
data= e), 200