tsLogger
A C++17 data logger for timeseries and snapshot data
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// tsLogger.cpp : This file contains the 'main' function. Program execution begins and ends there.
2//
3
4#include <iostream>
5#include <tsLogger.h>
6
7int main()
8{
9 // library initialization
10 std::cout << "Hello World!\n";
11 char newFileName[] = "testFile.csv";
12 tsLogger loggerA(newFileName);
13 // if no file name is provided,
14 // it will create one with the name "tsDataLog_YYYY-MM-DD-HHMM.csv"
15 char filePathA[256];
16 loggerA.getFilePath(filePathA, 256);
17 std::cout<<"File path for log file A: "<<filePathA<<std::endl;
18
19 // append things to the preabmle and add it to the text file
20 loggerA.appendToPreamble("Test Preamble\n1"); // new line character is removed automatically
21 loggerA.appendToPreamble("Test Preamble 2");
22 loggerA.appendToPreamble("Test Preamble 3");
23 loggerA.appendToPreamble("Test Preamble 4");
24 loggerA.appendToPreamble("Test Preamble 5");
25 loggerA.appendToPreamble("Test Preamble 6");
26 loggerA.appendToPreamble("Test Preamble 7");
27 loggerA.appendToPreamble("Test Preamble 8");
28
29 loggerA.addPreamble();
30
31 // test data points to link
32 int a = -1;
33 unsigned int b = 88;
34 long c = -324684;
35 unsigned long d = 684333;
36 float e = (float) 2.718;
37 double f = -53.2468143648136418;
38 char g = 'g';
39 unsigned char h = 254;
40 bool i = true;
41 long long j = -1314646343645;
42 unsigned long long k = 1314646343645;
43
44 // track data points
45 loggerA.trackDataPoint(&a, "First data tracked");
46 loggerA.trackDataPoint(&b, ""); // auto-labelled
47 loggerA.trackDataPoint(&c, "datapoint 3");
48 loggerA.trackDataPoint(&d, "data 4");
49 loggerA.trackDataPoint(&e, "just a float");
50 loggerA.trackDataPoint(&f, "double-precision sensor data");
51 loggerA.trackDataPoint(&g, "data point 7");
52 loggerA.trackDataPoint(&h, "another datapoint");
53 loggerA.trackDataPoint(&i, "binary values also supported");
54 loggerA.trackDataPoint(&j, "timestamp");
55 loggerA.trackDataPoint(&k, "last data point");
56
57 // add header to text file
58 loggerA.addDataHeader();
59
60 // log current state of data points
61 loggerA.logData();
62
63 // change state of data points
64 a = -176;
65 b = 564;
66 c = -87130;
67 d = 3418962;
68 e = (float) - 3842.718;
69 f = 0.123456789;
70 g = 'G';
71 h = 255;
72 i = false;
73 j = -9314646343645;
74 k = 9314646343645;
75
76
77 // log current state of data points
78 // - call as many times as you need to log data states
79 loggerA.logData();
80
81 return 0;
82}
83
The core class of the library is the tsLogger class. Multiple simultaneous class objects are supporte...
Definition: tsLogger.h:50
void appendToPreamble(std::string appendString)
Appends a line of text to the preamble block of the log file. Replaces new line characters with space...
Definition: tsLogger.cpp:123
unsigned trackDataPoint(T *dataPointer, const std::string &dataName)
Template member function that appends the data point to the list of tracked data.
Definition: tsLogger.h:143
void getFilePath(char *pathDestination, size_t pathDestinationLength)
Allows the user to read the file path of the log file.
Definition: tsLogger.cpp:113
void addDataHeader()
Add the data header (consisting of datapoint names separated by commas) to the header file....
Definition: tsLogger.cpp:142
void addPreamble()
Adds the preamble to the log file-can only be added once and only be called before the addDataHeader ...
Definition: tsLogger.cpp:131
void logData()
Logs the data points being tracked as a line in the log file.
Definition: tsLogger.cpp:173
int main()
Definition: main.cpp:7