-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatalogger.cpp
92 lines (72 loc) · 1.82 KB
/
datalogger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "datalogger.h"
#include "config.h"
DataLogger::DataLogger() { }
void DataLogger::setQueue(QueueHandle_t queue) {
_queue = queue;
}
void DataLogger::setGpsDateTime(long date, long time)
{
_date = String(date);
char buf[32];
sprintf(buf, "%02u:%02u:%02u.%c00", time / 1000000, (time % 1000000) / 10000, (time % 10000) / 100, '0' + (time % 100) / 10);
_time = String(buf);
_lastGpsMillis = millis();
/*
Serial.print("Set current GPS date/time to: ");
Serial.println(getDateTime());
*/
}
String DataLogger::getDateTime() {
unsigned long currentMillis = millis();
String _dt = String("20");
String _d = _date;
String _t = _time; //String(10 * _time + (currentMillis - _lastGpsMillis));
_dt.concat(_d.charAt(4));
_dt.concat(_d.charAt(5));
_dt.concat("-");
_dt.concat(_d.charAt(2));
_dt.concat(_d.charAt(3));
_dt.concat("-");
_dt.concat(_d.charAt(0));
_dt.concat(_d.charAt(1));
_dt.concat("T");
_dt.concat(_time);
_dt.concat("Z");
return _dt;
}
void DataLogger::log(uint16_t pid, float value)
{
char buf[24];
byte len = sprintf(buf, "%X,%.2f", pid, value);
write(buf, len);
}
void DataLogger::log(uint16_t pid, int value)
{
char buf[24];
byte len = sprintf(buf, "%X,%d", pid, value);
write(buf, len);
}
void DataLogger::log(uint16_t pid, unsigned int value)
{
char buf[24];
byte len = sprintf(buf, "%X,%u", pid, value);
write(buf, len);
}
void DataLogger::logFloat(uint16_t pid, float value)
{
char buf[32];
byte len = sprintf(buf, "%X,%f", pid, value);
write(buf, len);
}
void DataLogger::write(const char* buf, byte len)
{
String payload = getDateTime();
payload.concat(",");
payload.concat(buf);
char *message = "";
asprintf(&message, "%s", payload.c_str());
xQueueSend(_queue, (void *)&message, portMAX_DELAY);
}
void DataLogger::loop()
{
}