From 556d8c7d7f855a2af2cee63896a2c4a1f3ec47af Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Tue, 15 Mar 2022 15:14:41 +0100 Subject: [PATCH] close modem if the contact not found --- main.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 9fd84ca..9f2cddd 100644 --- a/main.py +++ b/main.py @@ -19,7 +19,7 @@ from pojo.serial_modem import SerialModem from logs.AppLogging import init_logger from utils.message_receiver import MessageReceiver -OTP_TIMEOUT = 60 +OTP_TIMEOUT = 80 is_finished = False commandor = Commandor() contacts = [] @@ -50,7 +50,6 @@ def send_command(cmd: str, ser, wait_time_in_s: int = 0) -> bytes: def create_modem_for_port(port: str) -> Union[SerialModem, None]: logger.info('Initializing modem... for ' + port) # Uncomment the following line to see what the modem is doing: - init_logger() serial_modem = None try: modem = GsmModem(port) @@ -72,7 +71,7 @@ def start_to_handle_sms(serial_modem: SerialModem): serial_modem.modem.smsReceivedCallback = handle_sms global is_finished is_finished = False - serial_modem.modem.smsTextMode = False + serial_modem.modem.smsTextMode =False logger.info('Waiting for SMS message, for phone number ' + str(serial_modem.phone_number)) listen_at = time.time() while not is_finished: @@ -165,8 +164,8 @@ def read_all_the_phone_number(): def start_book(): - slot_number = 1 - slot_sum = 30 + slot_number = 13 + slot_sum = 31 for i in range(slot_number, slot_sum + 1): card_pool.reset() logger.info("will switch to " + str(i)) @@ -191,7 +190,12 @@ def start_book(): if len(contact) > 0: modem.phone_number = contact[0].phone modem.contact = contact[0] + else: + logger.info("contact not found for this ccid") + modem.modem.close() + continue if modem.contact: + logger.info("contact found for this ccid") commandor.start_page(modem.contact) start_to_handle_sms(modem) except Exception as error: