2021-10-05 18:10:50 -04:00
|
|
|
#!/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'
|
2021-10-06 08:20:28 -04:00
|
|
|
}
|
2021-10-05 18:10:50 -04:00
|
|
|
|
|
|
|
vlcd = {
|
|
|
|
'STA': '-',
|
|
|
|
'PTT': '-',
|
|
|
|
'BND': '-',
|
|
|
|
'VLT': '-',
|
|
|
|
'PEP': '-',
|
|
|
|
'AVG': '-',
|
|
|
|
'SWR': '-',
|
|
|
|
'TMP': '-'
|
2021-10-06 08:20:28 -04:00
|
|
|
}
|
2021-10-05 18:10:50 -04:00
|
|
|
|
|
|
|
# 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 + ';'
|
2021-10-06 08:01:42 -04:00
|
|
|
#print(command)
|
2021-10-05 18:10:50 -04:00
|
|
|
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()
|
|
|
|
|
2021-10-06 08:01:42 -04:00
|
|
|
keying_methods = {
|
|
|
|
"off" : "0",
|
|
|
|
"ptt" : "1",
|
|
|
|
"cor" : "2",
|
|
|
|
"qrp" : "3"
|
|
|
|
}
|
2021-10-05 18:10:50 -04:00
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
try:
|
2021-10-06 08:01:42 -04:00
|
|
|
opts, args = getopt.getopt(argv,"hb:tk:")
|
2021-10-05 18:10:50 -04:00
|
|
|
except getopt.GetoptError:
|
2021-10-06 08:01:42 -04:00
|
|
|
print("Error :(")
|
|
|
|
print("Please consult help via ./hr50ctl.py -h")
|
2021-10-05 18:10:50 -04:00
|
|
|
sys.exit(2)
|
|
|
|
for opt, arg in opts:
|
|
|
|
if opt == '-h':
|
2021-10-06 08:01:42 -04:00
|
|
|
print("\nUSAGE: # ./hr50ctl.py -b <band> -t -k <keying mode>")
|
|
|
|
print("\nPARAMETERS:")
|
|
|
|
print(" -k: the following keying methods are available:")
|
|
|
|
print(" off, cor, ptt, qrp")
|
|
|
|
print(" This parameter changes the method how the HR50 will be put into TX mode.")
|
|
|
|
print(" -b: the following bands are available:")
|
|
|
|
print(" 6, 10, 12, 15, 20, 17, 20, 30, 40, 60, 80, 160")
|
|
|
|
print(" This parameter changes the band of the HR50")
|
|
|
|
print(" -t: no parameter required.")
|
|
|
|
print(" This parameters initiates the tuning during the next PTT")
|
|
|
|
print("\nEXAMPLES:")
|
|
|
|
print(" Change the band to 12m: # ./hr50ctl.py -b 12")
|
|
|
|
print(" Change the keying method to PTT: # ./hr50ctl.py -k ptt")
|
2021-10-06 08:20:28 -04:00
|
|
|
print(" Change the band to 6m and tune: # ./hr50ctl.py -b 6 -t\n")
|
2021-10-05 18:10:50 -04:00
|
|
|
sys.exit()
|
2021-10-06 08:01:42 -04:00
|
|
|
elif opt == "-b":
|
2021-10-05 18:10:50 -04:00
|
|
|
if arg in bands:
|
|
|
|
# change the band
|
|
|
|
send_command("HRBN",bands[arg])
|
2021-10-06 08:01:42 -04:00
|
|
|
elif opt == "-t":
|
|
|
|
# let the HR50 know that it should return
|
|
|
|
send_command("HRTU","1")
|
|
|
|
elif opt == "-k":
|
|
|
|
if arg in keying_methods:
|
2021-10-05 18:10:50 -04:00
|
|
|
# let the HR50 know that it should retunr
|
2021-10-06 08:01:42 -04:00
|
|
|
send_command("HRMD",keying_methods[arg])
|
2021-10-05 18:10:50 -04:00
|
|
|
|
|
|
|
# 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:])
|