STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
CommandDedupe.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstddef>
5#include <cstdint>
6#include <cstring>
7
8namespace fsw::calibration {
9
10/**
11 * Drops a CalibrationCommand the service has already handled.
12 *
13 * elodin-db delivers a table once per subscription to it, and a second subscribe on the same
14 * connection is a second subscription: every packet then arrives twice. The service's "no packets
15 * for 5 s, re-subscribe" fallback does exactly that, and it re-adds the command table each time —
16 * so after it had fired once, every capture landed twice (CI, 2026-11-07: ten captures stored
17 * twenty points, and a load cell's single "linear" capture became a two-point line that streamed
18 * the reference instead of PENDING physics). After N firings it would be N+1.
19 *
20 * The backend stamps every command with its own timestamp, so two commands with the same 16 bytes
21 * are one command delivered twice, whatever made the copy. Remembers the last kDepth.
22 */
24public:
25 static constexpr std::size_t kBytes = 16; // ts(8) | type(1) | pad(1) | sensor(2) | ref(4)
26 static constexpr std::size_t kDepth = 32;
27
28 /** true if this exact command was already seen (drop it); otherwise records it. */
29 bool seen(const uint8_t* cmd) {
30 for (std::size_t i = 0; i < count_; ++i)
31 if (std::memcmp(recent_[i].data(), cmd, kBytes) == 0)
32 return true;
33 std::memcpy(recent_[next_].data(), cmd, kBytes);
34 next_ = (next_ + 1) % kDepth;
35 if (count_ < kDepth)
36 ++count_;
37 return false;
38 }
39
40private:
41 std::array<std::array<uint8_t, kBytes>, kDepth> recent_{};
42 std::size_t next_ = 0;
43 std::size_t count_ = 0;
44};
45
46} // namespace fsw::calibration
Drops a CalibrationCommand the service has already handled.
static constexpr std::size_t kBytes
bool seen(const uint8_t *cmd)
true if this exact command was already seen (drop it); otherwise records it.
static constexpr std::size_t kDepth
std::array< std::array< uint8_t, kBytes >, kDepth > recent_
Output smoothing for calibrated PT pressure, per sensor uid (ESP32 and LabJack T7 alike).