Skip to content

Commit 2cade49

Browse files
authored
Merge pull request #89 from lwindg/develop
feat: Support secondary APN & retry timeout
2 parents 7db015d + b2c3c36 commit 2cade49

File tree

10 files changed

+284
-70
lines changed

10 files changed

+284
-70
lines changed

build-deb/debian/changelog

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
sanji-bundle-cellular (3.0.0-1) unstable; urgency=low
2+
3+
* feat: Support secondary APN.
4+
* feat: Support advanced signal information.
5+
* feat: Support phone number.
6+
7+
-- Aeluin Chen <[email protected]> Wed, 19 Oct 2016 17:24:12 +0800
8+
19
sanji-bundle-cellular (2.1.0-1) unstable; urgency=low
210

311
* fix: sh default timeout

build-deb/debian/control

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ X-Python-Version: >= 2.5
1313
Package: sanji-bundle-cellular
1414
Section: libs
1515
Architecture: all
16-
Depends: ${shlibs:Depends}, ${misc:Depends}, python2.7, python-pip, vnstat, moxa-cellular-utils (>= 1.9.4)
16+
Depends: ${shlibs:Depends}, ${misc:Depends}, python2.7, python-pip, vnstat, moxa-cellular-utils (>= 1.9.6)
1717
Description: This model provides cellular using QMI.
1818

bundle.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cellular",
3-
"version": "2.1.0",
3+
"version": "3.0.0",
44
"author": "Aeluin Chen",
55
"email": "[email protected]",
66
"description": "Provides the cellular configuration interface",

cellular_utility/cell_mgmt.py

+82-1
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,30 @@ class Signal(object):
214214
def __init__(
215215
self,
216216
mode=None,
217-
rssi_dbm=None):
217+
rssi_dbm=None,
218+
ecio_dbm=None,
219+
csq=None):
218220
self._mode = "none" if mode is None else mode
219221
self._rssi_dbm = 0 if rssi_dbm is None else rssi_dbm
222+
self._ecio_dbm = 0.0 if ecio_dbm is None else ecio_dbm
223+
self._csq = 0 if csq is None else csq
220224

221225
@property
222226
def mode(self):
223227
return self._mode
224228

229+
@property
230+
def csq(self):
231+
return self._csq
232+
225233
@property
226234
def rssi_dbm(self):
227235
return self._rssi_dbm
228236

237+
@property
238+
def ecio_dbm(self):
239+
return self._ecio_dbm
240+
229241

230242
class CellularLocation(object):
231243
def __init__(
@@ -248,6 +260,20 @@ def lac(self):
248260
return self._lac
249261

250262

263+
class CellularNumber(object):
264+
def __init__(
265+
self,
266+
number=None):
267+
if not isinstance(number, str):
268+
raise ValueError
269+
270+
self._number = number
271+
272+
@property
273+
def number(self):
274+
return self._number
275+
276+
251277
class CellMgmt(object):
252278
"""
253279
cell_mgmt utilty wrapper
@@ -263,6 +289,10 @@ class CellMgmt(object):
263289
r"DNS=([0-9\. ]*)\n")
264290
_signal_regex = re.compile(
265291
r"^([\S]+) (-[0-9]+) dbm\n$")
292+
_signal_adv_regex = re.compile(
293+
r"^CSQ: ([0-9]+)\n"
294+
r"RSSI: ([\S]+) (-[0-9]+) dBm\n"
295+
r"EcIo: ([\S]+) (-[0-9.]+) dBm\n")
266296
_m_info_regex = re.compile(
267297
r"^Module=([\S ]+)\n"
268298
r"WWAN_node=([\S]+)\n"
@@ -286,6 +316,9 @@ class CellMgmt(object):
286316
r"[\n\t ]*PUK1 retries: '([0-9]+)'\n"
287317
)
288318

319+
_number_regex = re.compile(
320+
r"^([^\n]*)[\n]{0,1}")
321+
289322
_at_response_ok_regex = re.compile(
290323
r"^[\r\n]*([+\S\s :]*)[\r\n]+OK[\r\n]*$")
291324
_at_response_err_regex = re.compile(
@@ -475,6 +508,54 @@ def signal(self):
475508
# signal out of range
476509
return Signal()
477510

511+
@critical_section
512+
@handle_error_return_code
513+
@retry_on_busy
514+
def signal_adv(self):
515+
"""Returns an instance of Signal."""
516+
517+
_logger.debug("cell_mgmt signal_adv")
518+
519+
output = self._cell_mgmt("signal_adv")
520+
output = str(output)
521+
522+
if self._invoke_period_sec != 0:
523+
sleep(self._invoke_period_sec)
524+
525+
match = CellMgmt._signal_adv_regex.match(output)
526+
if match:
527+
return Signal(
528+
csq=int(match.group(1)),
529+
mode=match.group(2),
530+
rssi_dbm=int(match.group(3)),
531+
ecio_dbm=float(match.group(5)))
532+
533+
_logger.warning("unexpected output: " + output)
534+
# signal out of range
535+
return Signal()
536+
537+
@critical_section
538+
@handle_error_return_code
539+
@retry_on_busy
540+
def number(self):
541+
"""Returns an instance of CellularNumber."""
542+
543+
_logger.debug("cell_mgmt number")
544+
545+
output = self._cell_mgmt("number")
546+
output = str(output)
547+
548+
if self._invoke_period_sec != 0:
549+
sleep(self._invoke_period_sec)
550+
551+
match = CellMgmt._number_regex.match(output)
552+
if match:
553+
return CellularNumber(
554+
number=match.group(1))
555+
556+
_logger.warning("unexpected output: " + output)
557+
return CellularNumber()
558+
478559
@critical_section
479560
def status(self):
480561
"""

cellular_utility/event.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def log_cellular_information(
3939
self._log(
4040
"mode {}, signal {} dBm, rssi {}, lac {}, cell_id {}".format(
4141
cellular_information.mode,
42-
str(cellular_information.signal_dbm),
43-
str(self._rssi_from_dbm(cellular_information.signal_dbm)),
42+
str(cellular_information.signal_rssi_dbm),
43+
str(cellular_information.signal_csq),
4444
cellular_information.lac,
4545
cellular_information.cell_id)
4646
)

0 commit comments

Comments
 (0)