156 lines
4.4 KiB
C
156 lines
4.4 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 successfull load into ecmc.
|
|
* Return value other than 0 will be considered error.
|
|
* configStr can be used for configuration parameters.
|
|
**/
|
|
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.
|
|
**/
|
|
void daqDestruct(void)
|
|
{
|
|
deleteAllDAQs();
|
|
if(lastConfStr){
|
|
free(lastConfStr);
|
|
}
|
|
}
|
|
|
|
/** Optional function.
|
|
* Will be called each realtime cycle if definded
|
|
* ecmcError: Error code of ecmc. Makes it posible for
|
|
* this plugin to react on ecmc errors
|
|
* Return value other than 0 will be considered to be an error code in ecmc.
|
|
**/
|
|
int daqRealtime(int ecmcError)
|
|
{
|
|
lastEcmcError = ecmcError;
|
|
return executeDAQs();
|
|
}
|
|
|
|
|
|
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.
|
|
**/
|
|
int daqExitRT(void){
|
|
return 0;
|
|
}
|
|
|
|
// // Plc function for clear of buffers
|
|
// double daq_clear(double index) {
|
|
// return (double)clearDAQ((int)index);
|
|
// }
|
|
|
|
// Plc function for enable
|
|
//double daq_enable(double index, double enable) {
|
|
// return 0; //(double)enableDAQ((int)index, (int)enable);
|
|
//}
|
|
|
|
// // Plc function for trigg new measurement (will clear buffers)
|
|
// double daq_trigg(double index) {
|
|
// return (double)triggDAQ((int)index);
|
|
// }
|
|
|
|
// Register data for plugin so ecmc know what to use
|
|
struct ecmcPluginData pluginDataDef = {
|
|
// Allways use ECMC_PLUG_VERSION_MAGIC
|
|
.ifVersion = ECMC_PLUG_VERSION_MAGIC,
|
|
// Name
|
|
.name = "ecmcPlugin_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},
|
|
// { /*----fft_clear----*/
|
|
// // Function name (this is the name you use in ecmc plc-code)
|
|
// .funcName = "daq_enable",
|
|
// // Function description
|
|
// .funcDesc = "daq_enable(index,enable) : Enable/disaable daq[index].",
|
|
// /**
|
|
// * 12 different prototypes allowed (only doubles since reg in plc).
|
|
// * Only funcArg${argCount} func shall be assigned the rest set to NULL.
|
|
// **/
|
|
// .funcArg0 = NULL,
|
|
// .funcArg1 = NULL,
|
|
// .funcArg2 = daq_enable,
|
|
// .funcArg3 = NULL,
|
|
// .funcArg4 = NULL,
|
|
// .funcArg5 = NULL,
|
|
// .funcArg6 = NULL,
|
|
// .funcArg7 = NULL,
|
|
// .funcArg8 = NULL,
|
|
// .funcArg9 = NULL,
|
|
// .funcArg10 = NULL,
|
|
// .funcGenericObj = NULL,
|
|
// },
|
|
.consts[0] = {0}, // last element set all to zero..
|
|
};
|
|
|
|
ecmc_plugin_register(pluginDataDef);
|
|
|
|
# ifdef __cplusplus
|
|
}
|
|
# endif // ifdef __cplusplus
|