setup-serial-dmesg.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 subprocess as sp
  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. for devfn in ["ttyUSB0", "ttyUSB1"]:
  33. s = sp.check_output("dmesg | grep " + devfn + " | tail -n1", shell=True)
  34. s = s.strip()
  35. print s
  36. if re.search(r'FTDI', s):
  37. print devfn, "-> /dev/ttyPIU (ftdi)"
  38. system("ln -s " + devfn + " /dev/ttyPIU")
  39. elif re.search(r'pl2303', s):
  40. print devfn, "-> /dev/ttyGPRS (pl2303)"
  41. system("ln -s " + devfn + " /dev/ttyGPRS")
  42. system("ln -s /dev/ttyACM0 /dev/ttyGPS")