Add setting to send old data, one cycle for scalars and one elemenbt for arrays (edwin needed for simpler triggering of incremental card timestamp).

This commit is contained in:
2024-03-27 12:06:48 +01:00
parent a462e343e7
commit 57946a17e3
8 changed files with 44 additions and 24 deletions

View File

@@ -55,7 +55,7 @@ ${SCRIPTEXEC} ${ecmc_plugin_daq_DIR}ecmcDAQAddDataItem.cmd, "PARAM=ec0.s1.po
#- EL5112: Incremental (treat as array, but same timestamp twice, the second actualy not used)
${SCRIPTEXEC} ${ecmc_plugin_daq_DIR}ecmcDAQAddChannel.cmd, "TYPE=1001"
${SCRIPTEXEC} ${ecmc_plugin_daq_DIR}ecmcDAQAddDataItem.cmd, "PARAM=ec0.s2.timestamp01, FORMAT=1"
${SCRIPTEXEC} ${ecmc_plugin_daq_DIR}ecmcDAQAddDataItem.cmd, "PARAM=ec0.s2.timestamp01, FORMAT=1"
${SCRIPTEXEC} ${ecmc_plugin_daq_DIR}ecmcDAQAddDataItem.cmd, "PARAM=ec0.s2.timestamp01, FORMAT=1, SEND_OLD=1"
${SCRIPTEXEC} ${ecmc_plugin_daq_DIR}ecmcDAQAddDataItem.cmd, "PARAM=ec0.s2.positionActual01"
${SCRIPTEXEC} ${ecmc_plugin_daq_DIR}ecmcDAQAddChannel.cmd, "TYPE=11"

View File

@@ -19,7 +19,8 @@
#- Useful for oversampling slaves where normally the nextsync time is available.\n");
#- The calculated time then would correspond to the first data in the array recived.\n");
#- 3 = time_ns_minus_period : Time: Raw value minus one period.\n");
#- SEND_OLD : 1 = Send one element old data (for scalars from last cycle, for arrays shift one element), defaults to 0 (send fresh data)
#-
#-################################################################################
ecmcDAQAddItem(${PARAM},${FORMAT=0})
ecmcDAQAddItem(${PARAM},${FORMAT=0},${SEND_OLD=0})

View File

