From 536b39e96d41cdc9ff351871f60f53366a0e7941 Mon Sep 17 00:00:00 2001 From: Manuel Pitz Date: Thu, 6 Jul 2023 11:36:13 +0200 Subject: [PATCH 1/5] hook: pmu_dft clenaup ifdefs for dumper Signed-off-by: Manuel Pitz --- lib/hooks/pmu_dft.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/hooks/pmu_dft.cpp b/lib/hooks/pmu_dft.cpp index c5cd3b00a..086b1f21a 100644 --- a/lib/hooks/pmu_dft.cpp +++ b/lib/hooks/pmu_dft.cpp @@ -112,11 +112,11 @@ protected: Dumper origSigSync; Dumper windowdSigSync; Dumper ppsSigSync; -#endif Dumper phasorRocof; Dumper phasorPhase; Dumper phasorAmplitude; Dumper phasorFreq; +#endif double angleUnitFactor; double phaseOffset; @@ -164,11 +164,11 @@ public: origSigSync(dumperPrefix + "origSigSync"), windowdSigSync(dumperPrefix + "windowdSigSync"), ppsSigSync(dumperPrefix + "ppsSigSync"), -#endif phasorRocof(dumperPrefix + "phasorRocof"), phasorPhase(dumperPrefix + "phasorPhase"), phasorAmplitude(dumperPrefix + "phasorAmplitude"), phasorFreq(dumperPrefix + "phasorFreq"), +#endif angleUnitFactor(1), phaseOffset(0.0), frequencyOffset(0.0), @@ -453,7 +453,7 @@ public: lastResult[i] = currentResult; } } - +#ifdef DFT_MEM_DUMP // The following is a debug output and currently only for channel 0 if (dumperEnable && windowSize * 5 < smpMemPos){ phasorFreq.writeDataBinary(1, &(smp->data[0 * 4 + 0].f)); @@ -461,6 +461,7 @@ public: phasorAmplitude.writeDataBinary(1, &(smp->data[0 * 4 + 1].f)); phasorRocof.writeDataBinary(1, &(smp->data[0 * 4 + 3].f)); } +#endif smp->length = windowSize < smpMemPos ? signalIndices.size() * 4 : 0; From 70d00ba774d7df661920ce1efbe972f9e735a3c4 Mon Sep 17 00:00:00 2001 From: Manuel Pitz Date: Thu, 6 Jul 2023 11:51:59 +0200 Subject: [PATCH 2/5] dumper: add function for naming the socket Signed-off-by: Manuel Pitz --- include/villas/dumper.hpp | 8 ++++++-- lib/dumper.cpp | 42 ++++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/include/villas/dumper.hpp b/include/villas/dumper.hpp index 41f07bd9b..0877dc7d6 100644 --- a/include/villas/dumper.hpp +++ b/include/villas/dumper.hpp @@ -18,19 +18,23 @@ namespace node { class Dumper { protected: + bool active; int socketFd; - std::string socketName; + std::string socketPath; bool supressRepeatedWarning; uint64_t warningCounter; Logger logger; public: - Dumper(const std::string &socketNameIn); + Dumper(); ~Dumper(); int openSocket(); int closeSocket(); + bool isActive(); + int setActive(); + int setPath(std::string socketPathIn); void writeDataCSV(unsigned len, double *yData, double *xData = nullptr); void writeDataBinary(unsigned len, double *yData, double *xData = nullptr); }; diff --git a/lib/dumper.cpp b/lib/dumper.cpp index 708507df8..9eb8431ee 100644 --- a/lib/dumper.cpp +++ b/lib/dumper.cpp @@ -18,30 +18,38 @@ using namespace villas; using namespace villas::node; -Dumper::Dumper(const std::string &socketNameIn) : - socketName(socketNameIn), +Dumper::Dumper() : + active(false), + socketPath(""), supressRepeatedWarning(true), warningCounter(0), logger(logging.get("dumper")) -{ - openSocket(); -} +{} Dumper::~Dumper() { closeSocket(); } +bool Dumper::isActive(){ + return active; +} + +int Dumper::setActive() { + active = true; + return 1; +} + int Dumper::openSocket() { socketFd = socket(AF_LOCAL, SOCK_STREAM, 0); if (socketFd < 0) { - logger->info("Error creating socket {}", socketName); + logger->info("Error creating socket {}", socketPath); return -1; } sockaddr_un socketaddrUn; socketaddrUn.sun_family = AF_UNIX; - strcpy(socketaddrUn.sun_path, socketName.c_str()); + strcpy(socketaddrUn.sun_path, socketPath.c_str()); int ret = connect(socketFd, (struct sockaddr *) &socketaddrUn, sizeof(socketaddrUn)); if (!ret) @@ -59,6 +67,11 @@ int Dumper::closeSocket() return 0; } +int Dumper::setPath(std::string socketPathIn) { + socketPath = socketPathIn; + return 1; +} + void Dumper::writeDataBinary(unsigned len, double *yData, double *xData){ if (warningCounter > 10) @@ -67,22 +80,23 @@ void Dumper::writeDataBinary(unsigned len, double *yData, double *xData){ if (yData == nullptr) return; - unsigned dataLen = len * sizeof(yData[0]); + unsigned dataLen = len * sizeof(double); ssize_t bytesWritten = write(socketFd, &dataLen, sizeof(dataLen)); if ((size_t) bytesWritten != sizeof(len)) { - logger->warn("Could not send all content (Len) to socket {}", socketName); + logger->warn("Could not send all content (Len) to socket {}", socketPath); warningCounter++; } - bytesWritten = write(socketFd, "d000", 4); - if (bytesWritten != 4) { - logger->warn("Could not send all content (Type) to socket {}", socketName); + static const char buf[] = "d000"; + bytesWritten = write(socketFd, buf, sizeof(buf)); + if (bytesWritten != sizeof(buf)) { + logger->warn("Could not send all content (Type) to socket {}", socketPath); warningCounter++; } bytesWritten = write(socketFd, yData, dataLen ); if (bytesWritten != (ssize_t) dataLen && (!supressRepeatedWarning || warningCounter <1 )) { - logger->warn("Could not send all content (Data) to socket {}", socketName); + logger->warn("Could not send all content (Data) to socket {}", socketPath); warningCounter++; } } @@ -102,7 +116,7 @@ void Dumper::writeDataCSV(unsigned len, double *yData, double *xData) auto str = ss.str(); auto bytesWritten = write(socketFd, str.c_str(), str.length()); if ((size_t) bytesWritten != str.length() && (!supressRepeatedWarning || warningCounter < 1)) { - logger->warn("Could not send all content to socket {}", socketName); + logger->warn("Could not send all content to socket {}", socketPath); warningCounter++; } } From 9c0517cb7409d747a88bba9ea17f03783af8ae6b Mon Sep 17 00:00:00 2001 From: Manuel Pitz Date: Thu, 6 Jul 2023 11:59:58 +0200 Subject: [PATCH 3/5] dumper: fix styles for steffen Signed-off-by: Manuel Pitz --- lib/dumper.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/dumper.cpp b/lib/dumper.cpp index 9eb8431ee..178bd529d 100644 --- a/lib/dumper.cpp +++ b/lib/dumper.cpp @@ -30,11 +30,13 @@ Dumper::~Dumper() { closeSocket(); } -bool Dumper::isActive(){ +bool Dumper::isActive() +{ return active; } -int Dumper::setActive() { +int Dumper::setActive() +{ active = true; return 1; } @@ -67,12 +69,14 @@ int Dumper::closeSocket() return 0; } -int Dumper::setPath(std::string socketPathIn) { +int Dumper::setPath(std::string socketPathIn) +{ socketPath = socketPathIn; return 1; } -void Dumper::writeDataBinary(unsigned len, double *yData, double *xData){ +void Dumper::writeDataBinary(unsigned len, double *yData, double *xData) +{ if (warningCounter > 10) return; From 85ab9f2100ddcd8cf543562d9f1bde6a83f2d959 Mon Sep 17 00:00:00 2001 From: Manuel Pitz Date: Thu, 6 Jul 2023 19:36:22 +0200 Subject: [PATCH 4/5] dumper: fix initalization list Signed-off-by: Manuel Pitz --- lib/dumper.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/dumper.cpp b/lib/dumper.cpp index 178bd529d..1e876d154 100644 --- a/lib/dumper.cpp +++ b/lib/dumper.cpp @@ -20,6 +20,7 @@ using namespace villas::node; Dumper::Dumper() : active(false), + socketFd(0), socketPath(""), supressRepeatedWarning(true), warningCounter(0), From 7b39c92b91fae687846b6d763c0745c34b4fd752 Mon Sep 17 00:00:00 2001 From: Manuel Pitz Date: Thu, 6 Jul 2023 19:56:18 +0200 Subject: [PATCH 5/5] dumper: fix style for cppcheck Signed-off-by: Manuel Pitz --- include/villas/dumper.hpp | 2 +- lib/dumper.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/villas/dumper.hpp b/include/villas/dumper.hpp index 0877dc7d6..35e0cda9b 100644 --- a/include/villas/dumper.hpp +++ b/include/villas/dumper.hpp @@ -34,7 +34,7 @@ public: bool isActive(); int setActive(); - int setPath(std::string socketPathIn); + int setPath(const std::string &socketPathIn); void writeDataCSV(unsigned len, double *yData, double *xData = nullptr); void writeDataBinary(unsigned len, double *yData, double *xData = nullptr); }; diff --git a/lib/dumper.cpp b/lib/dumper.cpp index 1e876d154..cbb737e40 100644 --- a/lib/dumper.cpp +++ b/lib/dumper.cpp @@ -70,7 +70,7 @@ int Dumper::closeSocket() return 0; } -int Dumper::setPath(std::string socketPathIn) +int Dumper::setPath(const std::string &socketPathIn) { socketPath = socketPathIn; return 1;