From c5c8f3d51438013e081ea490d963e60634f23f66 Mon Sep 17 00:00:00 2001 From: Maarten van Gompel Date: Tue, 30 Mar 2021 23:03:35 +0200 Subject: [PATCH] Modem monitor now tracks the modem for state changes and shows the state in the status bar --- scripts/core/sxmo_statusbar.sh | 9 ++++++ scripts/modem/sxmo_modemmonitor.sh | 45 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/scripts/core/sxmo_statusbar.sh b/scripts/core/sxmo_statusbar.sh index 5587edb..aa6025e 100755 --- a/scripts/core/sxmo_statusbar.sh +++ b/scripts/core/sxmo_statusbar.sh @@ -31,6 +31,15 @@ update() { # M symbol if modem monitoring is on & modem present 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 PCT="$(cat /sys/class/power_supply/*-battery/capacity)" diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh index b9668d0..4ade1dc 100755 --- a/scripts/modem/sxmo_modemmonitor.sh +++ b/scripts/modem/sxmo_modemmonitor.sh @@ -182,11 +182,25 @@ checkfornewtexts() { 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() { + #these may be premature and return nothing yet (because modem/sim might not be ready yet) checkforfinishedcalls checkforincomingcalls checkfornewtexts + # Monitor for incoming calls dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Voice',type='signal',member='CallAdded'" | \ while read -r line; do @@ -205,11 +219,42 @@ mainloop() { echo "$line" | grep -E "^signal" && checkforfinishedcalls 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 + + rm /tmp/modem.*.state 2>/dev/null + sxmo_statusbarupdate.sh } + echo "sxmo_modemmonitor: starting -- $(date)" >&2 rm -f "$CACHEDIR"/*.pickedupcall 2>/dev/null #new session, forget all calls we picked up previously mainloop