''' description: test connection to NSP via cereconn author: Ioannis Vlachos date: 15.11.18 Copyright (c) 2018 Ioannis Vlachos. All rights reserved.''' import time import cere_conn as cc import numpy as np ck = cc.CereConn() ck.send_open() t = time.time() while ck.get_state() != cc.ccS_Idle: time.sleep(0.005) print("It took {:5.3f}s to open CereConn\n".format(time.time() - t)) ck.send_record() t = time.time() while ck.get_state() != cc.ccS_Recording: time.sleep(0.02) print("It took {:5.3f}s to start CereConn recording\n".format(time.time() - t)) cb_time = ck.get_cb_time() # print(cb_time) n_comments = 2 start_time = time.time() round_trip_times = [] round_trip_times_abs = [] events = [] info = [] data2 = np.empty((0, 10)) data = ck.get_cont_data() for i in range(n_comments): cb_time = ck.get_cb_time() ck.send_comment("Baseline yes") # time.sleep(0.001) # cb_time = ck.get_cb_time() # ck.send_comment("Baseline no ".format(i+1, cb_time), cb_time) time.sleep(0.05) # ck.print_buffer_state() comments = ck.get_comment_data() data = ck.get_cont_data() # aa # print(data) for ii in range(len(comments['comments'])): events.append((comments['comments'][ii]['ts'], comments['comments'][ii]['text'])) info.append((data['ts'],data['sample_groups'][5]['data'].shape[0])) data2 = np.concatenate((data2, data['sample_groups'][5]['data'])) aa = np.arange(info[0][0]-info[0][1], info[1][0]) # print(aa.shape) data = ck.get_cont_data() print(ck.get_cb_time()) for ii in range(10): time.sleep(.1) data = ck.get_cont_data() data2 = data['sample_groups'][5]['data'] print(ck.get_cb_time()) print(ii, data2.shape) # print(cd) ck.send_close() t = time.time() while ck.get_state() != cc.ccS_Closed: time.sleep(0.05) print("It took {:5.3f}s to close connection to NSP\n".format(time.time() - t)) # SAVING EVENTS # print(events) # cnt = 0 # cnt = sum([(8 + len(ev[1])) for ev in events]) # print(cnt) # with open('events.bin', 'wb') as fh: # fh.write(np.int64(cnt).tobytes()) # for ev in events: # # print(ev) # fh.write(np.int64(ev[0]).tobytes()) # fh.write(ev[1]) # with open('events.bin', 'rb') as fh: # ev_cnt = int(np.frombuffer(fh.read(8), dtype=np.int64)[0]/20) # for ev in range(ev_cnt): # ts = np.frombuffer(fh.read(8), dtype=np.int64)[0] # comments = fh.read(12) # print(ts, comments)