Skip to content

Commit

Permalink
Merge pull request #127 from lwindg/develop
Browse files Browse the repository at this point in the history
3.3.0
  • Loading branch information
zack9433 authored Apr 13, 2017
2 parents d7bc9eb + 725b22e commit 5ad4a24
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 74 deletions.
7 changes: 7 additions & 0 deletions build-deb/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
sanji-bundle-cellular (3.3.0-1) unstable; urgency=low

* feat: Remove phone number query.
* feat: Add IMSI.

-- Aeluin Chen <[email protected]> Thu, 13 Apr 2017 14:49:02 +0800

sanji-bundle-cellular (3.2.0-1) unstable; urgency=low

* feat: TAC for LTE and NID, BID for CDMA.
Expand Down
2 changes: 1 addition & 1 deletion bundle.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cellular",
"version": "3.2.0",
"version": "3.3.0",
"author": "Aeluin Chen",
"email": "[email protected]",
"description": "Provides the cellular configuration interface",
Expand Down
97 changes: 58 additions & 39 deletions cellular_utility/cell_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,27 @@ def ecio_dbm(self):
return self._ecio_dbm


class CellularSimInfo(object):
def __init__(
self,
iccid="",
imsi=""):
if (not isinstance(iccid, str) or
not isinstance(imsi, str)):
raise ValueError

self._iccid = iccid
self._imsi = imsi

@property
def iccid(self):
return self._iccid

@property
def imsi(self):
return self._imsi


