can detected disabled sim card
This commit is contained in:
+25
-8
@@ -4,6 +4,7 @@ import time
|
||||
import serial
|
||||
from serial import Serial
|
||||
|
||||
from SIMError import SIMError
|
||||
from utils.excel_reader import ExcelHelper
|
||||
|
||||
|
||||
@@ -27,14 +28,26 @@ class ModemPool:
|
||||
# wait for 20 second, so that the modem can init all the sims
|
||||
time.sleep(20)
|
||||
|
||||
def _generate_error_msg(self, slot_position, index, error: SIMError):
|
||||
return "error for slot({}) SIM({}), error:{}".format(slot_position, index + 1,
|
||||
error.value)
|
||||
|
||||
def get_raw_phone_number(self, slot_position):
|
||||
for index, ser in enumerate(self._serial_list):
|
||||
print("will get phone number for slot({}) SIM({}), port:{}".format(slot_position, index + 1, ser.port))
|
||||
self._select_sim_storage(ser)
|
||||
if not self._select_sim_storage(ser):
|
||||
print(self._generate_error_msg(slot_position, index, SIMError.STORAGE_ERROR))
|
||||
continue
|
||||
msg = self._execut_USSD_cmd("AT+CUSD=1, *132#\r", ser)
|
||||
if "Unfortunately" in str(msg):
|
||||
print("error for for slot({}) SIM({}), port:{}".format(slot_position, index + 1, ser.port))
|
||||
return
|
||||
print(self._generate_error_msg(slot_position, index, SIMError.SIM_DISABLED))
|
||||
continue
|
||||
elif "CME ERROR" in str(msg):
|
||||
print(self._generate_error_msg(slot_position, index, SIMError.CME_ERROR))
|
||||
continue
|
||||
elif len(msg) == 0:
|
||||
print(self._generate_error_msg(slot_position, index, SIMError.TIMEOUT))
|
||||
continue
|
||||
# find phone number
|
||||
match = re.search(r'33\d{9}', str(msg))
|
||||
phone_number = match.group(0)
|
||||
@@ -49,13 +62,17 @@ class ModemPool:
|
||||
def get_own_number(self, ser: Serial):
|
||||
print("saved phone number: " + str(self._send_command(f'AT+CPBR={self.phone_number_position}\r', ser)))
|
||||
|
||||
def _select_sim_storage(self, ser):
|
||||
def _select_sim_storage(self, ser) -> bool:
|
||||
# use SIM Card storage
|
||||
cmd_sm = "AT+CPBS=\"SM\"\r"
|
||||
self._send_command(cmd_sm, ser)
|
||||
result = self._send_command(cmd_sm, ser)
|
||||
if "ERROR" in str(result):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def _send_command(self, cmd: str, ser, wait_time_in_s: int = 0) -> bytes:
|
||||
print("send command {}".format(cmd))
|
||||
# print("send command {}".format(cmd))
|
||||
ser.write(cmd.encode())
|
||||
msg = ser.read(100)
|
||||
count = 0
|
||||
@@ -67,6 +84,6 @@ class ModemPool:
|
||||
print(msg)
|
||||
return msg
|
||||
|
||||
def _execut_USSD_cmd(self, cmd, ser) -> str:
|
||||
def _execut_USSD_cmd(self, cmd, ser) -> bytes:
|
||||
# the timeout for ussd command can be 120 s in mac
|
||||
return str(self._send_command(cmd, ser, 120))
|
||||
return self._send_command(cmd, ser, 120)
|
||||
|
||||
Reference in New Issue
Block a user