1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

Merge pull request #689 from VILLASframework/dumper

Dumper move socket nameing from constructor to method
This commit is contained in:
Manuel 2023-07-06 20:31:00 +02:00 committed by GitHub
commit a553bc53a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 20 deletions

View file

@ -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(const std::string &socketPathIn);
void writeDataCSV(unsigned len, double *yData, double *xData = nullptr);
void writeDataBinary(unsigned len, double *yData, double *xData = nullptr);
};

View file

@ -18,30 +18,41 @@
using namespace villas;
using namespace villas::node;
Dumper::Dumper(const std::string &socketNameIn) :
socketName(socketNameIn),
Dumper::Dumper() :
active(false),
socketFd(0),
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,7 +70,14 @@ int Dumper::closeSocket()
return 0;
}
void Dumper::writeDataBinary(unsigned len, double *yData, double *xData){
int Dumper::setPath(const std::string &socketPathIn)
{
socketPath = socketPathIn;
return 1;
}
void Dumper::writeDataBinary(unsigned len, double *yData, double *xData)
{
if (warningCounter > 10)
return;
@ -67,22 +85,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 +121,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++;
}
}

View file

@ -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;