view data-provider.h @ 102:4f1f353e84f5

Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Mon, 08 Apr 2013 16:18:05 +0200
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