static void* acq_loop_fn(void* arg) { struct acq* acq = arg; struct eegdev* dev = acq->dev; void** buff = acq->buff; int lrun; ssize_t ns; while (1) { // Update status of the loop pthread_mutex_lock(&acq->lock); while (!(lrun = acq->running)) { pthread_cond_wait(&acq->cond, &acq->lock); } pthread_mutex_unlock(&acq->lock); if (lrun < 0) break; // Perform the actual transfer from dev to buffers ns = egd_get_data(dev, CHUNK_NS, buff[0], buff[1], buff[2]); if (ns <= 0) break; // Writes data to file if (xdf_write(acq->xdf, ns, buff[0], buff[1], buff[2]) < 0) break; // Execute callback if (acq->cb) acq->cb(acq->cbdata, ns, buff[0], buff[1], buff[2]); } return NULL; }
static int read_eegsignal(int bsigcheck, int pass) { struct eegdev* dev; int type = grp[0].datatype; size_t strides[3]; void *eeg_t = NULL, *exg_t = NULL; int32_t *tri_t = NULL; int ntri, fs, i, baddata, retcode = 1; size_t tsize = (type == EGD_FLOAT ? sizeof(float) : sizeof(double)); // Reset global variable used to track the expected signal checking = 0; nstot = nsread = 0; if (!(dev = open_device(grp))) goto exit; // Get number of channels and configure structures grp[0].sensortype = egd_sensor_type("eeg"); grp[1].sensortype = egd_sensor_type("undefined"); grp[2].sensortype = egd_sensor_type("trigger"); strides[0] = grp[0].nch*tsize; strides[1] = grp[1].nch*tsize; strides[2] = grp[2].nch*sizeof(int32_t); ntri = grp[2].nch; eeg_t = calloc(strides[0], NSAMPLE); exg_t = calloc(strides[1], NSAMPLE); tri_t = calloc(strides[2], NSAMPLE); fs = print_cap(dev); if (test_chinfo(dev)) { fprintf(stderr, "\tTest_chinfo failed\n"); goto exit; } if (egd_acq_setup(dev, 3, strides, 3, grp)) goto exit; if (egd_start(dev)) goto exit; for (i=0; i < fs*DURATION; i += NSAMPLE) { if (egd_get_data(dev, NSAMPLE, eeg_t, exg_t, tri_t) < 0) { fprintf(stderr, "\tAcq failed at sample %i\n",i); goto exit; } // No checking if (!bsigcheck) { if (simple_trigger_check(i, NSAMPLE, ntri, tri_t)) retcode = 2; continue; } if (type == EGD_FLOAT) baddata = check_signals_f(NSAMPLE, eeg_t, exg_t, tri_t); else baddata = check_signals_d(NSAMPLE, eeg_t, exg_t, tri_t); if (baddata) { retcode = 2; break; } } if (egd_stop(dev)) goto exit; if (egd_close(dev)) goto exit; dev = NULL; if (retcode == 1) retcode = 0; exit: if (retcode == 1) fprintf(stderr, "\terror caught at pass %i: %s", pass, strerror(errno)); egd_close(dev); free(eeg_t); free(exg_t); free(tri_t); return retcode; }