#!/usr/bin/python # (C) 2012, Mariano Alvira import sys,os,time from struct import * import re import serial if len(sys.argv) < 3: sys.stderr.write( "Usage: %s tty channel [outfile]\n" %(sys.argv[0])) sys.stderr.write( " channel = 11-26\n") sys.exit(2) # change the channel # rftest-rx increments it's channel everytime you send a character and returns "channel: num" # send a character until we get to the right channel try: serport = serial.Serial(sys.argv[1], 115200, timeout=1) except IOError: print "error opening port" sys.exit(2) chan = '' while chan != int(sys.argv[2]) - 11: serport.write(' ') chanstr = '' while 1: chanstr += serport.read(1) m = re.match(".*channel: (\w+)\s+", chanstr) if m is not None: chan = int(m.group(1)) break try: sys.stderr.write('writing to file %s \n' % (sys.argv[3])) outfile = open(sys.argv[3], 'w+b') except IndexError: outfile = sys.stdout sys.stderr.write("RX: 0\r") ### PCAP setup MAGIC = 0xa1b2c3d4; MAJOR = 2; MINOR = 4; ZONE = 0; SIG = 0; SNAPLEN = 0xffff; NETWORK = 230; # 802.15.4 no FCS # output overall PCAP header outfile.write(pack('