From 54536ee62798967dfc68585c0fe73ed4af2b683e Mon Sep 17 00:00:00 2001 From: Manuel Pitz Date: Fri, 25 Jun 2021 15:32:40 +0200 Subject: [PATCH] dumper: add binary socket and enable length and datatype for the socket com --- include/villas/dumper.hpp | 3 ++- lib/dumper.cpp | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/villas/dumper.hpp b/include/villas/dumper.hpp index 81f891ad3..c88666514 100644 --- a/include/villas/dumper.hpp +++ b/include/villas/dumper.hpp @@ -46,7 +46,8 @@ public: int openSocket(); int closeSocket(); - void writeData(unsigned len, double *yData, double *xData = nullptr); + void writeDataCSV(unsigned len, double *yData, double *xData = nullptr); + void writeDataBinary(unsigned len, double *yData, double *xData = nullptr); }; } /* namespace node */ diff --git a/lib/dumper.cpp b/lib/dumper.cpp index fa9443156..24bcf527c 100644 --- a/lib/dumper.cpp +++ b/lib/dumper.cpp @@ -74,7 +74,32 @@ int Dumper::closeSocket() return 0; } -void Dumper::writeData(unsigned len, double *yData, double *xData) +void Dumper::writeDataBinary(unsigned len, double *yData, double *xData){ + + if (yData == nullptr) + return; + + unsigned dataLen = len * sizeof(yData[0]); + long unsigned int bytesWritten = write(socketFd, &dataLen, sizeof(dataLen)); + if(bytesWritten != sizeof(len)) { + logger->warn("Could not send all content to socket {}", socketName); + warningCounter++; + } + + bytesWritten = write(socketFd, "d000", 4); + if(bytesWritten != 4) { + logger->warn("Could not send all content to socket {}", socketName); + warningCounter++; + } + + bytesWritten = write(socketFd, yData, dataLen ); + if (bytesWritten != dataLen && (!supressRepeatedWarning || warningCounter <1 )) { + logger->warn("Could not send all content to socket {}", socketName); + warningCounter++; + } +} + +void Dumper::writeDataCSV(unsigned len, double *yData, double *xData) { for (unsigned i = 0; i