def parse_record(self, record): """ determine if this is a engineering or data record and parse """ sample = None result_particle = [] if PROFILE_MATCHER.match(record): # send to WFP_eng_profiler if WFP match = PROFILE_MATCHER.match(record) fields = struct.unpack('>ihhII', match.group(0)) # use the profile stop time timestamp = int(fields[3]) self._timestamp = float(ntplib.system_to_ntp_time(timestamp)) sample = self._extract_sample(Wfp_eng__stc_imodem_statusParserDataParticle, PROFILE_MATCHER, record, self._timestamp) self._increment_state(STATUS_BYTES) elif DATA_SAMPLE_MATCHER.match(record): # pull out the timestamp for this record match = DATA_SAMPLE_MATCHER.match(record) fields = struct.unpack('>I', match.group(0)[:4]) timestamp = int(fields[0]) self._timestamp = float(ntplib.system_to_ntp_time(timestamp)) log.debug("Converting record timestamp %f to ntp timestamp %f", timestamp, self._timestamp) sample = self._extract_sample(Wfp_eng__stc_imodem_engineeringParserDataParticle, DATA_SAMPLE_MATCHER, record, self._timestamp) self._increment_state(SAMPLE_BYTES) if sample: # create particle log.trace("Extracting sample %s with read_state: %s", sample, self._read_state) result_particle = (sample, copy.copy(self._read_state)) return result_particle
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_prof = PROFILE_MATCHER.match(self.raw_data) if not match_prof: raise SampleException("WfpEngStcImodemStatusDataParticle: No regex match of parsed sample data: [%s]", self.raw_data) try: fields_prof = struct.unpack('>ihhII', match_prof.group(0)) indicator = int(fields_prof[0]) ramp_status = int(fields_prof[1]) profile_status = int(fields_prof[2]) profile_stop = int(fields_prof[3]) sensor_stop = int(fields_prof[4]) except (ValueError, TypeError, IndexError) as ex: raise SampleException("Error (%s) while decoding parameters in data: [%s]" % (ex, match_prof.group(0))) result = [self._encode_value(WfpEngStcImodemStatusDataParticleKey.INDICATOR, indicator, int), self._encode_value(WfpEngStcImodemStatusDataParticleKey.RAMP_STATUS, ramp_status, int), self._encode_value(WfpEngStcImodemStatusDataParticleKey.PROFILE_STATUS, profile_status, int), self._encode_value(WfpEngStcImodemStatusDataParticleKey.SENSOR_STOP, sensor_stop, int), self._encode_value(WfpEngStcImodemStatusDataParticleKey.PROFILE_STOP, profile_stop, int)] log.debug('WfpEngStcImodemStatusDataParticle: particle=%s', result) return result
def parse_record(self, record): """ determine if this is a engineering or data record and parse """ result_particle = [] # Attempt to match on the profile status record match = PROFILE_MATCHER.match(record) if match is not None: # send to WFP_eng_profiler if WFP fields = struct.unpack('>ihhII', match.group(0)) # use the profile stop time timestamp = int(fields[3]) self._timestamp = float(ntplib.system_to_ntp_time(timestamp)) log.debug(self._status_data_particle_class) sample = self._extract_sample(self._status_data_particle_class, None, record, internal_timestamp=self._timestamp) self._increment_state(STATUS_BYTES) else: # The record data must be an engineering data record since it was not a profile status record # pull out the timestamp for this record fields = struct.unpack('>I', record[:4]) timestamp = int(fields[0]) self._timestamp = float(ntplib.system_to_ntp_time(timestamp)) log.trace("Converting record timestamp %f to ntp timestamp %f", timestamp, self._timestamp) log.debug(self._engineering_data_particle_class) sample = self._extract_sample( self._engineering_data_particle_class, None, record, internal_timestamp=self._timestamp) self._increment_state(SAMPLE_BYTES) if sample: # create particle log.trace("Extracting sample %s with read_state: %s", sample, self._read_state) result_particle = (sample, copy.copy(self._read_state)) return result_particle
def parse_record(self, record): """ determine if this is a engineering or data record and parse """ result_particle = [] # Attempt to match on the profile status record match = PROFILE_MATCHER.match(record) if match is not None: # send to WFP_eng_profiler if WFP fields = struct.unpack('>ihhII', match.group(0)) # use the profile stop time timestamp = int(fields[3]) self._timestamp = float(ntplib.system_to_ntp_time(timestamp)) log.debug(self._status_data_particle_class) sample = self._extract_sample(self._status_data_particle_class, None, record, self._timestamp) self._increment_state(STATUS_BYTES) else: # The record data must be an engineering data record since it was not a profile status record # pull out the timestamp for this record fields = struct.unpack('>I', record[:4]) timestamp = int(fields[0]) self._timestamp = float(ntplib.system_to_ntp_time(timestamp)) log.trace("Converting record timestamp %f to ntp timestamp %f", timestamp, self._timestamp) log.debug(self._engineering_data_particle_class) sample = self._extract_sample(self._engineering_data_particle_class, None, record, self._timestamp) self._increment_state(SAMPLE_BYTES) if sample: # create particle log.trace("Extracting sample %s with read_state: %s", sample, self._read_state) result_particle = (sample, copy.copy(self._read_state)) return result_particle