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 <sstream>
10 #include <iomanip>
11 #include "dataDumper.h"
12 
13 int DataDumper::pushData(double timeStamp, std::string info, double val)
14 {
15  int retCode = 0;
17  {
18  timeStampVec[pushCounter] = timeStamp;
19  infoVec[pushCounter] = info;
20  dataVec[pushCounter] = val;
21 
22  }
23  else
24  {
25  retCode = 2;
26  if (pushCounter == maxFifoSize)
27  {
28  if (dumpFileName.length() > 0)
29  {
31  retCode = 1;
32  }
33  }
34  }
35  pushCounter++;
36  return (retCode);
37 }
38 
39 int DataDumper::writeDataToCsv(std::string filename)
40 {
41  FILE *fout;
42  int retCode = 0;
43  fout = fopen(filename.c_str(), "w");
44  if (fout != NULL)
45  {
46  for (int i = 0; i < pushCounter; i++)
47  {
48  fprintf(fout, "%8.6lf;%-10s;%12.8lf\n", timeStampVec[i], infoVec[i].c_str(), dataVec[i]);
49  }
50 
51  fclose(fout);
52  }
53  else
54  {
55  retCode = -1;
56  }
57  return (retCode);
58 }
59 
60 
62 {
63  dumpFileName = filename;
64  return (0);
65 }
66 
67 int DataDumper::dumpUcharBufferToConsole(unsigned char *buffer, int bufLen)
68 {
69  int ret = 0;
70  char asciiBuffer[255] = {0};
71  for (int i = 0; i < bufLen; i++)
72  {
73  if ((i % 8) == 0)
74  {
75  printf("%08x: ", i);
76  }
77 
78  printf("%02x ", buffer[i]);
79 
80  char ch = '.';
81  if ((buffer[i] >= 0x20) && (buffer[i] < 0x80))
82  {
83  ch = (char) buffer[i];
84  }
85  int iStrLen = strlen(asciiBuffer);
86  asciiBuffer[iStrLen] = ch;
87  asciiBuffer[iStrLen + 1] = '\0';
88 
89  if ((i % 8) == 7)
90  {
91  printf("%s\n", asciiBuffer);
92  strcpy(asciiBuffer, "");
93  }
94  }
95  if (bufLen % 8)
96  {
97 
98  printf("%s\n", asciiBuffer);
99  }
100  return(ret);
101 }
102 
108 std::string DataDumper::binDataToAsciiString(const uint8_t* binary_data, int length)
109 {
110  std::stringstream out;
111  for(int n = 0; n < length; n++)
112  {
113  int val = (int)(binary_data[n] & 0xFF);
114  if ((val == 0x20) || (val >= 48 && val <= 57) || (val >= 65 && val <= 90) || (val >= 97 && val <= 122))
115  {
116  out << std::string(1,(char)(val & 0xFF));
117  }
118  else
119  {
120  out << "\\x" << std::setfill('0') << std::setw(2) << std::hex << val;
121  }
122  }
123  return out.str();
124 }
125 
126 
128 {
129 
130  double testSignal;
131  double sampleRate = 1000.0;
132  double freq = 50.0;
133  DataDumper::instance().writeToFileNameWhenBufferIsFull("C:\\temp\\000_full.csv");
134 
135  int cnt = 0;
136  for (double t = 0; t < 5.0; t += 1.0 / sampleRate)
137  {
138  cnt++;
139  testSignal = 1.0 * cos(2 * M_PI * freq * t);
140  if (cnt == 1000)
141  {
142  DataDumper::instance().writeDataToCsv("C:\\temp\\000_partial.csv");
143  }
144  DataDumper::instance().pushData(t, "COS", testSignal);
145  testSignal = 1.0 * sin(2 * M_PI * freq * t);
146  DataDumper::instance().pushData(t, "SIN", testSignal);
147  }
148  return 0;
149 }
150 
151 #ifdef TEST_DATA_DUMPER
152 int main(int argc, char *argv)
153 {
155 }
156 #endif
int testbed()
Definition: dataDumper.cpp:127
static std::string binDataToAsciiString(const uint8_t *binary_data, int length)
Definition: dataDumper.cpp:108
int pushData(double timeStamp, std::string info, double val)
Definition: dataDumper.cpp:13
std::vector< std::string > infoVec
Definition: dataDumper.h:42
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:57
int writeDataToCsv(std::string fileName)
Definition: dataDumper.cpp:39
int pushCounter
Definition: dataDumper.h:44
int writeToFileNameWhenBufferIsFull(std::string filename)
Definition: dataDumper.cpp:61
static DataDumper & instance()
Definition: dataDumper.h:13
std::vector< double > timeStampVec
Definition: dataDumper.h:41
const int maxFifoSize
Definition: dataDumper.h:40
std::vector< double > dataVec
Definition: dataDumper.h:43
int dumpUcharBufferToConsole(unsigned char *buffer, int bufLen)
Definition: dataDumper.cpp:67


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Wed May 5 2021 03:05:47