Implemented client datasource

This commit is contained in:
Martino Ferrari
2026-06-25 00:45:45 +02:00
parent dca4872976
commit 0412c20edd
28 changed files with 3448 additions and 618 deletions
+27 -5
View File
@@ -255,13 +255,27 @@ bool StreamHub::Run() {
PushStats();
}
/* History: flush headers periodically */
/* History: flush headers at the configured interval, then re-broadcast
* historyInfo so new clients (or clients that saw empty signal lists
* before the first data was written) pick up the current state. */
if (history_.IsEnabled()) {
uint32 histFlushDiv = history_.Decimation() > 0u
? pushRateHz_ * 5u : pushRateHz_ * 5u; /* every 5s */
if (histFlushDiv == 0u) { histFlushDiv = 1u; }
if ((tickCount_ % histFlushDiv) == 0u) {
uint32 flushIntervalTicks = pushRateHz_ * 5u; /* default 5 s */
if (pushRateHz_ > 0u) {
flushIntervalTicks = pushRateHz_ * 5u;
}
if (flushIntervalTicks == 0u) { flushIntervalTicks = 1u; }
if ((tickCount_ % flushIntervalTicks) == 0u) {
history_.FlushHeaders();
/* Re-broadcast so clients see updated signal counts and
* time ranges after the first batch of data is written. */
uint32 cap2 = 8192u;
char *hbuf = new char[cap2];
uint32 hoff = 0u;
JsonAppendf(hbuf, hoff, cap2, "{\"type\":\"historyInfo\",");
history_.AppendInfoJSON(hbuf, hoff, cap2);
JsonAppendf(hbuf, hoff, cap2, "}");
wsServer_.BroadcastText(hbuf, hoff);
delete[] hbuf;
}
}
@@ -648,6 +662,14 @@ void StreamHub::OnWSClientConnected() {
wsServer_.BroadcastText(hbuf, hoff);
delete[] hbuf;
}
/* Inform the new client about the current MaxPoints setting. */
{
char mp[64];
int n = snprintf(mp, sizeof(mp),
"{\"type\":\"maxPointsUpdated\",\"maxPoints\":%u}", maxPoints_);
if (n > 0) { wsServer_.BroadcastText(mp, static_cast<uint32>(n)); }
}
}
void StreamHub::OnWSClientDisconnected() {