def do_filtering(options, args, id_dict): """ Parameters ---------- options : ArgumentParser.parse_args() output Contains options from commandline input args : list of raw strings Contains arguments from commandline input id_dict : dictionary """ # Parse input and do filtering. # myfiltered is a list of packets; each pack is a list of integers. if options.quick: quickstream = StringIO(' '.join(args[0:])) myfiltered = filtering_method(quickstream, f_id=options.my_f_id, \ f_instr=options.my_f_instr, f_cmd=options.my_f_cmd, \ sync_split=options.sync_split) else: with open(args[0], 'r') as fr: myfiltered = filtering_method(fr, f_id=options.my_f_id, \ f_instr=options.my_f_instr, f_cmd=options.my_f_cmd, \ sync_split=options.sync_split) # Optionally write filtered results to a new file if options.output != '': if options.quick: print translate_packet(myfiltered[0], id_dict, includetime=options.timestamp) elif len(myfiltered): with open(options.output, 'w') as fw: # either translated output if options.translate: for packet in myfiltered: packet = translate_packet(packet, id_dict, \ includetime=options.timestamp) fw.write("\t".join(packet) + "\n") # or raw integer output; float timestamp included if exists else: for packet in myfiltered: fw.write(" ".join([str(x) for x in packet]) + "\n") print "Filtered results written to {0}\n".format(options.output) else: print "No packets satisfied the filters specified." # Optionally tally packets and report if options.my_tally_by != None: tally_packets(myfiltered, tally_by=options.my_tally_by) return
def _handle_packet(byte_packet, byte_list, startTime): """Method handles completed packets Parameters ---------- byte_packet : `BytePacket` instance A BytePacket object allowing external thread access to the current packet byte_list : list of ints New byte packet to be stored in byte_packet if valid startTime : float Result of initial time.time() call """ checksumOK = byte_list[-3] == \ 255 - (sum(byte_list[:-3]) % 256) # Save packet # Note: saved packets have FF FF prepended to them if saveall: byte_packet.word = [0xff, 0xff] + byte_list[:-2] elif checksumOK: byte_packet.word = [0xff, 0xff] + byte_list[:-2] else: # continue return list() if translate: # logging.debug("\t".join(translate_packet(byte_packet.word))) print "\t".join(translate_packet(byte_packet.word, id_dict)) else: logging.debug(("packet: " + \ " ".join(["{0:<3}".format(x) \ for x in byte_packet.word]) + \ " packet ok?: " + str(checksumOK ))) # Get packet time if timing: byte_packet.timestamp = gettime() - startTime return list()
def _handle_packet(byte_packet, byte_list, startTime): """Method handles completed packets Parameters ---------- byte_packet : `BytePacket` instance A BytePacket object allowing external thread access to the current packet byte_list : list of ints New byte packet to be stored in byte_packet if valid startTime : float Result of initial time.time() call """ checksumOK = byte_list[-3] == \ 255 - (sum(byte_list[:-3]) % 256) # Save packet # Note: saved packets have FF FF prepended to them if saveall: byte_packet.word = [0xff,0xff] + byte_list[:-2] elif checksumOK: byte_packet.word = [0xff,0xff] + byte_list[:-2] else: # continue return list() if translate: # logging.debug("\t".join(translate_packet(byte_packet.word))) print "\t".join(translate_packet(byte_packet.word, id_dict)) else: logging.debug(("packet: " + \ " ".join(["{0:<3}".format(x) \ for x in byte_packet.word]) + \ " packet ok?: " + str(checksumOK ))) # Get packet time if timing: byte_packet.timestamp = gettime() - startTime return list()