This commit is contained in:
2024-03-04 11:22:34 +01:00
parent e092ed9dea
commit 21c010d0be
12 changed files with 433 additions and 184 deletions

View File

@@ -18,51 +18,77 @@
#include <stdexcept>
#include <string>
#include "ecmcDAQWrap.h"
#include "ecmcDAQChannel.h"
#include "ecmcDAQDataArray.h"
#include "ecmcDAQDefs.h"
#include <epicsExport.h>
#include <iocsh.h>
#define ECMC_PLUGIN_PORTNAME_PREFIX "PLUGIN.DAQ"
#define ECMC_PLUGIN_DAQ_ERROR_CODE 1
static std::vector<ecmcDAQChannel*> channels;
static int channelCounter = 0;
static std::vector<ecmcDAQDataArray*> arrays;
static int arrayCounter = 0;
int createDAQ(char* name) {
int createDAQArray(const char* name, const char* portName ) {
// create new ecmcFFT object
ecmcDAQChannel* channel = NULL;
ecmcDAQDataArray* array = NULL;
try {
channel = new ecmcDAQChannel(name);
array = new ecmcDAQDataArray(name, portName);
}
catch(std::exception& e) {
if(scope) {
delete channel;
if(array) {
delete array;
}
printf("Exception: %s. Plugin will unload.\n",e.what());
return ECMC_PLUGIN_DAQ_ERROR_CODE;
}
scopes.push_back(scope);
channelCounter++;
arrays.push_back(array);
arrayCounter++;
return 0;
}
int createDAQChannel(int type) {
try {
arrays.back()->addChannel(type);
}
catch(std::exception& e) {
printf("Exception: %s. Plugin will unload.\n",e.what());
return ECMC_PLUGIN_DAQ_ERROR_CODE;
}
return 0;
}
int createDAQItem(const char* name, int type) {
try {
arrays.back()->addDataItemToChannel(name,type);
}
catch(std::exception& e) {
printf("Exception: %s. Plugin will unload.\n",e.what());
return ECMC_PLUGIN_DAQ_ERROR_CODE;
}
return 0;
}
void deleteAllDAQs() {
for(std::vector<ecmcDAQChannel*>::iterator pDAQChannel = scopes.begin(); pDAQChannel != scopes.end(); ++pDAQChannel) {
if(*pDAQChannel) {
delete (*pDAQChannel);
for(std::vector<ecmcDAQDataArray*>::iterator pDAQArray = arrays.begin(); pDAQArray != arrays.end(); ++pDAQArray) {
if(*pDAQArray) {
delete (*pDAQArray);
}
}
}
int linkDataToDAQs() {
for(std::vector<ecmcDAQChannel*>::iterator pDAQChannel = scopes.begin(); pDAQChannel != scopes.end(); ++pDAQChannel) {
if(*pDAQChannel) {
for(std::vector<ecmcDAQDataArray*>::iterator pDAQArray = arrays.begin(); pDAQArray != arrays.end(); ++pDAQArray) {
if(*pDAQArray) {
try {
(*pDAQChannel)->connectToDataSources();
(*pDAQArray)->connectToDataSources();
}
catch(std::exception& e) {
printf("Exception: %s. Plugin will unload.\n",e.what());
@@ -73,22 +99,22 @@ int linkDataToDAQs() {
return 0;
}
int enableDAQ(int scopeIndex, int enable) {
try {
scopes.at(scopeIndex)->setEnable(enable);
}
catch(std::exception& e) {
printf("Exception: %s. DAQ index out of range.\n",e.what());
return ECMC_PLUGIN_DAQ_ERROR_CODE;
}
return 0;
}
//int enableDAQ(int scopeIndex, int enable) {
// try {
// arrays.at(scopeIndex)->setEnable(enable);
// }
// catch(std::exception& e) {
// printf("Exception: %s. DAQ index out of range.\n",e.what());
// return ECMC_PLUGIN_DAQ_ERROR_CODE;
// }
// return 0;
//}
int executeDAQCs() {
int executeDAQs() {
try {
for(std::vector<ecmcDAQChannel*>::iterator pDAQChannel = scopes.begin(); pDAQChannel != scopes.end(); ++pDAQChannel) {
if(*pDAQChannel) {
(*pDAQChannel)->execute();
for(std::vector<ecmcDAQDataArray*>::iterator pDAQArray = arrays.begin(); pDAQArray != arrays.end(); ++pDAQArray) {
if(*pDAQArray) {
(*pDAQArray)->execute();
}
}
}
@@ -99,52 +125,122 @@ int executeDAQCs() {
return 0;
}
/**
* EPICS iocsh shell command: ecmcAddDataType1ToChannel
* EPICS iocsh shell command: ecmcAddDAQArray
*/
void ecmcAddDataType1ToChannelPrintHelp() {
void ecmcAddDAQArrayHelp() {
printf("\n");
printf(" Use ecmcAddDataType1ToChannel(<ch_name>, <axis_index>)\n");
printf(" <ch_name> : Name of channel to add data to.\n");
printf(" <Axis id> : Axis index to add.\n");
printf(" <velo limit> : Axis standstill velo limit [unit of axis].\n");
printf(" <time> : Time for axis to be below velo limit [ms].\n");
printf(" Use ecmcAddDAQArray(<name>,<asyn_port_name>)\n");
printf(" <name> : Name of DAQ array object.\n");
printf(" <asyn_port_name> : Asyn port name.\n");
printf("\n");
}
int ecmcAddAxisToSafetyGroup(const char* name, int axis_id, double velo_lim, int stand_still_time) {
int ecmcAddDAQArray(const char* name,const char* portname) {
if(!name) {
ecmcAddAxisToSafetyGroupPrintHelp();
ecmcAddDAQArrayHelp();
return asynError;
}
if(!portname) {
ecmcAddDAQArrayHelp();
return asynError;
}
if(strcmp(name,"-h") == 0 || strcmp(name,"--help") == 0 ) {
ecmcAddAxisToSafetyGroupPrintHelp();
ecmcAddDAQArrayHelp();
return asynSuccess;
}
if(axis_id <= 0) {
printf("Error: Invalid axis id.\n");
exit(EXIT_FAILURE);
}
if(velo_lim < 0) {
printf("Error: Invalid velocity limit.\n");
exit(EXIT_FAILURE);
}
if(stand_still_time < 0) {
printf("Error: Invalid stand still filter time.\n");
exit(EXIT_FAILURE);
}
try {
return addAxisToSafetyGroup(name,axis_id, velo_lim, stand_still_time);
return createDAQArray(name,portname);
}
catch(std::exception& e) {
printf("Exception: %s. Add axis to safety group failed.\n",e.what());
printf("Exception: %s. Create DAQ array failed.\n",e.what());
exit(EXIT_FAILURE);
}
return asynSuccess;
}
static const iocshArg initArg0_0 =
{ "Array name", iocshArgString };
static const iocshArg initArg1_0 =
{ "Asyn port name", iocshArgString };
static const iocshArg *const initArgs_0[] = { &initArg0_0,
&initArg1_0};
static const iocshFuncDef initFuncDef_0 = { "ecmcAddDAQArray", 2, initArgs_0};
static void initCallFunc_0(const iocshArgBuf *args) {
ecmcAddDAQArray(args[0].sval, args[1].sval);
}
/**
* EPICS iocsh shell command: ecmcAddDAQChannel
*/
void ecmcAddDAQChannelHelp() {
printf("\n");
printf(" Use ecmcAddDAQChannel(<type>)\n");
printf(" <type> : Type identifier if channel (int).\n");
printf("\n");
}
int ecmcAddDAQChannel(int type) {
try {
return createDAQChannel(type);
}
catch(std::exception& e) {
ecmcAddDAQChannelHelp();
printf("Exception: %s. Create DAQ channel failed.\n",e.what());
exit(EXIT_FAILURE);
}
return asynSuccess;
}
static const iocshArg initArg0_1 =
{ "Type", iocshArgInt };
static const iocshArg *const initArgs_1[] = { &initArg0_1};
static const iocshFuncDef initFuncDef_1 = { "ecmcAddDAQChannel", 1, initArgs_1};
static void initCallFunc_1(const iocshArgBuf *args) {
ecmcAddDAQChannel(args[0].ival);
}
/**
* EPICS iocsh shell command: ecmcAddDAQItem
*/
void ecmcAddDAQItemHelp() {
printf("\n");
printf(" Use ecmcAddDAQItem(<dataitem_name>, <format>)\n");
printf(" <dataitem_name> : Data item name ex: 'ec0.s11.analogInput01' .\n");
printf(" <format> : Optional format conversion of data:.\n");
printf(" 0 = raw : Take raw value (do not apply special format)\n");
printf(" 1 = time_micro_s : Time: Recalc 64bit nano seconds to 32 bit micro second counter\n");
printf(" 2 = time_micro_s_minus_period : Time: Recalc 64bit nano seconds to 32 bit micro second counter minus one ec-period.\n");
printf(" Useful for oversampling slaves where normally the nextsync time is available.\n");
printf(" The calculated time then would correspond to the first data in the array recived.\n");
printf(" 3 = time_ns_minus_period : Time: Raw value minus one period.\n");
printf("\n");
}
int ecmcAddDAQItem(const char* name, int format) {
if(strcmp(name,"-h") == 0 || strcmp(name,"--help") == 0 ) {
ecmcAddDAQItemHelp();
return asynSuccess;
}
try {
return createDAQItem(name,format);
}
catch(std::exception& e) {
printf("Exception: %s. Create DAQ item failed.\n",e.what());
exit(EXIT_FAILURE);
}
@@ -152,33 +248,24 @@ int ecmcAddAxisToSafetyGroup(const char* name, int axis_id, double velo_lim, int
}
static const iocshArg initArg0_2 =
{ "Group name", iocshArgString };
{ "Data item name/path", iocshArgString };
static const iocshArg initArg1_2 =
{ "Axis id []", iocshArgInt };
static const iocshArg initArg2_2 =
{ "Velo limit [unit same as axis cfg]", iocshArgDouble };
static const iocshArg initArg3_2 =
{ "Velo stand still filter time [ms]", iocshArgInt };
{ "Type", iocshArgInt };
static const iocshArg *const initArgs_2[] = { &initArg0_2,
&initArg1_2,
&initArg2_2,
&initArg3_2};
static const iocshArg *const initArgs_2[] = { &initArg0_2,
&initArg1_2};
static const iocshFuncDef initFuncDef_2 = { "ecmcAddAxisToSafetyGroup", 4, initArgs_2};
static const iocshFuncDef initFuncDef_2 = { "ecmcAddDAQItem", 2, initArgs_2};
static void initCallFunc_2(const iocshArgBuf *args) {
ecmcAddAxisToSafetyGroup(args[0].sval, args[1].ival, args[2].dval, args[3].ival);
ecmcAddDAQItem(args[0].sval,args[1].ival);
}
void ecmcSafetyPlgRegister(void) {
// Register
void ecmcDAQPlgRegister(void) {
iocshRegister(&initFuncDef_0, initCallFunc_0);
iocshRegister(&initFuncDef_1, initCallFunc_1);
iocshRegister(&initFuncDef_2, initCallFunc_2);
}
epicsExportRegistrar(ecmcSafetyPlgRegister);
epicsExportRegistrar(ecmcDAQPlgRegister);