示例#1
0
    def _store_hskp_record(self, time_stamp):
        data_row = self._get_data_row(time_stamp)
        if data_row is None:
            return
        if self._data_file_state == 1:
            # Open new data file and write the header row to it
            self._data_file_path = "".join(
                (super_config.hskp_temp_dir, 'hskp_',
                 utils.time_stamp_str(time_stamp), '.dat.csv'))
            if not self._open_data_file():
                return
            self._write_to_data_file(self._data_file_hdr_row)
            self._write_to_data_file(data_row)
            self._data_file_state = 2
            return
        if self._data_file_state is 2:
            self._write_to_data_file(data_row)
            end_of_hour = (time_stamp.minute == 59) and (time_stamp.second
                                                         == 45)

            if end_of_hour:
                self._data_file.close()
                # Spin off a thread to execute the XMLRPC command.
                # If it's a big file, it will take a while for the USB mgr
                #  to copy the file to temp storage.
                compress = True
                save_file_thread = SaveFileThread(self._data_file_path,
                                                  compress, self._log)
                # save_file_thread deletes data file after storage
                self._data_file_path = None
                self._data_file_state = 1
            return
        self._log.error('StoreHskp._store_hskp: unknown state value')
示例#2
0
文件: fg_mgr.py 项目: VTMIST/field
    def _process_rx_pkt(self, rx_pkt, pkt_time_stamp):
        """Process a pkt from the instrument"""
        if self._data_file_state == 1:
            # Open new data file and write a pkt to it
            self._data_file_path = "".join(
                (fg_mgr_config.temp_dir, fg_mgr_config.proc_mnemonic, '_',
                 utils.time_stamp_str(pkt_time_stamp), '.dat.csv'))
            if not self._open_data_file():
                return
            self._write_to_data_file(self._data_file_hdr_row)
            self._format_and_write_pkt(rx_pkt, pkt_time_stamp)
            self._file_pkt_cnt = 1
            self._data_file_state = 2
            self._prev_pkt_time_stamp = pkt_time_stamp
            return
        if self._data_file_state is 2:

            # If there is a significant gap between instrument
            #  data pkts, don't store the current packet and
            #  start a new data file
            time_between_pkts = utils.total_seconds(pkt_time_stamp -
                                                    self._prev_pkt_time_stamp)
            self._prev_pkt_time_stamp = pkt_time_stamp
            #self._log.debug('time between pkts: %.3f' % time_between_pkts)
            data_gap = False
            if time_between_pkts > fg_mgr_config.max_data_pkt_gap:
                self._log.error(
                    'Excessive time gap between fluxgate data packets')
                data_gap = True
            if not data_gap:
                self._format_and_write_pkt(rx_pkt, pkt_time_stamp)
                self._file_pkt_cnt += 1
            end_of_hour = (pkt_time_stamp.minute
                           == 59) and (pkt_time_stamp.second == 59)

            if data_gap or end_of_hour:
                self._data_file.close()
                # Spin off a thread to execute the XMLRPC command.
                # If it's a big file, it will take a while for the USB mgr
                #  to copy the file to temp storage.
                compress = True
                save_file_thread = SaveFileThread(self._data_file_path,
                                                  compress, self._log)
                # save_file_thread deletes data file after storage
                self._data_file_path = None
                self._data_file_state = 1
            return
        self._log.error('DataThread._process_rx_pkt: unknown state value')
示例#3
0
    def _process_rx_pkt(self, rx_pkt, pkt_time_stamp):
        """Process a pkt from the instrument"""
        if self._data_file_state == 1:
            # Open new data file and write a pkt to it
            self._data_file_path = ''.join(
                (cases_mgr_config.temp_dir, cases_mgr_config.proc_mnemonic,
                 '_', utils.time_stamp_str(pkt_time_stamp), '.dat'))
            if not self._open_data_file():
                return
            self._file_time_stamp = pkt_time_stamp
            self._write_to_data_file(rx_pkt)
            self._data_file_state = 2
        elif self._data_file_state == 2:
            self._write_to_data_file(rx_pkt)

            # If tmp file is max size or too old
            #  save it in USB flash
            file_age = pkt_time_stamp - self._file_time_stamp
            #self._log.debug('file_age is %s' % str(file_age.seconds))
            file_size = utils.get_file_size(self._data_file_path)
            save_due_to_size = file_size >= cases_mgr_config.data_file_max_size
            save_due_to_age = file_age.seconds >= cases_mgr_config.data_file_storage_period

            # Compress low rate data only.  Low rate data is saved due to age, not size.
            compress = save_due_to_age

            if save_due_to_size or save_due_to_age:
                self._data_file.close()
                self.data_production_lock.acquire()
                self.data_production += os.path.getsize(self._data_file_path)
                self.data_production_lock.release()
                # Spin off a thread to execute the XMLRPC command.
                # If it's a big file, it will take a while for the USB mgr
                #  to copy the file to temp storage.  The serial buffer
                #  could overflow while waiting.
                save_file_thread = SaveFileThread(self._data_file_path,
                                                  compress, self._log)
                # save_file_thread deletes data file after storage
                self._data_file_path = None
                self._data_file_state = 1
        else:
            self._log.error(
                'RxDataThread._process_rx_pkt: unknown state value')
            self._data_file_state = 1
示例#4
0
 def _store_rx_buf(self):
     if len(self._rx_buf_list) == 0:
         self._log.debug('No received data to store')
         return
     self._data_file_path = "".join(
         (hf_mgr_config.temp_dir, hf_mgr_config.proc_mnemonic, '_',
          utils.time_stamp_str(self._time_stamp), '.txt'))
     if not self._open_data_file():
         return
     rx_str = ''.join(self._rx_buf_list)
     #self._log.debug(''.join(['Received from another system:', self._newline, rx_str]))
     self._write_to_data_file(rx_str)
     self._data_file.close()
     # Spin off a thread to execute the XMLRPC command.
     compress = True
     save_file_thread = SaveFileThread(self._data_file_path, compress,
                                       self._log)
     # save_file_thread deletes data file after storage
     self._data_file_path = None