# -*- coding: UTF-8 -*- ''' rtx - RetroText rtxModem: Modem-Funktionen by Anna Christina Naß released under GPL ''' import glob import serial import config import logging def init_modem(): """ send the modem init strings to the modem """ logging.debug("init_modem") if config.MODEM_INIT1 != "": logging.debug("sending MODEM_INIT1") glob.ser.write(bytes(config.MODEM_INIT1 + "\r", "latin-1")) rc = _serial_readline() logging.info("MODEM_INIT1: %s", rc) rc = _serial_readline() logging.info("MODEM_INIT1: %s", rc) if config.MODEM_INIT2 != "": logging.debug("sending MODEM_INIT2") glob.ser.write(bytes(config.MODEM_INIT2 + "\r", "latin-1")) rc = _serial_readline() logging.info("MODEM_INIT2: %s", rc) rc = _serial_readline() logging.info("MODEM_INIT2: %s", rc) def wait_for_caller(): """ waits for the RING of the modem and answers it """ modem_answered = False logging.debug("wait_for_caller") while not modem_answered: rc = _serial_readline() if rc.startswith(config.MODEM_RING): logging.info("modem ringing! Answering.") glob.ser.write(bytes(config.MODEM_ANSWER + "\r", "latin-1")) rc = _serial_readline() logging.info("Answer: %s", rc) rc = _serial_readline() logging.info("Answer: %s", rc) modem_answered=True else: modem_answered=False def _serial_readline(): line = "" in_byte = "" while not in_byte == b"\n": in_byte = glob.ser.read(1) #print(in_byte) line += str(in_byte, encoding="latin-1") return line