view data-provider.h @ 126:5bba1d1c3b46

Produce realistic data from fake data provider
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 13 Dec 2013 17:03:36 +0100
parents 8b90fbba59ef
children be87c8e78266
line wrap: on
line source

#ifndef __DATA_PROVIDER_H__
#define __DATA_PROVIDER_H__

#include <future.h>

/* data acquisition flag */
extern int acquiring;

/* data queue */
extern CmtTSQHandle dataQueue;

/* callback receiving messages in the main thread */
void CVICALLBACK MessageCB (void *callbackData);

/* data acquisition event */
struct event {
	struct timeval time;
	double data[4];
};

/* message buffer */
#define DATA_PROVIDER_MSGLEN 256
#define DATA_PROVIDER_MSGNUM 16
static char messages[DATA_PROVIDER_MSGLEN][DATA_PROVIDER_MSGNUM];
static unsigned int messageid = 0;

#define SendMessage(threadId, ...)                                     \
	do {                                                               \
		char *message = messages[messageid++ % DATA_PROVIDER_MSGNUM];  \
		snprintf(message, DATA_PROVIDER_MSGLEN - 1, ##__VA_ARGS__);    \
		PostDeferredCallToThread(MessageCB, message, threadId);        \
	} while (0)

#endif