Przeglądaj źródła

further attempts at automatically sniffing serial to USB devices

clementinecomputing 6 lat temu
rodzic
commit
8e527568ad

+ 86 - 0
busunit/scripts/setup-serial-fona.py

@@ -0,0 +1,86 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2019 Clementine Computing LLC.
+#
+# This file is part of PopuFare.
+#
+# PopuFare is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# PopuFare is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with PopuFare.  If not, see <https://www.gnu.org/licenses/>.
+#
+
+
+import serial
+import sys
+import re
+import time
+import os
+from os import listdir
+from os.path import isfile, join
+from os import system
+
+DEBUG = True
+VERBOSE = True
+
+ret = system("rm -f /dev/ttyPIU /dev/ttyGPRS /dev/ttyDIU /dev/ttyGPS")
+
+DEVDIR = "/dev"
+
+###################
+
+## setup GPRS modem from FONA
+##
+system("ln -s /dev/ttyAMA0 /dev/ttyGPRS")
+
+
+###################
+
+ttyfn = [f for f in listdir(DEVDIR) if re.match(r'^ttyUSB', f)]
+
+# sniff for GPRS and PIU
+#
+for devfn in ttyfn:
+  if DEBUG: print devfn
+
+  fqdevfn = join(DEVDIR,devfn)
+
+  info = os.popen("udevadm info " + str(fqdevfn)).read()
+  m = re.search(r'ID_MODEL=FT232R_USB_UART', info)
+  if m:
+
+    if VERBOSE:
+      print "found rs232 device, assuming PIU"
+    src_tty = join(DEVDIR,devfn)
+    dst_tty = join(DEVDIR,"ttyPIU")
+    system("ln -s " + src_tty + " " + dst_tty)
+    continue
+
+  m = re.search(r'SimTech_SIM5320', info)
+  if m:
+
+    if VERBOSE:
+      print "found sim5320 device"
+
+    m_ifacenum = re.search(r'ID_USB_INTERFACE_NUM=(.*)', info)
+    if m_ifacenum:
+
+      num = int(m_ifacenum.group(1))
+      if num == 3:
+        if VERBOSE:
+          print "tying sim5320 interface num 3 to GPS"
+
+        src_tty = join(DEVDIR,devfn)
+        dst_tty = join(DEVDIR,"ttyGPS")
+        system("ln -s " + src_tty + " " + dst_tty)
+        continue
+
+

+ 117 - 0
busunit/scripts/setup-serial-legacy.py

@@ -0,0 +1,117 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2019 Clementine Computing LLC.
+#
+# This file is part of PopuFare.
+#
+# PopuFare is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# PopuFare is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with PopuFare.  If not, see <https://www.gnu.org/licenses/>.
+#
+
+
+import serial
+import sys
+import re
+import time
+from os import listdir
+from os.path import isfile, join
+from os import system
+
+DEBUG = True
+VERBOSE = True
+
+ret = system("rm -f /dev/ttyPIU /dev/ttyGPRS /dev/ttyDIU /dev/ttyGPS")
+
+DEVDIR = "/dev"
+
+###################
+
+# sniff for our GPS
+#
+ttyfn = [f for f in listdir(DEVDIR) if re.match(r'^ttyACM', f)]
+for devfn in ttyfn:
+  if DEBUG: print devfn
+  ser = serial.Serial(join(DEVDIR,devfn), 9600, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=0, rtscts=0)
+
+
+  x0 = ser.readline()
+  if DEBUG: print "at n (0):", x0
+  x1 = ser.readline()
+  if DEBUG: print "at n (1):", x1
+  x2 = ser.readline()
+  if DEBUG: print "at n (2):", x2
+  time.sleep(1)
+
+  if (re.match(r'^\$GP', x0) or
+      re.match(r'^\$GP', x1) or
+      re.match(r'^\$GP', x2)):
+    src_tty = join(DEVDIR,devfn)
+    dst_tty = join(DEVDIR,"ttyGPS")
+
+    if VERBOSE:
+      print src_tty, "->", dst_tty
+
+    system("ln -s " + src_tty + " " + dst_tty)
+
+  ser.close()
+
+
+###################
+
+ttyfn = [f for f in listdir(DEVDIR) if re.match(r'^ttyUSB', f)]
+
+# sniff for GPRS and PIU
+#
+for devfn in ttyfn:
+  if DEBUG: print devfn
+  ser = serial.Serial(join(DEVDIR,devfn), 115200, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=0, rtscts=0)
+
+  ser.write("\rAT\r")
+  ser.flush()
+  x0 = ser.readline()
+  if DEBUG: print "at n (0):", x0
+  x1 = ser.readline()
+  if DEBUG: print "at n (1):", x1
+  x2 = ser.readline()
+  if DEBUG: print "at n (2):", x2
+  time.sleep(1)
+
+  x0 = x0.strip()
+  x1 = x1.strip()
+  x2 = x2.strip()
+
+  if (x0 == "ok" or x0 == "OK" or
+      x1 == "ok" or x1 == "OK" or
+      x2 == "ok" or x2 == "OK"):
+    src_tty = join(DEVDIR,devfn)
+    dst_tty = join(DEVDIR,"ttyGPRS")
+
+    if VERBOSE:
+      print src_tty, "->", dst_tty
+
+    system("ln -s " + src_tty + " " + dst_tty)
+
+  if (x0[0:4] == "/?: " or
+      x1[0:4] == "/?: " or
+      x2[0:4] == "/?: "):
+    src_tty = join(DEVDIR,devfn)
+    dst_tty = join(DEVDIR,"ttyPIU")
+
+    if VERBOSE:
+      print src_tty, "->", dst_tty
+
+    system("ln -s " + src_tty + " " + dst_tty)
+
+  ser.close()
+
+

