mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
first async / non block transmission
really ugly at this point. we need a lot of code cleanup.
This commit is contained in:
parent
65ec771133
commit
2c120065f5
3 changed files with 69 additions and 21 deletions
|
@ -661,7 +661,7 @@ def arq_disconnect_received(data_in):
|
||||||
# PING HANDLER
|
# PING HANDLER
|
||||||
#############################################################################################################
|
#############################################################################################################
|
||||||
|
|
||||||
def transmit_ping(callsign):
|
async def transmit_ping(callsign):
|
||||||
static.DXCALLSIGN = bytes(callsign, 'utf-8')
|
static.DXCALLSIGN = bytes(callsign, 'utf-8')
|
||||||
static.DXCALLSIGN_CRC8 = helpers.get_crc_8(static.DXCALLSIGN)
|
static.DXCALLSIGN_CRC8 = helpers.get_crc_8(static.DXCALLSIGN)
|
||||||
logging.info("PING ["+ str(static.MYCALLSIGN, 'utf-8') + "] >>> [" + str(static.DXCALLSIGN, 'utf-8') + "] [BER."+str(static.BER)+"]")
|
logging.info("PING ["+ str(static.MYCALLSIGN, 'utf-8') + "] >>> [" + str(static.DXCALLSIGN, 'utf-8') + "] [BER."+str(static.BER)+"]")
|
||||||
|
|
45
modem.py
45
modem.py
|
@ -54,6 +54,9 @@ class RF():
|
||||||
output=True,
|
output=True,
|
||||||
output_device_index=static.AUDIO_OUTPUT_DEVICE, #static.AUDIO_OUTPUT_DEVICE
|
output_device_index=static.AUDIO_OUTPUT_DEVICE, #static.AUDIO_OUTPUT_DEVICE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
self.streambuffer = bytes(2)
|
||||||
#--------------------------------------------START DECODER THREAD
|
#--------------------------------------------START DECODER THREAD
|
||||||
FREEDV_DECODER_THREAD_10 = threading.Thread(target=self.receive, args=[10], name="FREEDV_DECODER_THREAD_10")
|
FREEDV_DECODER_THREAD_10 = threading.Thread(target=self.receive, args=[10], name="FREEDV_DECODER_THREAD_10")
|
||||||
FREEDV_DECODER_THREAD_10.start()
|
FREEDV_DECODER_THREAD_10.start()
|
||||||
|
@ -67,6 +70,9 @@ class RF():
|
||||||
FREEDV_DECODER_THREAD_14 = threading.Thread(target=self.receive, args=[static.FREEDV_SIGNALLING_MODE], name="FREEDV_DECODER_THREAD_14")
|
FREEDV_DECODER_THREAD_14 = threading.Thread(target=self.receive, args=[static.FREEDV_SIGNALLING_MODE], name="FREEDV_DECODER_THREAD_14")
|
||||||
FREEDV_DECODER_THREAD_14.start()
|
FREEDV_DECODER_THREAD_14.start()
|
||||||
|
|
||||||
|
FREEDV_PLAYBACK_THREAD = threading.Thread(target=self.play_audio, name="FREEDV_DECODER_THREAD_14")
|
||||||
|
FREEDV_PLAYBACK_THREAD.start()
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------------------CONFIGURE HAMLIB
|
#--------------------------------------------CONFIGURE HAMLIB
|
||||||
Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE)
|
Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE)
|
||||||
|
@ -78,6 +84,7 @@ class RF():
|
||||||
self.my_rig.open ()
|
self.my_rig.open ()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if static.HAMLIB_PTT_TYPE == 'RIG_PTT_RIG':
|
if static.HAMLIB_PTT_TYPE == 'RIG_PTT_RIG':
|
||||||
self.hamlib_ptt_type = Hamlib.RIG_PTT_RIG
|
self.hamlib_ptt_type = Hamlib.RIG_PTT_RIG
|
||||||
elif static.HAMLIB_PTT_TYPE == 'RIG_PTT_SERIAL_DTR':
|
elif static.HAMLIB_PTT_TYPE == 'RIG_PTT_SERIAL_DTR':
|
||||||
|
@ -95,8 +102,28 @@ class RF():
|
||||||
|
|
||||||
self.my_rig.set_ptt(self.hamlib_ptt_type,0)
|
self.my_rig.set_ptt(self.hamlib_ptt_type,0)
|
||||||
|
|
||||||
|
|
||||||
|
def play_audio(self):
|
||||||
|
|
||||||
|
while True:
|
||||||
|
time.sleep(0.11)
|
||||||
|
state_before_transmit = static.CHANNEL_STATE
|
||||||
|
#print(len(self.streambuffer))
|
||||||
|
#print(bytes(self.streambuffer))
|
||||||
|
#print(static.CHANNEL_STATE)
|
||||||
|
|
||||||
|
#print(len(self.streambuffer))
|
||||||
|
while len(self.streambuffer) > 0:
|
||||||
|
static.CHANNEL_STATE = 'SENDING_SIGNALLING'
|
||||||
|
if len(self.streambuffer) > 0:
|
||||||
|
print("test")
|
||||||
|
print(len(self.streambuffer))
|
||||||
|
self.stream_tx.write(self.streambuffer)
|
||||||
|
time.sleep(0.1)
|
||||||
|
self.streambuffer = bytes(0)
|
||||||
|
static.CHANNEL_STATE = state_before_transmit
|
||||||
#--------------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------------
|
||||||
def transmit_signalling(self,ack_buffer):
|
def transmit_signalling(self,data_out):
|
||||||
|
|
||||||
state_before_transmit = static.CHANNEL_STATE
|
state_before_transmit = static.CHANNEL_STATE
|
||||||
static.CHANNEL_STATE = 'SENDING_SIGNALLING'
|
static.CHANNEL_STATE = 'SENDING_SIGNALLING'
|
||||||
|
@ -117,7 +144,7 @@ class RF():
|
||||||
mod_out_preamble = mod_out_preamble()
|
mod_out_preamble = mod_out_preamble()
|
||||||
|
|
||||||
buffer = bytearray(payload_per_frame) # use this if CRC16 checksum is required ( DATA1-3)
|
buffer = bytearray(payload_per_frame) # use this if CRC16 checksum is required ( DATA1-3)
|
||||||
buffer[:len(ack_buffer)] = ack_buffer # set buffersize to length of data which will be send
|
buffer[:len(data_out)] = data_out # set buffersize to length of data which will be send
|
||||||
|
|
||||||
crc = ctypes.c_ushort(self.c_lib.freedv_gen_crc16(bytes(buffer), payload_per_frame)) # generate CRC16
|
crc = ctypes.c_ushort(self.c_lib.freedv_gen_crc16(bytes(buffer), payload_per_frame)) # generate CRC16
|
||||||
crc = crc.value.to_bytes(2, byteorder='big') # convert crc to 2 byte hex string
|
crc = crc.value.to_bytes(2, byteorder='big') # convert crc to 2 byte hex string
|
||||||
|
@ -126,20 +153,25 @@ class RF():
|
||||||
|
|
||||||
self.c_lib.freedv_rawdatapreambletx(freedv, mod_out_preamble)
|
self.c_lib.freedv_rawdatapreambletx(freedv, mod_out_preamble)
|
||||||
self.c_lib.freedv_rawdatatx(freedv,mod_out,data) # modulate DATA and safe it into mod_out pointer
|
self.c_lib.freedv_rawdatatx(freedv,mod_out,data) # modulate DATA and safe it into mod_out pointer
|
||||||
|
|
||||||
txbuffer = bytearray()
|
txbuffer = bytearray()
|
||||||
txbuffer += bytes(mod_out_preamble)
|
txbuffer += bytes(mod_out_preamble)
|
||||||
txbuffer += bytes(mod_out)
|
txbuffer += bytes(mod_out)
|
||||||
|
|
||||||
# -------------- transmit audio
|
# -------------- transmit audio
|
||||||
logging.debug("SENDING SIGNALLING FRAME " + str(ack_buffer))
|
logging.debug("SENDING SIGNALLING FRAME " + str(data_out))
|
||||||
self.stream_tx.write(bytes(txbuffer))
|
#asyncio.run(self.stream_tx.write(bytes(txbuffer)))
|
||||||
|
#self.stream_tx.write(bytes(txbuffer))
|
||||||
|
self.streambuffer = bytes()
|
||||||
|
self.streambuffer = bytes(txbuffer)
|
||||||
|
#print(self.streambuffer)
|
||||||
|
#print(len(self.streambuffer))
|
||||||
self.my_rig.set_ptt(self.hamlib_ptt_type,0)
|
self.my_rig.set_ptt(self.hamlib_ptt_type,0)
|
||||||
static.PTT_STATE = False
|
static.PTT_STATE = False
|
||||||
static.CHANNEL_STATE = state_before_transmit
|
static.CHANNEL_STATE = state_before_transmit
|
||||||
|
|
||||||
self.c_lib.freedv_close(freedv)
|
self.c_lib.freedv_close(freedv)
|
||||||
time.sleep(0.5)
|
#time.sleep(0.5)
|
||||||
#--------------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------------
|
||||||
# GET ARQ BURST FRAME VOM BUFFER AND MODULATE IT
|
# GET ARQ BURST FRAME VOM BUFFER AND MODULATE IT
|
||||||
async def transmit_arq_burst(self):
|
async def transmit_arq_burst(self):
|
||||||
|
@ -317,7 +349,6 @@ class RF():
|
||||||
#self.c_lib.freedv_set_sync(freedv, 0)
|
#self.c_lib.freedv_set_sync(freedv, 0)
|
||||||
logging.warning("MODEM | SYNC 10 TRIGGER | M:" + str(mode) + " | " + str(static.CHANNEL_STATE))
|
logging.warning("MODEM | SYNC 10 TRIGGER | M:" + str(mode) + " | " + str(static.CHANNEL_STATE))
|
||||||
|
|
||||||
|
|
||||||
if stuck_in_sync_counter == 33 and self.c_lib.freedv_get_rx_status(freedv) == 10:
|
if stuck_in_sync_counter == 33 and self.c_lib.freedv_get_rx_status(freedv) == 10:
|
||||||
logging.critical("MODEM | stuck in sync #1")
|
logging.critical("MODEM | stuck in sync #1")
|
||||||
self.c_lib.freedv_set_sync(freedv, 0) #FORCE UNSYNC
|
self.c_lib.freedv_set_sync(freedv, 0) #FORCE UNSYNC
|
||||||
|
|
37
sock.py
37
sock.py
|
@ -20,6 +20,10 @@ import helpers
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import asyncbg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
|
|
||||||
def handle(self):
|
def handle(self):
|
||||||
|
@ -45,6 +49,7 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
# CQ CQ CQ -----------------------------------------------------
|
# CQ CQ CQ -----------------------------------------------------
|
||||||
if data == 'CQCQCQ':
|
if data == 'CQCQCQ':
|
||||||
asyncio.run(data_handler.transmit_cq())
|
asyncio.run(data_handler.transmit_cq())
|
||||||
|
#asyncio.run(asyncbg.call(data_handler.transmit_cq))
|
||||||
#######self.request.sendall(b'CALLING CQ')
|
#######self.request.sendall(b'CALLING CQ')
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,8 +58,18 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
#send ping frame and wait for ACK
|
#send ping frame and wait for ACK
|
||||||
pingcommand = data.split('PING:')
|
pingcommand = data.split('PING:')
|
||||||
dxcallsign = pingcommand[1]
|
dxcallsign = pingcommand[1]
|
||||||
data_handler.transmit_ping(dxcallsign)
|
#data_handler.transmit_ping(dxcallsign)
|
||||||
|
##loop = asyncio.get_event_loop()
|
||||||
|
##loop.create_task(data_handler.transmit_ping(dxcallsign))
|
||||||
|
##loop.run()
|
||||||
|
|
||||||
|
#asyncio.new_event_loop()
|
||||||
|
#asyncio.ensure_future(data_handler.transmit_ping(dxcallsign))
|
||||||
|
|
||||||
|
asyncio.run(data_handler.transmit_ping(dxcallsign))
|
||||||
|
|
||||||
|
#asyncio.create_task(data_handler.transmit_ping(dxcallsign))
|
||||||
|
#asyncio.run(data_handler.transmit_ping(dxcallsign))
|
||||||
|
|
||||||
# ARQ CONNECT TO CALLSIGN ----------------------------------------
|
# ARQ CONNECT TO CALLSIGN ----------------------------------------
|
||||||
if data.startswith('ARQ:CONNECT:'):
|
if data.startswith('ARQ:CONNECT:'):
|
||||||
|
@ -106,8 +121,10 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
arqdata = data.split('ARQ:')
|
arqdata = data.split('ARQ:')
|
||||||
data_out = bytes(arqdata[1], 'utf-8')
|
data_out = bytes(arqdata[1], 'utf-8')
|
||||||
|
|
||||||
asyncio.run(data_handler.arq_transmit(data_out))
|
|
||||||
|
|
||||||
|
asyncio.run(data_handler.arq_transmit(data_out))
|
||||||
|
###asyncio.run(asyncbg.call(data_handler.arq_transmit, data_out))
|
||||||
|
print("die funktion läuft weiter...")
|
||||||
#data_handler.arq_transmit(data_out)
|
#data_handler.arq_transmit(data_out)
|
||||||
#TRANSMIT_ARQ = threading.Thread(target=data_handler.transmit, args=[data_out], name="TRANSMIT_ARQ")
|
#TRANSMIT_ARQ = threading.Thread(target=data_handler.transmit, args=[data_out], name="TRANSMIT_ARQ")
|
||||||
#TRANSMIT_ARQ.start()
|
#TRANSMIT_ARQ.start()
|
||||||
|
@ -146,14 +163,14 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
if data == 'GET:DATA_STATE':
|
if data == 'GET:DATA_STATE':
|
||||||
output = {
|
output = {
|
||||||
"RX_BUFFER_LENGTH": str(len(static.RX_BUFFER)),
|
"RX_BUFFER_LENGTH": str(len(static.RX_BUFFER)),
|
||||||
"TX_N_MAX_RETRIES": static.TX_N_MAX_RETRIES,
|
"TX_N_MAX_RETRIES": str(static.TX_N_MAX_RETRIES),
|
||||||
"ARQ_TX_N_FRAMES_PER_BURST": static.ARQ_TX_N_FRAMES_PER_BURST,
|
"ARQ_TX_N_FRAMES_PER_BURST": str(static.ARQ_TX_N_FRAMES_PER_BURST),
|
||||||
"ARQ_TX_N_BURSTS": static.ARQ_TX_N_BURSTS,
|
"ARQ_TX_N_BURSTS": str(static.ARQ_TX_N_BURSTS),
|
||||||
"ARQ_TX_N_CURRENT_ARQ_FRAME": static.ARQ_TX_N_CURRENT_ARQ_FRAME,
|
"ARQ_TX_N_CURRENT_ARQ_FRAME": str(static.ARQ_TX_N_CURRENT_ARQ_FRAME),
|
||||||
"ARQ_TX_N_TOTAL_ARQ_FRAMES": static.ARQ_TX_N_TOTAL_ARQ_FRAMES,
|
"ARQ_TX_N_TOTAL_ARQ_FRAMES": str(static.ARQ_TX_N_TOTAL_ARQ_FRAMES),
|
||||||
"ARQ_RX_FRAME_N_BURSTS": static.ARQ_RX_FRAME_N_BURSTS,
|
"ARQ_RX_FRAME_N_BURSTS": str(static.ARQ_RX_FRAME_N_BURSTS),
|
||||||
"ARQ_RX_N_CURRENT_ARQ_FRAME": static.ARQ_RX_N_CURRENT_ARQ_FRAME,
|
"ARQ_RX_N_CURRENT_ARQ_FRAME": str(static.ARQ_RX_N_CURRENT_ARQ_FRAME),
|
||||||
"ARQ_N_ARQ_FRAMES_PER_DATA_FRAME": static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME
|
"ARQ_N_ARQ_FRAMES_PER_DATA_FRAME": str(static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME )
|
||||||
}
|
}
|
||||||
jsondata = json.dumps(output)
|
jsondata = json.dumps(output)
|
||||||
self.request.sendall(bytes(jsondata, encoding))
|
self.request.sendall(bytes(jsondata, encoding))
|
||||||
|
|
Loading…
Reference in a new issue