ESPectre SDK 2.8.0-280-gac7af68
Wi-Fi CSI motion sensing for ESP32 firmware
Loading...
Searching...
No Matches
runtime_sensing_schema.h
Go to the documentation of this file.
1/*
2 * ESPectre - Runtime Sensing Schema
3 *
4 * Shared sensing schema enums and defaults for runtime config.
5 *
6 * Author: Francesco Pace <francesco.pace@gmail.com>
7 * SPDX-License-Identifier: GPL-3.0-only
8 * Commercial licensing available under separate agreement; see LICENSING.md.
9 */
10#pragma once
11
12#include <cstddef>
13#include <cstdint>
14
15#include "detector_limits.h"
16#include "detector_types.h"
17#include "csi_traffic_types.h"
18#include "filter_config.h"
19
20/**
21 * @file runtime_sensing_schema.h
22 * @brief The schema behind `RuntimeConfig`: enums, defaults, and valid ranges.
23 *
24 * This is the single source of truth for what a sensing configuration may
25 * contain. Every tunable is declared as a `RUNTIME_<FIELD>_DEFAULT` plus, where
26 * a range applies, `_MIN` and `_MAX`. Read them instead of hardcoding limits,
27 * so a UI, a provisioning flow, or a config parser stays correct across SDK
28 * releases.
29 *
30 * The `static_assert` block at the end holds these values in lockstep with the
31 * detector and filter constants they mirror, so a drift between the runtime
32 * schema and `core/` fails the build rather than the device.
33 */
34
35namespace espectre {
36
37/** Which detector runs. See `docs/ALGORITHMS.md` for how they differ. */
39 /** Lightweight feature fusion. Self-calibrates, and needs no training data. Default. */
41 /** High-accuracy neural detector using the trained weights in `core/ml_weights.h`. */
43};
44
45/** Which runtime backend the controller builds. */
46enum class RuntimeProfile {
47 /** Detect motion on-device and report state. The normal profile. */
49 /**
50 * Ship raw CSI to a host collector instead of detecting.
51 *
52 * For dataset collection and offline analysis. Requires a build with the
53 * stream runtime compiled in; `setup()` fails otherwise.
54 */
56};
57
58/** Which packet the internal generator sends to solicit CSI from the AP. */
60 /** DNS queries. Useful where ICMP is filtered. */
62 /** ICMP echo. Default. */
64};
65
66constexpr const char *const RUNTIME_TRAFFIC_GENERATOR_MODE_DNS_NAME = "dns";
67constexpr const char *const RUNTIME_TRAFFIC_GENERATOR_MODE_PING_NAME = "ping";
68constexpr const char *const RUNTIME_TRAFFIC_GENERATOR_MODE_DEFAULT_NAME = "ping";
69
70constexpr const char *const RUNTIME_CSI_TRAFFIC_MODE_INTERNAL_NAME = "internal";
71constexpr const char *const RUNTIME_CSI_TRAFFIC_MODE_EXTERNAL_NAME = "external";
72constexpr const char *const RUNTIME_CSI_TRAFFIC_MODE_PACING_NAME = "pacing";
73constexpr const char *const RUNTIME_CSI_TRAFFIC_MODE_DISABLED_NAME = "disabled";
74constexpr const char *const RUNTIME_CSI_TRAFFIC_MODE_DEFAULT_NAME = "internal";
75
76constexpr const char *const RUNTIME_DETECTION_ALGORITHM_LIGHTWEIGHT_NAME = "lightweight";
77constexpr const char *const RUNTIME_DETECTION_ALGORITHM_HIGH_ACCURACY_NAME = "high_accuracy";
78constexpr const char *const RUNTIME_DETECTION_ALGORITHM_DEFAULT_NAME = "lightweight";
79
80constexpr float RUNTIME_THRESHOLD_MIN = 0.0f;
81constexpr float RUNTIME_THRESHOLD_MAX = 1.0f;
84
85constexpr uint32_t RUNTIME_SEGMENTATION_WINDOW_SIZE_MS_MIN = 1000U;
86constexpr uint32_t RUNTIME_SEGMENTATION_WINDOW_SIZE_MS_MAX = 2000U;
88
89constexpr uint32_t RUNTIME_CSI_TARGET_PPS_MIN = 1U;
90// The maximum public two-second window resolves to the detector's 1000-slot
91// storage ceiling at this rate. Supported hardware normally runs near 100 pps.
92constexpr uint32_t RUNTIME_CSI_TARGET_PPS_MAX = 500U;
93constexpr uint32_t RUNTIME_CSI_TARGET_PPS_DEFAULT = 100U;
94
95constexpr uint32_t RUNTIME_PUBLISH_INTERVAL_MS_MIN = 100;
96constexpr uint32_t RUNTIME_PUBLISH_INTERVAL_MS_MAX = 60000;
97constexpr uint32_t RUNTIME_PUBLISH_INTERVAL_MS_DEFAULT = 1000;
98constexpr uint32_t RUNTIME_EVALUATION_INTERVAL_MS_MIN = 10;
99constexpr uint32_t RUNTIME_EVALUATION_INTERVAL_MS_MAX = 10000;
101
102constexpr uint8_t RUNTIME_MOTION_HITS_MIN = 1;
103constexpr uint8_t RUNTIME_MOTION_HITS_MAX = 20;
104constexpr uint8_t RUNTIME_MOTION_ON_HITS_DEFAULT = 4;
106
107constexpr bool RUNTIME_LOWPASS_ENABLED_DEFAULT = false;
108constexpr float RUNTIME_LOWPASS_CUTOFF_MIN = 5.0f;
109constexpr float RUNTIME_LOWPASS_CUTOFF_MAX = 20.0f;
110constexpr float RUNTIME_LOWPASS_CUTOFF_DEFAULT = 11.0f;
111
112constexpr bool RUNTIME_HAMPEL_ENABLED_DEFAULT = true;
113constexpr uint8_t RUNTIME_HAMPEL_WINDOW_MIN = 3;
114constexpr uint8_t RUNTIME_HAMPEL_WINDOW_MAX = 11;
115constexpr uint8_t RUNTIME_HAMPEL_WINDOW_DEFAULT = 7;
116constexpr float RUNTIME_HAMPEL_THRESHOLD_MIN = 1.0f;
117constexpr float RUNTIME_HAMPEL_THRESHOLD_MAX = 10.0f;
118constexpr float RUNTIME_HAMPEL_THRESHOLD_DEFAULT = 5.0f;
119
121constexpr uint16_t RUNTIME_NETWORK_PORT_MIN = 1U;
122constexpr uint16_t RUNTIME_NETWORK_PORT_MAX = UINT16_MAX;
123constexpr uint32_t RUNTIME_STREAM_LOG_INTERVAL_MS_MIN = 100U;
124constexpr uint32_t RUNTIME_STREAM_LOG_INTERVAL_MS_MAX = 60000U;
129
130constexpr uint16_t RUNTIME_CSI_TRAFFIC_UDP_PORT_DEFAULT = 5555;
131constexpr const char *const RUNTIME_CSI_TRAFFIC_MULTICAST_GROUP_DEFAULT = "239.255.0.1";
133
138
140 return algorithm == DetectionAlgorithm::LIGHTWEIGHT ||
142}
143
144constexpr bool runtime_profile_valid(RuntimeProfile profile) {
145 return profile == RuntimeProfile::SENSING || profile == RuntimeProfile::STREAM;
146}
147
151
156
158 CsiTrafficMode mode) {
160 return false;
161 }
162 return profile == RuntimeProfile::STREAM || mode != CsiTrafficMode::PACING;
163}
164
170
171static_assert(RUNTIME_THRESHOLD_MIN == 0.0f, "Runtime threshold min must stay at zero");
173 "Runtime High Accuracy threshold max drifted from high_accuracy_detector.h");
175 "Lightweight and High Accuracy probability scales must stay aligned");
177 "Runtime segmentation threshold default drifted from lightweight_detector.h");
179 "Runtime segmentation window duration min drifted from detector_limits.h");
181 "Runtime segmentation window duration max drifted from detector_limits.h");
183 "Runtime segmentation window duration default drifted from detector_limits.h");
184static_assert(RUNTIME_LOWPASS_CUTOFF_MIN == LOWPASS_CUTOFF_MIN, "Runtime lowpass cutoff min drifted from filters.h");
185static_assert(RUNTIME_LOWPASS_CUTOFF_MAX == LOWPASS_CUTOFF_MAX, "Runtime lowpass cutoff max drifted from filters.h");
187 "Runtime lowpass cutoff default drifted from filters.h");
189 "Runtime Hampel window min drifted from filters.h");
191 "Runtime Hampel window max drifted from filters.h");
193 "Runtime Hampel window default drifted from filters.h");
195 "Runtime Hampel threshold default drifted from filters.h");
196
197} // namespace espectre
constexpr uint8_t RUNTIME_MOTION_ON_HITS_DEFAULT
constexpr float LIGHTWEIGHT_DEFAULT_THRESHOLD
constexpr float RUNTIME_HAMPEL_THRESHOLD_MAX
constexpr float RUNTIME_LOWPASS_CUTOFF_MIN
constexpr uint16_t RUNTIME_NETWORK_PORT_MAX
constexpr const char *const RUNTIME_TRAFFIC_GENERATOR_MODE_DNS_NAME
constexpr const char *const RUNTIME_TRAFFIC_GENERATOR_MODE_PING_NAME
constexpr const char *const RUNTIME_CSI_TRAFFIC_MODE_INTERNAL_NAME
constexpr const char *const RUNTIME_CSI_TRAFFIC_MODE_EXTERNAL_NAME
constexpr uint8_t RUNTIME_STREAM_TX_BATCH_RECORDS_DEFAULT
constexpr uint8_t RUNTIME_HAMPEL_WINDOW_DEFAULT
constexpr uint32_t RUNTIME_PUBLISH_INTERVAL_MS_MIN
constexpr float RUNTIME_SEGMENTATION_THRESHOLD_DEFAULT
constexpr float RUNTIME_HIGH_ACCURACY_THRESHOLD_MAX
constexpr uint32_t RUNTIME_PUBLISH_INTERVAL_MS_DEFAULT
constexpr uint8_t RUNTIME_STREAM_TX_BATCH_RECORDS_MAX
constexpr uint16_t RUNTIME_STREAM_COLLECTOR_PORT_DEFAULT
constexpr uint32_t RUNTIME_CSI_TARGET_PPS_MAX
constexpr uint8_t RUNTIME_MOTION_OFF_HITS_DEFAULT
constexpr bool runtime_csi_traffic_mode_valid_for_profile(RuntimeProfile profile, CsiTrafficMode mode)
constexpr uint8_t RUNTIME_MOTION_HITS_MAX
constexpr uint8_t HAMPEL_TURBULENCE_WINDOW_MAX
constexpr const char *const RUNTIME_CSI_TRAFFIC_MODE_PACING_NAME
constexpr const char *const RUNTIME_DETECTION_ALGORITHM_DEFAULT_NAME
constexpr uint8_t RUNTIME_HAMPEL_WINDOW_MIN
constexpr uint32_t RUNTIME_STREAM_LOG_INTERVAL_MS_DEFAULT
RuntimeProfile
Which runtime backend the controller builds.
@ STREAM
Ship raw CSI to a host collector instead of detecting.
@ SENSING
Detect motion on-device and report state.
constexpr uint8_t RUNTIME_HAMPEL_WINDOW_MAX
constexpr uint32_t RUNTIME_STREAM_LOG_INTERVAL_MS_MIN
constexpr float LOWPASS_CUTOFF_MAX
constexpr uint32_t RUNTIME_SEGMENTATION_WINDOW_SIZE_MS_DEFAULT
RuntimeTrafficMode
Which packet the internal generator sends to solicit CSI from the AP.
constexpr uint32_t RUNTIME_SEGMENTATION_WINDOW_SIZE_MS_MIN
constexpr uint32_t DETECTOR_WINDOW_SIZE_MS_MAX
constexpr const char *const RUNTIME_DETECTION_ALGORITHM_HIGH_ACCURACY_NAME
constexpr uint32_t RUNTIME_CSI_TARGET_PPS_DEFAULT
constexpr float RUNTIME_THRESHOLD_MAX
constexpr uint8_t HAMPEL_TURBULENCE_WINDOW_MIN
constexpr uint8_t HAMPEL_TURBULENCE_WINDOW_DEFAULT
constexpr const char *const RUNTIME_CSI_TRAFFIC_MULTICAST_GROUP_DEFAULT
CsiTrafficMode
Where the CSI-bearing traffic comes from.
@ DISABLED
No traffic management at all.
@ INTERNAL
The runtime generates its own traffic at csi_target_pps.
@ PACING
External traffic, with the runtime pacing the sender to hold the rate.
@ EXTERNAL
Another device supplies the traffic; the runtime only listens.
constexpr bool RUNTIME_LOWPASS_ENABLED_DEFAULT
constexpr uint32_t RUNTIME_EVALUATION_INTERVAL_MS_MAX
constexpr float RUNTIME_LOWPASS_CUTOFF_DEFAULT
constexpr uint16_t RUNTIME_NETWORK_PORT_MIN
constexpr float runtime_default_threshold(DetectionAlgorithm algorithm)
constexpr uint8_t RUNTIME_MOTION_HITS_MIN
constexpr uint32_t DETECTOR_WINDOW_SIZE_MS_DEFAULT
constexpr float HIGH_ACCURACY_MAX_THRESHOLD
constexpr uint8_t RUNTIME_STREAM_TX_BATCH_RECORDS_MIN
constexpr bool runtime_traffic_mode_valid(RuntimeTrafficMode mode)
constexpr uint32_t DETECTOR_WINDOW_SIZE_MS_MIN
constexpr uint32_t RUNTIME_PUBLISH_INTERVAL_MS_MAX
constexpr float HIGH_ACCURACY_DEFAULT_THRESHOLD
constexpr uint16_t RUNTIME_CSI_TRAFFIC_UDP_PORT_DEFAULT
constexpr uint32_t RUNTIME_EVALUATION_INTERVAL_MS_MIN
constexpr float HAMPEL_TURBULENCE_THRESHOLD_DEFAULT
constexpr float LOWPASS_CUTOFF_MIN
constexpr uint32_t RUNTIME_EVALUATION_INTERVAL_MS_DEFAULT
constexpr uint32_t RUNTIME_CSI_TARGET_PPS_MIN
constexpr bool runtime_profile_valid(RuntimeProfile profile)
constexpr size_t RUNTIME_CSI_TRAFFIC_EXPECTED_PAYLOAD_MAX
constexpr bool runtime_detection_algorithm_valid(DetectionAlgorithm algorithm)
constexpr uint32_t RUNTIME_STREAM_LOG_INTERVAL_MS_MAX
constexpr float LIGHTWEIGHT_MAX_THRESHOLD
constexpr bool runtime_csi_traffic_mode_valid(CsiTrafficMode mode)
constexpr float LOWPASS_CUTOFF_DEFAULT
constexpr const char *const RUNTIME_CSI_TRAFFIC_MODE_DISABLED_NAME
constexpr uint32_t RUNTIME_SEGMENTATION_WINDOW_SIZE_MS_MAX
constexpr float RUNTIME_HAMPEL_THRESHOLD_MIN
DetectionAlgorithm
Which detector runs.
@ HIGH_ACCURACY
High-accuracy neural detector using the trained weights in core/ml_weights.h.
@ LIGHTWEIGHT
Lightweight feature fusion.
constexpr const char *const RUNTIME_TRAFFIC_GENERATOR_MODE_DEFAULT_NAME
constexpr float RUNTIME_HAMPEL_THRESHOLD_DEFAULT
constexpr const char *const RUNTIME_CSI_TRAFFIC_MODE_DEFAULT_NAME
constexpr bool RUNTIME_HAMPEL_ENABLED_DEFAULT
constexpr float RUNTIME_LOWPASS_CUTOFF_MAX
constexpr const char *const RUNTIME_DETECTION_ALGORITHM_LIGHTWEIGHT_NAME
constexpr float RUNTIME_THRESHOLD_MIN
constexpr float runtime_threshold_max(DetectionAlgorithm algorithm)