2016-05-23 16:01:04 +02:00
|
|
|
# -*- 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():
|
2016-06-02 16:49:43 +02:00
|
|
|
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)
|
2016-05-23 16:01:04 +02:00
|
|
|
|
2016-06-02 16:49:43 +02:00
|
|
|
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)
|
2016-05-23 16:01:04 +02:00
|
|
|
|
|
|
|
def wait_for_caller():
|
2016-06-02 16:49:43 +02:00
|
|
|
""" 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
|
2016-05-23 16:01:04 +02:00
|
|
|
|
|
|
|
def _serial_readline():
|
2016-06-02 16:49:43 +02:00
|
|
|
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")
|
2016-05-23 16:01:04 +02:00
|
|
|
|
2016-06-02 16:49:43 +02:00
|
|
|
return line
|