Advertisement
Guest User

Untitled

a guest
May 25th, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3.  
  4. # Switches modem out of storage mode
  5. sudo usb_modeswitch -v 0x12d1 -p 0x14fe -V 0x12d1 -P 0x1506 -M '55534243123456780000000000000011062000000100000000000000000000' &> /dev/null
  6. sleep 30s
  7.  
  8. for path in $(ls /dev/ttyUSB*); do
  9. (
  10. MODEM=$path
  11. MODEMCMD=AT+CSQ
  12. INTERVAL=5
  13.  
  14. # Writes a command to modem
  15. wrmodem () {
  16. echo -ne "$*"'\r\n' >"$MODEM"
  17. }
  18.  
  19. # Formats and prints the signal to be a percentage
  20. formatsig () {
  21. result=$@
  22.  
  23. if [[ $result == *",99"* ]]
  24. then
  25. result=${result#$"+CSQ: "}
  26. result=${result%$",99"}
  27. result=$((result * 100))
  28. result=$((result / 31))
  29.  
  30. echo "$result%"
  31. kill $$
  32. fi
  33. }
  34.  
  35. # Listens for responses from the modem
  36. {
  37. trap EXIT
  38. while true ; do
  39. if read ; then
  40. formatsig "$(tr -d \\r <<<"$REPLY")"
  41. fi
  42. done
  43. } <"$MODEM" &
  44.  
  45. LOGGERPID=$!
  46. trap 'kill $LOGGERPID' EXIT
  47.  
  48. # requester
  49. wrmodem "$MODEMCMD"
  50. sleep $INTERVAL
  51. )
  52. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement