close modem if the contact not found

This commit is contained in:
2022-03-15 15:14:41 +01:00
parent cae27e2e7c
commit 556d8c7d7f
+9 -5
View File
@@ -19,7 +19,7 @@ from pojo.serial_modem import SerialModem
from logs.AppLogging import init_logger from logs.AppLogging import init_logger
from utils.message_receiver import MessageReceiver from utils.message_receiver import MessageReceiver
OTP_TIMEOUT = 60 OTP_TIMEOUT = 80
is_finished = False is_finished = False
commandor = Commandor() commandor = Commandor()
contacts = [] 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]: def create_modem_for_port(port: str) -> Union[SerialModem, None]:
logger.info('Initializing modem... for ' + port) logger.info('Initializing modem... for ' + port)
# Uncomment the following line to see what the modem is doing: # Uncomment the following line to see what the modem is doing:
init_logger()
serial_modem = None serial_modem = None
try: try:
modem = GsmModem(port) modem = GsmModem(port)
@@ -72,7 +71,7 @@ def start_to_handle_sms(serial_modem: SerialModem):
serial_modem.modem.smsReceivedCallback = handle_sms serial_modem.modem.smsReceivedCallback = handle_sms
global is_finished global is_finished
is_finished = False 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)) logger.info('Waiting for SMS message, for phone number ' + str(serial_modem.phone_number))
listen_at = time.time() listen_at = time.time()
while not is_finished: while not is_finished:
@@ -165,8 +164,8 @@ def read_all_the_phone_number():
def start_book(): def start_book():
slot_number = 1 slot_number = 13
slot_sum = 30 slot_sum = 31
for i in range(slot_number, slot_sum + 1): for i in range(slot_number, slot_sum + 1):
card_pool.reset() card_pool.reset()
logger.info("will switch to " + str(i)) logger.info("will switch to " + str(i))
@@ -191,7 +190,12 @@ def start_book():
if len(contact) > 0: if len(contact) > 0:
modem.phone_number = contact[0].phone modem.phone_number = contact[0].phone
modem.contact = contact[0] modem.contact = contact[0]
else:
logger.info("contact not found for this ccid")
modem.modem.close()
continue
if modem.contact: if modem.contact:
logger.info("contact found for this ccid")
commandor.start_page(modem.contact) commandor.start_page(modem.contact)
start_to_handle_sms(modem) start_to_handle_sms(modem)
except Exception as error: except Exception as error: