A quite sophisticated bash script for getting signal quality (AT+CSQ) from GPRS modem:
#!/bin/bash
function get_response
{
local ECHO
# cat will read the response, then die on timeout
cat <&5 >$TMP &
echo "$1" >&5
# wait for cat to die
wait $!
exec 6<$TMP
read ECHO <&6
if [ "$ECHO" != "$1" ]
then
exec 6<&-
return 1
fi
read ECHO <&6
read RESPONSE <&6
exec 6<&-
return 0
}
TMP="/tmp/response"
# Clear out old response
: > $TMP
# Set modem with timeout of 5/10 a second
stty -F /dev/ttyACM0 -echo igncr -icanon onlcr ixon min 0 time 5
# Open modem on FD 5
exec 5<>/dev/ttyACM0
get_response "AT" || echo "Bad response"
RESPONSE=`cat $TMP`
echo "Response was ${RESPONSE}"
echo
get_response "AT+CSQ" || echo "Bad response"
RESPONSE=`cat $TMP`
echo "Response was ${RESPONSE}"
exec 5<&-
No comments:
Post a Comment