try to init modem one by one

This commit is contained in:
2022-03-03 13:08:31 +01:00
parent db82f042a0
commit f4c6528c5e
2 changed files with 25 additions and 21 deletions
+18 -21
View File
@@ -22,6 +22,7 @@ BAUDRATE = 115200
OTP_TIMEOUT = 70 OTP_TIMEOUT = 70
is_finished = False is_finished = False
commandor = Commandor() commandor = Commandor()
contacts = []
card_pool = CardPool(CARD_POOL_PORT) card_pool = CardPool(CARD_POOL_PORT)
@@ -69,16 +70,12 @@ def create_modem_for_port(port: str) -> Union[SerialModem, None]:
serial_modem = None serial_modem = None
try: try:
modem = GsmModem(port) modem = GsmModem(port)
time.sleep(1) # time.sleep(1)
modem.connect() # modem.connect()
number = modem.ownNumber # number = modem.ownNumber
logger.info("The SIM card phone number is:") # logger.info("The SIM card phone number is:")
logger.info(number) # logger.info(number)
cmd = "AT+CCID\r" return SerialModem(modem=modem)
response = modem.write(cmd, True)
ccid = response[0].split(" ")[1].replace("\"", "")
logger.info("The SIM card ccid is:" + ccid)
return SerialModem(modem=modem, ccid=ccid)
except Exception as ext: except Exception as ext:
print(ext) print(ext)
return serial_modem return serial_modem
@@ -140,16 +137,6 @@ def init_modems() -> list:
serial_modem = create_modem_for_port(port) serial_modem = create_modem_for_port(port)
if serial_modem: if serial_modem:
modems.append(serial_modem) modems.append(serial_modem)
# read the contact, and contact the 2 objects together
excel_reader = ExcelHelper()
contacts = excel_reader.read_contacts()
for index, modem in enumerate(modems):
contact = [contact for contact in contacts if contact.ccid == modem.ccid]
if len(contact) > 0:
modem.phone_number = contact[0].phone
modem.contact = contact[0]
else:
logger.info("contact not found for {}, position:{}".format(modem.ccid, index + 1))
return modems return modems
@@ -196,7 +183,17 @@ def start_book():
modem_pool.reset_all_modems() modem_pool.reset_all_modems()
modem_list = init_modems() modem_list = init_modems()
# create listeners for chaque modem # create listeners for chaque modem
for modem in modem_list: # read the contact, and contact the 2 objects together
excel_reader = ExcelHelper()
global contacts
contacts = excel_reader.read_contacts()
for index, modem in modem_list:
# get contact for current modem
modem.get_ccid()
contact = [contact for contact in contacts if contact.ccid == modem.ccid]
if len(contact) > 0:
modem.phone_number = contact[0].phone
modem.contact = contact[0]
if modem.contact: if modem.contact:
commandor.start_page(modem.contact) commandor.start_page(modem.contact)
start_to_handle_sms(modem) start_to_handle_sms(modem)
+7
View File
@@ -13,3 +13,10 @@ class SerialModem():
def __init__(self, modem: GsmModem, ccid: str = None): def __init__(self, modem: GsmModem, ccid: str = None):
self.modem = modem self.modem = modem
self.ccid = ccid self.ccid = ccid
def get_ccid(self):
cmd = "AT+CCID\r"
self.modem.connect()
response = self.modem.write(cmd, True)
self.ccid = response[0].split(" ")[1].replace("\"", "")
print("The SIM card ccid is:" + self.ccid)