This commit is contained in:
2024-03-01 20:18:52 +01:00
parent b99a9e35ca
commit c1b7742561
8 changed files with 133 additions and 1629 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,117 +0,0 @@
/*************************************************************************\
* 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.
*
* ecmcDAQChannel.h
*
* Created on: Mar 22, 2020
* Author: anderssandstrom
*
\*************************************************************************/
#ifndef ECMC_SCOPE_H_
#define ECMC_SCOPE_H_
#include <stdexcept>
#include "ecmcDataItem.h"
#include "ecmcAsynPortDriver.h"
#include "ecmcDAQDefs.h"
#include "inttypes.h"
#include <string>
class ecmcDAQChannel {
public:
/** ecmc Scope class
* This object can throw:
* - bad_alloc
* - invalid_argument
* - runtime_error
* - out_of_range
*/
ecmcDAQChannel(int index, char* name);
~ecmcDAQChannel();
void connectToDataSources();
void setEnable(int enable);
void execute();
private:
void parseConfigStr(char *configStr);
void addDataToBuffer(double data);
bool sourceDataTypeSupported(ecmcEcDataType dt);
void initAsyn();
int64_t timeDiff();
asynParamType getResultAsynDTFromEcDT(ecmcEcDataType ecDT);
void setWaitForNextTrigg();
uint8_t* resultDataBuffer_;
uint8_t* lastScanSourceDataBuffer_;
size_t resultDataBufferBytes_;
size_t bytesInResultBuffer_;
ecmcDataItem *sourceDataItem_;
ecmcDataItemInfo *sourceDataItemInfo_;
ecmcDataItem *sourceDataNexttimeItem_;
ecmcDataItemInfo *sourceDataNexttimeItemInfo_;
ecmcDataItem *sourceTriggItem_;
ecmcDataItemInfo *sourceTriggItemInfo_;
int dataSourceLinked_; // To avoid link several times
int objectId_; // Unique object id
int triggOnce_;
int firstTrigg_;
uint64_t triggTime_;
uint64_t oldTriggTime_;
uint64_t sourceNexttime_;
int64_t sourceSampleRateNS_; // nanoseconds
ecmcDAQChannelState scopeState_;
uint64_t ecmcSmapleTimeNS_;
int64_t sourceElementsPerSample_;
size_t elementsInResultBuffer_;
double samplesSinceLastTrigg_;
// Config options
char* cfgDataSourceStr_; // Config: data source string
char* cfgDataNexttimeStr_; // Config: data source string
char* cfgTriggStr_; // Config: trigg string
int cfgDbgMode_; // Config: allow dbg printouts
size_t cfgBufferElementCount_; // Config: Data set size
int cfgEnable_; // Config: Enable data acq./calc.
int missedTriggs_;
int triggerCounter_;
// Asyn
ecmcAsynDataItem *sourceStrParam_;
ecmcAsynDataItem *triggStrParam_;
ecmcAsynDataItem *enbaleParam_;
ecmcAsynDataItem *resultParam_;
ecmcAsynDataItem *sourceNexttimeStrParam_;
ecmcAsynDataItem *asynMissedTriggs_;
ecmcAsynDataItem *asynTriggerCounter_;
ecmcAsynDataItem *asynTimeTrigg2Sample_;
// Some generic utility functions
static uint8_t getUint8(uint8_t* data);
static int8_t getInt8(uint8_t* data);
static uint16_t getUint16(uint8_t* data);
static int16_t getInt16(uint8_t* data);
static uint32_t getUint32(uint8_t* data);
static int32_t getInt32(uint8_t* data);
static uint64_t getUint64(uint8_t* data);
static int64_t getInt64(uint8_t* data);
static float getFloat32(uint8_t* data);
static double getFloat64(uint8_t* data);
static size_t getEcDataTypeByteSize(ecmcEcDataType dt);
static void printEcDataArray(uint8_t* data,
size_t size,
ecmcEcDataType dt,
int objId);
static std::string to_string(int value);
};
#endif /* ECMC_SCOPE_H_ */

63
src/ecmcDAQDataArray.cpp Normal file
View File

