dataDumper.cpp
Go to the documentation of this file.
1 // "dataDumper.cpp": Definiert den Einstiegspunkt für die Konsolenanwendung.
2 //
3 #define _CRT_SECURE_NO_WARNINGS
4 #define _USE_MATH_DEFINES
5 
6 #include <math.h>
7 #include <string.h>
8 #include <stdio.h>
9 #include "dataDumper.h"
10 
11 int DataDumper::pushData(double timeStamp, std::string info, double val)
12 {
13  int retCode = 0;
15  {
16  timeStampVec[pushCounter] = timeStamp;
17  infoVec[pushCounter] = info;
18  dataVec[pushCounter] = val;
19 
20  }
21  else
22  {
23  retCode = 2;
24  if (pushCounter == maxFifoSize)
25  {
26  if (dumpFileName.length() > 0)
27  {
29  retCode = 1;
30  }
31  }
32  }
33  pushCounter++;
34  return(retCode);
35 }
36 
37 int DataDumper::writeDataToCsv(std::string filename)
38 {
39  FILE *fout;
40  int retCode = 0;
41  fout = fopen(filename.c_str(), "w");
42  if (fout != NULL)
43  {
44  for (int i = 0; i < pushCounter; i++)
45  {
46  fprintf(fout, "%8.6lf;%-10s;%12.8lf\n", timeStampVec[i], infoVec[i].c_str(), dataVec[i]);
47  }
48 
49  fclose(fout);
50  }
51  else
52  {
53  retCode = -1;
54  }
55  return(retCode);
56 }
57 
58 
60 {
61  dumpFileName = filename;
62  return(0);
63 }
64 
65 int DataDumper::dumpUcharBufferToConsole(unsigned char *buffer, int bufLen)
66 {
67  char asciiBuffer[255] = {0};
68  for (int i = 0; i < bufLen; i++)
69  {
70  if ((i % 8) == 0)
71  {
72  printf("%08x: ", i);
73  }
74 
75  printf("%02x ", buffer[i]);
76 
77  char ch = '.';
78  if ((buffer[i] >= 0x20) && (buffer[i] < 0x80))
79  {
80  ch = (char)buffer[i];
81  }
82  int iStrLen = strlen(asciiBuffer);
83  asciiBuffer[iStrLen] = ch;
84  asciiBuffer[iStrLen+1] = '\0';
85 
86  if ((i % 8) == 7)
87  {
88  printf("%s\n", asciiBuffer);
89  strcpy(asciiBuffer,"");
90  }
91  }
92  if (bufLen % 8)
93  {
94 
95  printf("%s\n", asciiBuffer);
96  }
97 }
98 
100 {
101 
102  double testSignal;
103  double sampleRate = 1000.0;
104  double freq = 50.0;
105  DataDumper::instance().writeToFileNameWhenBufferIsFull("C:\\temp\\000_full.csv");
106 
107  int cnt = 0;
108  for (double t = 0; t < 5.0; t += 1.0 / sampleRate)
109  {
110  cnt++;
111  testSignal = 1.0 * cos(2 * M_PI*freq*t);
112  if (cnt == 1000)
113  {
114  DataDumper::instance().writeDataToCsv("C:\\temp\\000_partial.csv");
115  }
116  DataDumper::instance().pushData(t, "COS", testSignal);
117  testSignal = 1.0 * sin(2 * M_PI*freq*t);
118  DataDumper::instance().pushData(t, "SIN", testSignal);
119  }
120  return 0;
121 }
122 
123 #ifdef TEST_DATA_DUMPER
124 int main(int argc, char *argv)
125 {
127 }
128 #endif
int testbed()
Definition: dataDumper.cpp:99
int pushData(double timeStamp, std::string info, double val)
Definition: dataDumper.cpp:11
std::vector< std::string > infoVec
Definition: dataDumper.h:28
int main(int argc, char **argv)
Startup routine - if called with no argmuments we assume debug session. Set scanner name variable by ...
std::string dumpFileName
Definition: dataDumper.h:42
int writeDataToCsv(std::string fileName)
Definition: dataDumper.cpp:37
int pushCounter
Definition: dataDumper.h:30
int writeToFileNameWhenBufferIsFull(std::string filename)
Definition: dataDumper.cpp:59
static DataDumper & instance()
Definition: dataDumper.h:13
std::vector< double > timeStampVec
Definition: dataDumper.h:27
const int maxFifoSize
Definition: dataDumper.h:26
std::vector< double > dataVec
Definition: dataDumper.h:29
int dumpUcharBufferToConsole(unsigned char *buffer, int bufLen)
Definition: dataDumper.cpp:65


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