#!/usr/bin/python # (C) 2012, Mariano Alvira import sys,os,time from termios import * from struct import * import re if len(sys.argv) < 3: sys.stderr.write( "Usage: %s tty channel\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 = os.open(sys.argv[1], os.O_RDWR|os.O_NOCTTY) except IOError: print "error opening port" sys.exit(2) try: oldattrs = tcgetattr(serport) attrs = [IGNPAR, oldattrs[1], 0, 0, B115200, B115200, oldattrs[6]] attrs[2] = B115200 | CS8 | CLOCAL | CREAD attrs[6][VTIME] = 0 attrs[6][VMIN] = 1 tcflush(serport, TCIFLUSH) tcsetattr(serport, TCSANOW, attrs) except IOError: print "IOError in termios" sys.exit(2) chan = '' while chan != int(sys.argv[2]) - 11: os.write(serport, ' ') chanstr = '' while 1: chanstr += os.read(serport, 1) m = re.match(".*channel: (\w+)\s+", chanstr) if m != None: chan = int(m.group(1)) break os.close(serport) try: serport = open(sys.argv[1], 'r+') except IOError: print "error opening port" sys.exit(2) ### 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 sys.stdout.write(pack('