-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathWebContent.cpp
111 lines (102 loc) · 2.94 KB
/
WebContent.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <Arduino.h>
#include "WebServer.h"
#include "WebContent.h"
#include "DateTime.h"
#include "GPS.h"
#include "index_html.h"
#include "index_js.h"
WebContent webcontent;
static const char *jsonState(const char *filename) {
return webcontent.jsonState();
}
static const struct webpage webpages[] = {
{
indexHTML,
"/index.html",
NULL
},
{
indexJS,
"/index.js",
NULL
},
{
"File not found",
"/404.html",
NULL
},
{
NULL,
"/state.json",
jsonState
},
{
NULL, NULL, NULL
}
};
void WebContent::begin() {
webserver.setWebpages(webpages);
}
const char *WebContent::jsonState() {
int total = sizeof(jsonBuffer);
int offset = snprintf(
jsonBuffer,
sizeof(jsonBuffer),
"{\"ppsToGPS\": %lu, \"ppsMillis\": %lu, \"curMillis\": %lu, \"gpstime\": %lu, \"counterPPS\": %lu, \"offsetHuman\": %.9f, \"pidD\": %.9f, \"dChiSq\": %.9f, \"clockPpb\": %ld,",
ppsToGPS,
ppsMillis,
millis(),
gpstime,
counterPPS,
offsetHuman,
pidD,
dChiSq,
clockPpb
);
if (offset >= total) {
jsonBuffer[sizeof(jsonBuffer)-1] = '\0';
return jsonBuffer;
}
offset += snprintf(jsonBuffer + offset, sizeof(jsonBuffer) - offset,
"\"lockStatus\": %u, \"strongSignals\": %lu, \"weakSignals\": %lu, \"noSignals\": %lu, \"gpsCaptured\": %lu, \"pdop\": %.1f, \"hdop\": %.1f, \"vdop\": %.1f, \"satellites\": [",
gps.lockStatus(),
gps.strongSignals(),
gps.weakSignals(),
gps.noSignals(),
gps.capturedAt(),
gps.getPdop(),
gps.getHdop(),
gps.getVdop()
);
if (offset >= total) {
jsonBuffer[sizeof(jsonBuffer)-1] = '\0';
return jsonBuffer;
}
const struct satellite *satinfo = gps.getSatellites();
for(uint8_t i = 0; i < MAX_SATELLITES && satinfo[i].id; i++) {
const char *format = (i == 0) ? "[%u,%u,%u,%u]" : ",[%u,%u,%u,%u]";
offset += snprintf(jsonBuffer + offset, sizeof(jsonBuffer) - offset,
format, satinfo[i].id, satinfo[i].elevation, satinfo[i].azimuth, satinfo[i].snr
);
if (offset >= total) {
jsonBuffer[sizeof(jsonBuffer)-1] = '\0';
return jsonBuffer;
}
}
snprintf(jsonBuffer + offset, sizeof(jsonBuffer) - offset, "]}");
jsonBuffer[sizeof(jsonBuffer)-1] = '\0';
return jsonBuffer;
}
void WebContent::setPPSData(uint32_t new_ppsToGPS, uint32_t new_ppsMillis, uint32_t new_gpstime) {
ppsToGPS = new_ppsToGPS;
ppsMillis = new_ppsMillis;
gpstime = new_gpstime;
}
void WebContent::setLocalClock(uint32_t new_counterPPS, double new_offsetHuman, double new_pidD, double new_dChiSq, int32_t new_clockPpb, uint32_t new_gpstime) {
counterPPS = new_counterPPS;
offsetHuman = isnan(new_offsetHuman) ? 0 : new_offsetHuman;
pidD = isnan(new_pidD) ? 0 : new_pidD;
dChiSq = isnan(new_dChiSq) ? 0 : new_dChiSq;
clockPpb = new_clockPpb;
gpstime = new_gpstime;
}