+ 0 - 117
busunit/scripts/setup-serial.py

@@ -1,117 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (c) 2019 Clementine Computing LLC.
-#
-# This file is part of PopuFare.
-#
-# PopuFare is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# PopuFare is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with PopuFare.  If not, see <https://www.gnu.org/licenses/>.
-#
-
-
-import serial
-import sys
-import re
-import time
-from os import listdir
-from os.path import isfile, join
-from os import system
-
-DEBUG = True
-VERBOSE = True
-
-ret = system("rm -f /dev/ttyPIU /dev/ttyGPRS /dev/ttyDIU /dev/ttyGPS")
-
-DEVDIR = "/dev"
-
-###################
-
-# sniff for our GPS
-#
-ttyfn = [f for f in listdir(DEVDIR) if re.match(r'^ttyACM', f)]
-for devfn in ttyfn:
-  if DEBUG: print devfn
-  ser = serial.Serial(join(DEVDIR,devfn), 9600, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=0, rtscts=0)
-
-
-  x0 = ser.readline()
-  if DEBUG: print "at n (0):", x0
-  x1 = ser.readline()
-  if DEBUG: print "at n (1):", x1
-  x2 = ser.readline()
-  if DEBUG: print "at n (2):", x2
-  time.sleep(1)
-
-  if (re.match(r'^\$GP', x0) or
-      re.match(r'^\$GP', x1) or
-      re.match(r'^\$GP', x2)):
-    src_tty = join(DEVDIR,devfn)
-    dst_tty = join(DEVDIR,"ttyGPS")
-
-    if VERBOSE:
-      print src_tty, "->", dst_tty
-
-    system("ln -s " + src_tty + " " + dst_tty)
-
-  ser.close()
-
-
-###################
-
-ttyfn = [f for f in listdir(DEVDIR) if re.match(r'^ttyUSB', f)]
-
-# sniff for GPRS and PIU
-#
-for devfn in ttyfn:
-  if DEBUG: print devfn
-  ser = serial.Serial(join(DEVDIR,devfn), 115200, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=0, rtscts=0)
-
-  ser.write("\rAT\r")
-  ser.flush()
-  x0 = ser.readline()
-  if DEBUG: print "at n (0):", x0
-  x1 = ser.readline()
-  if DEBUG: print "at n (1):", x1
-  x2 = ser.readline()
-  if DEBUG: print "at n (2):", x2
-  time.sleep(1)
-
-  x0 = x0.strip()
-  x1 = x1.strip()
-  x2 = x2.strip()
-
-  if (x0 == "ok" or x0 == "OK" or
-      x1 == "ok" or x1 == "OK" or
-      x2 == "ok" or x2 == "OK"):
-    src_tty = join(DEVDIR,devfn)
-    dst_tty = join(DEVDIR,"ttyGPRS")
-
-    if VERBOSE:
-      print src_tty, "->", dst_tty
-
-    system("ln -s " + src_tty + " " + dst_tty)
-
-  if (x0[0:4] == "/?: " or
-      x1[0:4] == "/?: " or
-      x2[0:4] == "/?: "):
-    src_tty = join(DEVDIR,devfn)
-    dst_tty = join(DEVDIR,"ttyPIU")
-
-    if VERBOSE:
-      print src_tty, "->", dst_tty
-
-    system("ln -s " + src_tty + " " + dst_tty)
-
-  ser.close()
-
-

+ 1 - 0
busunit/scripts/setup-serial.py

@@ -0,0 +1 @@
+setup-serial-fona.py