def _finish_saving_session(self): """Send signal_saver_control_message to MX with number of samples and first sample timestamp (for tag_saver and info_saver). Also perform .finish_saving on data_proxy - it might be a long operation...""" if not self._session_is_active: self.logger.error("Attempting to stop saving signal to file while no file being opened!") return self._session_is_active = False l_vec = variables_pb2.VariableVector() l_var = l_vec.variables.add() l_var.key = 'first_sample_timestamp' l_var.value = repr(self._first_sample_timestamp) l_var = l_vec.variables.add() l_var.key = 'number_of_samples' l_var.value = str(self._number_of_samples) l_var = l_vec.variables.add() l_var.key = 'file_path' l_var.value = self._file_path l_files = self._data_proxy.finish_saving() self.conn.send_message( message=l_vec.SerializeToString(), type=types.__dict__[self.config.get_param("finished_signal_type")], flush=True) self.logger.info("Saved file "+str(l_files)) return l_files
def handle_message(self, mxmsg): v = variables_pb2.VariableVector() if mxmsg.type == types.SIGNAL_SAVER_FINISHED: LOGGER.info("got signal_saver_finished") v.ParseFromString(mxmsg.message) self._data_result = v elif mxmsg.type == types.INFO_SAVER_FINISHED: LOGGER.info("got info_saver_finished") v.ParseFromString(mxmsg.message) self._info_result = v elif mxmsg.type == types.TAG_SAVER_FINISHED: LOGGER.info("got tag_saver_finished") v.ParseFromString(mxmsg.message) self._tags_result = v else: LOGGER.warning("Unrecognised message received!!!!") self.no_response() if self._all_ready(): self.result = self._info_result, self._data_result, self._tags_result LOGGER.info(''.join([ "Stop acquisition_control with result: ", "\n", "info result:\n", debug_helper.get_str_variable_vector(self._info_result), "data result:\n", debug_helper.get_str_variable_vector(self._data_result), "tagsd result:\n", debug_helper.get_str_variable_vector(self._tags_result) ])) self.working = False
def _serialise_finished_msg(self, params): l_dict = { 'number_of_channels': str(params['number_of_channels']), 'sampling_frequency': str(params['sampling_frequency']), 'channels_numbers': ';'.join([str(i) for i in params['channels_numbers']]), 'channels_names': ';'.join(params['channels_names']), 'channels_gains': ';'.join([str(i) for i in params['channels_gains']]), 'channels_offsets': ';'.join([str(i) for i in params['channels_offsets']]), 'number_of_samples': str(params['number_of_samples']), 'file': str(params['file']), 'first_sample_timestamp': str(params['first_sample_timestamp']), #'file_path':self._file_path } l_vec = variables_pb2.VariableVector() for k, v in l_dict.iteritems(): l_var = l_vec.variables.add() l_var.key = k l_var.value = v return l_vec.SerializeToString()
def _finish_saving(self, p_first_sample_ts): """Save all tags to xml file, but first update their .position field so that it is relative to timestamp of a first sample stored by signal saver (p_first_sample_ts).""" # Save tags self.logger.info("Finish saving with first sample ts: " + str(p_first_sample_ts)) l_file_path = self._tags_proxy.finish_saving(p_first_sample_ts) l_vec = variables_pb2.VariableVector() l_var = l_vec.variables.add() l_var.key = 'file_path' l_var.value = self._file_path self.conn.send_message( message=l_vec.SerializeToString(), type=types.__dict__[self.config.get_param("finished_tag_type")], flush=True) self.logger.info("Tags file saved to: " + l_file_path) return l_file_path
def handle_message(self, mxmsg): """Handle messages: * signal_saver_control_message - a message from signal saver being a signal to finish saving.""" if mxmsg.type == types.__dict__[self.config.get_param( "finished_signal_type")]: self.logger.info("Got signal saver finished!") l_vec = variables_pb2.VariableVector() l_vec.ParseFromString(mxmsg.message) l_num_of_samples = None l_file_path = None for i_var in l_vec.variables: if i_var.key == 'number_of_samples': l_num_of_samples = i_var.value elif i_var.key == 'file_path': l_file_path = i_var.value elif i_var.key == 'first_sample_timestamp': l_first_sample_ts = i_var.value self._finish_saving(l_num_of_samples, l_file_path, l_first_sample_ts) time.sleep(3) sys.exit(0)
def handle_message(self, mxmsg): """Handle messages: * Tag message - raw data from mx (TAG) If session is active convey data to save_manager. * signal_saver_control_message - a message from signal saver is a signal to finishing saving tags. depending on data received.""" if mxmsg.type == types.TAG and \ self._session_is_active: str_tag = variables_pb2.Tag() str_tag.ParseFromString(mxmsg.message) tag_desc = dict() for i_var in str_tag.desc.variables: tag_desc[i_var.key] = i_var.value l_tag = tag_utils.pack_tag_to_dict(str_tag.start_timestamp, str_tag.end_timestamp, str_tag.name, tag_desc, str_tag.channels) self.logger.info(''.join([ 'Tag saver got tag: ', 'start_timestamp:', repr(l_tag['start_timestamp']), ', end_timestamp: ', repr(l_tag['end_timestamp']), ', name: ', l_tag['name'], '. <Change debug level to see desc.>' ])) self.logger.debug("Signal saver got tag: " + str(l_tag)) self._tag_received(l_tag) elif mxmsg.type == types.ACQUISITION_CONTROL_MESSAGE: ctr = mxmsg.message if ctr == 'finish': if not self._session_is_active: self.logger.error( "Attempting to finish saving tags while session is not active.!" ) return self._session_is_active = False self.logger.info( "Got finish saving message. Waiting for saver_finished message..." ) else: self.logger.warning("Tag saver got unknown control message " + ctr + "!") elif mxmsg.type == types.__dict__[self.config.get_param( "finished_signal_type")]: if self._session_is_active: self.logger.warning( "Got saver_finished before getting saver control message... This shouldn`t happen, but continue anyway..." ) self._session_is_active = False l_vec = variables_pb2.VariableVector() l_vec.ParseFromString(mxmsg.message) for i_var in l_vec.variables: # Assume that first_sample_timestamp key is # in a dictinary got from signal saver if i_var.key == 'first_sample_timestamp': self._finish_saving(float(i_var.value)) time.sleep(3) sys.exit(0) self.logger.error( "Got saver finished message without first_sample_timestamp. Do noting ..." ) self.no_response()