def download_log( self, timeout=3.0, data_callback=None, progress_update_function=None, unknown_entry_function=None, unhandled_entry_function=None ): """Download logged data from the MetaWear board :param timeout: Time to wait for download to resume if connection is lost. :param data_callback: Function called to process each downloaded sample. :param progress_update_function: Function called each `progress_update_each_n_sample` to give feedback on download progress. :param unknown_entry_function: Function called when unknown logging entries are encountered. :param unhandled_entry_function: Function called when unhandled entries are encountered. :return: The logged data, in case download was successful. """ if self._logger_running: # Stop logging if it is active. self.stop_logging() if data_callback is None: data_callback = data_handler(self._default_download_callback) if progress_update_function is None: progress_update_function = self._progress_update if unknown_entry_function is None: unknown_entry_function = self._unknown_entry if unhandled_entry_function is None: unhandled_entry_function = self._unhandled_entry data_point_handler = FnVoid_VoidP_DataP(context_callback(data_callback)) progress_update = FnVoid_VoidP_UInt_UInt(context_callback(progress_update_function)) unknown_entry = FnVoid_VoidP_UByte_Long_UByteP_UByte(context_callback(unknown_entry_function)) unhandled_entry = FnVoid_VoidP_DataP(data_handler(context_callback(unhandled_entry_function))) log_download_handler = LogDownloadHandler( received_progress_update=progress_update, received_unknown_entry=unknown_entry, received_unhandled_entry=unhandled_entry ) log.debug("Subscribe to Logger. (Logger#: {0})".format( self._logger_address)) libmetawear.mbl_mw_logger_subscribe( self._logger_address, None, data_point_handler) self._data_received = Event() log.debug("Waiting for completed download. (Logger#: {0})".format( self._logger_address)) libmetawear.mbl_mw_logging_download( self.board, 1000, byref(log_download_handler)) while not self._download_done: status = self._data_received.wait(timeout) self._data_received.clear() if not self._download_done and not status: if self._progress_bar is not None: self._progress_bar.close() self._progress_bar = None raise PyMetaWearDownloadTimeout( "Bluetooth connection lost! Please reconnect and retry download...") log.debug("Download done. (Logger#: {0})".format( self._logger_address)) log.debug("Remove logger. (Logger#: {0})".format( self._logger_address)) libmetawear.mbl_mw_logger_remove(self._logger_address) logged_data = self._logged_data self._logged_data = [] self._data_received = None return logged_data
def _download_log(self, n_notifies): libmetawear.mbl_mw_logging_download(self.board, n_notifies)
def download_log(self, timeout=3.0, data_callback=None, progress_update_function=None, unknown_entry_function=None, unhandled_entry_function=None): """Download logged data from the MetaWear board :param timeout: Time to wait for download to resume if connection is lost. :param data_callback: Function called to process each downloaded sample. :param progress_update_function: Function called each `progress_update_each_n_sample` to give feedback on download progress. :param unknown_entry_function: Function called when unknown logging entry is encountered. :param unhandled_entry_function: Function called when :return: The logged data, in case """ if self._logger_running: # Stop logging if it is active. self.stop_logging() if data_callback is None: data_callback = self._default_download_callback if progress_update_function is None: progress_update_function = self._progress_update if unknown_entry_function is None: unknown_entry_function = self._unknown_entry if unhandled_entry_function is None: unhandled_entry_function = self._unhandled_entry data_point_handler = FnVoid_DataP(data_handler(data_callback)) progress_update = FnVoid_UInt_UInt(progress_update_function) unknown_entry = FnVoid_UByte_Long_UByteP_UByte(unknown_entry_function) unhandled_entry = FnVoid_DataP(data_handler(unhandled_entry_function)) log_download_handler = LogDownloadHandler( received_progress_update=progress_update, received_unknown_entry=unknown_entry, received_unhandled_entry=unhandled_entry) if self._debug: log.debug("Subscribe to Logger. (Logger#: {0})".format( self._logger_address)) libmetawear.mbl_mw_logger_subscribe(self._logger_address, data_point_handler) if self._debug: log.debug("Waiting for completed download. (Logger#: {0})".format( self._logger_address)) libmetawear.mbl_mw_logging_download(self.board, 1000, byref(log_download_handler)) while not self._download_done: status = self.data_received.wait(timeout) self.data_received = Event() if not self._download_done and not status: if self._progress_bar is not None: self._progress_bar.close() self._progress_bar = None raise PyMetaWearDownloadTimeout( "Bluetooth connection lost! Please reconnect and retry download..." ) if self._debug: log.debug("Download done. (Logger#: {0})".format( self._logger_address)) if self._debug: log.debug("Remove logger. (Logger#: {0})".format( self._logger_address)) libmetawear.mbl_mw_logger_remove(self._logger_address) logged_data = self._logged_data self._logged_data = [] return logged_data