FreeDATA/tnc.py

77 lines
2.1 KiB
Python
Raw Normal View History

2020-12-12 18:59:37 +00:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 25 21:25:14 2020
2020-12-12 18:59:37 +00:00
@author: DJ2LS
"""
2020-12-12 18:59:37 +00:00
import socketserver
2020-12-23 16:48:54 +00:00
import threading
2020-12-26 18:27:09 +00:00
import logging
2020-12-12 18:59:37 +00:00
2020-12-23 16:48:54 +00:00
import static
2020-12-27 21:38:49 +00:00
import arq
2020-12-12 18:59:37 +00:00
2020-12-26 18:27:09 +00:00
2020-12-23 16:48:54 +00:00
class TCPRequestHandler(socketserver.BaseRequestHandler):
2020-12-12 18:59:37 +00:00
def handle(self):
2021-02-06 16:55:14 +00:00
self.data = bytes()
while True:
chunk = self.request.recv(8192)#.strip()
if chunk.endswith(b'\n'):
break
self.data += chunk
2020-12-23 16:48:54 +00:00
2020-12-12 18:59:37 +00:00
# self.request is the TCP socket connected to the client
2021-02-06 16:55:14 +00:00
#self.data = self.request.recv(1024).strip()
### self.data = self.request.recv(1000000).strip()
2020-12-23 16:48:54 +00:00
# interrupt listening loop "while true" by setting MODEM_RECEIVE to False
#if len(self.data) > 0:
# static.MODEM_RECEIVE = False
2020-12-23 16:48:54 +00:00
2020-12-26 18:27:09 +00:00
####print("{} wrote:".format(self.client_address[0]))
####print(self.data)
2020-12-23 16:48:54 +00:00
2020-12-12 18:59:37 +00:00
# just send back the same data, but upper-cased
2020-12-26 18:27:09 +00:00
#####self.request.sendall(self.data.upper())
2020-12-12 18:59:37 +00:00
2020-12-23 16:48:54 +00:00
#if self.data == b'TEST':
#logging.info("DER TEST KLAPPT! HIER KOMMT DER COMMAND PARSER HIN!")
2021-02-06 16:55:14 +00:00
if self.data.startswith(b'SHOWBUFFERSIZE'):
self.request.sendall(bytes(static.RX_BUFFER[-1]))
print(static.RX_BUFFER_SIZE)
2020-12-23 16:48:54 +00:00
# BROADCAST PARSER -----------------------------------------------------------
2020-12-12 18:59:37 +00:00
if self.data.startswith(b'BC:'):
2020-12-27 21:38:49 +00:00
#import modem
#modem = modem.RF()
2021-02-06 16:55:14 +00:00
2020-12-12 18:59:37 +00:00
data = self.data.split(b'BC:')
2020-12-27 21:38:49 +00:00
#modem.Transmit(data[1])
2021-02-06 16:55:14 +00:00
2020-12-27 21:38:49 +00:00
2020-12-27 21:38:49 +00:00
# SEND AN ARQ FRAME -----------------------------------------------------------
2021-02-06 16:55:14 +00:00
if self.data.startswith(b'ARQ:'):
2020-12-27 21:38:49 +00:00
2021-02-06 16:55:14 +00:00
data = self.data.split(b'ARQ:')
data_out = data[1]
2021-02-06 16:55:14 +00:00
#arq.transmit(data_out)
TRANSMIT_ARQ = threading.Thread(target=arq.transmit, args=[data_out], name="TRANSMIT_ARQ")
TRANSMIT_ARQ.start()
2021-02-06 16:55:14 +00:00