1
0
rtx/rtx.py

112 lines
2.8 KiB
Python
Raw Normal View History

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
import minibtx
2016-05-23 16:01:04 +02:00
import serial
import logging
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')
# 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
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:
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)
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
rtxHelpers.process_byte(in_byte)
if glob.mode == "modem":
if glob.ser.getCD() == False:
logging.info("modem hangup.")
break
2016-05-23 16:01:04 +02:00