parent
3c5a85a9a1
commit
a4b2724c4a
4 changed files with 178 additions and 174 deletions
@ -1,130 +1,111 @@ |
|||||||
#!/usr/bin/env sh |
#!/usr/bin/env sh |
||||||
TIMEOUT=3 |
TIMEOUT=3 |
||||||
LOGDIR="$XDG_CONFIG_HOME"/sxmo/modem |
LOGDIR="$XDG_CONFIG_HOME"/sxmo/modem |
||||||
ACTIVECALL="NONE" |
trap "gracefulexit" INT TERM |
||||||
trap "kill 0" INT |
|
||||||
|
|
||||||
err() { |
err() { |
||||||
printf %b "$1" | dmenu -fn Terminus-20 -c -l 10 |
notify-send "$1" |
||||||
|
gracefulexit |
||||||
|
} |
||||||
|
|
||||||
|
gracefulexit() { |
||||||
|
echo "gracefully exiting $0!" |
||||||
|
sxmo_setpineled green 0 |
||||||
kill -9 0 |
kill -9 0 |
||||||
} |
} |
||||||
|
|
||||||
modem_n() { |
modem_n() { |
||||||
MODEMS="$(mmcli -L)" |
MODEMS="$(mmcli -L)" |
||||||
echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' > /dev/null || err "Couldn't find modem - is your modem enabled?\nDisabling modem monitor" |
echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' > /dev/null || err "Couldn't find modem - is your modem enabled?\nDisabling modem monitor" |
||||||
echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 |
echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 |
||||||
} |
} |
||||||
|
|
||||||
newcall() { |
checkforincomingcalls() { |
||||||
VID="$1" |
VOICECALLID="$( |
||||||
sxmo_vibratepine 2000 & |
mmcli -m "$(modem_n)" --voice-list-calls -a | |
||||||
sxmo_setpineled green 1 |
grep -Eo '[0-9]+ incoming \(ringing-in\)' | |
||||||
|
grep -Eo '[0-9]+' |
||||||
|
)" |
||||||
|
|
||||||
|
if echo "$VOICECALLID" | grep -v .; then |
||||||
|
rm -f /tmp/sxmo_incomingcall |
||||||
|
return |
||||||
|
fi |
||||||
|
|
||||||
|
sxmo_vibratepine 2000 & sxmo_setpineled green 1 |
||||||
|
|
||||||
# Delete all terminated calls |
# Delete all previous calls which have been terminated calls |
||||||
for i in $(mmcli -m "$(modem_n)" --voice-list-calls | grep terminated | grep -oE "Call\/[0-9]+" | cut -d'/' -f2); do |
for CALLID in $( |
||||||
mmcli -m "$(modem_n)" --voice-delete-call "$i" |
mmcli -m "$(modem_n)" --voice-list-calls | |
||||||
|
grep terminated | |
||||||
|
grep -oE "Call\/[0-9]+" | |
||||||
|
cut -d'/' -f2 |
||||||
|
); do |
||||||
|
mmcli -m "$(modem_n)" --voice-delete-call "$CALLID" |
||||||
done |
done |
||||||
|
|
||||||
|
# Determine the incoming phone number |
||||||
echo "Incoming Call:" |
echo "Incoming Call:" |
||||||
INCOMINGNUMBER=$( |
INCOMINGNUMBER=$( |
||||||
mmcli -m "$(modem_n)" --voice-list-calls -o "$VID" -K | |
mmcli -m "$(modem_n)" --voice-list-calls -o "$VOICECALLID" -K | |
||||||
grep call.properties.number | |
grep call.properties.number | |
||||||
cut -d ':' -f 2 | |
cut -d ':' -f 2 | |
||||||
sed 's/^[+]//' | |
sed 's/^[+]//' | |
||||||
sed 's/^1//' |
sed 's/^1//' |
||||||
) |
) |
||||||
|
|
||||||
|
# Log to /tmp/incomingcall to allow pickup and log into modemlog |
||||||
TIME="$(date --iso-8601=seconds)" |
TIME="$(date --iso-8601=seconds)" |
||||||
mkdir -p "$LOGDIR" |
mkdir -p "$LOGDIR" |
||||||
printf %b "$TIME\tcall_ring\t$INCOMINGNUMBER\n" >> "$LOGDIR/modemlog.tsv" |
printf %b "$TIME\tcall_ring\t$INCOMINGNUMBER\n" >> "$LOGDIR/modemlog.tsv" |
||||||
echo "$VID:$INCOMINGNUMBER" > /tmp/sxmo_incomingcall |
echo "$VOICECALLID:$INCOMINGNUMBER" > /tmp/sxmo_incomingcall |
||||||
echo "Number: $INCOMINGNUMBER (VID: $VID)" |
echo "Number: $INCOMINGNUMBER (VOICECALLID: $VOICECALLID)" |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
newtexts() { |
checkfornewtexts() { |
||||||
sxmo_setpineled green 1 |
TEXTIDS="$( |
||||||
|
mmcli -m "$(modem_n)" --messaging-list-sms | |
||||||
echo "New Texts:" |
grep -Eo '/SMS/[0-9]+ \(received\)' | |
||||||
for i in $(printf %b "$1") ; do |
grep -Eo '[0-9]+' |
||||||
DAT="$(mmcli -m "$(modem_n)" -s "$i" -K)" |
)" |
||||||
|
echo "$TEXTIDS" | grep -v . && return |
||||||
TEXT="$(echo "$DAT" | grep sms.content.text | sed -E 's/^sms\.content\.text\s+:\s+//')" |
|
||||||
|
# Loop each textid received and read out the data into appropriate logfile |
||||||
|
{ |
||||||
|
sxmo_setpineled green 1 |
||||||
|
sxmo_vibratepine 200; |
||||||
|
sleep 0.1; |
||||||
|
sxmo_vibratepine 200; |
||||||
|
sleep 0.1; |
||||||
|
sxmo_vibratepine 200; |
||||||
|
} & |
||||||
|
|
||||||
|
for TEXTID in $(printf %b "$TEXTIDS") ; do |
||||||
|
TEXTDATA="$(mmcli -m "$(modem_n)" -s "$TEXTID" -K)" |
||||||
|
TEXT="$(echo "$TEXTDATA" | grep sms.content.text | sed -E 's/^sms\.content\.text\s+:\s+//')" |
||||||
NUM="$( |
NUM="$( |
||||||
echo "$DAT" | |
echo "$TEXTDATA" | |
||||||
grep sms.content.number | |
grep sms.content.number | |
||||||
sed -E 's/^sms\.content\.number\s+:\s+[+]?//' | |
sed -E 's/^sms\.content\.number\s+:\s+[+]?//' | |
||||||
sed 's/^[+]//' | |
sed 's/^[+]//' | |
||||||
sed 's/^1//' |
sed 's/^1//' |
||||||
)" |
)" |
||||||
TIME="$(echo "$DAT" | grep sms.properties.timestamp | sed -E 's/^sms\.properties\.timestamp\s+:\s+//')" |
TIME="$(echo "$TEXTDATA" | grep sms.properties.timestamp | sed -E 's/^sms\.properties\.timestamp\s+:\s+//')" |
||||||
TEXTSIZE="${#TEXT}" |
|
||||||
|
|
||||||
mkdir -p "$LOGDIR/$NUM" |
mkdir -p "$LOGDIR/$NUM" |
||||||
printf %b "Received from $NUM at $TIME:\n$TEXT\n\n" >> "$LOGDIR/$NUM/sms.txt" |
printf %b "Received from $NUM at $TIME:\n$TEXT\n\n" >> "$LOGDIR/$NUM/sms.txt" |
||||||
printf %b "$TIME\trecv_txt\t$NUM\t$TEXTSIZE chars\n" >> "$LOGDIR/modemlog.tsv" |
printf %b "$TIME\trecv_txt\t$NUM\t${#TEXT} chars\n" >> "$LOGDIR/modemlog.tsv" |
||||||
mmcli -m "$(modem_n)" --messaging-delete-sms="$i" |
mmcli -m "$(modem_n)" --messaging-delete-sms="$TEXTID" |
||||||
|
|
||||||
sxmo_vibratepine 300 && sleep 0.1 |
|
||||||
sxmo_vibratepine 300 && sleep 0.1 |
|
||||||
sxmo_vibratepine 300 |
|
||||||
done |
done |
||||||
} |
} |
||||||
|
|
||||||
killinprogresscall() { |
mainloop() { |
||||||
echo "Kill the in progress call" |
while true; do |
||||||
pkill -9 dmenu |
sxmo_setpineled green 0 |
||||||
} |
checkforincomingcalls |
||||||
|
checkfornewtexts |
||||||
inprogresscallchecker() { |
sleep $TIMEOUT & wait |
||||||
# E.g. register current call in progress as ACTIVECALL |
done |
||||||
CURRENTCALLS="$(mmcli -m "$(modem_n)" --voice-list-calls)" |
|
||||||
|
|
||||||
# E.g. if we've previously registered an ACTIVECALL, check if it |
|
||||||
# was terminated by the otherside, if so kill the incall script |
|
||||||
# and notify user |
|
||||||
if echo "$ACTIVECALL" | grep -E '[0-9]+'; then |
|
||||||
echo "$CURRENTCALLS" | grep -E "Call/${ACTIVECALL}.+terminated" && |
|
||||||
killinprogresscall |
|
||||||
fi |
|
||||||
|
|
||||||
# Register the active call so we can check in future loops if |
|
||||||
# other side hung up |
|
||||||
ACTIVECALL="$( |
|
||||||
echo "$CURRENTCALLS" | |
|
||||||
grep -oE "[0-9]+ (incoming|outgoing).+active" | |
|
||||||
cut -d' ' -f1 |
|
||||||
)" |
|
||||||
|
|
||||||
echo "Set new Activecall:<$ACTIVECALL>" |
|
||||||
} |
} |
||||||
|
|
||||||
while true |
mainloop |
||||||
do |
|
||||||
sxmo_setpineled green 0 |
|
||||||
VOICECALLID="$( |
|
||||||
mmcli -m "$(modem_n)" --voice-list-calls -a | |
|
||||||
grep -Eo '[0-9]+ incoming \(ringing-in\)' | |
|
||||||
grep -Eo '[0-9]+' |
|
||||||
)" |
|
||||||
|
|
||||||
TEXTIDS="$( |
|
||||||
mmcli -m "$(modem_n)" --messaging-list-sms | |
|
||||||
grep -Eo '/SMS/[0-9]+ \(received\)' | |
|
||||||
grep -Eo '[0-9]+' |
|
||||||
)" |
|
||||||
|
|
||||||
echo "Check status, VIDS: $VOICECALLID, TIDS: $TEXTIDS" |
|
||||||
|
|
||||||
inprogresscallchecker |
|
||||||
|
|
||||||
if echo "$VOICECALLID" | grep .; then |
|
||||||
newcall "$VOICECALLID" |
|
||||||
else |
|
||||||
rm -f /tmp/sxmo_incomingcall |
|
||||||
fi |
|
||||||
|
|
||||||
echo "$TEXTIDS" | grep . && newtexts "$TEXTIDS" |
|
||||||
|
|
||||||
sleep $TIMEOUT |
|
||||||
done |
|
||||||
|
Loading…
Reference in new issue