diff --git a/src/explorepy/_exploresdk_mac_apple_m.so b/src/explorepy/_exploresdk_mac_apple_m.so deleted file mode 100644 index 6c79daae..00000000 Binary files a/src/explorepy/_exploresdk_mac_apple_m.so and /dev/null differ diff --git a/src/explorepy/_exploresdk_mac_intel.so b/src/explorepy/_exploresdk_mac_intel.so deleted file mode 100644 index 80660600..00000000 Binary files a/src/explorepy/_exploresdk_mac_intel.so and /dev/null differ diff --git a/src/explorepy/btcpp.cp310-win_amd64.pyd b/src/explorepy/btcpp.cp310-win_amd64.pyd deleted file mode 100644 index 09255c83..00000000 Binary files a/src/explorepy/btcpp.cp310-win_amd64.pyd and /dev/null differ diff --git a/src/explorepy/btcpp.cpython-310-darwin_apple_m.so b/src/explorepy/btcpp.cpython-310-darwin_apple_m.so deleted file mode 100644 index 63b5135b..00000000 Binary files a/src/explorepy/btcpp.cpython-310-darwin_apple_m.so and /dev/null differ diff --git a/src/explorepy/btcpp.cpython-310-darwin_intel.so b/src/explorepy/btcpp.cpython-310-darwin_intel.so deleted file mode 100644 index 418ae81c..00000000 Binary files a/src/explorepy/btcpp.cpython-310-darwin_intel.so and /dev/null differ diff --git a/src/explorepy/explore.py b/src/explorepy/explore.py index 51478acb..765d72c3 100644 --- a/src/explorepy/explore.py +++ b/src/explorepy/explore.py @@ -63,6 +63,7 @@ def __init__(self, debug=False, debug_settings=None): self.recorders = {} self.lsl = {} self.device_name = None + self.initial_count = None self.last_rec_stat = 0 self.last_rec_start_time = 0 @@ -227,15 +228,19 @@ def stop_recording(self): self.recorders['timer'].cancel() self.recorders = {} logger.info('Recording stopped.') - self.last_rec_stat = ( - (self.stream_processor.packet_count - self.initial_count) / ( - (local_clock() - self.last_rec_start_time) * self.stream_processor.device_info['sampling_rate'] + try: + self.last_rec_stat = ( + (self.stream_processor.packet_count - self.initial_count) / ( + (local_clock() - self.last_rec_start_time) * self.stream_processor.device_info['sampling_rate'] + ) ) - ) - # clamp the stat variable - self.last_rec_stat = max(1, min(self.last_rec_stat, 1)) - logger.info('last recording stat : {}'.format(self.last_rec_stat)) - + # clamp the stat variable + self.last_rec_stat = max(1, min(self.last_rec_stat, 1)) + logger.info('last recording stat : {}'.format(self.last_rec_stat)) + except TypeError: + # handle uninitialized state + pass + self.initial_count = None else: logger.debug("Tried to stop recording while no recorder is running!") @@ -243,7 +248,8 @@ def get_last_record_stat(self): """Gets the last recording statistics as a number between 0 and 1""" return self.last_rec_stat - def convert_bin(self, bin_file, out_dir='', file_type='edf', do_overwrite=False, out_dir_is_full=False): + def convert_bin(self, bin_file, out_dir='', file_type='edf', do_overwrite=False, out_dir_is_full=False, + progress_callback=None, progress_dialog=None): """Convert a binary file to EDF or CSV file Args: @@ -251,8 +257,13 @@ def convert_bin(self, bin_file, out_dir='', file_type='edf', do_overwrite=False, out_dir (str): Output directory path (must be relative path to the current working directory) file_type (str): Output file type: 'edf' for EDF format and 'csv' for CSV format do_overwrite (bool): Whether to overwrite an existing file + out_dir_is_full(bool): Whether output directory is a full file path + progress_callback: + progress_dialog """ + total_file_bytes = os.path.getsize(bin_file) + bt_interface = explorepy.get_bt_interface() if file_type not in ['edf', 'csv']: raise ValueError('Invalid file type is given!') self.recorders['file_type'] = file_type @@ -346,14 +357,25 @@ def device_info_callback(packet): self.stream_processor.subscribe(callback=device_info_callback, topic=TOPICS.device_info) self.stream_processor.open_file(bin_file=bin_file) logger.info("Converting...") - while self.stream_processor.is_connected: - time.sleep(.1) - - if self.recorders['file_type'] == 'csv': - self.recorders["marker"].stop() - self.recorders["exg"].stop() - self.recorders["orn"].stop() - logger.info('Conversion finished.') + try: + while self.stream_processor.is_connected: + time.sleep(.1) + if progress_dialog and progress_dialog.close: + logger.info("Conversion process cancelled.") + break + + if progress_callback: + progress = ( + self.stream_processor.parser.total_packet_size_read / total_file_bytes + ) + progress_callback(int(progress * 100)) + finally: + if self.recorders['file_type'] == 'csv': + self.recorders["marker"].stop() + self.recorders["exg"].stop() + self.recorders["orn"].stop() + explorepy.set_bt_interface(bt_interface) + logger.info('Conversion process terminated.') def push2lsl(self, duration=None, block=False): r"""Push samples to two lsl streams (ExG and ORN streams) diff --git a/src/explorepy/packet.cp310-win_amd64.pyd b/src/explorepy/packet.cp310-win_amd64.pyd deleted file mode 100644 index ab425f70..00000000 Binary files a/src/explorepy/packet.cp310-win_amd64.pyd and /dev/null differ diff --git a/src/explorepy/packet.cpython-310-darwin_apple_m.so b/src/explorepy/packet.cpython-310-darwin_apple_m.so deleted file mode 100644 index 58d6366b..00000000 Binary files a/src/explorepy/packet.cpython-310-darwin_apple_m.so and /dev/null differ diff --git a/src/explorepy/packet.cpython-310-darwin_intel.so b/src/explorepy/packet.cpython-310-darwin_intel.so deleted file mode 100644 index 7ed53ef2..00000000 Binary files a/src/explorepy/packet.cpython-310-darwin_intel.so and /dev/null differ diff --git a/src/explorepy/parser.py b/src/explorepy/parser.py index 4dc48626..bcef9fb4 100644 --- a/src/explorepy/parser.py +++ b/src/explorepy/parser.py @@ -59,6 +59,7 @@ def __init__(self, callback, mode='device', debug=True): self._is_reconnecting = False self.seek_new_pid = asyncio.Event() self.usb_marker_port = None + self.total_packet_size_read = 0 def start_streaming(self, device_name, mac_address): """Start streaming data from Explore device""" @@ -110,7 +111,7 @@ def read_device_info(self, filename): packet = None try: while True: - packet = self._generate_packet() + packet, _ = self._generate_packet() if isinstance(packet, DeviceInfo): self.callback(packet=packet) break @@ -136,7 +137,8 @@ def _stream_loop(self): asyncio.set_event_loop(asyncio.new_event_loop()) while self._do_streaming: try: - packet = self._generate_packet() + packet, packet_size = self._generate_packet() + self.total_packet_size_read += packet_size self.callback(packet=packet) except ReconnectionFlowError: logger.info('Got exception in reconnection flow, normal operation continues') @@ -242,7 +244,8 @@ def _generate_packet(self): except ValueError: logger.debug('Got ValueError in payload conversion in parser, raising Fletcher') raise FletcherError - return packet + packet_size = 8 + (payload - 4) + return packet, packet_size def _parse_packet(self, pid, timestamp, bin_data): """Generates the packets according to the pid diff --git a/src/explorepy/tools.cp310-win_amd64.pyd b/src/explorepy/tools.cp310-win_amd64.pyd deleted file mode 100644 index 056d06e6..00000000 Binary files a/src/explorepy/tools.cp310-win_amd64.pyd and /dev/null differ diff --git a/src/explorepy/tools.cpython-310-darwin_apple_m.so b/src/explorepy/tools.cpython-310-darwin_apple_m.so deleted file mode 100644 index 3c120513..00000000 Binary files a/src/explorepy/tools.cpython-310-darwin_apple_m.so and /dev/null differ diff --git a/src/explorepy/tools.cpython-310-darwin_intel.so b/src/explorepy/tools.cpython-310-darwin_intel.so deleted file mode 100644 index 4ceda25f..00000000 Binary files a/src/explorepy/tools.cpython-310-darwin_intel.so and /dev/null differ