mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
final fixes
This commit is contained in:
parent
f1b3fa1492
commit
12589345ce
3 changed files with 33 additions and 15 deletions
|
@ -21,6 +21,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace villas {
|
||||
|
@ -37,8 +39,10 @@ protected:
|
|||
public:
|
||||
Dumper(const std::string &socketNameIn);
|
||||
~Dumper();
|
||||
|
||||
int openSocket();
|
||||
void closeSocket();
|
||||
int closeSocket();
|
||||
|
||||
void writeData(uint len, double *yData, double *xData = nullptr);
|
||||
};
|
||||
|
||||
|
|
|
@ -20,13 +20,16 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************************/
|
||||
|
||||
#include <villas/dumper.hpp>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <villas/log.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <villas/dumper.hpp>
|
||||
#include <villas/log.h>
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas::node;
|
||||
|
||||
|
@ -54,28 +57,37 @@ int Dumper::openSocket()
|
|||
socketaddrUn.sun_family = AF_UNIX;
|
||||
strcpy(socketaddrUn.sun_path, socketName.c_str());
|
||||
|
||||
connect(socketFd, (struct sockaddr *) &socketaddrUn, sizeof(socketaddrUn));
|
||||
int ret = connect(socketFd, (struct sockaddr *) &socketaddrUn, sizeof(socketaddrUn));
|
||||
if (!ret)
|
||||
return ret;
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Dumper::closeSocket()
|
||||
int Dumper::closeSocket()
|
||||
{
|
||||
close(socketFd);
|
||||
int ret = close(socketFd);
|
||||
if (!ret)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Dumper::writeData(unsigned len, double *yData, double *xData)
|
||||
{
|
||||
ssize_t bytesWritten;
|
||||
|
||||
for (unsigned i = 0; i<len; i++) {
|
||||
std::string str = std::to_string(yData[i]);
|
||||
if(xData != nullptr)
|
||||
str+= ";" + std::to_string(xData[i]);
|
||||
str += "\n";
|
||||
std::stringstream ss;
|
||||
|
||||
bytesWritten = write(socketFd, str.c_str(), str.length());
|
||||
if ((long unsigned int) bytesWritten != str.length() && (!supressRepeatedWarning || warningCounter<1)) {
|
||||
ss << yData[i];
|
||||
|
||||
if(xData != nullptr)
|
||||
ss << ";" << xData[i];
|
||||
|
||||
ss << std::endl;
|
||||
|
||||
auto str = ss.str();
|
||||
auto bytesWritten = write(socketFd, str.c_str(), str.length());
|
||||
if ((long unsigned int) bytesWritten != str.length() && (!supressRepeatedWarning || warningCounter <1 )) {
|
||||
warning("Could not send all content to socket %s", socketName.c_str());
|
||||
warningCounter++;
|
||||
}
|
||||
|
|
|
@ -137,6 +137,7 @@ public:
|
|||
signal_list_clear(&signals);
|
||||
|
||||
/* Initialize sample memory */
|
||||
smpMemory.clear();
|
||||
for (unsigned i = 0; i < signalIndex.size(); i++) {
|
||||
struct signal *freqSig;
|
||||
struct signal *amplSig;
|
||||
|
@ -166,6 +167,7 @@ public:
|
|||
freqCount = ceil((endFreqency - startFreqency) / frequencyResolution) + 1;
|
||||
|
||||
/* Initialize matrix of dft coeffients */
|
||||
dftMatrix.clear();
|
||||
for (unsigned i = 0; i < freqCount; i++)
|
||||
dftMatrix.emplace_back(windowSize * windowMultiplier, 0.0);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue