dist/tools/sniffer: whitespace fixes

This commit is contained in:
Joakim Gebart 2015-05-09 09:02:17 +02:00
parent f9059ea08d
commit 0d590e48bd
2 changed files with 52 additions and 53 deletions

View File

@ -55,4 +55,3 @@ For windows you can use the optional third argument to output to a
.pcap: .pcap:
$ ./rftestrx2pcap.py /dev/ttyUSB1 26 foo.pcap $ ./rftestrx2pcap.py /dev/ttyUSB1 26 foo.pcap

View File

@ -33,41 +33,41 @@ import re
import serial import serial
if len(sys.argv) < 3: if len(sys.argv) < 3:
sys.stderr.write( "Usage: %s tty channel [outfile]\n" %(sys.argv[0])) sys.stderr.write( "Usage: %s tty channel [outfile]\n" %(sys.argv[0]))
sys.stderr.write( " channel = 11-26\n") sys.stderr.write( " channel = 11-26\n")
sys.exit(2) sys.exit(2)
# change the channel # change the channel
try: try:
serport = serial.Serial(sys.argv[1], baudrate=115200, dsrdtr=0, rtscts=0, timeout=1) serport = serial.Serial(sys.argv[1], baudrate=115200, dsrdtr=0, rtscts=0, timeout=1)
serport.setDTR(0) serport.setDTR(0)
serport.setRTS(0) serport.setRTS(0)
except IOError: except IOError:
print "error opening port" print "error opening port"
sys.exit(2) sys.exit(2)
time.sleep(1) time.sleep(1)
chanstr = '' chanstr = ''
sys.stderr.write('chan %s\n' % sys.argv[2]) sys.stderr.write('chan %s\n' % sys.argv[2])
serport.write('chan %s\n' % sys.argv[2]) serport.write('chan %s\n' % sys.argv[2])
while 1: while 1:
c = serport.read(1) c = serport.read(1)
if (c == '\n'): if (c == '\n'):
chanstr = '' chanstr = ''
continue continue
chanstr += c chanstr += c
m = re.match(".*channel: (\w+)", chanstr) m = re.match(".*channel: (\w+)", chanstr)
if m: if m:
chan = int(m.group(1)) chan = int(m.group(1))
sys.stderr.write(chanstr + '\n') sys.stderr.write(chanstr + '\n')
break break
try: try:
sys.stderr.write('writing to file %s \n' % (sys.argv[3])) sys.stderr.write('writing to file %s \n' % (sys.argv[3]))
outfile = open(sys.argv[3], 'w+b') outfile = open(sys.argv[3], 'w+b')
except IndexError: except IndexError:
outfile = sys.stdout outfile = sys.stdout
sys.stderr.write("RX: 0\r") sys.stderr.write("RX: 0\r")
@ -88,39 +88,39 @@ fileempty = 1
newpacket = 0 newpacket = 0
try: try:
while 1: while 1:
line = serport.readline().rstrip() line = serport.readline().rstrip()
m_rftestline = re.match(".*rftest-rx --- len 0x(\w\w).*", line) m_rftestline = re.match(".*rftest-rx --- len 0x(\w\w).*", line)
if m_rftestline: if m_rftestline:
newpacket = 1 newpacket = 1
t = time.time() t = time.time()
sec = int(t) sec = int(t)
usec = (t - sec) * 100000 usec = (t - sec) * 100000
length = int(m_rftestline.group(1), 16) length = int(m_rftestline.group(1), 16)
continue continue
# if this is a new packet, add a packet header # if this is a new packet, add a packet header
if newpacket == 1: if newpacket == 1:
newpacket = 0 newpacket = 0
outfile.write(pack('<LLLL',sec,usec,length,length)) outfile.write(pack('<LLLL',sec,usec,length,length))
outfile.flush() outfile.flush()
count += 1 count += 1
sys.stderr.write("RX: %d\r" % count) sys.stderr.write("RX: %d\r" % count)
# clear file empty flag # clear file empty flag
if fileempty: if fileempty:
fileempty = 0 fileempty = 0
if fileempty == 0 : if fileempty == 0 :
# write payload # write payload
for d in line.split(' '): for d in line.split(' '):
# do a match because their might be a \r floating around # do a match because their might be a \r floating around
m = re.match('.*(\w\w).*', d) m = re.match('.*(\w\w).*', d)
if m: if m:
outfile.write(pack('<B', int(m.group(1),16))) outfile.write(pack('<B', int(m.group(1),16)))
outfile.flush() outfile.flush()
except KeyboardInterrupt: except KeyboardInterrupt:
# cn.close() # cn.close()
sys.exit(2) sys.exit(2)