1#ifndef FSW_CAPTURE_WINDOW_HPP
2#define FSW_CAPTURE_WINDOW_HPP
57#include <unordered_map>
129 void push(uint16_t uid, int32_t
adc, uint64_t ts_ns, uint64_t rx_ns);
137 void clear(uint16_t uid);
142 std::vector<uint16_t>
uids()
const;
145 size_t size(uint16_t uid)
const;
148 std::unordered_map<uint16_t, std::deque<AdcSample>>
rings_;
Per-sensor ring of recent samples, and the capture decision over it.
std::unordered_map< uint16_t, std::deque< AdcSample > > rings_
CaptureResult capture(uint16_t uid, uint64_t now_rx_ns) const
What this sensor reads now, or why that cannot be answered.
void clear()
Forget everything.
void push(uint16_t uid, int32_t adc, uint64_t ts_ns, uint64_t rx_ns)
Record one sample.
std::vector< uint16_t > uids() const
Every uid with at least one sample.
size_t size(uint16_t uid) const
Samples currently held for a uid (diagnostics and tests).
static STAR_MCP3201 adc(MCP3201_CS_PIN, &mcp_spi)
Output smoothing for calibrated PT pressure, per sensor uid (ESP32 and LabJack T7 alike).
constexpr const char * kReasonTooFew
constexpr const char * kReasonNoSamples
constexpr uint64_t kCaptureWindowMs
How far back a capture averages.
constexpr const char * kReasonOk
Why a capture was refused.
constexpr const char * kReasonStale
constexpr uint64_t kStaleSamplePeriods
Liveness allowance for a slow sensor, in its own sample periods: one late sample is jitter,...
constexpr size_t kMinCaptureSamples
Below this a "mean" is not one, and the settle check has nothing to say.
constexpr uint64_t kMaxCaptureWindowMs
Upper bound on the adaptive window and staleness allowance.
constexpr size_t kRingMax
constexpr double kSettleZ
Half-mean difference, in standard errors, above which the window is not settled.
constexpr uint64_t kRingSpanMs
Ring eviction: by span so it self-sizes across 1-250 Hz, by count so memory is bounded if a board eve...
constexpr uint64_t kMaxSampleAgeMs
Newest sample older than this (in OUR clock) means the sensor is not live.
Motorized ball valve position: raw ADC counts -> % open.
uint64_t ts_ns
sample time, board-derived (spacing is what matters)
uint64_t rx_ns
arrival time on OUR monotonic clock
uint64_t max_age_ms
the staleness limit it was held to
double drift_z
drift in standard errors
uint64_t age_ms
how old the newest sample is, our clock
uint64_t span_ms
ts span actually covered
uint64_t window_ms
the window this sensor's rate called for
bool ok
false → the caller must NOT create a point
double drift
|mean(2nd half) - mean(1st half)|
double spread
max - min inside the window
size_t n
samples inside the window
bool settled
false → recorded, but flagged