attempt to run socket commands as threats

asyncio seems to be blocking
This commit is contained in:
DJ2LS 2021-07-19 21:00:46 +02:00 committed by GitHub
parent 37fe94fc98
commit b4f822ea6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 9 deletions

View file

@ -523,6 +523,10 @@ def open_dc_and_transmit(data_out, mode, n_frames):
#on a new transmission we reset the timer
static.ARQ_START_OF_TRANSMISSION = int(time.time())
# lets wait a little bit so RX station is ready for receiving
wait_before_data_timer = time.time() + 0.5
while time.time() < wait_before_data_timer:
pass
# lets wait a little bit
#time.sleep(5)
@ -634,7 +638,8 @@ def arq_received_channel_is_open(data_in):
# PING HANDLER
# ############################################################################################################
async def transmit_ping(callsign):
#async def transmit_ping(callsign):
def transmit_ping(callsign):
static.DXCALLSIGN = bytes(callsign, 'utf-8').rstrip(b'\x00')
static.DXCALLSIGN_CRC8 = helpers.get_crc_8(static.DXCALLSIGN)
logging.info("PING [" + str(static.MYCALLSIGN, 'utf-8') + "] >>> [" + str(static.DXCALLSIGN, 'utf-8') + "] [SNR:" + str(static.SNR) + "]")
@ -687,7 +692,8 @@ def received_ping_ack(data_in):
# ############################################################################################################
async def transmit_cq():
#async def transmit_cq():
def transmit_cq():
logging.info("CQ CQ CQ")
cq_frame = bytearray(14)

View file

@ -24,7 +24,7 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
print("Client connected...")
# loop through socket buffer until timeout is reached. then close buffer
socketTimeout = time.time() + 3
socketTimeout = time.time() + 10
while socketTimeout > time.time():
time.sleep(0.01)
@ -50,9 +50,10 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
try:
received_json = json.loads(data)
#print(received_json)
print(received_json)
except:
received_json = ''
# GET COMMANDS
@ -80,16 +81,21 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
# CQ CQ CQ -----------------------------------------------------
#if data == 'CQCQCQ':
if received_json["command"] == "CQCQCQ":
asyncio.run(data_handler.transmit_cq())
socketTimeout = 0
#asyncio.run(data_handler.transmit_cq())
CQ_THREAD = threading.Thread(target=data_handler.transmit_cq, args=[], name="CQ")
CQ_THREAD.start()
# PING ----------------------------------------------------------
#if data.startswith('PING:'):
if received_json["command"] == "PING":
if received_json["type"] == 'PING' and received_json["command"] == "PING":
# send ping frame and wait for ACK
print(received_json)
dxcallsign = received_json["dxcallsign"]
asyncio.run(data_handler.transmit_ping(dxcallsign))
#asyncio.run(data_handler.transmit_ping(dxcallsign))
PING_THREAD = threading.Thread(target=data_handler.transmit_ping, args=[dxcallsign], name="CQ")
PING_THREAD.start()
# ARQ CONNECT TO CALLSIGN ----------------------------------------
#if data.startswith('ARQ:CONNECT:'):
#if received_json["command"] == "ARQ:CONNECT":