Makes calling work

Much of the code that interfaces with the modem was taken from SXMO.

Calling now works for both incoming and outgoing calls
Jonathan Hodgson 4 years ago
parent e1f096b885
commit 86840be8ee
  1. 142
      bin/.bin/modem/checkCall
  2. 2
      bin/.bin/modem/checkSMS
  3. 1
      bin/.bin/modem/common
  4. 92
      bin/.bin/modem/dialer
  5. 41
      bin/.bin/modem/makeCall
  6. 3
      bin/.bin/modem/monitorModem

@ -3,9 +3,10 @@
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source "$DIR/common" source "$DIR/common"
export DISPLAY=:0.0
usage(){ usage(){
echo "checkCall [options] [message|-]" echo "checkCall [options]"
echo "Options:" echo "Options:"
echo " -h|--help Display this help text" echo " -h|--help Display this help text"
echo " -m|--modem Specify a modem" echo " -m|--modem Specify a modem"
@ -22,24 +23,122 @@ lookupnumberfromcallid() {
tr -d ' ' tr -d ' '
} }
# Stolen from sxmo
toggleflag() {
TOGGLEFLAG=$1
shift
FLAGS="$*"
echo -- "$FLAGS" | grep -- "$TOGGLEFLAG" >&2 &&
NEWFLAGS="$(echo -- "$FLAGS" | sed "s/$TOGGLEFLAG//g")" ||
NEWFLAGS="$(echo -- "$FLAGS $TOGGLEFLAG")"
NEWFLAGS="$(echo -- "$NEWFLAGS" | sed "s/--//g; s/ / /g")"
# shellcheck disable=SC2086
megiaudioroute $NEWFLAGS
echo -- "$NEWFLAGS"
}
# Stolen from sxmo
toggleflagset() {
FLAGS="$(toggleflag "$1" "$FLAGS")"
}
lookupcontact(){ lookupcontact(){
local contact="$(contact-numbers "$1" | cut -d ' ' -f 1)"
if [ -n "$contact" ]; then
echo "$contact"
else
echo "$1" | echo "$1" |
# Remove the +44 and replace with 0 # Remove the +44 and replace with 0
sed 's/^\+44/0/' sed 's/^\+44/0/'
# This will eventually work with abook but for now just return the number fi
} }
answer-call(){ dtmf(){
export DISPLAY=:0.0 local id="$1"
svkbd-numbers &
local choice="$( (
echo "Exit"
) | rofi -dmenu -i -me-accept-entry '!MousePrimary' -p "Tones" -normal-window -font 'Iosevka 20' )"
if [ "$choice" = "Exit" ]; then
return
fi
echo "$choice" | grep -o '.' | while read -r tone; do
sleep 0.5
mmcli -m "$modem" -o "$id" --send-dtmf="$tone"
done
pkill svkbd-numbers
}
ongoingCall(){
local id="$1"
# Stolen from sxmo
FLAGS=" "
toggleflagset "-e"
toggleflagset "-m"
toggleflagset "-2"
toggleflagset "-2"
toggleflagset "-2"
notify-send "I get here"
while : ; do
choice="$( (
echo "Hang Up"
echo "DTMF Tones"
echo "Volume Up"
echo "Volume Down"
) | trofi)"
case "$choice" in
"Hang Up") rejectCall "$1"; break ;;
"DTMF Tones") dtmf "$1" ;;
"Volume"*) notify-send "Still need to implement" ;;
esac
done
}
answerCall(){
pkill mpv
sleep 0.2
echo "answer call $1" > /dev/tty echo "answer call $1" > /dev/tty
mmcli -m "$modem" -o "$1" --accept mmcli -m "$modem" -o "$1" --accept
ongoingCall "$1"
} }
reject-call(){ rejectCall(){
pkill mpv
echo "reject call $1" > /dev/tty
mmcli -m "$modem" -o "$1" --hangup mmcli -m "$modem" -o "$1" --hangup
mmcli -m "$modem" --voice-delete-call="$1"
mmcli -m "$modem" --voice-hangup-all
for CALLID in $( mmcli -m "$modem" --voice-list-calls | grep -oE "Call\/[0-9]+" | cut -d'/' -f2); do
echo mmcli -m "$modem" --voice-delete-call "$CALLID" > ~/.hangup.log
done
# Not sure why but sometimes the modem changes
# To be sure, re-check the modem and delete all calls
local tmpmodem="$(mmcli -L | grep -oE 'Modem\/[0-9]+' | head -n 1 | cut -d'/' -f2)"
mmcli -m "$tmpmodem" --voice-hangup-all
for CALLID in $( mmcli -m "$tmpmodem" --voice-list-calls | grep -oE "Call\/[0-9]+" | cut -d'/' -f2); do
echo mmcli -m "$tmpmodem" --voice-delete-call "$CALLID" > ~/.hangup.log
done
alsactl --file "$ALSA_CONF_DIR/default_alsa_sound.conf" restore
} }
prompt-incoming(){ promptIncoming(){
export DISPLAY=:0.0 export DISPLAY=:0.0
local answer="" local answer=""
@ -62,11 +161,21 @@ prompt-incoming(){
esac esac
} }
checkOutgoing(){
export DISPLAY=:0.0
if [ "$dryrun" = "true" ]; then
return
fi
notify-send "outgoing call" "$1"
mmcli -m "$modem" -o "$1" --start
ongoingCall "$1"
}
checkIncoming(){ checkIncoming(){
export DISPLAY=:0.0 export DISPLAY=:0.0
if [ "$dryrun" = "true" ]; then if [ "$dryrun" = "true" ]; then
prompt-incoming "+441234567890" promptIncoming "+441234567890"
return return
fi fi
local id="$( mmcli -m "$modem" --voice-list-calls | local id="$( mmcli -m "$modem" --voice-list-calls |
@ -81,11 +190,12 @@ checkIncoming(){
local action="" local action=""
while mmcli -m "$modem" --voice-list-calls | grep -Eoq "$id"' incoming \(ringing-in\)' && [ -z "$action" ]; do while mmcli -m "$modem" --voice-list-calls | grep -Eoq "$id"' incoming \(ringing-in\)' && [ -z "$action" ]; do
action="$(prompt-incoming "$contact")" mpv "$HOME/.local/share/soundeffects/ringtone" --loop &
action="$(promptIncoming "$contact")"
done done
case "$action" in case "$action" in
"accept") answer-call "$id"; break ;; "accept") answerCall "$id"; ;;
"reject") reject-call "$id"; break ;; "reject") rejectCall "$id"; ;;
esac esac
} }
@ -95,6 +205,7 @@ checkFinished(){
grep -Eo '[0-9]+ incoming \(terminated\)' | grep -Eo '[0-9]+' )" grep -Eo '[0-9]+ incoming \(terminated\)' | grep -Eo '[0-9]+' )"
local count="$(echo "$ids" | deleteEmptyLines | wc -l)" local count="$(echo "$ids" | deleteEmptyLines | wc -l)"
echo "Finished Count: $count"
[ "$count" -eq 0 ] && return [ "$count" -eq 0 ] && return
@ -103,13 +214,16 @@ checkFinished(){
local number="$(lookupnumberfromcallid "$id")" local number="$(lookupnumberfromcallid "$id")"
local contact="$(lookupcontact "$number")" local contact="$(lookupcontact "$number")"
echo "I get here"
# If there is a rofi process with the title of "call-from-number", then # If there is a rofi process with the title of "call-from-number", then
# it hasn't been answerd yet. # it hasn't been answerd yet.
# Treat as a missed call # Treat as a missed call
if ps aux | grep -E '\Wrofi' | grep -q "call-from-$number"; then if ps aux | grep -E '\Wrofi' | grep -q "call-from-$contact"; then
echo "Missed call from $contact" >> "$CALL_DIR/missed-calls" echo "Missed call from $contact" >> "$CALL_DIR/missed-calls"
pkill mpv
mmcli -m "$modem" --voice-delete-call "$id" mmcli -m "$modem" --voice-delete-call "$id"
ps aux | grep -E '\Wrofi' | grep "call-from-$number" | ps aux | grep -E '\Wrofi' | grep "call-from-$contact" |
awk '{print $2}' | xargs kill awk '{print $2}' | xargs kill
fi fi
@ -140,8 +254,12 @@ while [[ $1 = -?* ]]; do
shift shift
done done
if [ -n "$1" ]; then
checkOutgoing "$1" &
else
checkIncoming & checkIncoming &
checkFinished & checkFinished &
fi

@ -72,4 +72,4 @@ echo "$ids" | while read -r id; do
mmcli -m "$modem" --messaging-delete-sms="$id" mmcli -m "$modem" --messaging-delete-sms="$id"
done done
notify-send "$count new messages" echo "$count new messages"

@ -2,6 +2,7 @@
CALL_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/Calls/" CALL_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/Calls/"
SMS_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/SMS/" SMS_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/SMS/"
ALSA_CONF_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/alsa/"
die(){ die(){
echo "$@" > /dev/stderr echo "$@" > /dev/stderr

@ -1,33 +1,67 @@
#!/usr/bin/env bash #!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source "$DIR/common"
export DISPLAY=:0.0 export DISPLAY=:0.0
prompt="" usage(){
echo "dialer"
answer="" echo "Options:"
reject="" echo " -h|--help Display this help text"
echo " -m|--modem Specify a modem"
options="1 echo " -l|--letters Show letter keyboard rather than just numbers"
4 echo " --dry-run Don't actually call"
7 }
*
altKeyboard(){
2 notify-send "also here"
5 if [ "$keyboard" = "svkbd-numbers" ]; then
8 echo "svkbd-colemak"
0 else
$answer echo "svkbd-numbers"
3 fi
6 }
9
# modem="$(mmcli -L | grep -oE 'Modem\/[0-9]+' | head -n 1 | cut -d'/' -f2)"
X" keyboard="svkbd-numbers"
dryrun=""
while true; do
#notify-send "$prompt" # Read the options and set stuff
input="$(echo "$options" | while [[ $1 = -?* ]]; do
rofi -dmenu -p "$prompt" -theme themes/dialer.rasi \ case $1 in
-me-select-entry '' -me-accept-entry MousePrimary)" -h|--help) usage; exit;;
[ "$input" = "X" ] && exit -m|--modem) modem="$2"; shift ;;
#exit -l|--letters) keyboard="svkbd-colemak"; shift ;;
prompt+="$input" --dry-run) dryrun="--dry-run" ;;
--) shift; break ;;
*) die "invalid option: '$1'." ;;
esac
shift
done
while : ; do
# Stop any running keyboards
pkill -9 'svkbd-*'
# Open the keyboard that we are using
"$keyboard" &
choice="$( (
echo "Switch Keyboard"
echo "Exit"
contact-numbers
) | rofi -dmenu -i -me-accept-entry '!MousePrimary' -p "Call" -normal-window -font 'Iosevka 20' )"
case "$choice" in
"Switch Keyboard") keyboard="$(altKeyboard)" ;;
"Exit") break ;;
*)
num="$(echo "$choice" | cut -d ' ' -f 2)"
pkill -9 'svkbd-*'
makeCall -m "$modem" $dryrun "$num"
break ;;
esac
done done

