Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- # Switches modem out of storage mode
- sudo usb_modeswitch -v 0x12d1 -p 0x14fe -V 0x12d1 -P 0x1506 -M '55534243123456780000000000000011062000000100000000000000000000' &> /dev/null
- sleep 30s
- for path in $(ls /dev/ttyUSB*); do
- (
- MODEM=$path
- MODEMCMD=AT+CSQ
- INTERVAL=5
- # Writes a command to modem
- wrmodem () {
- echo -ne "$*"'\r\n' >"$MODEM"
- }
- # Formats and prints the signal to be a percentage
- formatsig () {
- result=$@
- if [[ $result == *",99"* ]]
- then
- result=${result#$"+CSQ: "}
- result=${result%$",99"}
- result=$((result * 100))
- result=$((result / 31))
- echo "$result%"
- kill $$
- fi
- }
- # Listens for responses from the modem
- {
- trap EXIT
- while true ; do
- if read ; then
- formatsig "$(tr -d \\r <<<"$REPLY")"
- fi
- done
- } <"$MODEM" &
- LOGGERPID=$!
- trap 'kill $LOGGERPID' EXIT
- # requester
- wrmodem "$MODEMCMD"
- sleep $INTERVAL
- )
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement