commit a1979cfe63bb7467efd44f6b3a34e77d1aa3f342 Author: Michael Clemens Date: Tue Oct 5 23:10:50 2021 +0100 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/hr50ctl.py b/hr50ctl.py new file mode 100755 index 0000000..dedfee8 --- /dev/null +++ b/hr50ctl.py @@ -0,0 +1,107 @@ +#!/usr/bin/python3 + +import serial +import sys +import time +import getopt +from prettytable import PrettyTable + +serial_port = '/dev/ttyUSB0' +baud = 19200 + +bands = { + '6': '0', + '10': '1', + '12': '2', + '15': '3', + '17': '4', + '20': '5', + '30': '6', + '40': '7', + '60': '8', + '80': '9', + '160': '10' +} + +vlcd = { + 'STA': '-', + 'PTT': '-', + 'BND': '-', + 'VLT': '-', + 'PEP': '-', + 'AVG': '-', + 'SWR': '-', + 'TMP': '-' +} + +# sends a command and an optional parameter to the +# Hardrock-50 via the serial interface +def send_command(cmd, param): + ser = serial.Serial(serial_port, baud, timeout=1) + command = cmd + param + ';' + ser.write(str.encode(command)) + ser.close() + +# Executed two commands vie the serial interface, +# parsed the result ad polulates a dict with the +# collected information +def get_info(): + ser = serial.Serial(serial_port, baud, timeout=1) + ser.write(b'HRRX;') + time.sleep(0.5) + res = ser.readline().decode("utf-8").rstrip().replace(';', '').split(',') + vlcd['STA'] = res[0] + vlcd['PTT'] = res[1] + vlcd['BND'] = res[2] + vlcd['TMP'] = res[3] + vlcd['VLT'] = res[4] + ser.write(b'HRMX;') + time.sleep(0.5) + res = ser.readline().decode("utf-8").rstrip().split() + vlcd['PEP'] = res[1][1:] + vlcd['AVG'] = res[2][1:] + if res[3][1:] != "0": + vlcd['SWR'] = res[3][1:2] + "." + res[3][2:3] + ser.close() + + +def main(argv): + try: + opts, args = getopt.getopt(argv,"hb:t",["band=","tune="]) + except getopt.GetoptError: + print("hr50ctl.py -b -t <1|0>") + sys.exit(2) + for opt, arg in opts: + if opt == '-h': + print("hr50ctl.py -b -t <1|0>") + sys.exit() + elif opt in ("-b", "--band"): + if arg in bands: + # change the band + send_command("HRBN",bands[arg]) + elif opt in ("-t", "--tune"): + if arg == "1": + # let the HR50 know that it should retunr + send_command("HRTU1","") + + # query all desired info from the HR50 + get_info() + + # print info to stdout + table = PrettyTable(['1', '2', '3', '4']) + table.add_row([ + "STA: " + vlcd["STA"], + "PTT: " + vlcd["PTT"], + "BND: " + vlcd["BND"], + "VLT: " + vlcd["VLT"]]) + table.add_row([ + "PEP: " + vlcd["PEP"], + "AVG: " + vlcd["AVG"], + "SWR: " + vlcd["SWR"], + "TMP: " + vlcd["TMP"]]) + table.align = "l" + table.header = False + print(table) + +if __name__ == "__main__": + main(sys.argv[1:])