From fb27299f51596ea3fbf46f78d5318272deed9c04 Mon Sep 17 00:00:00 2001 From: acn Date: Thu, 31 May 2018 17:11:18 +0200 Subject: [PATCH] neuer Modus "minibtx", reagiert auf 0x01 und 0x00 eines miniBtx bei der Anwahl --- cept.py | 4 +-- config.py | 10 +++--- glob.py | 2 ++ minibtx.py | 27 ++++++++++++++++ rtx.py | 88 +++++++++++++++++++++++++++++++++++++++++++-------- rtxHelpers.py | 2 +- rtxMask.py | 2 +- 7 files changed, 113 insertions(+), 22 deletions(-) create mode 100644 minibtx.py diff --git a/cept.py b/cept.py index 5bc8806..4ebf31c 100644 --- a/cept.py +++ b/cept.py @@ -65,7 +65,7 @@ btxlogo = ( "\x1b\x7e" # Zeichensatz G1 rechts "\x9b\x31\x40" # Farbtafel 1 (Halbtöne) "\x1b\x23\x20\x54" # ganzer Schirm blau - "\x1f\x3d1# 200961a\x1f\x2f" # Link zur Demo-Startseite 200961a + "\x1f\x3d1# 0a\x1f\x2f" # Link zur Startseite 0 "\x1f\x43\x48\xb8\xa3\x12\x57\xe4" "\x1f\x44\x47\xea\xa0\x12\x59\xb5" "\x1f\x45\x47\xea \xe0\xf8\xfc\xdf\x12\x49\xfc\xf4\xb0 \xb5" @@ -90,4 +90,4 @@ btxlogo = ( "\x87\x19\x50\x12\x67" "\x9b\x30\x40" # Farbtafel 0 "\x83Mit # fortfahren\r\n" - ) \ No newline at end of file + ) diff --git a/config.py b/config.py index c08fd3e..4dcc172 100644 --- a/config.py +++ b/config.py @@ -19,13 +19,15 @@ PAGES=[ LOGLEVEL=logging.DEBUG ## serial port settings: -PORT="/dev/pts/5" -#PORT="/dev/ttyUSB0" -BAUDRATE="2400" +#PORT="/dev/pts/5" +PORT="/dev/ttyUSB3" +BAUDRATE="1200" # if the system is connected directly (null-modem): MODE=direct # if the system is connected via a modem: MODE=modem +# if the system is connected to a miniBtx module: MODE=minibtx #MODE="modem" -MODE="direct" +#MODE="direct" +MODE="minibtx" # the init strings for the modem, sent serially at startup MODEM_INIT1="AT&F" MODEM_INIT2="AT%B1200/75%C0%E0%G1-J0\\N0&G1" diff --git a/glob.py b/glob.py index e57da05..af83b6b 100644 --- a/glob.py +++ b/glob.py @@ -13,4 +13,6 @@ from rtxPage import rtxPage cmdline = "" curpage = rtxPage() prevpage = rtxPage() # to be able to use ** to go back to last page + ser = serial.Serial() +mode = None diff --git a/minibtx.py b/minibtx.py new file mode 100644 index 0000000..973b7ab --- /dev/null +++ b/minibtx.py @@ -0,0 +1,27 @@ +# -*- coding: UTF-8 -*- +''' +rtx - RetroText +minibtx: Funktionen für das miniBtx-Modul +by Anna Christina Naß +released under GPL +''' + +import glob +import serial +import config +import logging + +MINIBTX_START = b'\x01' +MINIBTX_CONNECT = b'\x00' + +def wait_for_minibtx(): + connected = False + logging.debug("wait_for_minibtx") + while not connected: + rc = glob.ser.read(1) + logging.debug("miniBtx: >%s<", rc) + if rc == MINIBTX_START: + logging.info("miniBtx starts connection...") + if rc == MINIBTX_CONNECT: + logging.info("miniBtx connected!") + connected = True diff --git a/rtx.py b/rtx.py index cc7f22d..cb5082e 100755 --- a/rtx.py +++ b/rtx.py @@ -13,32 +13,92 @@ import glob # global variables import config import rtxHelpers import rtxModem +import minibtx import serial import logging +import getopt +import sys #### # 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() + # initialize serial connection to client -logging.debug("Serial port %s, Baud rate %s", config.PORT, config.BAUDRATE) -glob.ser = serial.Serial(config.PORT, config.BAUDRATE, timeout=None, rtscts=True, dsrdtr=True) -logging.info("Serial port %s opened", glob.ser.name) +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) while True: - if config.MODE=="modem": - rtxModem.init_modem() - rtxModem.wait_for_caller() - rtxHelpers.send_welcome_page() + if glob.mode == "modem": + rtxModem.init_modem() + rtxModem.wait_for_caller() + rtxHelpers.send_welcome_page() + elif glob.mode == "minibtx": + minibtx.wait_for_minibtx() + rtxHelpers.send_welcome_page() - # main loop to read data from client - while True: - in_byte = glob.ser.read(1) - rtxHelpers.process_byte(in_byte) - if config.MODE == "modem": - if glob.ser.getCD() == False: - break + # main loop to read data from client + while True: + in_byte = glob.ser.read(1) + rtxHelpers.process_byte(in_byte) + if glob.mode == "modem": + if glob.ser.getCD() == False: + break diff --git a/rtxHelpers.py b/rtxHelpers.py index 5ad1fc5..fd41bd0 100644 --- a/rtxHelpers.py +++ b/rtxHelpers.py @@ -21,7 +21,7 @@ def process_byte(in_byte): """ instr=str(in_byte, encoding="latin-1") - if config.MODE=="modem": + if glob.mode=="modem": logging.debug("> %s < CD: %s", instr, glob.ser.getCD()) # what to send back to the client diff --git a/rtxMask.py b/rtxMask.py index 6184213..6a8914e 100644 --- a/rtxMask.py +++ b/rtxMask.py @@ -80,7 +80,7 @@ class rtxMask: # read input and interpret it while weiter==True: # if the modem hangs up, exit the function: - #if config.MODE == "modem" and glob.ser.getCD() == False: + #if glob.mode == "modem" and glob.ser.getCD() == False: # weiter=False in_byte = glob.ser.read(1) instr = str(in_byte, encoding="latin-1")