setup-serial-fona.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/python
  2. #
  3. # Copyright (c) 2019 Clementine Computing LLC.
  4. #
  5. # This file is part of PopuFare.
  6. #
  7. # PopuFare is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # PopuFare is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. import serial
  21. import sys
  22. import re
  23. import time
  24. import os
  25. from os import listdir
  26. from os.path import isfile, join
  27. from os import system
  28. DEBUG = True
  29. VERBOSE = True
  30. ret = system("rm -f /dev/ttyPIU /dev/ttyGPRS /dev/ttyDIU /dev/ttyGPS")
  31. DEVDIR = "/dev"
  32. ###################
  33. ## setup GPRS modem from FONA
  34. ##
  35. system("ln -s /dev/ttyAMA0 /dev/ttyGPRS")
  36. ###################
  37. ttyfn = [f for f in listdir(DEVDIR) if re.match(r'^ttyUSB', f)]
  38. # sniff for GPRS and PIU
  39. #
  40. for devfn in ttyfn:
  41. if DEBUG: print devfn
  42. fqdevfn = join(DEVDIR,devfn)
  43. info = os.popen("udevadm info " + str(fqdevfn)).read()
  44. m = re.search(r'ID_MODEL=FT232R_USB_UART', info)
  45. if m:
  46. if VERBOSE:
  47. print "found rs232 device, assuming PIU"
  48. src_tty = join(DEVDIR,devfn)
  49. dst_tty = join(DEVDIR,"ttyPIU")
  50. system("ln -s " + src_tty + " " + dst_tty)
  51. continue
  52. m = re.search(r'SimTech_SIM5320', info)
  53. if m:
  54. if VERBOSE:
  55. print "found sim5320 device"
  56. m_ifacenum = re.search(r'ID_USB_INTERFACE_NUM=(.*)', info)
  57. if m_ifacenum:
  58. num = int(m_ifacenum.group(1))
  59. if num == 3:
  60. if VERBOSE:
  61. print "tying sim5320 interface num 3 to GPS"
  62. src_tty = join(DEVDIR,devfn)
  63. dst_tty = join(DEVDIR,"ttyGPS")
  64. system("ln -s " + src_tty + " " + dst_tty)
  65. continue