added new options

This commit is contained in:
micha 2021-11-07 17:48:54 +01:00
parent e11ec75ef7
commit e0f5f3d1e0

View File

@ -43,7 +43,7 @@ keying_methods = {
def get_serial(port, baud): def get_serial(port, baud):
try: try:
ser = serial.Serial(port, baud, timeout=1) ser = serial.Serial(port, baud, timeout=2)
return ser return ser
except serial.serialutil.SerialException as e: except serial.serialutil.SerialException as e:
print("The following error has occured while opening the serial connection to {} with {} baud:".format(port, baud)) print("The following error has occured while opening the serial connection to {} with {} baud:".format(port, baud))
@ -54,13 +54,16 @@ def get_serial(port, baud):
# Hardrock-50 via the serial interface # Hardrock-50 via the serial interface
def send_command(cmd, param): def send_command(cmd, param):
ser = get_serial(serial_port, baud) ser = get_serial(serial_port, baud)
res = None
try: try:
command = cmd + param + ';' command = cmd + param + ';'
ser.write(str.encode(command)) ser.write(str.encode(command))
res = ser.readline().decode("utf-8").rstrip()
except Exception as e: except Exception as e:
print("The following error has occured while sending the command {} to the HR50:".format(port, baud)) print("The following error has occured while sending the command {} to the HR50:".format(port, baud))
print(e) print(e)
ser.close() ser.close()
return res
# Executed two commands vie the serial interface, # Executed two commands vie the serial interface,
# parsed the result ad polulates a dict with the # parsed the result ad polulates a dict with the
@ -92,15 +95,18 @@ def get_info():
def main(argv): def main(argv):
show_info = True
try: try:
opts, args = getopt.getopt(argv,"hb:tk:") opts, args = getopt.getopt(argv,"hb:sntk:")
except getopt.GetoptError: except getopt.GetoptError:
print("Error :(") print("Error :(")
print("Please consult help via ./hr50ctl.py -h") print("Please consult help via ./hr50ctl.py -h")
sys.exit(2) sys.exit(2)
for opt, arg in opts: for opt, arg in opts:
if opt == '-n':
show_info = False
if opt == '-h': if opt == '-h':
print("\nUSAGE: # ./hr50ctl.py -b <band> -t -k <keying mode>") print("\nUSAGE: # ./hr50ctl.py -b <band> -t -s -k <keying mode>")
print("\nPARAMETERS:") print("\nPARAMETERS:")
print(" -k: the following keying methods are available:") print(" -k: the following keying methods are available:")
print(" off, cor, ptt, qrp") print(" off, cor, ptt, qrp")
@ -110,6 +116,10 @@ def main(argv):
print(" This parameter changes the band of the HR50") print(" This parameter changes the band of the HR50")
print(" -t: no parameter required.") print(" -t: no parameter required.")
print(" This parameters initiates the tuning during the next PTT") print(" This parameters initiates the tuning during the next PTT")
print(" -s: no parameter required.")
print(" Query the status of the last tuning cycle")
print(" -n: no parameter required.")
print(" only send command, don't query status afterwards")
print("\nEXAMPLES:") print("\nEXAMPLES:")
print(" Change the band to 12m: # ./hr50ctl.py -b 12") print(" Change the band to 12m: # ./hr50ctl.py -b 12")
print(" Change the keying method to PTT: # ./hr50ctl.py -k ptt") print(" Change the keying method to PTT: # ./hr50ctl.py -k ptt")
@ -122,31 +132,35 @@ def main(argv):
elif opt == "-t": elif opt == "-t":
# let the HR50 know that it should return # let the HR50 know that it should return
send_command("HRTU","1") send_command("HRTU","1")
elif opt == "-s":
# query result of last tuning cycle
print(send_command("HRTS",""))
elif opt == "-k": elif opt == "-k":
if arg in keying_methods: if arg in keying_methods:
# let the HR50 know that it should retunr # let the HR50 know that it should retunr
send_command("HRMD",keying_methods[arg]) send_command("HRMD",keying_methods[arg])
# query all desired info from the HR50 if show_info:
get_info() # query all desired info from the HR50
get_info()
# print info to stdout # print info to stdout
table = PrettyTable() table = PrettyTable()
table.add_row([ table.add_row([
"STA: " + vlcd["STA"], "STA: " + vlcd["STA"],
"PTT: " + vlcd["PTT"], "PTT: " + vlcd["PTT"],
"BND: " + vlcd["BND"], "BND: " + vlcd["BND"],
"VLT: " + vlcd["VLT"]]) "VLT: " + vlcd["VLT"]])
table.add_row([ table.add_row([
"PEP: " + vlcd["PEP"], "PEP: " + vlcd["PEP"],
"AVG: " + vlcd["AVG"], "AVG: " + vlcd["AVG"],
"SWR: " + vlcd["SWR"], "SWR: " + vlcd["SWR"],
"TMP: " + vlcd["TMP"]]) "TMP: " + vlcd["TMP"]])
table.align = "l" table.align = "l"
table.header = False table.header = False
print("") print("")
print(table) print(table)
print("") print("")
if __name__ == "__main__": if __name__ == "__main__":
main(sys.argv[1:]) main(sys.argv[1:])