From 82f93fd2e66096f808b399019202f99a42e2344b Mon Sep 17 00:00:00 2001 From: Tham Date: Fri, 13 Sep 2024 09:28:14 +0700 Subject: [PATCH] python: handle warning 30 to export record --- python/cortex.py | 6 +++++- python/record.py | 17 ++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/python/cortex.py b/python/cortex.py index 7ef52b4..4dedaf8 100644 --- a/python/cortex.py +++ b/python/cortex.py @@ -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 @@ -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'] @@ -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. diff --git a/python/record.py b/python/record.py index 2860463..6f3c611 100644 --- a/python/record.py +++ b/python/record.py @@ -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) @@ -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:')