class CellularLocation(object):
def __init__(
self,
Expand Down Expand Up @@ -292,20 +313,6 @@ def nid(self):
return self._nid


class CellularNumber(object):
def __init__(
self,
number=None):
if not isinstance(number, str):
raise ValueError

self._number = number

@property
def number(self):
return self._number


class CellMgmt(object):
"""
cell_mgmt utilty wrapper
Expand Down Expand Up @@ -351,6 +358,13 @@ class CellMgmt(object):
r"PS: attached\n"
)

_sim_info_iccid_regex = re.compile(
r"ICC-ID: ([\S]*)\n"
)
_sim_info_imsi_regex = re.compile(
r"IMSI: ([\S]*)\n"
)

_location_info_lac_regex = re.compile(
r"LAC: ([\S]*)\n"
)
Expand All @@ -367,9 +381,6 @@ class CellMgmt(object):
r"BID: ([\S]*)\n"
)

_number_regex = re.compile(
r"^([^\n]*)[\n]{0,1}")

_at_response_ok_regex = re.compile(
r"^[\r\n]*([+\S\s :]*)[\r\n]+OK[\r\n]*$")
_at_response_err_regex = re.compile(
Expand Down Expand Up @@ -579,28 +590,6 @@ def signal_adv(self):
# signal out of range
return Signal()

@critical_section
@handle_error_return_code
@retry_on_busy
def number(self):
"""Returns an instance of CellularNumber."""

_logger.debug("cell_mgmt number")

output = self._cell_mgmt("number")
output = str(output)

if self._invoke_period_sec != 0:
sleep(self._invoke_period_sec)

match = CellMgmt._number_regex.match(output)
if match:
return CellularNumber(
number=match.group(1))

_logger.warning("unexpected output: " + output)
return CellularNumber()

@critical_section
@handle_error_return_code
@retry_on_busy
Expand Down Expand Up @@ -816,6 +805,36 @@ def get_pin_retry_remain(self):
output = self._cell_mgmt("pin_retries")
return int(output)

@critical_section
@handle_error_return_code
def get_cellular_sim_info(self):
"""
Return CellularSimInfo instance.
"""
iccid = ""
imsi = ""

_logger.debug("cell_mgmt iccid")
_logger.debug("cell_mgmt imsi")

# `cell_mgmt iccid`
# ICCID: xxx
output = str(self._cell_mgmt("iccid"))
found = self._sim_info_iccid_regex.search(output)
if found:
iccid = found.group(1)

# `cell_mgmt imsi`
# IMSI: xxx
output = str(self._cell_mgmt("imsi"))
found = self._sim_info_imsi_regex.search(output)
if found:
imsi = found.group(1)

return CellularSimInfo(
iccid=iccid,
imsi=imsi)

@critical_section
@handle_error_return_code
def get_cellular_location(self):
Expand Down
45 changes: 19 additions & 26 deletions cellular_utility/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
from traceback import format_exc

from cellular_utility.cell_mgmt import (
CellMgmt, CellMgmtError, SimStatus, CellularLocation, Signal,
CellularNumber
CellMgmt, CellMgmtError, SimStatus, CellularLocation, Signal
)
from cellular_utility.event import Log

Expand All @@ -38,8 +37,7 @@ def __init__(
tac=None,
nid=None,
cell_id=None,
bid=None,
number=None):
bid=None):

if (not isinstance(mode, str) or
not isinstance(signal_csq, int) or
Expand All @@ -50,8 +48,7 @@ def __init__(
not isinstance(tac, str) or
not isinstance(nid, str) or
not isinstance(cell_id, str) or
not isinstance(bid, str) or
not isinstance(number, str)):
not isinstance(bid, str)):
raise ValueError

if lac == "Unknown" or cell_id == "Unknown":
Expand All @@ -67,7 +64,6 @@ def __init__(
self._nid = nid
self._cell_id = cell_id
self._bid = bid
self._number = number

@property
def mode(self):
Expand Down Expand Up @@ -109,10 +105,6 @@ def cell_id(self):
def bid(self):
return self._bid

@property
def number(self):
return self._number

@staticmethod
def get():
cell_mgmt = CellMgmt()
Expand All @@ -137,13 +129,6 @@ def get():
lac="n/a",
cell_id="n/a")

try:
number = cell_mgmt.number()

except CellMgmtError:
number = CellularNumber(
number="n/a")

return CellularInformation(
signal.mode,
signal.csq,
Expand All @@ -154,8 +139,7 @@ def get():
cellular_location.tac,
cellular_location.nid,
cellular_location.cell_id,
cellular_location.bid,
number.number)
cellular_location.bid)


class CellularObserver(object):
Expand Down Expand Up @@ -277,25 +261,32 @@ class StaticInformation(object):
def __init__(
self,
pin_retry_remain=None,
icc_id=None,
iccid=None,
imsi=None,
imei=None):

if (not isinstance(pin_retry_remain, int) or
not isinstance(icc_id, str) or
not isinstance(iccid, str) or
not isinstance(imsi, str) or
not isinstance(imei, str)):
raise ValueError

self._pin_retry_remain = pin_retry_remain
self._icc_id = icc_id
self._iccid = iccid
self._imsi = imsi
self._imei = imei

@property
def pin_retry_remain(self):
return self._pin_retry_remain

@property
def icc_id(self):
return self._icc_id
def iccid(self):
return self._iccid

@property
def imsi(self):
return self._imsi

@property
def imei(self):
Expand Down Expand Up @@ -563,10 +554,12 @@ def _initialize_static_information(self):
try:
pin_retry_remain = self._cell_mgmt.get_pin_retry_remain()
minfo = self._cell_mgmt.m_info()
sinfo = self._cell_mgmt.get_cellular_sim_info()

self._static_information = Manager.StaticInformation(
pin_retry_remain=pin_retry_remain,
icc_id=minfo.icc_id,
iccid=sinfo.iccid,
imsi=sinfo.imsi,
imei=minfo.imei)

break
Expand Down
4 changes: 2 additions & 2 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,11 @@ def _get(self):
"nid": "n/a" if cinfo is None else cinfo.nid,
"cellId": "n/a" if cinfo is None else cinfo.cell_id,
"bid": "n/a" if cinfo is None else cinfo.bid,
"iccId": "n/a" if sinfo is None else sinfo.icc_id,
"imsi": "n/a" if sinfo is None else sinfo.imsi,
"iccId": "n/a" if sinfo is None else sinfo.iccid,
"imei": "n/a" if sinfo is None else sinfo.imei,
"pinRetryRemain": (
-1 if sinfo is None else sinfo.pin_retry_remain),
"phoneNumber": "n/a" if cinfo is None else cinfo.number,

"status": status.name,
"ip": "n/a" if ninfo is None else ninfo.ip,
Expand Down
12 changes: 6 additions & 6 deletions schema/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ definitions:
iccId:
type: string
description: ICC ID of SIM card.
imsi:
type: string
description: IMSI of SIM card.
imei:
type: string
description: IMEI of cellular module.
pinRetryRemain:
type: integer
description: PIN Retry remaining.
phoneNumber:
type: string
description: Phone number of the SIM card.
status:
type: string
description: Indicate current status of cellular connection. Could be one of "nosim", "pin", "noservice", "ready", "connected", "connecting", "connect-failed".
Expand Down Expand Up @@ -309,13 +309,13 @@ externalDocs:
"ecio": -8.5
},
"operatorName": "Chunghwa Telecom",
"lac": "0xF339",
"lac": "11114",
"tac": "",
"nid": "",
"cellId": "0x3194",
"cellId": "1249",
"bid": "",
"iccId": "",
"phoneNumber": "",
"imsi": "466977502877452",
"imei": "356853050370859",
"pinRetryRemain": 3,
"status": "connected",
Expand Down

0 comments on commit 5ad4a24

Please sign in to comment.