summaryrefslogtreecommitdiff
path: root/umtsmodem.py
diff options
context:
space:
mode:
Diffstat (limited to 'umtsmodem.py')
-rwxr-xr-xumtsmodem.py35
1 files changed, 25 insertions, 10 deletions
diff --git a/umtsmodem.py b/umtsmodem.py
index b700584..a5f20cc 100755
--- a/umtsmodem.py
+++ b/umtsmodem.py
@@ -100,7 +100,6 @@ def cell_info(modem):
retry = False
response = send_command(modem, 'AT*EGNCI\r', None)
if 'ERROR\r\n' in response:
- print "error"
retry = True
time.sleep(1)
continue
@@ -118,13 +117,9 @@ def cell_info(modem):
cells.add((mcc, mnc, lac, cid))
except:
retry = True
- print "retrying"
time.sleep(2)
break
-
- for (mcc, mnc, lac, cid) in cells:
- print "MCC: " + str(mcc) + ", MNC: " + str(mnc) + ", LAC: " + str(lac) + ", CellID: " + str(cid)
-
+ return cells
# # get UMTS cell information
# send_command(modem, 'AT+CFUN=6\r', None)
@@ -133,13 +128,28 @@ def cell_info(modem):
# for line in response:
# if line.startswith('*EWNCI: '):
# print line.rstrip()
-
# # switch back to default mode
# send_command(modem, 'AT+CFUN=1\r', None)
+def log_cells(modem):
+ cells = set()
+ while True:
+ try:
+ current_cells = cell_info(modem)
+ for cell in current_cells:
+ if cell not in cells:
+ (mcc, mnc, lac, cid) = cell
+ print "MCC: " + str(mcc) + ", MNC: " + str(mnc) + ", LAC: " + str(lac) + ", CellID: " + str(cid)
+ cells.update(current_cells)
+ time.sleep(2)
+ print "foo"
+ except KeyboardInterrupt:
+ break
+
+
def print_state(modem):
- modem.timeout = 0.1
+ modem.timeout = 0.3
modem.write('AT+CSQ\r')
response = modem.readlines()
for line in response:
@@ -202,6 +212,7 @@ def show_usage():
print "\tdisconnect: disconnect from internet"
print "\tstate: show signal/base station info"
print "\tcellinfo: show info about all received cells"
+ print "\tlogcells: continuous output of newly received cells"
if len(sys.argv) != 2:
show_usage()
@@ -223,8 +234,12 @@ elif sys.argv[1] == "disconnect":
elif sys.argv[1] == "state":
print_state(modem)
elif sys.argv[1] == "cellinfo":
-# start_modem(modem)
- cell_info(modem)
+ cells = cell_info(modem)
+ for (mcc, mnc, lac, cid) in cells:
+ print "MCC: " + str(mcc) + ", MNC: " + str(mnc) + ", LAC: " + str(lac) + ", CellID: " + str(cid)
+elif sys.argv[1] == "logcells":
+ log_cells(modem)
+
else:
show_usage()