weather/stations/davis.py
def _dmpaft_cmd(self, time_fields):
        '''
        issue a command to read the archive records after a known time stamp.
        '''
        records = []
        # convert time stamp fields to buffer
        tbuf = struct.pack('2H', *time_fields)

        # 1. send 'DMPAFT' cmd
        self._cmd('DMPAFT')

        # 2. send time stamp + crc
        crc = VProCRC.get(tbuf)
        crc = struct.pack('>H', crc)  # crc in big-endian format
        log_raw('send', tbuf + crc)
        self.port.write(tbuf + crc)  # send time stamp + crc
        ack = self.port.read(len(self.ACK))  # read ACK
        log_raw('read', ack)
        if ack != self.ACK: return  # if bad ack, return

        # 3. read pre-amble data
        raw = self.port.read(DmpStruct.size)
        log_raw('read', raw)
        if not VProCRC.verify(raw):  # check CRC value
            log_raw('send ESC', self.ESC)
            self.port.write(self.ESC)  # if bad, escape and abort
            return
        log_raw('send ACK', self.ACK)
        self.port.write(self.ACK)  # send ACK

        # 4. loop through all page records
        dmp = DmpStruct.unpack(raw)
        log.info('reading %d pages, start offset %d' %
                 (dmp['Pages'], dmp['Offset']))
        for i in xrange(dmp['Pages']):
            # 5. read page data
            raw = self.port.read(DmpPageStruct.size)
            log_raw('read', raw)
            if not VProCRC.verify(raw):  # check CRC value
                log_raw('send ESC', self.ESC)
                self.port.write(self.ESC)  # if bad, escape and abort
                return
            log_raw('send ACK', self.ACK)
            self.port.write(self.ACK)  # send ACK

            # 6. loop through archive records
            page = DmpPageStruct.unpack(raw)
            offset = 0  # assume offset at 0
            if i == 0:
                offset = dmp['Offset'] * ArchiveAStruct.size
            while offset < ArchiveAStruct.size * 5:
                log.info('page %d, reading record at offset %d' %
                         (page['Index'], offset))
                if self._use_rev_b_archive(page['Records'], offset):
                    a = ArchiveBStruct.unpack_from(page['Records'], offset)
                else:
                    a = ArchiveAStruct.unpack_from(page['Records'], offset)
                # 7. verify that record has valid data, and store
                if a['DateStamp'] != 0xffff and a['TimeStamp'] != 0xffff:
                    records.append(a)
                offset += ArchiveAStruct.size
        log.info('read all pages')
        return records
def _dmpaft_cmd(self, time_fields):
        '''
        issue a command to read the archive records after a known time stamp.
        '''
        records = []
        # convert time stamp fields to buffer
        tbuf = struct.pack('2H', *time_fields)

        # 1. send 'DMPAFT' cmd
        self._cmd('DMPAFT')

        # 2. send time stamp + crc
        crc = VProCRC.get(tbuf)
        crc = struct.pack('>H', crc)  # crc in big-endian format
        log_raw('send', tbuf + crc)
        self.port.write(tbuf + crc)  # send time stamp + crc
        ack = self.port.read(len(self.ACK))  # read ACK
        log_raw('read', ack)
        if ack != self.ACK: return  # if bad ack, return

        # 3. read pre-amble data
        raw = self.port.read(DmpStruct.size)
        log_raw('read', raw)
        if not VProCRC.verify(raw):  # check CRC value
            log_raw('send ESC', self.ESC)
            self.port.write(self.ESC)  # if bad, escape and abort
            return
        log_raw('send ACK', self.ACK)
        self.port.write(self.ACK)  # send ACK

        # 4. loop through all page records
        dmp = DmpStruct.unpack(raw)
        log.info('reading %d pages, start offset %d' %
                 (dmp['Pages'], dmp['Offset']))
        for i in xrange(dmp['Pages']):
            # 5. read page data
            raw = self.port.read(DmpPageStruct.size)
            log_raw('read', raw)
            if not VProCRC.verify(raw):  # check CRC value
                log_raw('send ESC', self.ESC)
                self.port.write(self.ESC)  # if bad, escape and abort
                return
            log_raw('send ACK', self.ACK)
            self.port.write(self.ACK)  # send ACK

            # 6. loop through archive records
            page = DmpPageStruct.unpack(raw)
            offset = 0  # assume offset at 0
            if i == 0:
                offset = dmp['Offset'] * ArchiveAStruct.size
            while offset < ArchiveAStruct.size * 5:
                log.info('page %d, reading record at offset %d' %
                         (page['Index'], offset))
                if self._use_rev_b_archive(page['Records'], offset):
                    a = ArchiveBStruct.unpack_from(page['Records'], offset)
                else:
                    a = ArchiveAStruct.unpack_from(page['Records'], offset)
                # 7. verify that record has valid data, and store
                if a['DateStamp'] != 0xffff and a['TimeStamp'] != 0xffff:
                    records.append(a)
                offset += ArchiveAStruct.size
        log.info('read all pages')
        return records
issue a command to read the archive records after a known time stamp.