From 4fb8b78b03af0302096c9c2c77512bb7b94038f1 Mon Sep 17 00:00:00 2001 From: Manuel Pitz Date: Wed, 24 Nov 2021 12:40:29 +0100 Subject: [PATCH] update signal renaming behaviour for rms and pmu_dft hook --- lib/hooks/pmu_dft.cpp | 23 ++++++++++++++++------- lib/hooks/rms.cpp | 16 ---------------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/lib/hooks/pmu_dft.cpp b/lib/hooks/pmu_dft.cpp index 162e9530b..39a74e9ac 100644 --- a/lib/hooks/pmu_dft.cpp +++ b/lib/hooks/pmu_dft.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -96,8 +97,9 @@ protected: unsigned ppsIndex; unsigned windowSize; unsigned windowMultiplier; /**< Multiplyer for the window to achieve frequency resolution */ - unsigned freqCount; /**< Number of requency bins that are calculated */ + unsigned freqCount; /**< Number of requency bins that are calculated */ bool sync; + bool channelNameEnable; /**< Rename the output values with channel name or only descriptive name */ uint64_t smpMemPos; uint64_t lastSequence; @@ -150,6 +152,7 @@ public: windowMultiplier(0), freqCount(0), sync(0), + channelNameEnable(1), smpMemPos(0), lastSequence(0), windowCorrectionFactor(0), @@ -184,10 +187,15 @@ public: struct signal *rocofSig; /* Add signals */ - freqSig = signal_create("frequency", "Hz", SignalType::FLOAT); - amplSig = signal_create("amplitude", "V", SignalType::FLOAT); - phaseSig = signal_create("phase", "rad", SignalType::FLOAT); - rocofSig = signal_create("rocof", "Hz/s", SignalType::FLOAT); + std::stringstream ss_freq, ss_ampl, ss_phase, ss_rocof; + ss_freq << "frequency" << (channelNameEnable)?signalNames[i]:""; + freqSig = signal_create(ss_freq.str().c_str(), "Hz", SignalType::FLOAT); + ss_ampl << "amplitude" << (channelNameEnable)?signalNames[i]:""; + amplSig = signal_create(ss_ampl.str().c_str(), "V", SignalType::FLOAT); + ss_phase << "phase" << (channelNameEnable)?signalNames[i]:""; + phaseSig = signal_create(ss_phase.str().c_str(), "rad", SignalType::FLOAT); + ss_rocof << "rocof" << (channelNameEnable)?signalNames[i]:""; + rocofSig = signal_create(ss_rocof.str().c_str(), "Hz/s", SignalType::FLOAT); if (!freqSig || !amplSig || !phaseSig || !rocofSig) throw RuntimeError("Failed to create new signals"); @@ -254,7 +262,7 @@ public: Hook::parse(json); - ret = json_unpack_ex(json, &err, 0, "{ s?: i, s?: F, s?: F, s?: F, s?: i, s?: i, s?: s, s?: s, s?: s, s?: b, s?: i, s?: s}", + ret = json_unpack_ex(json, &err, 0, "{ s?: i, s?: F, s?: F, s?: F, s?: i, s?: i, s?: s, s?: s, s?: s, s?: b, s?: i, s?: s, s?: b}", "sample_rate", &sampleRate, "start_freqency", &startFrequency, "end_freqency", &endFreqency, @@ -266,7 +274,8 @@ public: "frequency_estimate_type", &freqEstimateTypeC, "sync", &sync, "pps_index", &ppsIndex, - "angle_unit", &angleUnitC + "angle_unit", &angleUnitC, + "add_channel_name", &channelNameEnable ); if (ret) throw ConfigError(json, err, "node-config-hook-dft"); diff --git a/lib/hooks/rms.cpp b/lib/hooks/rms.cpp index 449459cdc..739e8ef4f 100644 --- a/lib/hooks/rms.cpp +++ b/lib/hooks/rms.cpp @@ -26,7 +26,6 @@ #include #include -#include namespace villas { namespace node { @@ -62,21 +61,6 @@ public: throw RuntimeError("The rms hook can only operate on signals of type float!"); } - signal_list_clear(&signals); - for (unsigned i = 0; i < signalIndices.size(); i++) { - struct signal *rmsVal; - - /* Add signals */ - std::stringstream ss; - ss << "rms_" << signalNames[i]; - rmsVal = signal_create(ss.str().c_str(), "", SignalType::FLOAT); - - if (!rmsVal) - throw RuntimeError("Failed to create new signals"); - - vlist_push(&signals, rmsVal); - } - /* Initialize memory for each channel*/ smpMemory.clear(); for (unsigned i = 0; i < signalIndices.size(); i++){