|
|
@ -1,16 +1,23 @@ |
|
|
|
#!/usr/bin/env sh |
|
|
|
#!/usr/bin/env sh |
|
|
|
LOGDIR="$XDG_CONFIG_HOME"/sxmo/modem |
|
|
|
LOGDIR="$XDG_CONFIG_HOME"/sxmo/modem |
|
|
|
trap "kill 0" INT |
|
|
|
trap "gracefulexit" INT TERM |
|
|
|
|
|
|
|
|
|
|
|
err() { |
|
|
|
fatalerr() { |
|
|
|
printf %b "$1" | dmenu -fn Terminus-20 -c -l 10 |
|
|
|
# E.g. hangup all calls, switch back to default audio, notify user, and die |
|
|
|
|
|
|
|
sxmo_vibratepine 1000 |
|
|
|
|
|
|
|
mmcli -m "$(mmcli -L | grep -qoE 'Modem\/([0-9]+)')" --voice-hangup-all |
|
|
|
alsactl --file /usr/share/sxmo/default_alsa_sound.conf restore |
|
|
|
alsactl --file /usr/share/sxmo/default_alsa_sound.conf restore |
|
|
|
|
|
|
|
notify-send "$1" |
|
|
|
kill -9 0 |
|
|
|
kill -9 0 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gracefulexit() { |
|
|
|
|
|
|
|
fatalerr "Terminated via SIGTERM/SIGINT" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
modem_n() { |
|
|
|
modem_n() { |
|
|
|
MODEMS="$(mmcli -L)" |
|
|
|
MODEMS="$(mmcli -L)" |
|
|
|
echo "$MODEMS" | grep -qoE 'Modem\/([0-9]+)' || err "Couldn't find modem - is your modem enabled?" |
|
|
|
echo "$MODEMS" | grep -qoE 'Modem\/([0-9]+)' || fatalerr "Couldn't find modem - is your modem enabled?" |
|
|
|
echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 |
|
|
|
echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -25,7 +32,7 @@ modem_cmd_errcheck() { |
|
|
|
RES="$(mmcli $@ 2>&1)" |
|
|
|
RES="$(mmcli $@ 2>&1)" |
|
|
|
OK="$?" |
|
|
|
OK="$?" |
|
|
|
echo "Command: mmcli $*" |
|
|
|
echo "Command: mmcli $*" |
|
|
|
if [ "$OK" != 0 ]; then err "Problem executing mmcli command!\n$RES"; fi |
|
|
|
if [ "$OK" != 0 ]; then fatalerr "Problem executing mmcli command!\n$RES"; fi |
|
|
|
echo "$RES" |
|
|
|
echo "$RES" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -73,39 +80,39 @@ dialmenu() { |
|
|
|
echo "$NUMBER" | grep "Close Menu" && kill 0 |
|
|
|
echo "$NUMBER" | grep "Close Menu" && kill 0 |
|
|
|
|
|
|
|
|
|
|
|
NUMBER="$(echo "$NUMBER" | awk -F' ' '{print $NF}' | tr -d -)" |
|
|
|
NUMBER="$(echo "$NUMBER" | awk -F' ' '{print $NF}' | tr -d -)" |
|
|
|
echo "$NUMBER" | grep -qE '^[+0-9]+$' || err "$NUMBER is not a number" |
|
|
|
echo "$NUMBER" | grep -qE '^[+0-9]+$' || fatalerr "$NUMBER is not a number" |
|
|
|
|
|
|
|
|
|
|
|
echo "Attempting to dial: $NUMBER" >&2 |
|
|
|
echo "Attempting to dial: $NUMBER" >&2 |
|
|
|
VID="$( |
|
|
|
CALLID="$( |
|
|
|
mmcli -m "$(modem_n)" --voice-create-call "number=$NUMBER" | |
|
|
|
mmcli -m "$(modem_n)" --voice-create-call "number=$NUMBER" | |
|
|
|
grep -Eo "Call/[0-9]+" | |
|
|
|
grep -Eo "Call/[0-9]+" | |
|
|
|
grep -oE "[0-9]+" |
|
|
|
grep -oE "[0-9]+" |
|
|
|
)" |
|
|
|
)" |
|
|
|
echo "Starting call with VID: $VID" >&2 |
|
|
|
echo "Starting call with CALLID: $CALLID" >&2 |
|
|
|
startcall "$VID" >&2 |
|
|
|
startcall "$CALLID" >&2 |
|
|
|
echo "$VID" |
|
|
|
echo "$CALLID" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
startcall() { |
|
|
|
startcall() { |
|
|
|
VID="$1" |
|
|
|
CALLID="$1" |
|
|
|
#modem_cmd_errcheck --voice-status -o $VID |
|
|
|
#modem_cmd_errcheck --voice-status -o $CALLID |
|
|
|
modem_cmd_errcheck -m "$(modem_n)" -o "$VID" --start |
|
|
|
modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --start |
|
|
|
log_event "call_start" "$VID" |
|
|
|
log_event "call_start" "$CALLID" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
acceptcall() { |
|
|
|
acceptcall() { |
|
|
|
VID="$1" |
|
|
|
CALLID="$1" |
|
|
|
echo "Attempting to pickup VID $VID" |
|
|
|
echo "Attempting to pickup CALLID $CALLID" |
|
|
|
#mmcli --voice-status -o $VID |
|
|
|
#mmcli --voice-status -o $CALLID |
|
|
|
modem_cmd_errcheck -m "$(modem_n)" -o "$VID" --accept |
|
|
|
modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --accept |
|
|
|
log_event "call_pickup" "$VID" |
|
|
|
log_event "call_pickup" "$CALLID" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
hangup() { |
|
|
|
hangup() { |
|
|
|
VID="$1" |
|
|
|
CALLID="$1" |
|
|
|
modem_cmd_errcheck -m "$(modem_n)" -o "$VID" --hangup |
|
|
|
modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --hangup |
|
|
|
log_event "call_hangup" "$VID" |
|
|
|
log_event "call_hangup" "$CALLID" |
|
|
|
err "Call hungup ok" |
|
|
|
fatalerr "Call hungup ok" |
|
|
|
exit 1 |
|
|
|
exit 1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -117,12 +124,11 @@ togglewindowify() { |
|
|
|
fi |
|
|
|
fi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
incallmenu() { |
|
|
|
incallsetup() { |
|
|
|
DMENUIDX=0 |
|
|
|
DMENUIDX=0 |
|
|
|
VID="$1" |
|
|
|
CALLID="$1" |
|
|
|
NUMBER="$(vid_to_number "$VID")" |
|
|
|
NUMBER="$(vid_to_number "$CALLID")" |
|
|
|
WINDOWIFIED=0 |
|
|
|
WINDOWIFIED=0 |
|
|
|
|
|
|
|
|
|
|
|
# E.g. There's some bug with the modem that' requires us to toggle the |
|
|
|
# E.g. There's some bug with the modem that' requires us to toggle the |
|
|
|
# DAI a few times before starting the call for it to kick in |
|
|
|
# DAI a few times before starting the call for it to kick in |
|
|
|
FLAGS=" " |
|
|
|
FLAGS=" " |
|
|
@ -131,8 +137,20 @@ incallmenu() { |
|
|
|
toggleflagset "-2" |
|
|
|
toggleflagset "-2" |
|
|
|
toggleflagset "-2" |
|
|
|
toggleflagset "-2" |
|
|
|
toggleflagset "-2" |
|
|
|
toggleflagset "-2" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
incallmonitor() { |
|
|
|
|
|
|
|
CALLID="$1" |
|
|
|
while true; do |
|
|
|
while true; do |
|
|
|
|
|
|
|
if mmcli -m "$(modem_n)" -K -o "$CALLID" | grep -E "^call.properties.state.+terminated"; then |
|
|
|
|
|
|
|
fatalerr "$NUMBER hung up the call" |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
echo "Call still in progress" |
|
|
|
|
|
|
|
sleep 3 |
|
|
|
|
|
|
|
done |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
incallmenuloop() { |
|
|
|
CHOICES=" |
|
|
|
CHOICES=" |
|
|
|
Volume ↑ ^ sxmo_vol.sh up |
|
|
|
Volume ↑ ^ sxmo_vol.sh up |
|
|
|
Volume ↓ ^ sxmo_vol.sh down |
|
|
|
Volume ↓ ^ sxmo_vol.sh down |
|
|
@ -142,32 +160,28 @@ incallmenu() { |
|
|
|
Earpiece $(echo -- "$FLAGS" | grep -q -- -e && echo ✓) ^ toggleflagset -e |
|
|
|
Earpiece $(echo -- "$FLAGS" | grep -q -- -e && echo ✓) ^ toggleflagset -e |
|
|
|
Linejack $(echo -- "$FLAGS" | grep -q -- -h && echo ✓) ^ toggleflagset -h |
|
|
|
Linejack $(echo -- "$FLAGS" | grep -q -- -h && echo ✓) ^ toggleflagset -h |
|
|
|
Speakerphone $(echo -- "$FLAGS" | grep -q -- -s && echo ✓) ^ toggleflagset -s |
|
|
|
Speakerphone $(echo -- "$FLAGS" | grep -q -- -s && echo ✓) ^ toggleflagset -s |
|
|
|
DTMF Tones ^ dtmfmenu $VID |
|
|
|
DTMF Tones ^ dtmfmenu $CALLID |
|
|
|
Hangup ^ hangup $VID |
|
|
|
Hangup ^ hangup $CALLID |
|
|
|
$([ "$WINDOWIFIED" = 0 ] && echo Windowify || echo Unwindowify) ^ togglewindowify |
|
|
|
$([ "$WINDOWIFIED" = 0 ] && echo Windowify || echo Unwindowify) ^ togglewindowify |
|
|
|
" |
|
|
|
" |
|
|
|
|
|
|
|
|
|
|
|
PICKED="" |
|
|
|
|
|
|
|
PICKED=$( |
|
|
|
|
|
|
|
echo "$CHOICES" | |
|
|
|
echo "$CHOICES" | |
|
|
|
xargs -0 echo | |
|
|
|
xargs -0 echo | |
|
|
|
cut -d'^' -f1 | |
|
|
|
cut -d'^' -f1 | |
|
|
|
sed '/^[[:space:]]*$/d' | |
|
|
|
sed '/^[[:space:]]*$/d' | |
|
|
|
awk '{$1=$1};1' | |
|
|
|
awk '{$1=$1};1' | |
|
|
|
dmenu -idx $DMENUIDX -l 14 $([ "$WINDOWIFIED" = 0 ] && echo "-c" || echo "-wm") -fn "Terminus-30" -p "$NUMBER" |
|
|
|
dmenu -idx $DMENUIDX -l 14 "$([ "$WINDOWIFIED" = 0 ] && echo "-c" || echo "-wm")" -fn "Terminus-30" -p "$NUMBER" | |
|
|
|
) |
|
|
|
( |
|
|
|
|
|
|
|
PICKED="$(cat)"; |
|
|
|
# E.g. in modem watcher script we just kill dmenu if the other side hangsup |
|
|
|
echo "$PICKED" | grep -Ev "." && fatalerr "$NUMBER hung up the call" |
|
|
|
echo "$PICKED" | grep -Ev "." && err "$NUMBER hung up the call" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CMD=$(echo "$CHOICES" | grep "$PICKED" | cut -d '^' -f2) |
|
|
|
CMD=$(echo "$CHOICES" | grep "$PICKED" | cut -d '^' -f2) |
|
|
|
DMENUIDX=$(echo "$(echo "$CHOICES" | grep -n "$PICKED" | cut -d ':' -f1)" - 1 | bc) |
|
|
|
DMENUIDX=$(echo "$(echo "$CHOICES" | grep -n "$PICKED" | cut -d ':' -f1)" - 1 | bc) |
|
|
|
eval "$CMD" |
|
|
|
eval "$CMD" |
|
|
|
done |
|
|
|
incallmenuloop |
|
|
|
|
|
|
|
) & wait # E.g. bg & wait to allow for SIGINT propogation |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dtmfmenu() { |
|
|
|
dtmfmenu() { |
|
|
|
VID="$1" |
|
|
|
CALLID="$1" |
|
|
|
DTMFINDEX=0 |
|
|
|
DTMFINDEX=0 |
|
|
|
NUMS="0123456789*#ABCD" |
|
|
|
NUMS="0123456789*#ABCD" |
|
|
|
|
|
|
|
|
|
|
@ -178,19 +192,24 @@ dtmfmenu() { |
|
|
|
)" |
|
|
|
)" |
|
|
|
echo "$PICKED" | grep "Return to Call Menu" && return |
|
|
|
echo "$PICKED" | grep "Return to Call Menu" && return |
|
|
|
DTMFINDEX=$(echo "$NUMS" | grep -bo "$PICKED" | cut -d: -f1 | xargs -IN echo 2+N | bc) |
|
|
|
DTMFINDEX=$(echo "$NUMS" | grep -bo "$PICKED" | cut -d: -f1 | xargs -IN echo 2+N | bc) |
|
|
|
modem_cmd_errcheck -m "$(modem_n)" -o "$VID" --send-dtmf="$PICKED" |
|
|
|
modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --send-dtmf="$PICKED" |
|
|
|
done |
|
|
|
done |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dial() { |
|
|
|
dial() { |
|
|
|
VID="$(dialmenu)" |
|
|
|
CALLID="$(dialmenu)" |
|
|
|
incallmenu "$VID" |
|
|
|
incallsetup "$CALLID" |
|
|
|
|
|
|
|
incallmonitor "$CALLID" & |
|
|
|
|
|
|
|
incallmenuloop "$CALLID" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pickup() { |
|
|
|
pickup() { |
|
|
|
acceptcall "$1" |
|
|
|
acceptcall "$1" |
|
|
|
incallmenu "$1" |
|
|
|
incallsetup "$1" |
|
|
|
|
|
|
|
incallmonitor "$1" & |
|
|
|
|
|
|
|
incallmenuloop "$1" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
modem_n || err "Couldn't determine modem number - is modem online?" |
|
|
|
modem_n || fatalerr "Couldn't determine modem number - is modem online?" |
|
|
|
"$1" "$2" |
|
|
|
"$1" "$2" |