| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #!/usr/bin/python
- import serial
- import sys
- import re
- import time
- from os import listdir
- from os.path import isfile, join
- from os import system
- DEBUG = False
- VERBOSE = True
- ret = system("rm -f /dev/ttyPIU /dev/ttyGPRS /dev/ttyDIU /dev/ttyGPS")
- DEVDIR = "/dev"
- ###################
- 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)]
- 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()
|