added new options

This commit is contained in:
micha 2021-11-07 17:48:54 +01:00
parent e11ec75ef7
commit e0f5f3d1e0
1 changed files with 36 additions and 22 deletions

View File

@ -43,7 +43,7 @@ keying_methods = {
def get_serial(port, baud):
try:
ser = serial.Serial(port, baud, timeout=1)
ser = serial.Serial(port, baud, timeout=2)
return ser
except serial.serialutil.SerialException as e:
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
def send_command(cmd, param):
ser = get_serial(serial_port, baud)
res = None
try:
command = cmd + param + ';'
ser.write(str.encode(command))
res = ser.readline().decode("utf-8").rstrip()
except Exception as e:
print("The following error has occured while sending the command {} to the HR50:".format(port, baud))
print(e)
ser.close()
return res
# Executed two commands vie the serial interface,
# parsed the result ad polulates a dict with the
@ -92,15 +95,18 @@ def get_info():
def main(argv):
show_info = True
try:
opts, args = getopt.getopt(argv,"hb:tk:")
opts, args = getopt.getopt(argv,"hb:sntk:")
except getopt.GetoptError:
print("Error :(")
print("Please consult help via ./hr50ctl.py -h")
sys.exit(2)
for opt, arg in opts:
if opt == '-n':
show_info = False
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(" -k: the following keying methods are available:")
print(" off, cor, ptt, qrp")
@ -110,6 +116,10 @@ def main(argv):
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(" -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(" Change the band to 12m: # ./hr50ctl.py -b 12")
print(" Change the keying method to PTT: # ./hr50ctl.py -k ptt")
@ -122,31 +132,35 @@ def main(argv):
elif opt == "-t":
# let the HR50 know that it should return
send_command("HRTU","1")
elif opt == "-s":
# query result of last tuning cycle
print(send_command("HRTS",""))
elif opt == "-k":
if arg in keying_methods:
# let the HR50 know that it should retunr
send_command("HRMD",keying_methods[arg])
# query all desired info from the HR50
get_info()
if show_info:
# query all desired info from the HR50
get_info()
# print info to stdout
table = PrettyTable()
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("")
print(table)
print("")
# print info to stdout
table = PrettyTable()
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("")
print(table)
print("")
if __name__ == "__main__":
main(sys.argv[1:])