113 lines
3.1 KiB
C++
113 lines
3.1 KiB
C++
/*************************************************************************\
|
|
* Copyright (c) 2024 PSI
|
|
* ecmc is distributed subject to a Software License Agreement found
|
|
* in file LICENSE that is included with this distribution.
|
|
*
|
|
* ecmcDAQDataChannel.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 "ecmcDAQDataChannel.h"
|
|
|
|
ecmcDAQDataChannel::ecmcDAQDataChannel(int type){
|
|
itemCounter_ = 0;
|
|
type_ = (double) type;
|
|
dataElementCount_ = 0;
|
|
returnedDataCounter_ = 0;
|
|
currItemIndex_ = 0;
|
|
dataSourcesLinked_ = 0;
|
|
}
|
|
|
|
ecmcDAQDataChannel::~ecmcDAQDataChannel() {
|
|
}
|
|
|
|
void ecmcDAQDataChannel::addDataItem(const char* name, int format) {
|
|
dataItems_.push_back(new ecmcDAQChannelItem(name, (ecmcDAQDataFormat)format));
|
|
itemCounter_++;
|
|
}
|
|
|
|
void ecmcDAQDataChannel::connectToDataSources() {
|
|
if( dataSourcesLinked_ ) {
|
|
return;
|
|
}
|
|
|
|
dataElementCount_ = 0;
|
|
|
|
for(std::vector<ecmcDAQChannelItem*>::iterator pDataItem = dataItems_.begin(); pDataItem != dataItems_.end(); ++pDataItem) {
|
|
if(!(*pDataItem)) {
|
|
throw std::runtime_error( "Data item empty..");
|
|
}
|
|
(*pDataItem)->connectToSource();
|
|
dataElementCount_ = dataElementCount_ + (*pDataItem)->getDataElementCount();
|
|
}
|
|
printf("ecmcDAQDataChannel::connectToDataSources()::dataElementCount_=%zu\n",dataElementCount_);
|
|
dataSourcesLinked_ = 1;
|
|
}
|
|
|
|
size_t ecmcDAQDataChannel::getDataElementCount(){
|
|
return dataElementCount_;
|
|
}
|
|
|
|
double ecmcDAQDataChannel::getType() {
|
|
return type_;
|
|
}
|
|
|
|
double ecmcDAQDataChannel::getData(int first){
|
|
if(first) {
|
|
currItemIndex_ = 0;
|
|
returnedDataCounter_= 0;;
|
|
}
|
|
|
|
// Get data from the first index
|
|
dataItems_[currItemIndex_]->resetIndex(first);
|
|
|
|
if(dataItems_[currItemIndex_]->empty()){
|
|
if(currItemIndex_ < itemCounter_ - 1) {
|
|
first = true;
|
|
currItemIndex_++;
|
|
dataItems_[currItemIndex_]->resetIndex(first);
|
|
} else {
|
|
printf("ecmcDAQDataChannel::ERROR: No more data item in list but array still requires data (items %zu)\n",itemCounter_);
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
if(currItemIndex_ >= itemCounter_) {
|
|
printf("ecmcDAQDataChannel::ERROR: item counter out of range (items %zu)\n",itemCounter_);
|
|
return 0;
|
|
//throw std::runtime_error( "Item index out of range");
|
|
}
|
|
|
|
returnedDataCounter_++;
|
|
return dataItems_[currItemIndex_]->getData();
|
|
}
|
|
|
|
bool ecmcDAQDataChannel::empty(){
|
|
return returnedDataCounter_>=dataElementCount_;
|
|
}
|
|
|
|
int ecmcDAQDataChannel::validate() {
|
|
if(dataElementCount_==0) {
|
|
throw std::runtime_error("Error: DAQ-Channel element count 0");
|
|
}
|
|
if(itemCounter_==0) {
|
|
throw std::runtime_error("Error: DAQ-Channel data item count 0");
|
|
}
|
|
for(std::vector<ecmcDAQChannelItem*>::iterator pDataItem = dataItems_.begin(); pDataItem != dataItems_.end(); ++pDataItem) {
|
|
if(!(*pDataItem)) {
|
|
throw std::runtime_error( "Data item empty..");
|
|
}
|
|
(*pDataItem)->validate();
|
|
}
|
|
return 0;
|
|
}
|
|
|