@@ -35,16 +35,19 @@ enum class ecmcDAQDataFormat { raw = 0,
* Useful for oversampling slaves where normally the nextsync time is available.
* The calculated time then would correspond to the first data in the array recived.
* 3=time_ns_minus_period : Time: Raw value minus one period.
* sendOneCycleOldData : Send data from previous cycle (or for arrays elements are shifted one index). To be used by Edwin to trigger on timechange for incremntal timestamped cards..
*/
class ecmcDAQChannelItem {
public:
ecmcDAQChannelItem(const char* name, ecmcDAQDataFormat format) {
ecmcDAQChannelItem(const char* name, ecmcDAQDataFormat format, int sendOneCycleOldData) {
dataItem_ = NULL;
dataItemInfo_ = NULL;
name_ = name;
cstrName_ = strdup(name);
format_ = format; // micro s in int32
sendOneCycleOldData_ = sendOneCycleOldData; // Will only work for scalars (if arrays the elements are shifted once)
sampleTimeCompensation_ = 0;
dataIndexToReturn_ = 0;
dataElementCount_ = 0;
@@ -60,6 +63,7 @@ class ecmcDAQChannelItem {
float32Ptr_ = NULL;
float64Ptr_ = NULL;
dataType_ = ECMC_EC_NONE;
dataOld_ = 0;
printf("ecmcDAQChannelItem: Created new item %s, format %d\n",name,(int)format);
}
@@ -204,13 +208,21 @@ class ecmcDAQChannelItem {
break;
}
//if(dataIndexToReturn_>0) {
// printf("%s[%zu] data = %lf\n",cstrName_,dataIndexToReturn_,data);
//}
dataIndexToReturn_++;
return formatData(data,time);
double freshData = formatData(data,time);
double dataToSend = 0;
if(sendOneCycleOldData_) {
dataToSend = dataOld_;
} else {
dataToSend = freshData;
}
// Store the fresh data here
dataOld_ = freshData;
return dataToSend;
}
double formatData(double data, uint64_t time){
@@ -274,6 +286,8 @@ class ecmcDAQChannelItem {
uint64_t *uint64Ptr_;
float *float32Ptr_;
double *float64Ptr_;
int sendOneCycleOldData_;
double dataOld_;
};
#endif /* ECMC_DAQ_CHANNEL_ITEM_H_ */

View File

@@ -62,9 +62,9 @@ void ecmcDAQDataArray::addChannel(int type) {
channelCounter_++;
}
void ecmcDAQDataArray::addDataItemToChannel(const char* name, int format) {
void ecmcDAQDataArray::addDataItemToChannel(const char* name, int format, int oldData) {
// Always add to last added channel
dataChannels_.back()->addDataItem(name, format);
dataChannels_.back()->addDataItem(name, format, oldData);
}
void ecmcDAQDataArray::connectToDataSources() {

View File

@@ -28,7 +28,7 @@ class ecmcDAQDataArray : public asynPortDriver {
void connectToDataSources();
void execute();
void addChannel(int type);
void addDataItemToChannel(const char* name, int format); // Always add to last added channel
void addDataItemToChannel(const char* name, int format, int oldData); // Always add to last added channel
void setEnable(int enable);
size_t getArraySize();
int validate();

View File

@@ -29,8 +29,8 @@ ecmcDAQDataChannel::ecmcDAQDataChannel(int type){
ecmcDAQDataChannel::~ecmcDAQDataChannel() {
}
void ecmcDAQDataChannel::addDataItem(const char* name, int format) {
dataItems_.push_back(new ecmcDAQChannelItem(name, (ecmcDAQDataFormat)format));
void ecmcDAQDataChannel::addDataItem(const char* name, int format,int oldData) {
dataItems_.push_back(new ecmcDAQChannelItem(name, (ecmcDAQDataFormat)format, oldData));
itemCounter_++;
}

View File

@@ -23,7 +23,7 @@ class ecmcDAQDataChannel {
ecmcDAQDataChannel(int type);
~ecmcDAQDataChannel();
void connectToDataSources();
void addDataItem(const char* name, int format);
void addDataItem(const char* name, int format, int oldData);
size_t getDataElementCount();
double getData(int first);
bool empty();

View File

@@ -91,9 +91,9 @@ int createDAQChannel(int type) {
return 0;
}
int createDAQItem(const char* name, int type) {
int createDAQItem(const char* name, int type, int oldData) {
try {
arrays.back()->addDataItemToChannel(name,type);
arrays.back()->addDataItemToChannel(name,type,oldData);
}
catch(std::exception& e) {
printf("Exception: %s. Plugin will unload.\n",e.what());
@@ -261,7 +261,7 @@ static void initCallFunc_1(const iocshArgBuf *args) {
*/
void ecmcAddDAQItemHelp() {
printf("\n");
printf(" Use ecmcAddDAQItem(<dataitem_name>, <format>)\n");
printf(" Use ecmcAddDAQItem(<dataitem_name>, <format>,<send_one_cycle_old_data>)\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");
@@ -270,17 +270,18 @@ void ecmcAddDAQItemHelp() {
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(" <send_one_cycle_old_data> : Send data from the previous cycle (for scalars). If waveform the elemtes will be shifted one index");
printf("\n");
}
int ecmcAddDAQItem(const char* name, int format) {
int ecmcAddDAQItem(const char* name, int format, int oldData) {
if(strcmp(name,"-h") == 0 || strcmp(name,"--help") == 0 ) {
ecmcAddDAQItemHelp();
return asynSuccess;
}
try {
return createDAQItem(name,format);
return createDAQItem(name,format, oldData);
}
catch(std::exception& e) {
printf("Exception: %s. Create DAQ item failed.\n",e.what());
@@ -296,12 +297,16 @@ static const iocshArg initArg0_2 =
static const iocshArg initArg1_2 =
{ "Type", iocshArgInt };
static const iocshArg *const initArgs_2[] = { &initArg0_2,
&initArg1_2};
static const iocshArg initArg2_2 =
{ "Old value", iocshArgInt };
static const iocshFuncDef initFuncDef_2 = { "ecmcDAQAddItem", 2, initArgs_2};
static const iocshArg *const initArgs_2[] = { &initArg0_2,
&initArg1_2,
&initArg2_2};
static const iocshFuncDef initFuncDef_2 = { "ecmcDAQAddItem", 3, initArgs_2};
static void initCallFunc_2(const iocshArgBuf *args) {
ecmcAddDAQItem(args[0].sval,args[1].ival);
ecmcAddDAQItem(args[0].sval, args[1].ival, args[2].ival);
}