Implemented history writer

This commit is contained in:
Martino Ferrari
2026-06-14 14:09:51 +02:00
parent f25bd7f08e
commit dd7dd22cb0
27 changed files with 1537 additions and 104 deletions
+73
View File
@@ -253,6 +253,23 @@ std::string BuildZoom(uint32_t reqId, double t0, double t1, int n,
return out;
}
std::string BuildHistoryZoom(uint32_t reqId, double t0, double t1, int n,
const std::string& signalsCsv) {
char head[256];
snprintf(head, sizeof(head),
"{\"type\":\"historyZoom\",\"reqId\":%u,"
"\"t0\":%.17g,\"t1\":%.17g,\"n\":%d,\"signals\":\"",
static_cast<unsigned>(reqId), t0, t1, n);
std::string out(head);
out += signalsCsv;
out += "\"}";
return out;
}
std::string BuildHistoryInfo() {
return "{\"type\":\"historyInfo\"}";
}
std::string BuildSetMaxPoints(uint32_t n) {
char buf[128];
snprintf(buf, sizeof(buf), "{\"type\":\"setMaxPoints\",\"maxPoints\":%u}",
@@ -530,4 +547,60 @@ bool ParseMaxPointsUpdated(const std::string& json, uint32_t& maxPoints) {
return true;
}
/* ---- historyInfo -------------------------------------------------------- */
bool ParseHistoryInfo(const std::string& json, HistoryInfoMsg& out) {
out.signals.clear();
out.enabled = false;
char tmp[16] = "";
jsonGetStr(json.c_str(), "enabled", tmp, sizeof(tmp));
out.enabled = (strcmp(tmp, "true") == 0);
double df = 0.0;
jsonGetDouble(json.c_str(), "durationHours", df);
out.durationHours = df;
double decF = 0.0;
jsonGetDouble(json.c_str(), "decimation", decF);
out.decimation = static_cast<uint32_t>(decF);
/* Parse "signals":{...} block — same key iteration as zoom */
const char *sig = strstr(json.c_str(), "\"signals\":{");
if (!sig) { return out.enabled; }
sig += 11; /* past '{"signals":{' */
while (*sig) {
/* Find next "key":{ */
const char *q = strchr(sig, '"');
if (!q) { break; }
q++;
const char *qEnd = strchr(q, '"');
if (!qEnd) { break; }
HistorySignalRange hr;
hr.key = std::string(q, qEnd);
/* Find the nested object */
const char *brace = strchr(qEnd, '{');
if (!brace) { break; }
jsonGetDouble(brace, "t0", hr.t0);
jsonGetDouble(brace, "t1", hr.t1);
double cntF = 0.0, capF = 0.0;
jsonGetDouble(brace, "count", cntF);
jsonGetDouble(brace, "capacity", capF);
hr.count = static_cast<uint32_t>(cntF);
hr.capacity = static_cast<uint32_t>(capF);
out.signals.push_back(hr);
/* Advance past the closing brace */
const char *end = strchr(brace, '}');
if (!end) { break; }
sig = end + 1;
}
return true;
}
} /* namespace StreamHubClient */