~mil/sxmo-utils

edc48a01d24a95226335d4d197533a7a5108af6d — Maarten van Gompel 3 months ago 13b29f7
ModemMonitor: Periodically check whether the modem is still alive, reset it if not

Signed-off-by: Stacy Harper <contact@stacyharper.net>
A configs/sudo/modem => configs/sudo/modem +4 -0
@@ 0,0 1,4 @@
ALL ALL=NOPASSWD: /sbin/rc-service eg25-manager restart
ALL ALL=NOPASSWD: /sbin/rc-service modemmanager stop
ALL ALL=NOPASSWD: /sbin/rc-service modemmanager start
ALL ALL=NOPASSWD: /sbin/rc-service modemmanager restart

M scripts/core/sxmo_appmenu.sh => scripts/core/sxmo_appmenu.sh +1 -0
@@ 140,6 140,7 @@ programchoicesinit() {
			$icon_aru Brightness               ^ 1 ^ sxmo_brightness.sh up
			$icon_ard Brightness               ^ 1 ^ sxmo_brightness.sh down
			$icon_phn Modem Toggle               ^ 1 ^ sxmo_modemmonitortoggle.sh
			$icon_phn Modem Reset                ^ 1 ^ sxmo_modemmonitortoggle.sh reset
			$icon_inf Modem Info                 ^ 0 ^ sxmo_modeminfo.sh
			$icon_phl Modem Log                  ^ 0 ^ sxmo_modemlog.sh
			$icon_wif Wifi $(

M scripts/core/sxmo_statusbar.sh => scripts/core/sxmo_statusbar.sh +2 -0
@@ 48,6 48,8 @@ update() {
			MODEMMON=""
		elif [ connected = "$MODEMSTATE" ]; then
			MODEMMON=""
		elif [ failed = "$MODEMSTATE" ] || [ disconnected = "$MODEMSTATE" ]; then
			MODEMMON=""
		else
			MODEMMON=""
		fi

M scripts/modem/sxmo_modemmonitor.sh => scripts/modem/sxmo_modemmonitor.sh +33 -0
@@ 295,6 295,10 @@ mainloop() {
				elif echo "$newstate" | grep "int32 11"; then
					echo connected > "$MODEMSTATEFILE"
					#3G/2G/4G available
				elif echo "$newstate" | grep "int32 -1"; then
					echo failed > "$MODEMSTATEFILE"
				elif echo "$newstate" | grep "int32 3"; then
					echo disabled > "$MODEMSTATEFILE"
				else
					echo unknown > "$MODEMSTATEFILE"
				fi


@@ 302,6 306,35 @@ mainloop() {
			fi
		done &

	(   #check whether the modem is still alive every minute, reset the modem if not
		while :
		do
			sleep 60
			TRIES=0
			while [ "$TRIES" -lt 10 ]; do
				MODEMS="$(mmcli -L)"
				if echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' > /dev/null; then
					break
				elif grep -q rtc "$UNSUSPENDREASONFILE"; then
					#don't bother checking in rtc-wake situations
					TRIES=0
					break
				else
					TRIES=$((TRIES+1))
					echo "sxmo_modemmonitor: modem not found, waiting for modem... (try #$TRIES)">&2
					sleep 2
					if [ "$TRIES" -eq 10 ]; then
						echo failed > "$MODEMSTATEFILE"
						echo "sxmo_modemmonitor: forcing modem reset">&2
						sxmo_modemmonitortoggle.sh reset #will kill the modemmonitor too
						break
					fi
				fi
			done
		done
	) &

	wait
	wait
	wait
	wait

M scripts/modem/sxmo_modemmonitortoggle.sh => scripts/modem/sxmo_modemmonitortoggle.sh +19 -1
@@ 3,12 3,30 @@
# This script toggles the modem monitor
# It optionally takes a parameter "on" or "off"
# forcing it to toggle only to that desired state if applicable.
# It may also take a "reset" parameter that forces the
# entire modem subsystem to reload

# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"

if [ "$1" != "on" ] && pgrep -f sxmo_modemmonitor.sh; then
if [ "$1" = "reset" ]; then
	#does a hard reset of the entire modem
	echo "sxmo_modemmonitortoggle: forcing modem reset">&2
	notify-send "Resetting modem, this may take a minute..."
	pkill -TERM -f sxmo_modemmonitor.sh
	sudo rc-service modemmanager stop
	sudo rc-service eg25-manager stop
	sleep 5
	while ! rc-service eg25-manager status | grep -q started; do
		sudo rc-service eg25-manager start
		sleep 2
	done
	sleep 5
	sudo rc-service modemmanager start
	sleep 30
	setsid -f sxmo_modemmonitor.sh &
elif [ "$1" != "on" ] && pgrep -f sxmo_modemmonitor.sh; then
	pkill -TERM -f sxmo_modemmonitor.sh
elif [ "$1" != "off" ] && ! pgrep -f sxmo_modemmonitor.sh; then
	setsid -f sxmo_modemmonitor.sh &