Exemplo n.º 1
0
    def _parse_header(self):
        """
        Parse the start time of the profile and the sensor
        """
        # read the first bytes from the file
        header = self._stream_handle.read(HEADER_BYTES)

        match = HEADER_MATCHER.match(header)

        # parse the header
        if match is not None:

            # use the profile start time as the timestamp
            fields = struct.unpack('>II', match.group(2))
            timestamp = int(fields[1])
            self._timestamp = float(ntplib.system_to_ntp_time(timestamp))
            log.debug(self._start_data_particle_class)
            sample = self._extract_sample(self._start_data_particle_class,
                                          None,
                                          header, self._timestamp)

            if sample:
                # create particle
                self._increment_state(HEADER_BYTES)
                log.debug("Extracting header %s with read_state: %s", sample, self._read_state)
                self._saved_header = (sample, copy.copy(self._read_state))
        else:
            raise SampleException("File header does not match header regex")
    def _build_parsed_values(self):
        """
        Take something in the data format and turn it into
        a particle with the appropriate tag.
        @throws SampleException If there is a problem with sample creation
        """
        match = HEADER_MATCHER.match(self.raw_data)

        if not match:
            raise SampleException(
                "WfpEngStcImodemStartDataParticle: No regex match of parsed sample data: [%s]",
                self.raw_data)

        try:
            fields = struct.unpack('>II', match.group(2))
            sensor_start = int(fields[0])
            profile_start = int(fields[1])
            log.debug('Unpacked sensor start %d, profile start %d',
                      sensor_start, profile_start)
        except (ValueError, TypeError, IndexError) as ex:
            raise SampleException(
                "Error (%s) while decoding parameters in data: [%s]" %
                (ex, match.group(0)))

        result = [
            self._encode_value(
                WfpEngStcImodemStartDataParticleKey.SENSOR_START, sensor_start,
                int),
            self._encode_value(
                WfpEngStcImodemStartDataParticleKey.PROFILE_START,
                profile_start, int)
        ]
        log.debug('WfpEngStcImodemStartDataParticle: particle=%s', result)
        return result
Exemplo n.º 3
0
    def _parse_header(self):
        """
        Parse the start time of the profile and the sensor
        """
        # read the first bytes from the file
        header = self._stream_handle.read(HEADER_BYTES)

        match = HEADER_MATCHER.match(header)

        # parse the header
        if match is not None:

            # use the profile start time as the timestamp
            fields = struct.unpack('>II', match.group(2))
            timestamp = int(fields[1])
            self._timestamp = float(ntplib.system_to_ntp_time(timestamp))
            log.debug(self._start_data_particle_class)
            sample = self._extract_sample(self._start_data_particle_class,
                                          None, header, self._timestamp)

            if sample:
                # create particle
                self._increment_state(HEADER_BYTES)
                log.debug("Extracting header %s with read_state: %s", sample,
                          self._read_state)
                self._saved_header = (sample, copy.copy(self._read_state))
        else:
            raise SampleException("File header does not match header regex")
    def _build_parsed_values(self):
        """
        Take something in the data format and turn it into
        a particle with the appropriate tag.
        @throws SampleException If there is a problem with sample creation
        """
        match = HEADER_MATCHER.match(self.raw_data)

        if not match:
            raise SampleException(
                "WfpEngStcImodemStartDataParticle: No regex match of parsed sample data: [%s]",
                self.raw_data)

        try:
            fields = struct.unpack('>II', match.group(2))
            sensor_start = int(fields[0])
            profile_start = int(fields[1])
            log.debug('Unpacked sensor start %d, profile start %d', sensor_start, profile_start)
        except (ValueError, TypeError, IndexError) as ex:
            raise SampleException("Error (%s) while decoding parameters in data: [%s]"
                                  % (ex, match.group(0)))

        result = [self._encode_value(WfpEngStcImodemStartDataParticleKey.SENSOR_START, sensor_start, int),
                  self._encode_value(WfpEngStcImodemStartDataParticleKey.PROFILE_START, profile_start, int)]
        log.debug('WfpEngStcImodemStartDataParticle: particle=%s', result)
        return result
    def _parse_header(self):
        """
        Parse the start time of the profile and the sensor
        """
	# read the first bytes from the file
	header = self._stream_handle.read(HEADER_BYTES)
	# parse the header
        if HEADER_MATCHER.match(header):
            match = HEADER_MATCHER.match(header)
            # use the profile start time as the timestamp
            fields = struct.unpack('>II', match.group(2))
            timestamp = int(fields[1])
            self._timestamp = float(ntplib.system_to_ntp_time(timestamp))
            sample = self._extract_sample(Wfp_eng__stc_imodem_startParserDataParticle, HEADER_MATCHER,
                                          header, self._timestamp)
	    # store this in case we need the data to calculate other timestamps
            self._profile_start_stop_data = fields
            if sample:
                # create particle
		self._increment_state(HEADER_BYTES)
                log.debug("Extracting header %s with read_state: %s", sample, self._read_state)
                self._saved_header = (sample, copy.copy(self._read_state))
        else:
            raise SampleException("File header does not match header regex")