forked from SolidRun/SolidSense-Modem_GPS_Service
-
Notifications
You must be signed in to change notification settings - Fork 1
/
modem_status
150 lines (138 loc) · 3 KB
/
modem_status
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
147
148
149
150
#!/usr/bin/env bash
#
# modem gps service on solid sense status request
#
# Global variables
PROG_NAME="$(basename "${0}")"
MDM_DIR=/opt/SolidSense/modem_gps
# functions
usage () {
echo "${PROG_NAME}:"
echo " -h|--help :display this help"
echo " -l|--list :list available networks"
echo " -t|--test :test the modem and attachment (as sudo), up to 2 optional arguments"
echo " -n|--network :select an network"
echo " -r|--rat :select a RAT (GSM/UTRAN/LTE)"
echo " -R|--reset :reset the modem (as sudo)"
echo " -F|--factory_reset :reset the modem to factory default(as sudo)"
echo " -c|--check :check modem presence (as sudo)"
echo " no arguments :print the modem status"
exit 1
}
reset () {
echo " Resetting the modem, all communication will stop"
sudo systemctl stop modem_gps
sudo python3 ${MDM_DIR}/Factory_Reset.py
echo "Wait 30 seconds before performing further actions. Power cycle recommended"
}
factory_reset() {
echo " Resetting the modem to factory default, all communication will stop"
sudo systemctl stop modem_gps
sudo python3 ${MDM_DIR}/Factory_Reset.py FULL
echo "Wait 30 seconds before performing further actions. Power cycle recommended"
}
check () {
if [ -e /dev/ttyUSB2 ] ; then
echo "Modem control file present"
sudo systemctl stop modem_gps
sudo python3 ${MDM_DIR}/Test_Modem.py
return 0
else
echo "No Modem control file detected"
lsusb
return 1
fi
}
COMMAND="status"
NETWORK=""
RAT=""
OPT1=""
OPT2=""
TEST_MODEM=1
while (( "$#" ))
do
case "${1}" in
-h|--help )
usage
;;
-l|--list )
COMMAND="operator"
shift
;;
-n|--network )
NETWORK="${2}"
shift 2
;;
-r|--rat )
RAT="${2}"
shift 2
;;
-c|--check )
shift
check
exit
;;
-t|--test )
shift
TEST_MODEM=0
;;
-R|--reset )
shift
reset
exit
;;
-F|--factory_reset )
shift
factory_reset
exit
;;
-- )
shift
break
;;
--*=|-* )
echo "Error: Unsupported flag ${1}" >&2
usage
exit 1
;;
* )
if [ -z "${PARAMS}" ]; then
PARAMS="${1}"
else
PARAMS="${PARAMS} ${1}"
fi
shift
;;
esac
done
if [ -n "${NETWORK}" ]; then
COMMAND="operator"
OPT1=${NETWORK}
fi
if [ -n "${RAT}" ]; then
if [ -z "${NETWORK}" ]; then
COMMAND="operator"
OPT1="CURRENT"
OPT2=${RAT}
else
OPT2=${RAT}
fi
fi
if [ ${TEST_MODEM} -eq 0 ]; then
echo "Testing the modem - service will stop"
sudo systemctl stop modem_gps
if [ -z "${PARAMS}" ]; then
python3 ${MDM_DIR}/Test_Modem.py
else
if [ $# -gt 2 ]; then
echo "More than 2 optional arguments for '--test'"
usage
exit 1
fi
echo "Test additional parameters:${PARAMS}"
python3 ${MDM_DIR}/Test_Modem.py ${PARAMS}
fi
echo "To restart the restart if test is ok: sudo systemctl start modem_gps"
else
python3 ${MDM_DIR}/Modem_Service_Client.py 127.0.0.1:20231 ${COMMAND} ${OPT1} "${OPT2}"
fi