summaryrefslogtreecommitdiff
path: root/gpscat
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2006-11-23 08:24:35 +0000
committerEric S. Raymond <esr@thyrsus.com>2006-11-23 08:24:35 +0000
commit4644b974be4cb771b506b36a655f9785ded4a834 (patch)
tree8b5334e794cb25f746a7cf4ab37b05f4d2910700 /gpscat
parentb0591cfbe3f1f9e621b8ee61988f210a2591b52e (diff)
downloadgpsd-4644b974be4cb771b506b36a655f9785ded4a834.tar.gz
Make gpscat able to set parity and stopbits.
Diffstat (limited to 'gpscat')
-rwxr-xr-xgpscat25
1 files changed, 23 insertions, 2 deletions
diff --git a/gpscat b/gpscat
index 83b249c6..a6a83012 100755
--- a/gpscat
+++ b/gpscat
@@ -28,9 +28,15 @@ if __name__ == '__main__':
print "gpscat: " + str(msg)
raise SystemExit, 1
- speed = -1
+ speed = None
+ parity = None
+ stopbits = None
for (switch, val) in options:
if switch == '-s':
+ if val[-2] in ('N', 'E', 'O'):
+ parity = val[-2]
+ stopbits = int(val[-1])
+ val = val[:-2]
speed = int(val)
elif switch == '-h':
sys.stderr.write("usage: gpscat [-s] serial-port\n")
@@ -40,13 +46,28 @@ if __name__ == '__main__':
raise SystemExit, 0
tty = os.open(arguments[0], os.O_RDWR)
- if speed != -1:
+ if speed != None:
(iflag, oflag, cflag, lflag, ispeed, ospeed, cc) = termios.tcgetattr(tty)
try:
ispeed = ospeed = eval("termios.B%d" % speed)
except AttributeError:
sys.stderr.write("gpscat: unknown baud rate %d\n" % speed)
raise SystemExit, 1
+ if stopbits:
+ cflag &= ~termios.CSIZE
+ cflag |= (termios.CS8, termios.CS7)[stopbits-1]
+ if parity:
+ if parity == 'N':
+ iflag &= ~termios.PARENB
+ iflag &= ~termios.INPCK
+ elif parity == 'O':
+ iflag |= termios.INPCK
+ cflag |= termios.PARENB
+ cflag |= termios.PARODD
+ elif parity == 'E':
+ iflag |= termios.INPCK
+ cflag |= termios.PARENB
+ cflag &= ~termios.PARODD
termios.tcsetattr(tty, termios.TCSANOW,
[iflag, oflag, cflag, lflag, ispeed, ospeed, cc])