Beispiel #1
0
    def _process_packet(self):
        chunk = self._filehandle.read(1024)
        if chunk != '':
            self.buffer += chunk
            new_index = 0
            for match in self.ooi_ts_regex.finditer(self.buffer):
                payload = match.group(2)
                try:
                    packet_time = string_to_ntp_date_time(match.group(1))
                    header = PacketHeader(
                        packet_type=PacketType.FROM_INSTRUMENT,
                        payload_size=len(payload),
                        packet_time=packet_time)
                    header.set_checksum(payload)
                    packet = PlaybackPacket(payload=payload, header=header)
                    self.callback(packet)
                except ValueError:
                    log.error('Unable to extract timestamp from record: %r' %
                              match.group())
                new_index = match.end()

            if new_index > 0:
                self.buffer = self.buffer[new_index:]

            if len(self.buffer) > self.MAXBUF:
                self.buffer = self.buffer[-self.MAXBUF:]

            return True

        return False
Beispiel #2
0
    def _process_packet(self):
        chunk = self._filehandle.read(1024)
        if chunk != '':
            self.buffer += chunk
            new_index = 0
            for match in self.ooi_ts_regex.finditer(self.buffer):
                payload = match.group(2)
                try:
                    packet_time = string_to_ntp_date_time(match.group(1))
                    header = PacketHeader(packet_type=PacketType.FROM_INSTRUMENT,
                                          payload_size=len(payload), packet_time=packet_time)
                    header.set_checksum(payload)
                    packet = PlaybackPacket(payload=payload, header=header)
                    self.callback(packet)
                except ValueError:
                    log.error('Unable to extract timestamp from record: %r' % match.group())
                new_index = match.end()

            if new_index > 0:
                self.buffer = self.buffer[new_index:]

            if len(self.buffer) > self.MAXBUF:
                self.buffer = self.buffer[-self.MAXBUF:]

            return True

        return False
Beispiel #3
0
 def _process_packet(self):
     data = self._filehandle.read(1024)
     if data != '':
         header = PacketHeader(packet_type=PacketType.FROM_INSTRUMENT,
                               payload_size=len(data), packet_time=0)
         header.set_checksum(data)
         packet = PlaybackPacket(payload=data, header=header)
         self.callback(packet)
         return True
     return False
Beispiel #4
0
 def _process_packet(self):
     data = self._filehandle.read(1024)
     if data != '':
         header = PacketHeader(packet_type=PacketType.FROM_INSTRUMENT,
                               payload_size=len(data), packet_time=0)
         header.set_checksum(data)
         packet = PlaybackPacket(payload=data, header=header)
         self.callback(packet)
         return True
     return False
    def _process_packet(self):

        for name in self.file_name_list:
            data = 'downloaded file:' + name + '\n'
            header = PacketHeader(packet_type=PacketType.FROM_INSTRUMENT,
                                  payload_size=len(data), packet_time=0)
            header.set_checksum(data)
            packet = PlaybackPacket(payload=data, header=header)
            self.callback(packet)

        return False
Beispiel #6
0
    def _process_packet(self):

        for name in self.file_name_list:
            data = 'downloaded file:' + name + '\n'
            header = PacketHeader(packet_type=PacketType.FROM_INSTRUMENT,
                                  payload_size=len(data), packet_time=0)
            header.set_checksum(data)
            packet = PlaybackPacket(payload=data, header=header)
            self.callback(packet)

        return False
Beispiel #7
0
    def packet_from_fh(file_handle):
        data_buffer = bytearray()
        while True:
            byte = file_handle.read(1)
            if byte == '':
                return None

            data_buffer.append(byte)
            sync_index = data_buffer.find(PacketHeader.sync)
            if sync_index != -1:
                # found the sync bytes, read the rest of the header
                data_buffer.extend(file_handle.read(PacketHeader.header_size - len(PacketHeader.sync)))

                if len(data_buffer) < PacketHeader.header_size:
                    return None

                header = PacketHeader.from_buffer(data_buffer, sync_index)
                # read the payload
                payload = file_handle.read(header.payload_size)
                if len(payload) == header.payload_size:
                    packet = PlaybackPacket(payload=payload, header=header)
                    return packet
Beispiel #8
0
    def packet_from_fh(file_handle):
        data_buffer = bytearray()
        while True:
            byte = file_handle.read(1)
            if byte == '':
                return None

            data_buffer.append(byte)
            sync_index = data_buffer.find(PacketHeader.sync)
            if sync_index != -1:
                # found the sync bytes, read the rest of the header
                data_buffer.extend(file_handle.read(PacketHeader.header_size - len(PacketHeader.sync)))

                if len(data_buffer) < PacketHeader.header_size:
                    return None

                header = PacketHeader.from_buffer(data_buffer, sync_index)
                # read the payload
                payload = file_handle.read(header.payload_size)
                if len(payload) == header.payload_size:
                    packet = PlaybackPacket(payload=payload, header=header)
                    return packet