FreeDATA/tnc.py

46 lines
1.2 KiB
Python
Raw Normal View History

2020-12-12 18:59:37 +00:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import socketserver
2020-12-23 16:48:54 +00:00
import threading
2020-12-12 18:59:37 +00:00
2020-12-23 16:48:54 +00:00
import modem
import static
2020-12-12 18:59:37 +00:00
2020-12-23 16:48:54 +00:00
modem = modem.RF()
2020-12-12 18:59:37 +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):
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
self.data = self.request.recv(1024).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-12 18:59:37 +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
self.request.sendall(self.data.upper())
2020-12-23 16:48:54 +00:00
#if self.data == b'TEST':
#logging.info("DER TEST KLAPPT! HIER KOMMT DER COMMAND PARSER HIN!")
# BROADCAST PARSER -----------------------------------------------------------
2020-12-12 18:59:37 +00:00
if self.data.startswith(b'BC:'):
2020-12-23 16:48:54 +00:00
static.MODEM_RECEIVE = False
print(static.MODEM_RECEIVE)
2020-12-12 18:59:37 +00:00
data = self.data.split(b'BC:')
2020-12-23 16:48:54 +00:00
daten = modem.Transmit(data[1])
static.MODEM_RECEIVE = True
print(static.MODEM_RECEIVE)