view fake-data-provider.c @ 183:791ca26fee6a

Rewrite data writing to file Fmt() uses by default truncation to conver double arguments to their text representation. Rounding must be used. Rewrite using standard C functions to get rid of this problem (and probably make it more efficient). Extend to handle arbitrary number of channels and to report errors on opening the data files.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 21 Feb 2014 18:42:30 +0100
parents 8a94f1913b4e
children a40c8af8b028
line wrap: on
line source

/* FXAnalise fake data provider */

#include <analysis.h>
#include <userint.h>
#include <utility.h>

#include "future.h"
#include "data-provider.h"

#define PERIOD 1.0
#define INCREMENT 0.1
#define NOISE 0.25


int CVICALLBACK FakeDataProvider (void *functionData)
{
	int i, mainThreadId;
	double mark;
	struct event event = { 0, };
	double f[NCHAN] = { 55000000.0, 10000.0, 10000.0, 275000.0 };
	double noise[NCHAN];
	
	/* get main thread id to post messages to it */
	mainThreadId = CmtGetMainThreadID();
	
	while (acquiring) {
   		mark = Timer();
		
		/* update data */
		gettimeofday(&event.time, NULL);
		f[0] += INCREMENT;
		for (i = 0; i < NCHAN; i++) 
			event.data[i] = f[i];
		
#ifdef NOISE
		/* add noise */
		GaussNoise(NCHAN, NOISE, -1, noise);
		for (i = 0; i < NCHAN; i++) 
			event.data[i] += noise[i];
#endif
		
		/* push data into the data queue */
		CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0);
		
		/* wait till next second */
   		SyncWait(mark, PERIOD);
	}
	
	return 0;
}