1
0
rtx/rtxModem.py
2016-06-01 17:14:09 +02:00

63 lines
1.6 KiB
Python

# -*- coding: UTF-8 -*-
'''
rtx - RetroText
rtxModem: Modem-Funktionen
by Anna Christina Naß <acn@acn.wtf>
released under GPL
'''
import glob
import serial
import config
import logging
def init_modem():
logging.debug("clearing input/output buffers")
glob.ser.reset_input_buffer()
glob.ser.reset_output_buffer()
""" 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