Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update public repo #313

Merged
merged 6 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed src/explorepy/_exploresdk_mac_apple_m.so
Binary file not shown.
Binary file removed src/explorepy/_exploresdk_mac_intel.so
Binary file not shown.
Binary file removed src/explorepy/btcpp.cp310-win_amd64.pyd
Binary file not shown.
Binary file removed src/explorepy/btcpp.cpython-310-darwin_apple_m.so
Binary file not shown.
Binary file removed src/explorepy/btcpp.cpython-310-darwin_intel.so
Binary file not shown.
56 changes: 39 additions & 17 deletions src/explorepy/explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -227,32 +228,42 @@ 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!")

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:
bin_file (str): Path to the binary file recorded by Explore device
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
Expand Down Expand Up @@ -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)
Expand Down
Binary file removed src/explorepy/packet.cp310-win_amd64.pyd
Binary file not shown.
Binary file removed src/explorepy/packet.cpython-310-darwin_apple_m.so
Binary file not shown.
Binary file removed src/explorepy/packet.cpython-310-darwin_intel.so
Binary file not shown.
9 changes: 6 additions & 3 deletions src/explorepy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand Down
Binary file removed src/explorepy/tools.cp310-win_amd64.pyd
Binary file not shown.
Binary file removed src/explorepy/tools.cpython-310-darwin_apple_m.so
Binary file not shown.
Binary file removed src/explorepy/tools.cpython-310-darwin_intel.so
Binary file not shown.
Loading