2016-05-23 16:01:04 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
'''
|
|
|
|
rtx - RetroText
|
|
|
|
v0.1
|
|
|
|
by Anna Christina Naß <acn@acn.wtf>
|
|
|
|
released under GPL
|
|
|
|
'''
|
|
|
|
|
|
|
|
from cept import *
|
|
|
|
from rtxPage import rtxPage
|
|
|
|
import glob # global variables
|
|
|
|
import config
|
|
|
|
import rtxHelpers
|
|
|
|
import rtxModem
|
2018-05-31 17:11:18 +02:00
|
|
|
import minibtx
|
2016-05-23 16:01:04 +02:00
|
|
|
|
|
|
|
import serial
|
|
|
|
import logging
|
2018-05-31 17:11:18 +02:00
|
|
|
import getopt
|
|
|
|
import sys
|
2016-05-23 16:01:04 +02:00
|
|
|
|
|
|
|
####
|
|
|
|
|
|
|
|
# configure the logging format
|
|
|
|
logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', level=config.LOGLEVEL, datefmt='%Y-%m-%d %I:%M:%S')
|
|
|
|
|
2018-05-31 17:11:18 +02:00
|
|
|
# read command line parameters
|
|
|
|
def OptionsError():
|
|
|
|
""" Fehler beim Kommandozeilenparameter """
|
|
|
|
print("Aufrufparamter:\n -d [device] -m [direct|modem|minibtx] -b [baudrate]")
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
localport = None
|
|
|
|
localmode = None
|
|
|
|
localbaud = None
|
|
|
|
|
|
|
|
try:
|
|
|
|
opts, args = getopt.gnu_getopt(sys.argv[1:], 'd:m:b:')
|
|
|
|
except getopt.GetoptError as err:
|
|
|
|
OptionsError()
|
|
|
|
|
|
|
|
for opt, arg in opts:
|
|
|
|
if opt == "-d":
|
|
|
|
localport = arg
|
|
|
|
if opt == "-m":
|
|
|
|
localmode = arg
|
|
|
|
if opt == "-b":
|
|
|
|
localbaud = arg
|
|
|
|
|
|
|
|
if localbaud:
|
|
|
|
if not localbaud.isdigit():
|
|
|
|
OptionsError()
|
|
|
|
if localmode:
|
|
|
|
if not localmode in ("direct","modem","minibtx"):
|
|
|
|
OptionsError()
|
|
|
|
|
2016-05-23 16:01:04 +02:00
|
|
|
# initialize serial connection to client
|
2018-05-31 17:11:18 +02:00
|
|
|
if localport is not None:
|
|
|
|
serport = localport
|
|
|
|
else:
|
|
|
|
serport = config.PORT
|
|
|
|
if localbaud is not None:
|
|
|
|
serbaud = localbaud
|
|
|
|
else:
|
|
|
|
serbaud = config.BAUDRATE
|
|
|
|
if localmode is not None:
|
|
|
|
glob.mode = localmode
|
|
|
|
else:
|
|
|
|
glob.mode = config.MODE
|
|
|
|
|
|
|
|
logging.debug("Serial port %s, Baud rate %s", serport, serbaud)
|
|
|
|
|
|
|
|
if glob.mode == "direct" or glob.mode == "modem":
|
|
|
|
glob.ser = serial.Serial(serport, serbaud, timeout=None, rtscts=True, dsrdtr=True)
|
|
|
|
elif glob.mode == "minibtx":
|
|
|
|
glob.ser = serial.Serial(serport, serbaud, timeout=None, bytesize=8, parity='N', stopbits=2, rtscts=False, dsrdtr=False)
|
|
|
|
else:
|
|
|
|
logging.error("wrong mode: %s - this should not happen", glob.mode)
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
#glob.ser = serial.Serial(config.PORT, config.BAUDRATE, timeout=None, rtscts=True, dsrdtr=True)
|
|
|
|
glob.ser = serial.Serial(config.PORT, config.BAUDRATE, timeout=None, bytesize=8, parity='N', stopbits=2, rtscts=False, dsrdtr=False)
|
|
|
|
|
|
|
|
logging.debug("Serial port %s opened", glob.ser.name)
|
2016-05-23 16:01:04 +02:00
|
|
|
|
|
|
|
while True:
|
2018-05-31 17:11:18 +02:00
|
|
|
if glob.mode == "modem":
|
|
|
|
rtxModem.init_modem()
|
|
|
|
rtxModem.wait_for_caller()
|
|
|
|
rtxHelpers.send_welcome_page()
|
|
|
|
|
|
|
|
# main loop to read data from client
|
|
|
|
while True:
|
|
|
|
in_byte = glob.ser.read(1)
|
2018-06-01 13:09:23 +02:00
|
|
|
|
|
|
|
if glob.mode == "minibtx":
|
|
|
|
if in_byte == b'\x01':
|
|
|
|
logging.info("miniBtx starts connection... waiting for connection...")
|
|
|
|
minibtx.wait_for_minibtx()
|
|
|
|
rtxHelpers.send_welcome_page()
|
|
|
|
break
|
|
|
|
|
2018-05-31 17:11:18 +02:00
|
|
|
rtxHelpers.process_byte(in_byte)
|
2018-06-01 13:09:23 +02:00
|
|
|
|
2018-05-31 17:11:18 +02:00
|
|
|
if glob.mode == "modem":
|
|
|
|
if glob.ser.getCD() == False:
|
2018-06-01 13:09:23 +02:00
|
|
|
logging.info("modem hangup.")
|
2018-05-31 17:11:18 +02:00
|
|
|
break
|
2016-05-23 16:01:04 +02:00
|
|
|
|
|
|
|
|