@@ -0,0 +1,63 @@
7/*************************************************************************\
* Copyright (c) 2024 PSI
* ecmc is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*
* ecmcDAQDataArray.cpp
*
* Created on: March 1, 2024
* Author: anders sandstrom
* Credits to https://github.com/sgreg/dynamic-loading
*
\*************************************************************************/
// Needed to get headers in ecmc right...
#define ECMC_IS_PLUGIN
#include <sstream>
#include "ecmcDAQDataArray.h"
#include "ecmcPluginClient.h"
ecmcDAQDataArray::ecmcDAQDataArray(size_t nelm){
buffer_ = new double [nelm];
nelm_ = nelm;
channelCounter_ = 0;
}
ecmcDAQDataArray::~ecmcDAQDataArray() {
}
void ecmcDAQDataArray::addDataItem(char* name, int timeFormat) {
dataChannels_.push_back(new ecmcDataChannel(name, timeFormat);
channelCounter_++;
}
void ecmcDAQDataArray::connectToDataSources() {
if( dataSourceLinked_ ) {
return;
}
for(std::vector<ecmcDataChannel*>::iterator pDataCh = dataChannels_.begin(); pDataCh != dataChannels_.end(); ++pDataCh) {
if(!(*pDataCh)) {
throw std::runtime_error( "Channel empty..");
}
(*pDataCh)->connectToSource();
}
// Register asyn parameters
initAsyn();
dataSourceLinked_ = 1;
}
void ecmcDAQDataArray::buildHeader(){
// Each Data channel takes 4 doubles
}
void ecmcDAQDataArray::execute() {
}

70
src/ecmcDAQDataArray.h Normal file
View File

@@ -0,0 +1,70 @@
/*************************************************************************\
* Copyright (c) 2024 PSI
* ecmc is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*
* ecmcDAQDataArray.h
*
* Created on: Mar 01, 2024
* Author: anders sandstrom
*
\*************************************************************************/
#ifndef ECMC_DAQ_DATA_ARRAY_H_
#define ECMC_DAQ_DATA_ARRAY_H_
#include <stdexcept>
#include <vector>
#include <string>
#include "ecmcDAQDataArray.h"
#include "ecmcDataItem.h"
/* Class to store data channels */
class ecmcDataChannel {
public:
ecmcDataChannel(char* name, int formatAsTime) {
dataItem_ = NULL;
dataItemInfo_ = NULL;
name_ = name;
timeFormat_ = formatAsTime;
}
void connectToSource() {
// Get data item for
dataItem_ = (ecmcDataItem*) getEcmcDataItem(name_.c_str());
if(!dataItem_) {
printf("ERROR: DataItem %s NULL.\n", name_.c_str());
throw std::runtime_error( "ERROR: DataItem NULL." );
}
dataItemInfo_ = dataItem_->getDataItemInfo();
if(!dataItemInfo_) {
printf("ERROR: DataItemInfo %s NULL.\n", name_.c_str());
throw std::runtime_error( "ERROR: DataItemInfo NULL." );
}
}
ecmcDataItem* dataItem_;
ecmcDataItemInfo* dataItemInfo_;
std::string name_;
int timeFormat_;
};
/* Class to fromat an array of ecmcDataChannels with headers and push over asyn to epics */
class ecmcDAQDataArray {
public:
ecmcDAQDataArray(size_t nelm);
~ecmcDAQDataArray();
void connectToDataSources();
void execute();
void addDataItem(char* name, int timeFormat);
private:
double *buffer_;
std::vector<ecmcDataChannel*> dataChannels_;
size_t channelCounter_;
};
#endif /* ECMC_DAQ_DATA_ARRAY_H_ */

View File

@@ -1,290 +0,0 @@
/*************************************************************************\
* Copyright (c) 2024 PSI
* ecmc is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*
* ecmcDAQDataTypeBase.cpp
*
* Created on: March 1, 2024
* Author: anders sandstrom
* Credits to https://github.com/sgreg/dynamic-loading
*
\*************************************************************************/
// Needed to get headers in ecmc right...
#define ECMC_IS_PLUGIN
#include <sstream>
#include "ecmcDAQDataTypeBase.h"
#include "ecmcPluginClient.h"
ecmcDAQDataTypeBase::ecmcDAQDataTypeBase(int type, char* name){
dataSourceLinked_ = 0;
name_ = name;
type_ = type;
}
ecmcDAQDataTypeBase::~ecmcDAQDataTypeBase() {
}
bool ecmcDAQDataTypeBase::getDataSourcesLinked() {
return dataSourceLinked_;
}
char* ecmcDAQDataTypeBase::getName() {
return name_.c_str();
}
int ecmcDAQDataTypeBase::getType() {
return type_;
}
void ecmcDAQDataTypeBase::printEcDataArray(uint8_t* data,
size_t size,
ecmcEcDataType dt,
int objId) {
printf("INFO: Scope id: %d, data: ",objId);
size_t dataElementSize = getEcDataTypeByteSize(dt);
uint8_t *pData = data;
for(unsigned int i = 0; i < size / dataElementSize; ++i) {
if(i % 10 == 0) {
printf("\n");
} else {
printf(", ");
}
switch(dt) {
case ECMC_EC_U8:
printf("%hhu",getUint8(pData));
break;
case ECMC_EC_S8:
printf("%hhd",getInt8(pData));
break;
case ECMC_EC_U16:
printf("%hu",getUint16(pData));
break;
case ECMC_EC_S16:
printf("%hd",getInt16(pData));
break;
case ECMC_EC_U32:
printf("%u",getUint32(pData));
break;
case ECMC_EC_S32:
printf("%d",getInt32(pData));
break;
case ECMC_EC_U64:
printf("%" PRIu64 "",getInt64(pData));
break;
case ECMC_EC_S64:
printf("%" PRId64 "",getInt64(pData));
break;
case ECMC_EC_F32:
printf("%f",getFloat32(pData));
break;
case ECMC_EC_F64:
printf("%lf",getFloat64(pData));
break;
default:
break;
}
pData += dataElementSize;
}
printf("\n");
}
uint8_t ecmcDAQDataTypeBase::getUint8(uint8_t* data) {
return *data;
}
int8_t ecmcDAQDataTypeBase::getInt8(uint8_t* data) {
int8_t* p=(int8_t*)data;
return *p;
}
uint16_t ecmcDAQDataTypeBase::getUint16(uint8_t* data) {
uint16_t* p=(uint16_t*)data;
return *p;
}
int16_t ecmcDAQDataTypeBase::getInt16(uint8_t* data) {
int16_t* p=(int16_t*)data;
return *p;
}
uint32_t ecmcDAQDataTypeBase::getUint32(uint8_t* data) {
uint32_t* p=(uint32_t*)data;
return *p;
}
int32_t ecmcDAQDataTypeBase::getInt32(uint8_t* data) {
int32_t* p=(int32_t*)data;
return *p;
}
uint64_t ecmcDAQDataTypeBase::getUint64(uint8_t* data) {
uint64_t* p=(uint64_t*)data;
return *p;
}
int64_t ecmcDAQDataTypeBase::getInt64(uint8_t* data) {
int64_t* p=(int64_t*)data;
return *p;
}
float ecmcDAQDataTypeBase::getFloat32(uint8_t* data) {
float* p=(float*)data;
return *p;
}
double ecmcDAQDataTypeBase::getFloat64(uint8_t* data) {
double* p=(double*)data;
return *p;
}
size_t ecmcDAQDataTypeBase::getEcDataTypeByteSize(ecmcEcDataType dt){
switch(dt) {
case ECMC_EC_NONE:
return 0;
break;
case ECMC_EC_B1:
return 1;
break;
case ECMC_EC_B2:
return 1;
break;
case ECMC_EC_B3:
return 1;
break;
case ECMC_EC_B4:
return 1;
break;
case ECMC_EC_U8:
return 1;
break;
case ECMC_EC_S8:
return 1;
break;
case ECMC_EC_U16:
return 2;
break;
case ECMC_EC_S16:
return 2;
break;
case ECMC_EC_U32:
return 4;
break;
case ECMC_EC_S32:
return 4;
break;
case ECMC_EC_U64:
return 8;
break;
case ECMC_EC_S64:
return 8;
break;
case ECMC_EC_F32:
return 4;
break;
case ECMC_EC_F64:
return 8;
break;
default:
return 0;
break;
}
return 0;
}
asynParamType ecmcDAQDataTypeBase::getResultAsynDTFromEcDT(ecmcEcDataType ecDT) {
/*typedef enum {
asynParamNotDefined,
asynParamInt32,
asynParamUInt32Digital,
asynParamFloat64,
asynParamOctet,
asynParamInt8Array,
asynParamInt16Array,
asynParamInt32Array,
asynParamFloat32Array,
asynParamFloat64Array,
asynParamGenericPointer
} asynParamType;*/
switch(ecDT) {
case ECMC_EC_NONE:
return asynParamNotDefined;
break;
case ECMC_EC_B1 :
return asynParamNotDefined;
break;
case ECMC_EC_B2 :
return asynParamNotDefined;
break;
case ECMC_EC_B3 :
return asynParamNotDefined;
break;
case ECMC_EC_B4 :
return asynParamNotDefined;
break;
case ECMC_EC_U8 :
return asynParamInt8Array;
break;
case ECMC_EC_S8 :
return asynParamInt8Array;
break;
case ECMC_EC_U16:
return asynParamInt16Array;
break;
case ECMC_EC_S16:
return asynParamInt16Array;
break;
case ECMC_EC_U32:
return asynParamInt32Array;
break;
case ECMC_EC_S32:
return asynParamInt32Array;
break;
case ECMC_EC_U64:
return asynParamNotDefined;
break;
case ECMC_EC_S64:
return asynParamNotDefined;
break;
case ECMC_EC_F32:
return asynParamFloat32Array;
break;
case ECMC_EC_F64:
return asynParamFloat64Array;
break;
default:
return asynParamNotDefined;
break;
}
return asynParamNotDefined;
}
// Avoid issues with std:to_string()
std::string ecmcDAQDataTypeBase::to_string(int value) {
std::ostringstream os;
os << value;
return os.str();
}

View File

@@ -1,57 +0,0 @@
/*************************************************************************\
* Copyright (c) 2024 PSI
* ecmc is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*
* ecmcDAQDataTypeBase.h
*
* Created on: Mar 01, 2024
* Author: anders sandstrom
*
\*************************************************************************/
#ifndef ECMC_DAQ_DATATYPE_BASE_H_
#define ECMC_DAQ_DATATYPE_BASE_H_
#include <stdexcept>
#include "ecmcDataItem.h"
#include <string>
class ecmcDAQDataTypeBase {
public:
ecmcDAQDataTypeBase(int type, char* name);
~ecmcDAQDataTypeBase();
virtual void connectToDataSources() = 0;
virtual void execute() = 0;
virtual size_t getDataElementCount() = 0;
virtual double* getDataPtr() = 0;
bool getDataSourcesLinked();
char* getName();
int getType();
protected:
bool dataSourceLinked_;
std::string name_;
int type_;
// Some generic utility functions
static uint8_t getUint8(uint8_t* data);
static int8_t getInt8(uint8_t* data);
static uint16_t getUint16(uint8_t* data);
static int16_t getInt16(uint8_t* data);
static uint32_t getUint32(uint8_t* data);
static int32_t getInt32(uint8_t* data);
static uint64_t getUint64(uint8_t* data);
static int64_t getInt64(uint8_t* data);
static float getFloat32(uint8_t* data);
static double getFloat64(uint8_t* data);
static size_t getEcDataTypeByteSize(ecmcEcDataType dt);
static void printEcDataArray(uint8_t* data,
size_t size,
ecmcEcDataType dt,
int objId);
static std::string to_string(int value);
};
#endif /* ECMC_DAQ_DATATYPE_BASE_H_ */

View File

@@ -1,116 +0,0 @@
/*************************************************************************\
* Copyright (c) 2024 PSI
* ecmc is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*
* ecmcDAQDataTypeGeneric.cpp
*
* Created on: March 1, 2024
* Author: anders sandstrom
* Credits to https://github.com/sgreg/dynamic-loading
*
\*************************************************************************/
// Needed to get headers in ecmc right...
#define ECMC_IS_PLUGIN
#include <sstream>
#include "ecmcDAQDataTypeGeneric.h"
#include "ecmcPluginClient.h"
ecmcDAQDataTypeGeneric::ecmcDAQDataTypeGeneric(char *ecTimeRising,char *ecTimeFalling){
sEcTimeRising_ = ecTimeRising;
sEcTimeFalling_ = ecTimeFalling;
dataItemTimeRising_ = NULL;
dataItemInfoTimeRising_ = NULL;
dataItemTimeFalling_ = NULL;
dataItemInfoTimeFalling_ = NULL;
for(int i=0; i< ECMC_DAQ_DATA_TYPE_1_DATA_ELEMENTS, ++i) {
buffer_[i] = 0.0;
}
}
ecmcDAQDataTypeGeneric::~ecmcDAQDataTypeGeneric() {
delete(dataItemTimeRising_);
delete(dataItemInfoTimeRising_);
delete(dataItemTimeFalling_);
delete(dataItemInfoTimeFalling_);
}
void ecmcDAQDataTypeGeneric::connectToDataSources() {
if( dataSourceLinked_ ) {
return;
}
// Get data item for
dataItemTimeRising_ = (ecmcDataItem*) getEcmcDataItem(sEcTimeRising_.c_str());
if(!dataItemTimeRising_) {
throw std::runtime_error( "ERROR: Dataitem for time rinsing edge NULL." );
}
dataItemInfoTimeRising_ = dataItemTimeRising_->getDataItemInfo();
if(!dataItemInfoTimeRising_) {
throw std::runtime_error( "ERROR: Dataiteminfo for time rising edge NULL." );
}
// Get source nexttime dataItem
sourceDataNexttimeItem_ = (ecmcDataItem*) getEcmcDataItem(cfgDataNexttimeStr_);
if(!sourceDataNexttimeItem_) {
SCOPE_DBG_PRINT("ERROR: Source nexttime dataitem NULL.\n");
throw std::runtime_error( "ERROR: Source nexttime dataitem NULL." );
}
sourceDataNexttimeItemInfo_ = sourceDataNexttimeItem_->getDataItemInfo();
if(!sourceDataNexttimeItemInfo_) {
SCOPE_DBG_PRINT("ERROR: Source nexttime dataitem info NULL.\n");
throw std::runtime_error( "ERROR: Source nexttime dataitem info NULL." );
}
// Get trigg dataItem
sourceTriggItem_ = (ecmcDataItem*) getEcmcDataItem(cfgTriggStr_);
if(!sourceTriggItem_) {
SCOPE_DBG_PRINT("ERROR: Trigg dataitem NULL.\n");
throw std::runtime_error( "ERROR: Trigg dataitem NULL." );
}
sourceTriggItemInfo_ = sourceTriggItem_->getDataItemInfo();
if(!sourceTriggItemInfo_) {
SCOPE_DBG_PRINT("ERROR: Trigg dataitem info NULL.\n");
throw std::runtime_error( "ERROR: Trigg dataitem info NULL." );
}
if( sourceTriggItem_->read((uint8_t*)(&oldTriggTime_),sourceTriggItemInfo_->dataElementSize)){
SCOPE_DBG_PRINT("ERROR: Failed read trigg time.\n");
throw std::runtime_error( "ERROR: Failed read trigg time." );
}
if(!sourceDataTypeSupported(sourceDataItem_->getEcmcDataType())) {
SCOPE_DBG_PRINT("ERROR: Source data type not suppported.\n");
throw std::runtime_error( "ERROR: Source data type not suppported.");
}
// Register asyn parameters
initAsyn();
dataSourceLinked_ = 1;
scopeState_ = ECMC_SCOPE_STATE_WAIT_TRIGG;
}
void ecmcDAQDataTypeGeneric::execute() {
}
size_t ecmcDAQDataTypeGeneric::getDataElementCount() {
return ECMC_DAQ_DATA_TYPE_1_DATA_ELEMENTS;
}
double* ecmcDAQDataTypeGeneric::getDataPtr() {
return &buffer[0];
}
double ecmcDAQDataTypeGeneric::getType() {
return ECMC_DAQ_DATA_TYPE_1_ID;
}

View File

@@ -1,47 +0,0 @@
/*************************************************************************\
* Copyright (c) 2024 PSI
* ecmc is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*
* ecmcDAQDataTypeGeneric.h
*
* Created on: Mar 01, 2024
* Author: anders sandstrom
*
\*************************************************************************/
#ifndef ECMC_DAQ_DATATYPE_1_H_
#define ECMC_DAQ_DATATYPE_1_H_
#include <stdexcept>
#include "ecmcDataItem.h"
#include <string>
#include "ecmcDAQDataTypeBase.h"
#include "ecmcDataItem.h"
#include <vector>
#define ECMC_DAQ_DATA_TYPE_1_DATA_ELEMENTS 2
class ecmcDAQDataTypeGeneric : public ecmcDAQDataTypeBase {
public:
ecmcDAQDataTypeGeneric();
~ecmcDAQDataTypeGeneric();
void connectToDataSources();
void execute();
size_t getDataElementCount();
double* getDataPtr();
double getType();
void addEcData(char* ec)
private:
std::string sEcTimeRising_;
std::string sEcTimeFalling_;
double *buffer_;
ecmcEc *ecMaster_;
static std::vector<ecmcEcEntry*> entries;
};
#endif /* ECMC_DAQ_DATATYPE_1_H_ */