added automatic band control, added some error handling

This commit is contained in:
Michael Clemens 2024-03-03 09:51:33 +01:00
parent a64e266f97
commit c061041088
1 changed files with 92 additions and 11 deletions

103
hrctl.py
View File

@ -17,8 +17,10 @@ class SerialHamlib:
self._ser = serial.Serial(port, timeout=0.5)
def write_cmd(self, cmd) -> None:
# TODO add error handling an try catch
self._ser.write(cmd)
try:
self._ser.write(cmd)
except:
print("Error while sending serial command.")
def get_temperature(self) -> int:
try:
@ -56,6 +58,39 @@ class SerialHamlib:
def set_tune_next(self) -> None:
self._ser.write(b'HRTU1;')
def set_band_6(self) -> None:
self._ser.write(b'HRBN0;')
def set_band_10(self) -> None:
self._ser.write(b'HRBN1;')
def set_band_12(self) -> None:
self._ser.write(b'HRBN2;')
def set_band_15(self) -> None:
self._ser.write(b'HRBN3;')
def set_band_17(self) -> None:
self._ser.write(b'HRBN4;')
def set_band_20(self) -> None:
self._ser.write(b'HRBN5;')
def set_band_30(self) -> None:
self._ser.write(b'HRBN6;')
def set_band_40(self) -> None:
self._ser.write(b'HRBN7;')
def set_band_60(self) -> None:
self._ser.write(b'HRBN8;')
def set_band_80(self) -> None:
self._ser.write(b'HRBN9;')
def set_band_160(self) -> None:
self._ser.write(b'HRBN10;')
def set_auto_tx_data(self, enable: int =1) -> None:
self._ser.write(b'HRRP1;')
@ -126,14 +161,18 @@ def band_tostr(band: int) -> str:
rpc = JSONRPCProtocol()
hardrock = SerialHamlib('/dev/ttyUSB0')
match = None
print("Temp:", hardrock.get_temperature())
print("Volt:", hardrock.get_voltage())
print("Band:", band_tostr(hardrock.get_band()))
print("ATU:", hardrock.get_atu_status())
tx_status = hardrock.get_tx_status()
try:
print("Temp:", hardrock.get_temperature())
print("Volt:", hardrock.get_voltage())
print("Band:", band_tostr(hardrock.get_band()))
print("ATU:", hardrock.get_atu_status())
tx_status = hardrock.get_tx_status()
match = re.search("HRMX P(\d+) A(\d+) S(\d+) T(\d+)",tx_status)
except:
print("Error while querying data from Hardrock 50.")
match = re.search("HRMX P(\d+) A(\d+) S(\d+) T(\d+)",tx_status)
# print("TX:", tx_status)
if match:
@ -177,6 +216,50 @@ def setTune():
hardrock.set_tune_next()
return hardrock.get_tune_next()
@dispatcher.public
def setBand6():
hardrock.set_band_6()
@dispatcher.public
def setBand10():
hardrock.set_band_10()
@dispatcher.public
def setBand12():
hardrock.set_band_12()
@dispatcher.public
def setBand15():
hardrock.set_band_15()
@dispatcher.public
def setBand17():
hardrock.set_band_17()
@dispatcher.public
def setBand20():
hardrock.set_band_20()
@dispatcher.public
def setBand30():
hardrock.set_band_30()
@dispatcher.public
def setBand40():
hardrock.set_band_40()
@dispatcher.public
def setBand60():
hardrock.set_band_60()
@dispatcher.public
def setBand80():
hardrock.set_band_80()
@dispatcher.public
def setBand160():
hardrock.set_band_160()
@dispatcher.public
def getStatus():
result = {}
@ -199,6 +282,4 @@ def getStatus():
return result
# in the main greenlet, run our rpc_server
rpc_server.serve_forever()
rpc_server.serve_forever()