예제 #1
0
 def reset_connection(self):
     self.residual = None
     self.reader = _modes.Reader(self.mode)
     if self.mode is None:
         self.feed = self.detect
     else:
         self.feed = self.reader.feed
     # configure filter, seen-tracking
     self.reader.seen = set()
     self.reader.default_filter = self.default_filter
     self.reader.specific_filter = self.specific_filter
예제 #2
0
    def __init__(self, *, loop, id, host, port, correlator):
        self.loop = loop
        self.id = id
        self.host = host
        self.port = port

        self.parser = _modes.Reader(_modes.BEAST)
        self.parser.default_filter = [False] * 32
        self.parser.default_filter[17] = True

        self.frequency = None
        self.task = asyncio.async(self.handle_connection())
        self.correlator = correlator
예제 #3
0
def detect_data_format(data):
    """Try to work out what sort of data format this is.

    Returns (offset, mode) where offset is the byte offset
    to start at and mode is the decoder mode to use,
    or None if detection failed."""

    for i in range(len(data) - 4):
        mode = None

        if data[i] != b'\x1a' and data[i + 1:i + 3] in (b'\x1a1', b'\x1a2',
                                                        b'\x1a3', b'\x1a4'):
            mode = _modes.BEAST
            offset = 1

        elif data[i:i + 4] == b'\x10\0x03\x10\0x02':
            mode = _modes.SBS
            offset = 2

        else:
            if data[i:i + 3] in (b';\n\r', b';\r\n'):
                avr_prefix = 3
            elif data[i:i + 2] in (b';\n', b';\r'):
                avr_prefix = 2
            else:
                avr_prefix = None

            if avr_prefix:
                firstbyte = data[i + avr_prefix]
                if firstbyte in (ord('@'), ord('%'), ord('<')):
                    mode = _modes.AVRMLAT
                    offset = avr_prefix
                elif firstbyte in (ord('*'), ord('.')):
                    mode = _modes.AVR
                    offset = avr_prefix

        if mode:
            reader = _modes.Reader(mode)
            # don't actually want any data, just parse it
            reader.want_events = False
            reader.default_filter = [False] * 32
            try:
                n, _, pending_error = reader.feed(data[i + offset:])
                if n > 0 and not pending_error:
                    # consumed some data without problems
                    return (i + offset, mode)
            except ValueError:
                # parse error, ignore it
                pass

    return (0, None)
예제 #4
0
def clock_epoch(args):
    return _modes.Reader(_receiver_types[args.input_type][0]).epoch
예제 #5
0
def clock_frequency(args):
    return _modes.Reader(_receiver_types[args.input_type][0]).frequency