-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTest_Modem.py
More file actions
146 lines (122 loc) · 3.87 KB
/
Test_Modem.py
File metadata and controls
146 lines (122 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#-------------------------------------------------------------------------------
# Name: Test Modem
# Purpose: Perform basic testing of the modem function
#
# Author: Laurent Carré
#
# Created: 11/02/2020
# Copyright: (c) Laurent Carré Sterwen Technologies 2020
# Licence: <your licence>
#-------------------------------------------------------------------------------
import logging
import sys
import time
from QuectelAT_Service import *
log=None
def checkSMS(modem):
global log
resp=modem.sendATcommand("+CSMS?")
s=modem.splitResponse("+CSMS",resp[0])
log.info("SMS service type: "+str(s[0])+" MO:"+str(s[1])+" MT:"+str(s[2])+" BM:"+str(s[3]))
resp=modem.sendATcommand("+CSCA?")
s=modem.splitResponse("+CSCA",resp[0])
log.info("SMS Service center:"+str(s[0]) )
def init(modem):
modem.resetCard()
time.sleep(20.)
modem.clearFPLMN()
modem.allowRoaming()
modem.logModemStatus()
def rescan(modem):
global log
log.info("Resetting network scan mode")
modem.sendATcommand('+QCFG=”nwscanmode”,0,1')
modem.selectOperator('AUTO')
def checkGPS(modem):
global log
if modem.gpsStatus() :
log.info("Reading GPS")
sg=modem.getGpsStatus()
if sg['fix'] :
pf="LAT {0} LONG {1}".format(sg['Latitude'],sg['Longitude'])
log.info(pf)
else:
log.info("GPS not fixed")
else:
log.infp("GPS is turned off")
def main():
global log
log=logging.getLogger('Modem_GPS_Service')
log.addHandler(logging.StreamHandler())
log.setLevel(logging.DEBUG)
QuectelModem.checkModemPresence()
try:
modem=QuectelModem('/dev/ttyUSB2',True)
except Exception as err:
log.error(str(err))
return
log.info("SIM Status:"+modem.SIM_Status())
if modem.checkSIM() == "NO SIM":
log.error("No SIM card inserted")
return
option="None"
if len(sys.argv) > 1 :
option=sys.argv[1]
log.info("Test Option:"+option)
if modem.SIM_Status() == "SIM PIN":
modem.setpin('0000')
time.sleep(2.0)
modem.checkSIM()
modem.logModemStatus()
if option == "init":
init(modem)
elif option == "cmd":
if len(sys.argv) >2 :
log.info("sending:"+sys.argv[2])
resp=modem.sendATcommand(sys.argv[2],False)
for r in resp:
log.info(r)
else:
log.info("Missing command argument")
elif option == "scan":
if modem.SIM_Ready():
rescan(modem)
elif option == "oper":
if len(sys.argv) > 2:
log.info("selecting operator:"+sys.argv[2])
if sys.argv[2].isdecimal():
f="numeric"
else:
f='long'
modem.selectOperator(sys.argv[2],f,None)
else:
log.info("Missing operator name or ID")
elif option == 'sms':
checkSMS(modem)
elif option == 'gps':
checkGPS(modem)
else:
modem.allowRoaming()
if modem.SIM_Ready():
# we have a SIM so look how it goaes
res= modem.networkStatus()
if not res :
# let's see what is the situation
state=modem.regStatus()
log.info("Modem registration status:"+state)
if state == "IN PROGRESS":
# just wait
log.info("Registration in progress => waiting")
nb_attempt=0
while nb_attempt < 10:
time.sleep(2.0)
res=modem.networkStatus()
if res: break
nb_attempt += 1
if not res and option == 'list':
log.info(modem.visibleOperators())
# try to Register from scratch
# clear forbidden PLMN and allow roaming
modem.close()
if __name__ == '__main__':
main()