diff --git a/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFT.cpp b/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFT.cpp index d52ff81..872242b 100644 --- a/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFT.cpp +++ b/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFT.cpp @@ -241,6 +241,7 @@ void ecmcFFT::dataUpdatedCallback(uint8_t* data, calcFFT(); // FFT cacluation () scaleFFT(); // Scale FFT calcFFTAmp(); // Calculate amplitude from complex + triggOnce_ = 0; // Wait for nex trigger if in trigg mode // Update asyn with both input and result asynRawData_->refreshParamRT(1); // Forced update (do not consider record rate) @@ -255,8 +256,11 @@ void ecmcFFT::dataUpdatedCallback(uint8_t* data, ECMC_EC_F64, objectId_); } - // Buffer new data - clearBuffers(); + + // If mode continious then start over + if(cfgMode_ == CONT) { + clearBuffers(); + } } return; } diff --git a/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFTDefs.h b/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFTDefs.h index a9f5b80..13114fb 100644 --- a/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFTDefs.h +++ b/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFTDefs.h @@ -26,11 +26,11 @@ #define ECMC_PLUGIN_MODE_CONT_OPTION "CONT" #define ECMC_PLUGIN_MODE_TRIGG_OPTION "TRIGG" -enum FFT_MODE{ +typedef enum FFT_MODE{ NO_MODE = 0, CONT = 1, TRIGG = 2, -}; +} FFT_MODE; /** Just one error code in "c" part of plugin (error handled with exceptions i c++ part) */ diff --git a/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFTWrap.cpp b/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFTWrap.cpp index 4efe104..bba8039 100644 --- a/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFTWrap.cpp +++ b/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFTWrap.cpp @@ -89,7 +89,7 @@ int clearFFT(int fftIndex) { return 0; } -int triggFFT(int fftIndex) { +int triggFFT(int fftIndex) { try { ffts.at(fftIndex)->triggFFT(); } @@ -100,9 +100,9 @@ int triggFFT(int fftIndex) { return 0; } -int setModeFFT(int fftIndex, FFT_MODE mode) { +int modeFFT(int fftIndex, FFT_MODE mode) { try { - ffts.at(fftIndex)->setMode(mode); + ffts.at(fftIndex)->setModeFFT(mode); } catch(std::exception& e) { printf("Exception: %s. FFT index out of range.\n",e.what()); diff --git a/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFTWrap.h b/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFTWrap.h index f430fd0..11a2690 100644 --- a/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFTWrap.h +++ b/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcFFTWrap.h @@ -17,13 +17,16 @@ extern "C" { # endif // ifdef __cplusplus +// To one fft object int createFFT(char *source); -int linkDataToFFTs(); -void deleteAllFFTs(); int enableFFT(int fftIndex, int enable); int clearFFT(int fftIndex); int triggFFT(int fftIndex); -int setModeFFT(int fftIndex, FFT_MODE mode); +int modeFFT(int fftIndex, FFT_MODE mode); +// To all fft objects +int linkDataToFFTs(); +void deleteAllFFTs(); + # ifdef __cplusplus } # endif // ifdef __cplusplus diff --git a/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcPluginFFT.c b/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcPluginFFT.c index 65f136b..3c2d5ae 100644 --- a/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcPluginFFT.c +++ b/ecmcPlugin_FFT-loc/ecmcPlugin_FFTApp/src/ecmcPluginFFT.c @@ -80,7 +80,7 @@ int fftExitRT(void){ return 0; } -// Plc function for clear +// Plc function for clear of buffers double fft_clear(double index) { return (double)clearFFT((int)index); } @@ -90,14 +90,14 @@ double fft_enable(double index, double enable) { return (double)enableFFT((int)index, (int)enable); } -// Plc function for trigg new measurement +// Plc function for trigg new measurement (will clear buffers) double fft_trigg(double index) { return (double)triggFFT((int)index); } // Plc function for enable double fft_mode(double index, double mode) { - return (double)setModeFFT((int)index, (FFT_MODE)mode); + return (double)modeFFT((int)index, (FFT_MODE)((int)mode)); } // Register data for plugin so ecmc know what to use @@ -120,15 +120,15 @@ struct ecmcPluginData pluginDataDef = { // Plugin version .version = ECMC_EXAMPLE_PLUGIN_VERSION, // Optional construct func, called once at load. NULL if not definded. - .constructFnc = fft_exampleConstruct, + .constructFnc = fftConstruct, // Optional destruct func, called once at unload. NULL if not definded. - .destructFnc = fft_exampleDestruct, + .destructFnc = fftDestruct, // Optional func that will be called each rt cycle. NULL if not definded. - .realtimeFnc = fft_exampleRealtime, + .realtimeFnc = fftRealtime, // Optional func that will be called once just before enter realtime mode - .realtimeEnterFnc = fft_exampleEnterRT, + .realtimeEnterFnc = fftEnterRT, // Optional func that will be called once just before exit realtime mode - .realtimeExitFnc = fft_exampleExitRT, + .realtimeExitFnc = fftExitRT, // PLC funcs .funcs[0] = { /*----fft_clear----*/ @@ -179,7 +179,7 @@ struct ecmcPluginData pluginDataDef = { // Function name (this is the name you use in ecmc plc-code) .funcName = "fft_trigg", // Function description - .funcDesc = "double fft_trigg(index) : Trigg new measurement for fft[index].", + .funcDesc = "double fft_trigg(index) : Trigg new measurement for fft[index]. Will clear buffers.", /** * 7 different prototypes allowed (only doubles since reg in plc). * Only funcArg${argCount} func shall be assigned the rest set to NULL. @@ -208,7 +208,7 @@ struct ecmcPluginData pluginDataDef = { **/ .funcArg0 = NULL, .funcArg1 = NULL, - .funcArg2 = fft_trigg, + .funcArg2 = fft_mode, .funcArg3 = NULL, .funcArg4 = NULL, .funcArg5 = NULL, @@ -222,13 +222,13 @@ struct ecmcPluginData pluginDataDef = { // PLC consts /* CONTINIOUS MODE = 1 */ .consts[0] = { - .constName = "fft_MODE_CONT", + .constName = "fft_CONT", .constDesc = "Continious mode", .constValue = CONT }, /* TRIGGERED MODE = 2 */ .consts[1] = { - .constName = "fft_MODE_TRIGG", + .constName = "fft_TRIGG", .constDesc = "Triggered mode", .constValue = TRIGG },