Add nfft config. Some cleanup.

This commit is contained in:
Anders Sandström
2020-04-04 19:58:29 +02:00
parent 453365794c
commit 33b100c392
3 changed files with 56 additions and 40 deletions

View File

@@ -20,6 +20,14 @@
#include "ecmcAsynPortDriver.h"
#include "kissfft/kissfft.hh"
#define PRINT_IF_DBG_MODE(fmt, ...) \
{ \
if(dbgMode_){ \
printf(fmt, ## __VA_ARGS__); \
} \
} \
// New data callback from ecmc
static int printMissingObjError = 1;
@@ -34,16 +42,16 @@ void f_dataUpdatedCallback(uint8_t* data, size_t size, ecmcEcDataType dt, void*
}
ecmcFFT * fftObj = (ecmcFFT*)obj;
// Fill object buffer with data
// Call the correct fft object with new data
fftObj->dataUpdatedCallback(data,size,dt);
}
/** ecmc FFT class
*can throw:
* bad_alloc
* invalid_argument
* runtime_error
* This object can throw:
* - bad_alloc
* - invalid_argument
* - runtime_error
*/
ecmcFFT::ecmcFFT(int fftIndex, // index of this object
char* configStr) {
@@ -82,7 +90,7 @@ ecmcFFT::~ecmcFFT() {
}
}
int ecmcFFT::parseConfigStr(char *configStr) {
void ecmcFFT::parseConfigStr(char *configStr) {
// check config parameters
if (configStr && configStr[0]) {
@@ -107,8 +115,15 @@ int ecmcFFT::parseConfigStr(char *configStr) {
else if (!strncmp(pThisOption, ECMC_PLUGIN_SOURCE_OPTION_CMD, strlen(ECMC_PLUGIN_SOURCE_OPTION_CMD))) {
pThisOption += strlen(ECMC_PLUGIN_SOURCE_OPTION_CMD);
// get string to next ';'
dataSourceStr_=strdup(pThisOption);
}
dataSourceStr_=strdup(pThisOption);
}
// ECMC_PLUGIN_NFFT_OPTION_CMD
else if (!strncmp(pThisOption, ECMC_PLUGIN_NFFT_OPTION_CMD, strlen(ECMC_PLUGIN_NFFT_OPTION_CMD))) {
pThisOption += strlen(ECMC_PLUGIN_NFFT_OPTION_CMD);
// get string to next ';'
nfft_ = atoi(pThisOption);
}
pThisOption = pNextOption;
}
free(pOptions);
@@ -118,11 +133,11 @@ int ecmcFFT::parseConfigStr(char *configStr) {
}
}
int ecmcFFT::connectToDataSource() {
void ecmcFFT::connectToDataSource() {
// Get dataItem
dataItem_ = (ecmcDataItem*) getEcmcDataItem(dataSourceStr_);
if(!dataItem_) {
throw std::runtime_error("Data item NULL");
throw std::runtime_error("Data item NULL.");
}
// Register data callback
@@ -134,9 +149,8 @@ int ecmcFFT::connectToDataSource() {
// Check data source
if( !dataTypeSupported(dataItem_->getEcmcDataType()) ) {
throw std::invalid_argument( "Data type not supported");
throw std::invalid_argument( "Data type not supported.");
}
return 0;
}
void ecmcFFT::dataUpdatedCallback(uint8_t* data,
@@ -146,12 +160,14 @@ void ecmcFFT::dataUpdatedCallback(uint8_t* data,
if(!dataBuffer_) {
return;
}
if(dbgMode_) {
printf("fft id: %d, data: ",objectId_);
printData(data,size,dt);
printf("fft id: %d, data: ",objectId_);
printData(data,size,dt);
if(bytesInBuffer_ == bufferSizeBytes_) {
printf("Buffer full (%zu bytes appended).\n",bytesInBuffer_);
if(bytesInBuffer_ == bufferSizeBytes_) {
printf("Buffer full (%zu bytes appended).\n",bytesInBuffer_);
}
}
// Start to fill buffer
@@ -168,10 +184,6 @@ void ecmcFFT::clearBuffer() {
bytesInBuffer_ = 0;
}
int ecmcFFT::getErrorId() {
return errorId_;
}
void ecmcFFT::printData(uint8_t* data,
size_t size,
ecmcEcDataType dt) {

View File

@@ -12,37 +12,40 @@
#ifndef ECMC_FFT_H_
#define ECMC_FFT_H_
#define ECMC_PLUGIN_DEFAULT_NFFT 8192
#include <stdexcept>
#include "ecmcDataItem.h"
#include "ecmcAsynPortDriver.h"
#include "inttypes.h"
#include <stdexcept>
class ecmcFFT {
public:
ecmcFFT(int fftIndex, // index of this object
/** ecmc FFT class
* This object can throw:
* - bad_alloc
* - invalid_argument
* - runtime_error
*/
ecmcFFT(int fftIndex, // index of this object
char* configStr);
~ecmcFFT();
int getErrorId();
// Add data to buffer
void dataUpdatedCallback(uint8_t* data,
size_t size,
ecmcEcDataType dt);
private:
int parseConfigStr(char *configStr);
int connectToDataSource();
void clearBuffer();
void parseConfigStr(char *configStr);
void connectToDataSource();
void clearBuffer();
ecmcDataItem *dataItem_;
ecmcAsynPortDriver *asynPort_;
uint8_t* dataBuffer_;
size_t nfft_;
size_t bufferSizeBytes_;
size_t bytesInBuffer_;
int errorId_;
// ecmc callback handle for use when deregister at unload
int callbackHandle_;
int dbgMode_; //Allow dbg printouts
char* dataSourceStr_;
@@ -50,7 +53,7 @@ class ecmcFFT {
int objectId_;
static int dataTypeSupported(ecmcEcDataType dt);
//Some utility functions
// Some utility functions
static uint8_t getUint8(uint8_t* data);
static int8_t getInt8(uint8_t* data);
static uint16_t getUint16(uint8_t* data);
@@ -61,13 +64,10 @@ class ecmcFFT {
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 printData(uint8_t* data,
size_t size,
ecmcEcDataType dt);
static void printData(uint8_t* data,
size_t size,
ecmcEcDataType dt);
};
#endif /* ECMC_FFT_H_ */

View File

@@ -15,10 +15,14 @@
#define ECMC_FFT_DEFS_H_
// Options
#define ECMC_PLUGIN_DBG_OPTION_CMD "DBG_PRINT="
#define ECMC_PLUGIN_DBG_OPTION_CMD "DBG_PRINT="
#define ECMC_PLUGIN_SOURCE_OPTION_CMD "SOURCE="
#define ECMC_PLUGIN_NFFT_OPTION_CMD "NFFT="
// Just one error code in "c" part of plugin
#define ECMC_PLUGIN_FFT_ERROR_CODE 1
// Default size (must be n²)
#define ECMC_PLUGIN_DEFAULT_NFFT 8192
#endif /* ECMC_FFT_DEFS_H_ */