Modem monitor now tracks the modem for state changes and shows the state in the status bar

master
Maarten van Gompel 4 years ago
parent 6951639886
commit c5c8f3d514
  1. 9
      scripts/core/sxmo_statusbar.sh
  2. 45
      scripts/modem/sxmo_modemmonitor.sh

@ -31,6 +31,15 @@ update() {
# M symbol if modem monitoring is on & modem present # M symbol if modem monitoring is on & modem present
MODEMMON="" MODEMMON=""
pgrep -f sxmo_modemmonitor.sh && MODEMMON="" pgrep -f sxmo_modemmonitor.sh && MODEMMON=""
if [ -n "$MODEMMON" ]; then
if [ -f /tmp/modem.locked.state ]; then
MODEMMON=""
elif [ -f /tmp/modem.registered.state ]; then
MODEMMON=""
elif [ -f /tmp/modem.connected.state ]; then
MODEMMON=""
fi
fi
# Battery pct # Battery pct
PCT="$(cat /sys/class/power_supply/*-battery/capacity)" PCT="$(cat /sys/class/power_supply/*-battery/capacity)"

@ -182,11 +182,25 @@ checkfornewtexts() {
done done
} }
initialmodemstatus() {
rm /tmp/modem.*.state 2>/dev/null
state=$(mmcli -m "$(modem_n)")
if echo "$state" | grep -q -E "^.*state:.*connected.*$"; then
touch /tmp/modem.connected.state
elif echo "$state" | grep -q -E "^.*state:.*registered.*$"; then
touch /tmp/modem.registered.state
elif echo "$state" | grep -q -E "^.*state:.*locked.*$"; then
touch /tmp/modem.locked.state
fi
}
mainloop() { mainloop() {
#these may be premature and return nothing yet (because modem/sim might not be ready yet)
checkforfinishedcalls checkforfinishedcalls
checkforincomingcalls checkforincomingcalls
checkfornewtexts checkfornewtexts
# Monitor for incoming calls # Monitor for incoming calls
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Voice',type='signal',member='CallAdded'" | \ dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Voice',type='signal',member='CallAdded'" | \
while read -r line; do while read -r line; do
@ -205,11 +219,42 @@ mainloop() {
echo "$line" | grep -E "^signal" && checkforfinishedcalls echo "$line" | grep -E "^signal" && checkforfinishedcalls
done & done &
#Monitor for modem state changes
# arg1 holds the new state: MM_MODEM_STATE_FAILED = -1, MM_MODEM_STATE_UNKNOWN = 0, ... MM_MODEM_STATE_REGISTERED=8, MM_MODEM_STATE_CONNECTED = 11
initialmodemstatus
sxmo_statusbarupdate.sh
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem',type='signal',member='StateChanged'" | \
while read -r line; do
if echo "$line" | grep -E "^signal.*StateChanged"; then
rm /tmp/modem.*.state 2>/dev/null
read -r oldstate
read -r newstate
if echo "$newstate" | grep "int32 2"; then
touch /tmp/modem.locked.state
elif echo "$newstate" | grep "int32 8"; then
touch /tmp/modem.registered.state
checkforfinishedcalls
checkforincomingcalls
checkfornewtexts
elif echo "$newstate" | grep "int32 11"; then
touch /tmp/modem.connected.state
#3G/2G/4G available
fi
sxmo_statusbarupdate.sh
fi
done &
wait
wait wait
wait wait
wait wait
rm /tmp/modem.*.state 2>/dev/null
sxmo_statusbarupdate.sh
} }
echo "sxmo_modemmonitor: starting -- $(date)" >&2 echo "sxmo_modemmonitor: starting -- $(date)" >&2
rm -f "$CACHEDIR"/*.pickedupcall 2>/dev/null #new session, forget all calls we picked up previously rm -f "$CACHEDIR"/*.pickedupcall 2>/dev/null #new session, forget all calls we picked up previously
mainloop mainloop

Loading…
Cancel
Save