|
56 | 56 | REFRESH_HEADSET_LIST_ID = 25 |
57 | 57 | QUERY_RECORDS_ID = 26 |
58 | 58 | REQUEST_DOWNLOAD_RECORDS_ID = 27 |
| 59 | +SYNC_WITH_HEADSET_CLOCK_ID = 28 |
59 | 60 |
|
60 | 61 | #define error_code |
61 | 62 | ERR_PROFILE_ACCESS_DENIED = -32046 |
@@ -89,7 +90,7 @@ class Cortex(Dispatcher): |
89 | 90 | 'warn_record_post_processing_done', 'query_records_done', 'request_download_records_done', |
90 | 91 | 'inject_marker_done', 'update_marker_done', 'export_record_done', 'new_data_labels', |
91 | 92 | 'new_com_data', 'new_fe_data', 'new_eeg_data', 'new_mot_data', 'new_dev_data', |
92 | | - 'new_met_data', 'new_pow_data', 'new_sys_data'] |
| 93 | + 'new_met_data', 'new_pow_data', 'new_sys_data', 'sync_with_headset_clock_done'] |
93 | 94 | def __init__(self, client_id, client_secret, debug_mode=False, **kwargs): |
94 | 95 | """ |
95 | 96 | Initialize a Cortex instance with authentication and configuration options. |
@@ -220,6 +221,7 @@ def _get_result_handler(self, req_id): |
220 | 221 | EXPORT_RECORD_ID: self._handle_export_record, |
221 | 222 | INJECT_MARKER_REQUEST_ID: self._handle_inject_marker_request, |
222 | 223 | UPDATE_MARKER_REQUEST_ID: self._handle_update_marker_request, |
| 224 | + SYNC_WITH_HEADSET_CLOCK_ID: self._handle_sync_with_headset_clock |
223 | 225 | } |
224 | 226 | return handlers.get(req_id) |
225 | 227 |
|
@@ -420,6 +422,9 @@ def _handle_inject_marker_request(self, result_dic): |
420 | 422 | def _handle_update_marker_request(self, result_dic): |
421 | 423 | self.emit('update_marker_done', data=result_dic['marker']) |
422 | 424 |
|
| 425 | + def _handle_sync_with_headset_clock(self, result_dic): |
| 426 | + self.emit('sync_with_headset_clock_done', data=result_dic) |
| 427 | + |
423 | 428 | def handle_error(self, recv_dic): |
424 | 429 | req_id = recv_dic['id'] |
425 | 430 | print('handle_error: request Id ' + str(req_id)) |
@@ -1091,6 +1096,29 @@ def refresh_headset_list(self): |
1091 | 1096 |
|
1092 | 1097 | self.ws.send(json.dumps(refresh_request, indent=4)) |
1093 | 1098 |
|
| 1099 | + def sync_with_headset_clock(self, headset_id=None): |
| 1100 | + print('sync with headset clock --------------------------------') |
| 1101 | + |
| 1102 | + # Use instance headset_id if not provided |
| 1103 | + if headset_id is None: |
| 1104 | + headset_id = self.headset_id |
| 1105 | + |
| 1106 | + sync_request = { |
| 1107 | + "jsonrpc": "2.0", |
| 1108 | + "id": SYNC_WITH_HEADSET_CLOCK_ID, # Using next available ID |
| 1109 | + "method": "syncWithHeadsetClock", |
| 1110 | + "params": { |
| 1111 | + "headset": headset_id, |
| 1112 | + "systemTime": time.time(), |
| 1113 | + "monotonicTime": time.monotonic() |
| 1114 | + } |
| 1115 | + } |
| 1116 | + |
| 1117 | + if self.debug: |
| 1118 | + print('sync with headset clock request \n', json.dumps(sync_request, indent=4)) |
| 1119 | + |
| 1120 | + self.ws.send(json.dumps(sync_request)) |
| 1121 | + |
1094 | 1122 | # ------------------------------------------------------------------- |
1095 | 1123 | # ------------------------------------------------------------------- |
1096 | 1124 | # ------------------------------------------------------------------- |
0 commit comments