Ejemplo n.º 1
0
int acq_start(struct acq* acq)
{
	if (!acq || !acq->xdf)
		return -1;

	egd_start(acq->dev);

	// Inform the acquisition thread to run
	pthread_mutex_lock(&acq->lock);
	acq->running = 1;
	pthread_cond_signal(&acq->cond);
	pthread_mutex_unlock(&acq->lock);

	return 0;
}
Ejemplo n.º 2
0
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;
}