@ -0,0 +1,41 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source "$DIR/common"
export DISPLAY=:0.0
usage(){
echo "makeCall number"
echo "Options:"
echo " -h|--help Display this help text"
echo " -m|--modem Specify a modem"
echo " --dry-run Don't actually call"
}
modem="$(mmcli -L | grep -oE 'Modem\/[0-9]+' | head -n 1 | cut -d'/' -f2)"
# Read the options and set stuff
while [[ $1 = -?* ]]; do
case $1 in
-h|--help) usage; exit;;
-m|--modem) modem="$2"; shift ;;
--dry-run) dryrun="--dry-run" ;;
--) shift; break ;;
*) die "invalid option: '$1'." ;;
esac
shift
done
number="$1"
[ -z "$number" ] && die "No Number Specified"
callID="$(mmcli -m "$modem" --voice-create-call "number=$number" |
grep -Eo 'Call\/[0-9]+' | head -n 1 | cut -d'/' -f2)"
checkCall $dryrun "$callID"

@ -5,6 +5,8 @@
# #
# Although the proccess for managing calls etc is a bit simpler IMO # Although the proccess for managing calls etc is a bit simpler IMO
export DISPLAY=:0.0
# 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
@ -14,6 +16,7 @@ dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Voice',typ
# Monitor for incoming texts # Monitor for incoming texts
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Messaging',type='signal',member='Added'" | \ dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Messaging',type='signal',member='Added'" | \
while read -r line; do while read -r line; do
notify-send "Added (SMS)"
echo "$line" | grep -E "^signal" && checkSMS echo "$line" | grep -E "^signal" && checkSMS
done & done &

Loading…
Cancel
Save