def __init__(self, logfp, predump=False): self.sentences = [] # This is the interesting part if type(logfp) == type(""): logfp = open(logfp, "r"); self.name = logfp.name self.logfp = logfp self.predump = predump self.logfile = logfp.name self.type = None self.sourcetype = "pty" self.serial = None # Grab the packets getter = sniffer.new() #gps.packet.register_report(reporter) type_latch = None while True: (plen, ptype, packet, counter) = getter.get(logfp.fileno()) if plen <= 0: break elif ptype == sniffer.COMMENT_PACKET: # Some comments are magic if "Serial:" in packet: # Change serial parameters packet = packet[1:].strip() try: (xx, baud, params) = packet.split() baud = int(baud) if params[0] in ('7', '8'): databits = int(params[0]) else: raise ValueError if params[1] in ('N', 'O', 'E'): parity = params[1] else: raise ValueError if params[2] in ('1', '2'): stopbits = int(params[2]) else: raise ValueError except (ValueError, IndexError): raise TestLoadError("bad serial-parameter spec in %s"%\ logfp.name) self.serial = (baud, databits, parity, stopbits) elif "UDP" in packet: self.sourcetype = "UDP" else: if type_latch is None: type_latch = ptype if self.predump: print `packet` if not packet: raise TestLoadError("zero-length packet from %s"%\ logfp.name) self.sentences.append(packet) # Look at the first packet to grok the GPS type self.textual = (type_latch == sniffer.NMEA_PACKET) if self.textual: self.legend = "gpsfake: line %d: " else: self.legend = "gpsfake: packet %d"
def __init__(self, logfp, predump=False): self.sentences = [] # This is the interesting part if type(logfp) == type(""): logfp = open(logfp, "r") self.name = logfp.name self.logfp = logfp self.predump = predump self.logfile = logfp.name self.type = None self.sourcetype = "pty" self.serial = None # Grab the packets getter = sniffer.new() #gps.packet.register_report(reporter) type_latch = None while True: (plen, ptype, packet, counter) = getter.get(logfp.fileno()) if plen <= 0: break elif ptype == sniffer.COMMENT_PACKET: # Some comments are magic if "Serial:" in packet: # Change serial parameters packet = packet[1:].strip() try: (xx, baud, params) = packet.split() baud = int(baud) if params[0] in ('7', '8'): databits = int(params[0]) else: raise ValueError if params[1] in ('N', 'O', 'E'): parity = params[1] else: raise ValueError if params[2] in ('1', '2'): stopbits = int(params[2]) else: raise ValueError except (ValueError, IndexError): raise TestLoadError("bad serial-parameter spec in %s"%\ logfp.name) self.serial = (baud, databits, parity, stopbits) elif "UDP" in packet: self.sourcetype = "UDP" else: if type_latch is None: type_latch = ptype if self.predump: print repr(packet) if not packet: raise TestLoadError("zero-length packet from %s"%\ logfp.name) self.sentences.append(packet) # Look at the first packet to grok the GPS type self.textual = (type_latch == sniffer.NMEA_PACKET) if self.textual: self.legend = "gpsfake: line %d: " else: self.legend = "gpsfake: packet %d"
def __init__(self, logfp, predump=False): self.sentences = [] # This is the interesting part if type(logfp) == type(""): logfp = open(logfp, "r") self.name = logfp.name self.logfp = logfp self.predump = predump self.type = None self.sourcetype = "pty" self.serial = None self.delay = WRITE_PAD self.delimiter = None # Stash away a copy in case we need to resplit text = logfp.read() logfp = open(logfp.name) # Grab the packets in the normal way getter = sniffer.new() #gps.packet.register_report(reporter) type_latch = None commentlen = 0 while True: (plen, ptype, packet, _counter) = getter.get(logfp.fileno()) if plen <= 0: break elif ptype == sniffer.COMMENT_PACKET: commentlen += len(packet) # Some comments are magic if "Serial:" in packet: # Change serial parameters packet = packet[1:].strip() try: (_xx, baud, params) = packet.split() baud = int(baud) if params[0] in ('7', '8'): databits = int(params[0]) else: raise ValueError if params[1] in ('N', 'O', 'E'): parity = params[1] else: raise ValueError if params[2] in ('1', '2'): stopbits = int(params[2]) else: raise ValueError except (ValueError, IndexError): raise TestLoadError("bad serial-parameter spec in %s"%\ self.name) self.serial = (baud, databits, parity, stopbits) elif "Transport: UDP" in packet: self.sourcetype = "UDP" elif "Transport: TCP" in packet: self.sourcetype = "TCP" elif "Delay-Cookie:" in packet: if packet.startswith("#"): packet = packet[1:] try: (_dummy, self.delimiter, delay) = packet.strip().split() self.delay = float(delay) except ValueError: raise TestLoadError("bad Delay-Cookie line in %s"%\ self.name) self.resplit = True else: if type_latch is None: type_latch = ptype if self.predump: print(repr(packet)) if not packet: raise TestLoadError("zero-length packet from %s"%\ self.name) self.sentences.append(packet) # Look at the first packet to grok the GPS type self.textual = (type_latch == sniffer.NMEA_PACKET) if self.textual: self.legend = "gpsfake: line %d: " else: self.legend = "gpsfake: packet %d" # Maybe this needs to be split on different delimiters? if self.delimiter is not None: self.sentences = text[commentlen:].split(self.delimiter)