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
+38
View File
@@ -503,6 +503,8 @@ void App::handleJSON(const std::string& json) {
else if (type == "stats") { onStats(json); }
else if (type == "triggerState") { onTriggerState(json); }
else if (type == "zoom") { onZoom(json); }
else if (type == "historyZoom") { onHistoryZoom(json); }
else if (type == "historyInfo") { onHistoryInfo(json); }
else if (type == "maxPointsUpdated") { onMaxPointsUpdated(json); }
/* pong: ignore */
}
@@ -705,4 +707,40 @@ void App::onMaxPointsUpdated(const std::string& json) {
}
}
/* ---- History ------------------------------------------------------------ */
void App::onHistoryZoom(const std::string& json) {
ZoomResponse resp;
if (!ParseZoom(json, resp)) { return; }
/* Route the reply to the plot that requested it (via histZoomCache_) */
for (int i = 0; i < kMaxPlotSlots; i++) {
auto& hc = histZoomCache_[i];
if (hc.pending && hc.reqId == resp.reqId) {
hc.signals = std::move(resp.signals);
hc.t0 = hc.reqT0;
hc.t1 = hc.reqT1;
hc.valid = true;
hc.pending = false;
return;
}
}
}
void App::onHistoryInfo(const std::string& json) {
ParseHistoryInfo(json, historyInfo_);
}
void App::requestHistoryZoom(int plotIdx, double t0, double t1,
const std::string& signalsCsv) {
if (plotIdx < 0 || plotIdx >= kMaxPlotSlots) { return; }
if (!ws_.isConnected() || signalsCsv.empty()) { return; }
auto& hc = histZoomCache_[plotIdx];
hc.reqId = nextZoomReqId_++;
hc.reqT0 = t0;
hc.reqT1 = t1;
hc.pending = true;
ws_.sendText(BuildHistoryZoom(hc.reqId, t0, t1, 2400, signalsCsv));
}
} /* namespace StreamHubClient */