2020-12-26 10:02:14 +00:00
|
|
|
#!/usr/bin/python3
|
2020-12-23 16:48:22 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Created on Tue Dec 22 16:58:45 2020
|
|
|
|
|
|
|
|
@author: DJ2LS
|
|
|
|
|
2022-03-04 15:50:32 +00:00
|
|
|
main module for running the tnc
|
2020-12-23 16:48:22 +00:00
|
|
|
"""
|
2022-11-05 21:27:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
# run tnc self test on startup before we are doing other things
|
2022-11-06 17:37:47 +00:00
|
|
|
# import selftest
|
|
|
|
# selftest.TEST()
|
2022-11-05 21:27:33 +00:00
|
|
|
|
|
|
|
# continue if we passed the test
|
|
|
|
|
2020-12-23 17:25:50 +00:00
|
|
|
import argparse
|
2022-05-11 22:10:59 +00:00
|
|
|
import multiprocessing
|
|
|
|
import os
|
|
|
|
import signal
|
2022-01-06 21:15:14 +00:00
|
|
|
import socketserver
|
2022-05-11 22:10:59 +00:00
|
|
|
import sys
|
|
|
|
import threading
|
|
|
|
import time
|
2022-09-20 09:34:28 +00:00
|
|
|
import config
|
2022-05-11 22:10:59 +00:00
|
|
|
import data_handler
|
|
|
|
import helpers
|
2022-04-11 09:10:32 +00:00
|
|
|
import log_handler
|
|
|
|
import modem
|
2022-05-11 22:10:59 +00:00
|
|
|
import static
|
2022-05-26 01:23:30 +00:00
|
|
|
import structlog
|
2022-11-05 21:27:33 +00:00
|
|
|
import explorer
|
2022-05-26 01:23:30 +00:00
|
|
|
|
2022-06-01 00:35:35 +00:00
|
|
|
log = structlog.get_logger("main")
|
2021-11-18 18:40:22 +00:00
|
|
|
|
2022-02-16 08:11:32 +00:00
|
|
|
def signal_handler(sig, frame):
|
2022-03-04 15:50:32 +00:00
|
|
|
"""
|
|
|
|
a signal handler, which closes the network/socket when closing the application
|
|
|
|
Args:
|
|
|
|
sig: signal
|
2022-05-09 00:41:49 +00:00
|
|
|
frame:
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
Returns: system exit
|
|
|
|
|
|
|
|
"""
|
2022-05-26 01:23:30 +00:00
|
|
|
print("Closing TNC...")
|
2022-02-16 08:11:32 +00:00
|
|
|
sock.CLOSE_SIGNAL = True
|
|
|
|
sys.exit(0)
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2022-06-24 18:55:59 +00:00
|
|
|
|
2022-02-16 08:11:32 +00:00
|
|
|
signal.signal(signal.SIGINT, signal_handler)
|
|
|
|
|
2022-05-26 01:23:30 +00:00
|
|
|
if __name__ == "__main__":
|
2022-05-28 15:52:05 +00:00
|
|
|
# This is for Windows multiprocessing support
|
2022-02-17 19:45:20 +00:00
|
|
|
multiprocessing.freeze_support()
|
2021-03-12 13:14:36 +00:00
|
|
|
# --------------------------------------------GET PARAMETER INPUTS
|
2022-05-26 01:23:30 +00:00
|
|
|
PARSER = argparse.ArgumentParser(description="FreeDATA TNC")
|
2022-09-20 09:34:28 +00:00
|
|
|
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--use-config",
|
|
|
|
dest="configfile",
|
|
|
|
action="store_true",
|
|
|
|
help="Use the default config file config.ini",
|
|
|
|
)
|
2022-05-26 01:23:30 +00:00
|
|
|
PARSER.add_argument(
|
2022-09-20 09:34:28 +00:00
|
|
|
"--mycall",
|
|
|
|
dest="mycall",
|
|
|
|
default="AA0AA",
|
|
|
|
help="My callsign",
|
|
|
|
type=str
|
2022-05-26 01:23:30 +00:00
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--ssid",
|
|
|
|
dest="ssid_list",
|
|
|
|
nargs="*",
|
|
|
|
default=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
|
|
|
help="SSID list we are responding to",
|
2022-11-29 06:45:17 +00:00
|
|
|
type=int,
|
2022-05-26 01:23:30 +00:00
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
2022-09-20 09:34:28 +00:00
|
|
|
"--mygrid",
|
|
|
|
dest="mygrid",
|
|
|
|
default="JN12AA",
|
|
|
|
help="My gridsquare",
|
|
|
|
type=str
|
2022-05-26 01:23:30 +00:00
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--rx",
|
|
|
|
dest="audio_input_device",
|
|
|
|
default=0,
|
|
|
|
help="listening sound card",
|
2022-12-04 15:12:43 +00:00
|
|
|
type=str,
|
2022-05-26 01:23:30 +00:00
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--tx",
|
|
|
|
dest="audio_output_device",
|
|
|
|
default=0,
|
|
|
|
help="transmitting sound card",
|
2022-12-04 15:12:43 +00:00
|
|
|
type=str,
|
2022-05-26 01:23:30 +00:00
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--port",
|
|
|
|
dest="socket_port",
|
|
|
|
default=3000,
|
|
|
|
help="Socket port in the range of 1024-65536",
|
|
|
|
type=int,
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--deviceport",
|
|
|
|
dest="hamlib_device_port",
|
|
|
|
default="/dev/ttyUSB0",
|
|
|
|
help="Hamlib device port",
|
|
|
|
type=str,
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--devicename",
|
|
|
|
dest="hamlib_device_name",
|
|
|
|
default="2028",
|
|
|
|
help="Hamlib device name",
|
|
|
|
type=str,
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--serialspeed",
|
|
|
|
dest="hamlib_serialspeed",
|
|
|
|
choices=[1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200],
|
|
|
|
default=9600,
|
|
|
|
help="Serialspeed",
|
|
|
|
type=int,
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--pttprotocol",
|
|
|
|
dest="hamlib_ptt_type",
|
|
|
|
choices=[
|
|
|
|
"USB",
|
|
|
|
"RIG",
|
|
|
|
"RTS",
|
|
|
|
"DTR",
|
|
|
|
"CM108",
|
|
|
|
"MICDATA",
|
|
|
|
"PARALLEL",
|
|
|
|
"DTR-H",
|
|
|
|
"DTR-L",
|
|
|
|
"NONE",
|
|
|
|
],
|
|
|
|
default="USB",
|
|
|
|
help="PTT Type",
|
|
|
|
type=str,
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--pttport",
|
|
|
|
dest="hamlib_ptt_port",
|
|
|
|
default="/dev/ttyUSB0",
|
|
|
|
help="PTT Port",
|
|
|
|
type=str,
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--data_bits",
|
|
|
|
dest="hamlib_data_bits",
|
|
|
|
choices=[7, 8],
|
|
|
|
default=8,
|
|
|
|
help="Hamlib data bits",
|
|
|
|
type=int,
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--stop_bits",
|
|
|
|
dest="hamlib_stop_bits",
|
|
|
|
choices=[1, 2],
|
|
|
|
default=1,
|
|
|
|
help="Hamlib stop bits",
|
|
|
|
type=int,
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--handshake",
|
|
|
|
dest="hamlib_handshake",
|
|
|
|
default="None",
|
|
|
|
help="Hamlib handshake",
|
|
|
|
type=str,
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--radiocontrol",
|
|
|
|
dest="hamlib_radiocontrol",
|
|
|
|
choices=["disabled", "direct", "rigctl", "rigctld"],
|
|
|
|
default="disabled",
|
|
|
|
help="Set how you want to control your radio",
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--rigctld_port",
|
|
|
|
dest="rigctld_port",
|
|
|
|
default=4532,
|
|
|
|
type=int,
|
|
|
|
help="Set rigctld port",
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--rigctld_ip", dest="rigctld_ip", default="localhost", help="Set rigctld ip"
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--scatter",
|
|
|
|
dest="send_scatter",
|
|
|
|
action="store_true",
|
|
|
|
help="Send scatter information via network",
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--fft",
|
|
|
|
dest="send_fft",
|
|
|
|
action="store_true",
|
|
|
|
help="Send fft information via network",
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--500hz",
|
2022-05-30 20:40:58 +00:00
|
|
|
dest="low_bandwidth_mode",
|
2022-05-26 01:23:30 +00:00
|
|
|
action="store_true",
|
2022-05-30 20:40:58 +00:00
|
|
|
help="Enable low bandwidth mode ( 500 Hz only )",
|
2022-05-26 01:23:30 +00:00
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--fsk",
|
|
|
|
dest="enable_fsk",
|
|
|
|
action="store_true",
|
|
|
|
help="Enable FSK mode for ping, beacon and CQ",
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--qrv",
|
|
|
|
dest="enable_respond_to_cq",
|
|
|
|
action="store_true",
|
|
|
|
help="Enable sending a QRV frame if CQ received",
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--tuning_range_fmin",
|
|
|
|
dest="tuning_range_fmin",
|
|
|
|
choices=[-50.0, -100.0, -150.0, -200.0, -250.0],
|
|
|
|
default=-50.0,
|
|
|
|
help="Tuning range fmin",
|
|
|
|
type=float,
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--tuning_range_fmax",
|
|
|
|
dest="tuning_range_fmax",
|
|
|
|
choices=[50.0, 100.0, 150.0, 200.0, 250.0],
|
|
|
|
default=50.0,
|
|
|
|
help="Tuning range fmax",
|
|
|
|
type=float,
|
|
|
|
)
|
|
|
|
PARSER.add_argument(
|
|
|
|
"--tx-audio-level",
|
|
|
|
dest="tx_audio_level",
|
|
|
|
default=50,
|
|
|
|
help="Set the tx audio level at an early stage",
|
|
|
|
type=int,
|
|
|
|
)
|
2022-09-05 08:47:03 +00:00
|
|
|
PARSER.add_argument(
|
|
|
|
"--rx-buffer-size",
|
|
|
|
dest="rx_buffer_size",
|
2022-09-05 09:54:50 +00:00
|
|
|
default=16,
|
2022-09-05 08:47:03 +00:00
|
|
|
help="Set the maximum size of rx buffer.",
|
|
|
|
type=int,
|
|
|
|
)
|
2022-11-05 21:27:33 +00:00
|
|
|
PARSER.add_argument(
|
|
|
|
"--explorer",
|
|
|
|
dest="enable_explorer",
|
|
|
|
action="store_true",
|
|
|
|
help="Enable sending tnc data to https://explorer.freedata.app",
|
|
|
|
)
|
2021-03-11 17:03:48 +00:00
|
|
|
ARGS = PARSER.parse_args()
|
2022-09-20 09:34:28 +00:00
|
|
|
if ARGS.configfile:
|
|
|
|
# init config
|
|
|
|
config = config.CONFIG().read_config()
|
2022-12-04 15:22:11 +00:00
|
|
|
try:
|
2022-12-04 15:43:50 +00:00
|
|
|
# additional step for being sure our callsign is correctly
|
|
|
|
# in case we are not getting a station ssid
|
|
|
|
# then we are forcing a station ssid = 0
|
|
|
|
mycallsign = bytes(config['STATION']['mycall'], "utf-8")
|
|
|
|
mycallsign = helpers.callsign_to_bytes(mycallsign)
|
|
|
|
static.MYCALLSIGN = helpers.bytes_to_callsign(mycallsign)
|
|
|
|
static.MYCALLSIGN_CRC = helpers.get_crc_24(static.MYCALLSIGN)
|
2022-12-04 15:22:11 +00:00
|
|
|
|
2022-12-05 06:44:51 +00:00
|
|
|
static.SSID_LIST = config['STATION']['ssid_list']
|
2022-12-04 15:43:50 +00:00
|
|
|
static.MYGRID = bytes(config['STATION']['mygrid'], "utf-8")
|
|
|
|
# check if we have an int or str as device name
|
|
|
|
try:
|
|
|
|
static.AUDIO_INPUT_DEVICE = int(config['AUDIO']['rx'])
|
|
|
|
except ValueError:
|
|
|
|
static.AUDIO_INPUT_DEVICE = config['AUDIO']['rx']
|
|
|
|
try:
|
|
|
|
static.AUDIO_OUTPUT_DEVICE = int(config['AUDIO']['tx'])
|
|
|
|
except ValueError:
|
|
|
|
static.AUDIO_OUTPUT_DEVICE = config['AUDIO']['tx']
|
2022-01-05 13:15:59 +00:00
|
|
|
|
2022-12-04 15:43:50 +00:00
|
|
|
static.PORT = int(config['NETWORK']['tncport'])
|
|
|
|
# TODO: disabled because we don't need these settings anymore.
|
|
|
|
#static.HAMLIB_DEVICE_NAME = config['RADIO']['devicename']
|
|
|
|
#static.HAMLIB_DEVICE_PORT = config['RADIO']['deviceport']
|
|
|
|
#static.HAMLIB_PTT_TYPE = config['RADIO']['pttprotocol']
|
|
|
|
#static.HAMLIB_PTT_PORT = config['RADIO']['pttport']
|
|
|
|
#static.HAMLIB_SERIAL_SPEED = str(config['RADIO']['serialspeed'])
|
|
|
|
#static.HAMLIB_DATA_BITS = str(config['RADIO']['data_bits'])
|
|
|
|
#static.HAMLIB_STOP_BITS = str(config['RADIO']['stop_bits'])
|
|
|
|
#static.HAMLIB_HANDSHAKE = config['RADIO']['handshake']
|
|
|
|
static.HAMLIB_RADIOCONTROL = config['RADIO']['radiocontrol']
|
|
|
|
static.HAMLIB_RIGCTLD_IP = config['RADIO']['rigctld_ip']
|
|
|
|
static.HAMLIB_RIGCTLD_PORT = str(config['RADIO']['rigctld_port'])
|
|
|
|
static.ENABLE_SCATTER = config['TNC']['scatter']
|
|
|
|
static.ENABLE_FFT = config['TNC']['fft']
|
|
|
|
static.ENABLE_FSK = False
|
|
|
|
static.LOW_BANDWIDTH_MODE = config['TNC']['narrowband']
|
|
|
|
static.TUNING_RANGE_FMIN = float(config['TNC']['fmin'])
|
|
|
|
static.TUNING_RANGE_FMAX = float(config['TNC']['fmax'])
|
|
|
|
static.TX_AUDIO_LEVEL = config['AUDIO']['txaudiolevel']
|
|
|
|
static.RESPOND_TO_CQ = config['TNC']['qrv']
|
2022-12-07 14:52:22 +00:00
|
|
|
static.RX_BUFFER_SIZE = int(config['TNC']['rxbuffersize'])
|
2022-12-04 15:43:50 +00:00
|
|
|
static.ENABLE_EXPLORER = config['TNC']['explorer']
|
2022-12-05 14:23:03 +00:00
|
|
|
|
2022-12-04 15:43:50 +00:00
|
|
|
except KeyError as e:
|
|
|
|
log.warning("[CFG] Error reading config file near", key=str(e))
|
|
|
|
except Exception as e:
|
|
|
|
log.warning("[CFG] Error", e=e)
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2022-09-20 09:34:28 +00:00
|
|
|
else:
|
|
|
|
# additional step for being sure our callsign is correctly
|
|
|
|
# in case we are not getting a station ssid
|
|
|
|
# then we are forcing a station ssid = 0
|
2022-11-09 11:23:59 +00:00
|
|
|
try:
|
|
|
|
mycallsign = bytes(ARGS.mycall.upper(), "utf-8")
|
|
|
|
mycallsign = helpers.callsign_to_bytes(mycallsign)
|
|
|
|
static.MYCALLSIGN = helpers.bytes_to_callsign(mycallsign)
|
|
|
|
static.MYCALLSIGN_CRC = helpers.get_crc_24(static.MYCALLSIGN)
|
|
|
|
static.SSID_LIST = ARGS.ssid_list
|
2022-12-08 17:17:01 +00:00
|
|
|
# check if own ssid is always part of ssid list
|
2022-12-08 17:44:29 +00:00
|
|
|
own_ssid = int(mycallsign.split(b"-")[1])
|
2022-12-08 17:17:01 +00:00
|
|
|
if own_ssid not in static.SSID_LIST:
|
|
|
|
static.SSID_LIST.append(own_ssid)
|
|
|
|
|
2022-11-09 11:23:59 +00:00
|
|
|
static.MYGRID = bytes(ARGS.mygrid, "utf-8")
|
2022-12-04 15:22:11 +00:00
|
|
|
|
|
|
|
# check if we have an int or str as device name
|
|
|
|
try:
|
|
|
|
static.AUDIO_INPUT_DEVICE = int(ARGS.audio_input_device)
|
|
|
|
except ValueError:
|
|
|
|
static.AUDIO_INPUT_DEVICE = ARGS.audio_input_device
|
|
|
|
try:
|
|
|
|
static.AUDIO_OUTPUT_DEVICE = int(ARGS.audio_output_device)
|
|
|
|
except ValueError:
|
|
|
|
static.AUDIO_OUTPUT_DEVICE = ARGS.audio_output_device
|
|
|
|
|
2022-11-09 11:23:59 +00:00
|
|
|
static.PORT = ARGS.socket_port
|
|
|
|
static.HAMLIB_DEVICE_NAME = ARGS.hamlib_device_name
|
|
|
|
static.HAMLIB_DEVICE_PORT = ARGS.hamlib_device_port
|
|
|
|
static.HAMLIB_PTT_TYPE = ARGS.hamlib_ptt_type
|
|
|
|
static.HAMLIB_PTT_PORT = ARGS.hamlib_ptt_port
|
|
|
|
static.HAMLIB_SERIAL_SPEED = str(ARGS.hamlib_serialspeed)
|
|
|
|
static.HAMLIB_DATA_BITS = str(ARGS.hamlib_data_bits)
|
|
|
|
static.HAMLIB_STOP_BITS = str(ARGS.hamlib_stop_bits)
|
|
|
|
static.HAMLIB_HANDSHAKE = ARGS.hamlib_handshake
|
|
|
|
static.HAMLIB_RADIOCONTROL = ARGS.hamlib_radiocontrol
|
|
|
|
static.HAMLIB_RIGCTLD_IP = ARGS.rigctld_ip
|
|
|
|
static.HAMLIB_RIGCTLD_PORT = str(ARGS.rigctld_port)
|
|
|
|
static.ENABLE_SCATTER = ARGS.send_scatter
|
|
|
|
static.ENABLE_FFT = ARGS.send_fft
|
|
|
|
static.ENABLE_FSK = ARGS.enable_fsk
|
|
|
|
static.LOW_BANDWIDTH_MODE = ARGS.low_bandwidth_mode
|
|
|
|
static.TUNING_RANGE_FMIN = ARGS.tuning_range_fmin
|
|
|
|
static.TUNING_RANGE_FMAX = ARGS.tuning_range_fmax
|
|
|
|
static.TX_AUDIO_LEVEL = ARGS.tx_audio_level
|
|
|
|
static.RESPOND_TO_CQ = ARGS.enable_respond_to_cq
|
|
|
|
static.RX_BUFFER_SIZE = ARGS.rx_buffer_size
|
|
|
|
static.ENABLE_EXPLORER = ARGS.enable_explorer
|
|
|
|
except Exception as e:
|
|
|
|
log.error("[DMN] Error reading config file", exception=e)
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2021-05-13 15:11:26 +00:00
|
|
|
# we need to wait until we got all parameters from argparse first before we can load the other modules
|
2022-05-09 00:41:49 +00:00
|
|
|
import sock
|
|
|
|
|
|
|
|
# config logging
|
|
|
|
try:
|
2022-05-26 01:23:30 +00:00
|
|
|
if sys.platform == "linux":
|
|
|
|
logging_path = os.getenv("HOME") + "/.config/" + "FreeDATA/" + "tnc"
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2022-05-26 01:23:30 +00:00
|
|
|
if sys.platform == "darwin":
|
|
|
|
logging_path = (
|
|
|
|
os.getenv("HOME")
|
|
|
|
+ "/Library/"
|
|
|
|
+ "Application Support/"
|
|
|
|
+ "FreeDATA/"
|
|
|
|
+ "tnc"
|
|
|
|
)
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2022-05-26 01:23:30 +00:00
|
|
|
if sys.platform in ["win32", "win64"]:
|
|
|
|
logging_path = os.getenv("APPDATA") + "/" + "FreeDATA/" + "tnc"
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2022-02-21 16:58:44 +00:00
|
|
|
if not os.path.exists(logging_path):
|
|
|
|
os.makedirs(logging_path)
|
|
|
|
log_handler.setup_logging(logging_path)
|
2022-05-26 01:23:30 +00:00
|
|
|
except Exception as err:
|
|
|
|
log.error("[DMN] logger init error", exception=err)
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2022-05-26 01:23:30 +00:00
|
|
|
log.info(
|
|
|
|
"[TNC] Starting FreeDATA", author="DJ2LS", year="2022", version=static.VERSION
|
|
|
|
)
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2022-01-07 10:25:28 +00:00
|
|
|
# start data handler
|
|
|
|
data_handler.DATA()
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2022-01-07 10:25:28 +00:00
|
|
|
# start modem
|
|
|
|
modem = modem.RF()
|
|
|
|
|
2022-11-05 21:32:04 +00:00
|
|
|
# optionally start explorer module
|
2022-11-05 21:27:33 +00:00
|
|
|
if static.ENABLE_EXPLORER:
|
|
|
|
log.info("[EXPLORER] Publishing to https://explorer.freedata.app", state=static.ENABLE_EXPLORER)
|
|
|
|
explorer = explorer.explorer()
|
|
|
|
|
2021-03-12 13:14:36 +00:00
|
|
|
# --------------------------------------------START CMD SERVER
|
2022-01-06 21:15:14 +00:00
|
|
|
try:
|
2022-05-26 01:23:30 +00:00
|
|
|
log.info("[TNC] Starting TCP/IP socket", port=static.PORT)
|
2022-01-06 21:15:14 +00:00
|
|
|
# https://stackoverflow.com/a/16641793
|
|
|
|
socketserver.TCPServer.allow_reuse_address = True
|
2022-05-26 01:23:30 +00:00
|
|
|
cmdserver = sock.ThreadedTCPServer(
|
|
|
|
(static.HOST, static.PORT), sock.ThreadedTCPRequestHandler
|
|
|
|
)
|
2022-01-06 21:15:14 +00:00
|
|
|
server_thread = threading.Thread(target=cmdserver.serve_forever)
|
2022-02-16 08:11:32 +00:00
|
|
|
|
2022-01-06 21:15:14 +00:00
|
|
|
server_thread.daemon = True
|
|
|
|
server_thread.start()
|
|
|
|
|
2022-05-26 01:23:30 +00:00
|
|
|
except Exception as err:
|
|
|
|
log.error("[TNC] Starting TCP/IP socket failed", port=static.PORT, e=err)
|
2022-05-11 22:10:59 +00:00
|
|
|
sys.exit(1)
|
2022-05-28 02:17:15 +00:00
|
|
|
while True:
|
2022-02-17 13:25:22 +00:00
|
|
|
time.sleep(1)
|