mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
updated hamlib handling
This commit is contained in:
parent
cadee776e0
commit
29bd4f6af0
2 changed files with 40 additions and 84 deletions
105
tnc/daemon.py
105
tnc/daemon.py
|
@ -20,7 +20,7 @@ import serial.tools.list_ports
|
||||||
import static
|
import static
|
||||||
import crcengine
|
import crcengine
|
||||||
import re
|
import re
|
||||||
|
import rig
|
||||||
import logging, structlog, log_handler
|
import logging, structlog, log_handler
|
||||||
|
|
||||||
log_handler.setup_logging("daemon")
|
log_handler.setup_logging("daemon")
|
||||||
|
@ -276,101 +276,38 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
|
|
||||||
if received_json["type"] == 'GET' and received_json["command"] == 'TEST_HAMLIB':
|
if received_json["type"] == 'GET' and received_json["command"] == 'TEST_HAMLIB':
|
||||||
|
|
||||||
print(received_json["parameter"])
|
|
||||||
|
|
||||||
devicename = str(received_json["parameter"][0]["devicename"])
|
|
||||||
deviceport = str(received_json["parameter"][0]["deviceport"])
|
|
||||||
serialspeed = str(received_json["parameter"][0]["serialspeed"])
|
|
||||||
pttprotocol = str(received_json["parameter"][0]["pttprotocol"])
|
|
||||||
pttport = str(received_json["parameter"][0]["pttport"])
|
|
||||||
|
|
||||||
pttspeed = str(received_json["parameter"][0]["pttspeed"])
|
|
||||||
data_bits = str(received_json["parameter"][0]["data_bits"])
|
|
||||||
stop_bits = str(received_json["parameter"][0]["stop_bits"])
|
|
||||||
handshake = str(received_json["parameter"][0]["handshake"])
|
|
||||||
|
|
||||||
# try to init hamlib
|
|
||||||
try:
|
try:
|
||||||
|
print(received_json["parameter"])
|
||||||
|
|
||||||
Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE)
|
devicename = str(received_json["parameter"][0]["devicename"])
|
||||||
|
deviceport = str(received_json["parameter"][0]["deviceport"])
|
||||||
|
serialspeed = str(received_json["parameter"][0]["serialspeed"])
|
||||||
|
pttprotocol = str(received_json["parameter"][0]["pttprotocol"])
|
||||||
|
pttport = str(received_json["parameter"][0]["pttport"])
|
||||||
|
|
||||||
# get devicenumber by looking for deviceobject in Hamlib module
|
pttspeed = str(received_json["parameter"][0]["pttspeed"])
|
||||||
try:
|
data_bits = str(received_json["parameter"][0]["data_bits"])
|
||||||
devicenumber = getattr(Hamlib, devicename)
|
stop_bits = str(received_json["parameter"][0]["stop_bits"])
|
||||||
except:
|
handshake = str(received_json["parameter"][0]["handshake"])
|
||||||
structlog.get_logger("structlog").error("[DMN] Hamlib: rig not supported...")
|
|
||||||
devicenumber = 0
|
|
||||||
|
|
||||||
|
|
||||||
my_rig = Hamlib.Rig(int(devicenumber))
|
|
||||||
my_rig.set_conf("rig_pathname", deviceport)
|
|
||||||
my_rig.set_conf("retry", "1")
|
|
||||||
my_rig.set_conf("serial_speed", serialspeed)
|
|
||||||
my_rig.set_conf("serial_handshake", handshake)
|
|
||||||
my_rig.set_conf("stop_bits", stop_bits)
|
|
||||||
my_rig.set_conf("data_bits", data_bits)
|
|
||||||
|
|
||||||
if pttprotocol == 'RIG':
|
hamlib = rig.radio()
|
||||||
hamlib_ptt_type = Hamlib.RIG_PTT_RIG
|
hamlib.open_rig(devicename=devicename, deviceport=deviceport, hamlib_ptt_type=pttprotocol, serialspeed=serialspeed)
|
||||||
|
|
||||||
elif pttprotocol == 'DTR-H':
|
|
||||||
hamlib_ptt_type = Hamlib.RIG_PTT_SERIAL_DTR
|
|
||||||
my_rig.set_conf("dtr_state", "HIGH")
|
|
||||||
my_rig.set_conf("ptt_type", "DTR")
|
|
||||||
|
|
||||||
elif pttprotocol == 'DTR-L':
|
|
||||||
hamlib_ptt_type = Hamlib.RIG_PTT_SERIAL_DTR
|
|
||||||
my_rig.set_conf("dtr_state", "LOW")
|
|
||||||
my_rig.set_conf("ptt_type", "DTR")
|
|
||||||
|
|
||||||
elif pttprotocol == 'RTS':
|
|
||||||
hamlib_ptt_type = Hamlib.RIG_PTT_SERIAL_RTS
|
|
||||||
my_rig.set_conf("dtr_state", "OFF")
|
|
||||||
my_rig.set_conf("ptt_type", "RTS")
|
|
||||||
|
|
||||||
elif pttprotocol == 'PARALLEL':
|
|
||||||
hamlib_ptt_type = Hamlib.RIG_PTT_PARALLEL
|
|
||||||
|
|
||||||
elif pttprotocol == 'MICDATA':
|
|
||||||
hamlib_ptt_type = Hamlib.RIG_PTT_RIG_MICDATA
|
|
||||||
|
|
||||||
elif pttprotocol == 'CM108':
|
|
||||||
hamlib_ptt_type = Hamlib.RIG_PTT_CM108
|
|
||||||
|
|
||||||
else: # static.HAMLIB_PTT_TYPE == 'RIG_PTT_NONE':
|
|
||||||
hamlib_ptt_type = Hamlib.RIG_PTT_NONE
|
|
||||||
|
|
||||||
|
hamlib.set_ptt(True)
|
||||||
my_rig.open()
|
pttstate = hamlib.get_rig_data()[3]
|
||||||
|
if pttstate:
|
||||||
try:
|
|
||||||
# lets determine the error message when opening rig
|
|
||||||
error = str(Hamlib.rigerror(my_rig.error_status)).splitlines()
|
|
||||||
error = error[1].split('err=')
|
|
||||||
error = error[1]
|
|
||||||
|
|
||||||
if error == 'Permission denied':
|
|
||||||
structlog.get_logger("structlog").error("[DMN] Hamlib has no permissions", e = error)
|
|
||||||
help_url = 'https://github.com/DJ2LS/FreeDATA/wiki/UBUNTU-Manual-installation#1-permissions'
|
|
||||||
structlog.get_logger("structlog").error("[DMN] HELP:", check = help_url)
|
|
||||||
except:
|
|
||||||
structlog.get_logger("structlog").info("[DMN] Hamlib device openend", status='SUCCESS')
|
|
||||||
|
|
||||||
my_rig.set_ptt(hamlib_ptt_type, 1)
|
|
||||||
pttstate = my_rig.get_ptt()
|
|
||||||
if pttstate == 1:
|
|
||||||
structlog.get_logger("structlog").info("[DMN] Hamlib PTT", status = 'SUCCESS')
|
structlog.get_logger("structlog").info("[DMN] Hamlib PTT", status = 'SUCCESS')
|
||||||
data = {'COMMAND': 'TEST_HAMLIB', 'RESULT': 'SUCCESS'}
|
data = {'COMMAND': 'TEST_HAMLIB', 'RESULT': 'SUCCESS'}
|
||||||
elif pttstate == 0:
|
elif not pttstate:
|
||||||
structlog.get_logger("structlog").warning("[DMN] Hamlib PTT", status = 'NO SUCCESS')
|
structlog.get_logger("structlog").warning("[DMN] Hamlib PTT", status = 'NO SUCCESS')
|
||||||
data = {'COMMAND': 'TEST_HAMLIB', 'RESULT': 'NOSUCCESS'}
|
data = {'COMMAND': 'TEST_HAMLIB', 'RESULT': 'NOSUCCESS'}
|
||||||
else:
|
else:
|
||||||
structlog.get_logger("structlog").error("[DMN] Hamlib PTT", status = 'FAILED')
|
structlog.get_logger("structlog").error("[DMN] Hamlib PTT", status = 'FAILED')
|
||||||
data = {'COMMAND': 'TEST_HAMLIB', 'RESULT': 'FAILED'}
|
data = {'COMMAND': 'TEST_HAMLIB', 'RESULT': 'FAILED'}
|
||||||
|
|
||||||
my_rig.set_ptt(hamlib_ptt_type, 0)
|
hamlib.set_ptt(False)
|
||||||
my_rig.close
|
hamlib.close_rig()
|
||||||
|
|
||||||
jsondata = json.dumps(data)
|
jsondata = json.dumps(data)
|
||||||
self.request.sendall(bytes(jsondata, encoding))
|
self.request.sendall(bytes(jsondata, encoding))
|
||||||
|
|
||||||
|
|
19
tnc/rig.py
19
tnc/rig.py
|
@ -103,6 +103,22 @@ class radio:
|
||||||
|
|
||||||
self.my_rig.open()
|
self.my_rig.open()
|
||||||
atexit.register(self.my_rig.close)
|
atexit.register(self.my_rig.close)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# lets determine the error message when opening rig
|
||||||
|
error = str(Hamlib.rigerror(my_rig.error_status)).splitlines()
|
||||||
|
error = error[1].split('err=')
|
||||||
|
error = error[1]
|
||||||
|
|
||||||
|
if error == 'Permission denied':
|
||||||
|
structlog.get_logger("structlog").error("[DMN] Hamlib has no permissions", e = error)
|
||||||
|
help_url = 'https://github.com/DJ2LS/FreeDATA/wiki/UBUNTU-Manual-installation#1-permissions'
|
||||||
|
structlog.get_logger("structlog").error("[DMN] HELP:", check = help_url)
|
||||||
|
except:
|
||||||
|
structlog.get_logger("structlog").info("[DMN] Hamlib device openend", status='SUCCESS')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# set rig mode to USB
|
# set rig mode to USB
|
||||||
self.my_rig.set_mode(Hamlib.RIG_MODE_USB)
|
self.my_rig.set_mode(Hamlib.RIG_MODE_USB)
|
||||||
|
@ -134,3 +150,6 @@ class radio:
|
||||||
else:
|
else:
|
||||||
self.my_rig.set_ptt(self.hamlib_ptt_type, 0)
|
self.my_rig.set_ptt(self.hamlib_ptt_type, 0)
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
def close_rig(self):
|
||||||
|
self.my_rig.close()
|
||||||
|
|
Loading…
Reference in a new issue