return states as json

This commit is contained in:
DJ2LS 2021-03-08 10:49:50 +01:00 committed by GitHub
parent ad1bdfced9
commit 48cf553f77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

80
sock.py
View file

@ -10,6 +10,7 @@ import socketserver
import threading import threading
import logging import logging
import time import time
import json
import static import static
import data_handler import data_handler
@ -43,8 +44,8 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
# CQ CQ CQ ----------------------------------------------------- # CQ CQ CQ -----------------------------------------------------
if data == 'CQCQCQ': if data == 'CQCQCQ':
for i in range(0,3): for i in range(0,3):
data_handler.transmit_cq() asyncio.run(data_handler.transmit_cq())
self.request.sendall(bytes("CALLING CQ")) #self.request.sendall(bytes("CALLING CQ"))
while static.ARQ_STATE == 'SENDING_SIGNALLING': while static.ARQ_STATE == 'SENDING_SIGNALLING':
time.sleep(0.1) time.sleep(0.1)
pass pass
@ -90,10 +91,10 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
# TRANSMIT ARQ MESSAGE ------------------------------------------ # TRANSMIT ARQ MESSAGE ------------------------------------------
# wen need to change the TNC_STATE to "CONNECTE" and need to make sure we have a valid callsign and callsign crc8 of the DX station # wen need to change the TNC_STATE to "CONNECTE" and need to make sure we have a valid callsign and callsign crc8 of the DX station
#print(static.ARQ_STATE) #print(static.ARQ_STATE)
if data.startswith('ARQ:DATA') and static.ARQ_STATE == 'CONNECTED': if data.startswith('ARQ:DATA:') and static.ARQ_STATE == 'CONNECTED':
static.ARQ_READY_FOR_DATA = False static.ARQ_READY_FOR_DATA = False
logging.info("CMD | NEW ARQ DATA") logging.info("CMD | NEW ARQ DATA")
self.request.sendall(b'SENDIN ARQ DATA') self.request.sendall(b'SENDING ARQ DATA')
asyncio.run(data_handler.arq_open_data_channel()) asyncio.run(data_handler.arq_open_data_channel())
#data_handler.arq_open_data_channel() #data_handler.arq_open_data_channel()
@ -126,56 +127,43 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
static.MYCALLSIGN_CRC8 = helpers.get_crc_8(static.MYCALLSIGN) static.MYCALLSIGN_CRC8 = helpers.get_crc_8(static.MYCALLSIGN)
self.request.sendall(static.MYCALLSIGN) self.request.sendall(static.MYCALLSIGN)
logging.info("CMD | MYCALLSIGN: " + str(static.MYCALLSIGN)) logging.info("CMD | MYCALLSIGN: " + str(static.MYCALLSIGN))
if data == 'GET:MYCALLSIGN': if data == 'GET:MYCALLSIGN':
self.request.sendall(bytes(static.MYCALLSIGN, encoding)) self.request.sendall(bytes(static.MYCALLSIGN, encoding))
if data == 'GET:MYCALLSIGN_CRC8': #if data == 'GET:MYCALLSIGN_CRC8':
self.request.sendall(bytes(static.MYCALLSIGN_CRC8, encoding)) # self.request.sendall(bytes(static.MYCALLSIGN_CRC8, encoding))
if data == 'GET:DXCALLSIGN': if data == 'GET:DXCALLSIGN':
self.request.sendall(bytes(static.DXCALLSIGN, encoding)) self.request.sendall(bytes(static.DXCALLSIGN, encoding))
if data == 'GET:TNC_STATE': if data == 'GET:TNC_STATE':
self.request.sendall(static.TNC_STATE) output = {
"PTT_STATE": str(static.PTT_STATE),
if data == 'GET:PTT_STATE': "CHANNEL_STATE": static.CHANNEL_STATE,
self.request.sendall(bytes(str(static.PTT_STATE), encoding)) "TNC_STATE": static.TNC_STATE,
"ARQ_STATE": static.ARQ_STATE
# ARQ }
if data == 'GET:ARQ_STATE': jsondata = json.dumps(output)
self.request.sendall(bytes(static.ARQ_STATE, encoding)) self.request.sendall(bytes(jsondata, encoding))
if data == 'GET:TX_N_MAX_RETRIES': if data == 'GET:DATA_STATE':
self.request.sendall(bytes([static.TX_N_MAX_RETRIES], encoding)) output = {
"RX_BUFFER_LENGTH": str(len(static.RX_BUFFER)),
if data == 'GET:TX_N_RETRIES': "TX_N_MAX_RETRIES": static.TX_N_MAX_RETRIES,
self.request.sendall(bytes([static.TX_N_RETRIES], encoding)) "ARQ_TX_N_FRAMES_PER_BURST": static.ARQ_TX_N_FRAMES_PER_BURST,
"ARQ_TX_N_BURSTS": static.ARQ_TX_N_BURSTS,
if data == 'GET:ARQ_TX_N_FRAMES_PER_BURST': "ARQ_TX_N_CURRENT_ARQ_FRAME": static.ARQ_TX_N_CURRENT_ARQ_FRAME,
self.request.sendall(bytes([static.ARQ_TX_N_FRAMES_PER_BURST], encoding)) "ARQ_TX_N_TOTAL_ARQ_FRAMES": static.ARQ_TX_N_TOTAL_ARQ_FRAMES,
"ARQ_RX_FRAME_N_BURSTS": static.ARQ_RX_FRAME_N_BURSTS,
if data == 'GET:ARQ_TX_N_BURSTS': "ARQ_RX_N_CURRENT_ARQ_FRAME": static.ARQ_RX_N_CURRENT_ARQ_FRAME,
self.request.sendall(bytes([static.ARQ_TX_N_BURSTS], encoding)) "ARQ_N_ARQ_FRAMES_PER_DATA_FRAME": static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME
}
if data == 'GET:ARQ_TX_N_CURRENT_ARQ_FRAME': jsondata = json.dumps(output)
self.request.sendall(bytes([static.ARQ_TX_N_CURRENT_ARQ_FRAME], encoding)) self.request.sendall(bytes(jsondata, encoding))
if data == 'GET:ARQ_TX_N_TOTAL_ARQ_FRAMES':
self.request.sendall(bytes([static.ARQ_TX_N_TOTAL_ARQ_FRAMES], encoding))
if data == 'GET:ARQ_RX_FRAME_N_BURSTS':
self.request.sendall(bytes([static.ARQ_RX_FRAME_N_BURSTS], encoding))
if data == 'GET:ARQ_RX_N_CURRENT_ARQ_FRAME':
self.request.sendall(bytes([static.ARQ_RX_N_CURRENT_ARQ_FRAME], encoding))
if data == 'GET:ARQ_N_ARQ_FRAMES_PER_DATA_FRAME':
self.request.sendall(bytes([static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME], encoding))
if data == 'GET:RX_BUFFER_LENGTH':
self.request.sendall(bytes(str(len(static.RX_BUFFER)),encoding))
if data.startswith('GET:RX_BUFFER:'): if data.startswith('GET:RX_BUFFER:'):