dataDumper.cpp
Go to the documentation of this file.
00001 // "dataDumper.cpp": Definiert den Einstiegspunkt für die Konsolenanwendung.
00002 //
00003 #define _CRT_SECURE_NO_WARNINGS
00004 #define _USE_MATH_DEFINES
00005 
00006 #include <math.h>
00007 #include <string.h>
00008 #include <stdio.h>
00009 #include "dataDumper.h"
00010 
00011 int DataDumper::pushData(double timeStamp, std::string info, double val)
00012 {
00013         int retCode = 0;
00014         if (pushCounter < maxFifoSize)
00015         {
00016                 timeStampVec[pushCounter] = timeStamp;
00017                 infoVec[pushCounter] = info;
00018                 dataVec[pushCounter] = val;
00019 
00020         }
00021         else
00022         {
00023                 retCode = 2;
00024                 if (pushCounter == maxFifoSize)
00025                 {
00026                         if (dumpFileName.length() > 0)
00027                         {
00028                                 writeDataToCsv(dumpFileName);
00029                                 retCode = 1;
00030                         }
00031                 }
00032         }
00033         pushCounter++;
00034         return(retCode);
00035 }
00036 
00037 int DataDumper::writeDataToCsv(std::string filename)
00038 {
00039         FILE *fout;
00040         int retCode = 0;
00041         fout = fopen(filename.c_str(), "w");
00042         if (fout != NULL)
00043         {
00044                 for (int i = 0; i < pushCounter; i++)
00045                 {
00046                         fprintf(fout, "%8.6lf;%-10s;%12.8lf\n", timeStampVec[i], infoVec[i].c_str(), dataVec[i]);
00047                 }
00048 
00049                 fclose(fout);
00050         }
00051         else
00052         {
00053                 retCode = -1;
00054         }
00055         return(retCode);
00056 }
00057 
00058 
00059 int DataDumper::writeToFileNameWhenBufferIsFull(std::string filename)
00060 {
00061         dumpFileName = filename;
00062         return(0);
00063 }
00064 
00065 int DataDumper::dumpUcharBufferToConsole(unsigned char *buffer, int bufLen)
00066 {
00067         char asciiBuffer[255] = {0};
00068         for (int i = 0; i < bufLen; i++)
00069         {
00070                   if ((i % 8) == 0)
00071                         {
00072                         printf("%08x: ", i);
00073                         }
00074 
00075                         printf("%02x ", buffer[i]);
00076 
00077                   char ch = '.';
00078                   if ((buffer[i] >= 0x20) && (buffer[i] < 0x80))
00079                 {
00080                         ch = (char)buffer[i];
00081                 }
00082                 int iStrLen = strlen(asciiBuffer);
00083                   asciiBuffer[iStrLen] = ch;
00084                   asciiBuffer[iStrLen+1] = '\0';
00085 
00086                   if ((i % 8) == 7)
00087                         {
00088                         printf("%s\n", asciiBuffer);
00089                         strcpy(asciiBuffer,"");
00090                         }
00091         }
00092         if (bufLen % 8)
00093         {
00094 
00095                 printf("%s\n", asciiBuffer);
00096         }
00097 }
00098 
00099 int DataDumper::testbed()
00100 {
00101 
00102         double testSignal;
00103         double sampleRate = 1000.0;
00104         double freq = 50.0;
00105         DataDumper::instance().writeToFileNameWhenBufferIsFull("C:\\temp\\000_full.csv");
00106 
00107         int cnt = 0;
00108         for (double t = 0; t < 5.0; t += 1.0 / sampleRate)
00109         {
00110                 cnt++;
00111                 testSignal = 1.0 * cos(2 * M_PI*freq*t);
00112                 if (cnt == 1000)
00113                 {
00114                         DataDumper::instance().writeDataToCsv("C:\\temp\\000_partial.csv");
00115                 }
00116                 DataDumper::instance().pushData(t, "COS", testSignal);
00117                 testSignal = 1.0 * sin(2 * M_PI*freq*t);
00118                 DataDumper::instance().pushData(t, "SIN", testSignal);
00119         }
00120         return 0;
00121 }
00122 
00123 #ifdef TEST_DATA_DUMPER
00124 int main(int argc, char *argv)
00125 {
00126         DataDumper::instance().testbed();
00127 }
00128 #endif


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Tue Jul 9 2019 05:05:34