FreeDATA/tnc.py

65 lines
1.7 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):
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-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!")
# 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()
static.MODEM_RECEIVE = True ####### FALSE....
2020-12-23 16:48:54 +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])
2020-12-23 16:48:54 +00:00
static.MODEM_RECEIVE = True
2020-12-27 21:38:49 +00:00
2020-12-27 21:38:49 +00:00
# SEND AN ARQ FRAME -----------------------------------------------------------
if self.data.startswith(b'ACK:'):
static.MODEM_RECEIVE = True ############## FALSE
2020-12-27 21:38:49 +00:00
data = self.data.split(b'ACK:')
data_out = data[1]
2020-12-27 21:38:49 +00:00
arq.transmit(data_out)