Skip to content

Commit

Permalink
python: handle warning 30 to export record
Browse files Browse the repository at this point in the history
  • Loading branch information
thamha-emotiv committed Sep 13, 2024
1 parent 12e4623 commit 82f93fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
6 changes: 5 additions & 1 deletion python/cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
EULA_ACCEPTED = 17
DISKSPACE_LOW = 19
DISKSPACE_CRITICAL = 20
CORTEX_RECORD_POST_PROCESSING_DONE = 30
HEADSET_CANNOT_CONNECT_TIMEOUT = 102
HEADSET_DISCONNECTED_TIMEOUT = 103
HEADSET_CONNECTED = 104
Expand All @@ -63,7 +64,7 @@ class Cortex(Dispatcher):

_events_ = ['inform_error','create_session_done', 'query_profile_done', 'load_unload_profile_done',
'save_profile_done', 'get_mc_active_action_done','mc_brainmap_done', 'mc_action_sensitivity_done',
'mc_training_threshold_done', 'create_record_done', 'stop_record_done','warn_cortex_stop_all_sub',
'mc_training_threshold_done', 'create_record_done', 'stop_record_done','warn_cortex_stop_all_sub', 'warn_record_post_processing_done',
'inject_marker_done', 'update_marker_done', 'export_record_done', 'new_data_labels',
'new_com_data', 'new_fe_data', 'new_eeg_data', 'new_mot_data', 'new_dev_data',
'new_met_data', 'new_pow_data', 'new_sys_data']
Expand Down Expand Up @@ -334,6 +335,9 @@ def handle_warning(self, warning_dic):
if session_id == self.session_id:
self.emit('warn_cortex_stop_all_sub', data=session_id)
self.session_id = ''
elif warning_code == CORTEX_RECORD_POST_PROCESSING_DONE:
record_id = warning_msg['recordId']
self.emit('warn_record_post_processing_done', data=record_id)
elif warning_code == HEADSET_SCANNING_FINISHED:
# After headset scanning finishes, if no headset is connected yet, the app should call the controlDevice("refresh") again
# We recommend the app should NOT call controlDevice("refresh") when a headset is connected, to have the best data stream quality.
Expand Down
17 changes: 6 additions & 11 deletions python/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def __init__(self, app_client_id, app_client_secret, **kwargs):
self.c.bind(create_session_done=self.on_create_session_done)
self.c.bind(create_record_done=self.on_create_record_done)
self.c.bind(stop_record_done=self.on_stop_record_done)
self.c.bind(warn_cortex_stop_all_sub=self.on_warn_cortex_stop_all_sub)
self.c.bind(warn_record_post_processing_done=self.on_warn_record_post_processing_done)
self.c.bind(export_record_done=self.on_export_record_done)
self.c.bind(inform_error=self.on_inform_error)

Expand Down Expand Up @@ -108,20 +108,15 @@ def on_stop_record_done(self, *args, **kwargs):
start_time = data['startDatetime']
end_time = data['endDatetime']
title = data['title']
print('on_stop_record_done: recordId: {0}, title: {1}, startTime: {2}, endTime: {3}'.format(record_id, title, start_time, end_time))
print('The record has been stopped: recordId: {0}, title: {1}, startTime: {2}, endTime: {3}'.format(record_id, title, start_time, end_time))

# disconnect headset to export record
print('on_stop_record_done: Disconnect the headset to export record')
self.c.disconnect_headset()

def on_warn_cortex_stop_all_sub(self, *args, **kwargs):
print('on_warn_cortex_stop_all_sub')
# cortex has closed session. Wait some seconds before exporting record
time.sleep(3)
def on_warn_record_post_processing_done(self, *args, **kwargs):
record_id = kwargs.get('data')
print('on_warn_record_post_processing_done: The record', record_id, 'has been post-processed. Now, you can export the record')

#export record
self.export_record(self.record_export_folder, self.record_export_data_types,
self.record_export_format, [self.record_id], self.record_export_version)
self.record_export_format, [record_id], self.record_export_version)

def on_export_record_done(self, *args, **kwargs):
print('on_export_record_done: the successful record exporting as below:')
Expand Down

0 comments on commit 82f93fd

Please sign in to comment.