add del rx_buffer via sock

This commit is contained in:
DJ2LS 2021-02-18 15:11:37 +01:00 committed by GitHub
parent 171dc0e5a0
commit 1f1234254a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 33 deletions

15
main.py
View file

@ -31,14 +31,6 @@ if __name__ == '__main__':
# list audio devices
helpers.list_audio_devices()
#static.MYCALLSIGN = b'DJ2LS'
#static.MYCALLSIGN_CRC8 = helpers.get_crc_8(static.MYCALLSIGN)
static.DXCALLSIGN = b'DH3WO'
static.DXCALLSIGN_CRC8 = helpers.get_crc_8(static.DXCALLSIGN)
#--------------------------------------------GET PARAMETER INPUTS
@ -50,13 +42,12 @@ if __name__ == '__main__':
args = parser.parse_args()
#--------------------------------------------START CMD & DATA SERVER
static.FREEDV_DATA_MODE = args.freedv_data_mode
static.AUDIO_INPUT_DEVICE = args.audio_input_device
static.AUDIO_OUTPUT_DEVICE = args.audio_output_device
static.PORT = args.socket_port
#--------------------------------------------START CMD SERVER
import sock # we need to wait until we got all parameters from argparse
cmd_server_thread = threading.Thread(target=sock.start_cmd_socket, name="cmd server")
@ -64,5 +55,3 @@ if __name__ == '__main__':

32
sock.py
View file

@ -19,18 +19,13 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
def handle(self):
encoding = 'utf-8'
encoding = 'utf-8'
data = str(self.request.recv(1024), 'utf-8')
#cur_thread = threading.current_thread()
#response = bytes("{}: {}".format(cur_thread.name, data), 'ascii')
#self.request.sendall(response)
#print(threading.enumerate())
# SOCKETTEST
if data == 'SOCKETTEST':
cur_thread = threading.current_thread()
response = bytes("WELL DONE! YOU ARE ABLE TO COMMUNICATE WITH THE TNC ---THREAD: " + str(cur_thread), 'utf-8')
response = bytes("WELL DONE! YOU ARE ABLE TO COMMUNICATE WITH THE TNC", encoding)
self.request.sendall(response)
# TRANSMIT ARQ MESSAGE
@ -48,11 +43,13 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
# SETTINGS AND STATUS
if data.startswith('SET:MYCALLSIGN:'):
data = data.split('SET:MYCALLSIGN:')
static.MYCALLSIGN = bytes(data[1], encoding)
static.MYCALLSIGN_CRC8 = helpers.get_crc_8(static.MYCALLSIGN)
#self.request.sendall(bytes(static.MYCALLSIGN, encoding))
self.request.sendall(static.MYCALLSIGN)
logging.info("CMD | MYCALLSIGN: " + str(static.MYCALLSIGN))
if bytes(data[1], encoding) == b'':
self.request.sendall(b'INVALID CALLSIGN')
else:
static.MYCALLSIGN = bytes(data[1], encoding)
static.MYCALLSIGN_CRC8 = helpers.get_crc_8(static.MYCALLSIGN)
self.request.sendall(static.MYCALLSIGN)
logging.info("CMD | MYCALLSIGN: " + str(static.MYCALLSIGN))
if data == 'GET:MYCALLSIGN':
@ -102,21 +99,16 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
data = data.split('GET:RX_BUFFER:')
bufferposition = int(data[1])-1
print(static.RX_BUFFER)
if bufferposition == -1:
if len(static.RX_BUFFER) > 0:
self.request.sendall(static.RX_BUFFER[-1])
if bufferposition <= len(static.RX_BUFFER) > 0:
#print(static.RX_BUFFER[0])
#print(static.RX_BUFFER[1])
#print(static.RX_BUFFER[2])
#print(type(bufferposition))
#print(bufferposition)
self.request.sendall(bytes(static.RX_BUFFER[bufferposition]))
if data == 'DEL:RX_BUFFER':
static.RX_BUFFER = []