Files
ecmc_plugin_daq/src/ecmcPluginDAQ.c

120 lines
3.3 KiB
C

/*************************************************************************\
* Copyright (c) 2019 European Spallation Source ERIC
* ecmc is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*
* ecmcPluginDAQ.cpp
*
* Created on: Sept 21, 2020
* Author: anderssandstrom
*
\*************************************************************************/
// Needed to get headers in ecmc right...
#define ECMC_IS_PLUGIN
#define ECMC_EXAMPLE_PLUGIN_VERSION 2
#ifdef __cplusplus
extern "C" {
#endif // ifdef __cplusplus
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ecmcPluginDefs.h"
#include "ecmcDAQDefs.h"
#include "ecmcDAQWrap.h"
static int lastEcmcError = 0;
static char* lastConfStr = NULL;
static int alreadyLoaded = 0;
/** Optional.
* Will be called once after successful load into ecmc.
* Return value other than 0 will be considered error.
* configStr can be used for configuration parameters.
**/
static int daqConstruct(char *configStr)
{
if(alreadyLoaded) {
printf("Error: Plugin ecmc_plugin_daq already loaded and can only be loaded once.");
return -1;
}
// create FFT object and register data callback
lastConfStr = strdup(configStr);
return 0; //createDAQ(configStr); //create from iocsh commands instead
}
/** Optional function.
* Will be called once at unload.
**/
static void daqDestruct(void)
{
// Segfaults here during destruction?! need to check..
//deleteAllDAQs();
//if(lastConfStr){
// free(lastConfStr);
//}
}
/** Optional function.
* Will be called each realtime cycle if defined
* ecmcError: Error code of ecmc. Makes it possible for
* this plugin to react on ecmc errors
* Return value other than 0 will be considered to be an error code in ecmc.
**/
static int daqRealtime(int ecmcError)
{
lastEcmcError = ecmcError;
return executeDAQs();
}
static int daqEnterRT(){
return validateDAQs(); //linkDataToDAQs();
}
/** Optional function.
* Will be called once just before leaving realtime mode
* Return value other than 0 will be considered error.
**/
static int daqExitRT(void){
return 0;
}
// Register data for plugin so ecmc know what to use
static struct ecmcPluginData pluginDataDef = {
// Allways use ECMC_PLUG_VERSION_MAGIC
.ifVersion = ECMC_PLUG_VERSION_MAGIC,
// Name
.name = "ecmc_plugin_daq",
// Description
.desc = "DAQ plugin for use with ecmc.",
// Option description
.optionDesc = "\n "ECMC_PLUGIN_DBG_PRINT_OPTION_CMD"<1/0> : Enables/disables printouts from plugin, default = disabled.\n",
// Plugin version
.version = ECMC_EXAMPLE_PLUGIN_VERSION,
// Optional construct func, called once at load. NULL if not definded.
.constructFnc = daqConstruct,
// Optional destruct func, called once at unload. NULL if not definded.
.destructFnc = daqDestruct,
// Optional func that will be called each rt cycle. NULL if not definded.
.realtimeFnc = daqRealtime,
// Optional func that will be called once just before enter realtime mode
.realtimeEnterFnc = daqEnterRT,
// Optional func that will be called once just before exit realtime mode
.realtimeExitFnc = daqExitRT,
// PLC funcs
.funcs[0] = {0},
.consts[0] = {0}, // last element set all to zero..
};
ecmc_plugin_register(pluginDataDef);
# ifdef __cplusplus
}
# endif // ifdef __cplusplus