|
ESPectre SDK 2.8.0-280-gac7af68
Wi-Fi CSI motion sensing for ESP32 firmware
|
Abstract base class for motion detection algorithms. More...
#include <base_detector.h>
Public Member Functions | |
| BaseDetector (uint16_t window_size=DETECTOR_DEFAULT_WINDOW_SIZE) | |
| Constructor. | |
| virtual | ~BaseDetector () |
| BaseDetector (BaseDetector &&other) noexcept | |
| BaseDetector & | operator= (BaseDetector &&other) noexcept |
| BaseDetector (const BaseDetector &)=delete | |
| BaseDetector & | operator= (const BaseDetector &)=delete |
| virtual void | process_packet (const int8_t *csi_data, size_t csi_len, const uint8_t *selected_subcarriers=nullptr, uint8_t num_subcarriers=0, int8_t rssi_dbm=INT8_MIN) |
| Process a CSI packet and update internal state. | |
| void | set_packet_timestamp_us (uint64_t timestamp_us) |
| Supply the monotonic arrival timestamp consumed by time-binned features. | |
| virtual void | reset () |
| Reset detector state. | |
| virtual MotionState | get_state () const |
| Get current motion state. | |
| virtual bool | is_ready () const |
| Check if detector is ready (buffer filled). | |
| virtual void | advance_missing_slots (uint32_t count) |
| Advance packet-indexed feature rings for absent temporal slots. | |
| void | set_minimum_valid_samples (uint16_t count) |
| Set the valid-slot occupancy floor used by is_ready(). | |
| virtual uint32_t | get_total_packets () const |
| Get total packets processed. | |
| virtual void | update_state ()=0 |
| Update state machine (call at publish interval). | |
| float | get_motion_metric () const |
| Get current motion metric value. | |
| virtual bool | set_threshold (float threshold)=0 |
| Set detection threshold. | |
| virtual bool | set_adaptive_threshold (float threshold) |
| Apply a detector-specific startup-calibrated threshold. | |
| virtual float | get_threshold () const =0 |
| Get current threshold. | |
| virtual const char * | get_name () const =0 |
| Get detector name for logging. | |
| virtual float | get_startup_threshold_factor () const |
| Get the detector-specific automatic startup multiplier. | |
| virtual bool | startup_gate_enabled () const |
| Whether startup calibration uses the consistency gate (threshold.h). | |
| virtual void | on_startup_calibration_begin () |
| Hook called immediately before startup calibration begins. | |
| virtual void | on_startup_calibration_complete () |
| Hook called when startup calibration completes successfully. | |
| virtual void | configure_lowpass (bool enabled, float cutoff_hz=LOWPASS_CUTOFF_DEFAULT) |
| Configure low-pass filter. | |
| virtual void | configure_hampel (bool enabled, uint8_t window_size=HAMPEL_TURBULENCE_WINDOW_DEFAULT, float threshold=HAMPEL_TURBULENCE_THRESHOLD_DEFAULT) |
| Configure Hampel filter. | |
| virtual void | clear_buffer () |
| Clear turbulence buffer (cold restart). | |
| const float * | get_turbulence_buffer () const |
| Get turbulence buffer pointer. | |
| uint16_t | get_buffer_count () const |
| Get number of valid samples in buffer. | |
| uint16_t | get_valid_buffer_count () const |
| uint16_t | get_window_size () const |
| Get configured window size. | |
| float | get_last_turbulence () const |
| Get last turbulence value. | |
| bool | is_lowpass_enabled () const |
| Check if low-pass filter is enabled. | |
| bool | is_hampel_enabled () const |
| Check if Hampel filter is enabled. | |
Protected Member Functions | |
| void | clear_evaluation_state_ () |
| Drop the last evaluation result. | |
| void | process_amplitudes (const float *amplitudes, uint8_t count) |
| uint64_t | packet_timestamp_us_or (uint64_t fallback) const |
| void | add_turbulence_to_buffer (float turbulence) |
| Add turbulence value to buffer (with filtering). | |
| const float * | ordered_turbulence (uint16_t &count) const |
| View the turbulence ring in chronological order. | |
Static Protected Member Functions | |
| static float * | alloc_zeroed_floats (uint16_t count) |
| Allocate a zeroed float buffer on the heap. | |
Protected Attributes | |
| float * | turbulence_buffer_ |
| float * | ordered_turbulence_ |
| uint16_t | buffer_index_ |
| uint16_t | buffer_count_ |
| uint16_t | valid_buffer_count_ |
| uint16_t | minimum_valid_samples_ |
| uint16_t | window_size_ |
| MotionState | state_ |
| float | current_metric_ |
| uint32_t | total_packets_ |
| uint32_t | packet_index_ |
| uint64_t | packet_timestamp_us_ |
| bool | has_packet_timestamp_ |
| hampel_filter_state_t | hampel_state_ |
| lowpass_filter_state_t | lowpass_state_ |
Abstract base class for motion detection algorithms.
Provides shared functionality:
Subclasses must implement:
Definition at line 41 of file base_detector.h.
|
explicit |
Constructor.
| window_size | Buffer window size (10-200 packets) |
|
virtual |
|
noexcept |
|
delete |
|
noexcept |
|
delete |
|
virtual |
Process a CSI packet and update internal state.
Calculates spatial turbulence from CSI data, applies filtering, and stores in circular buffer.
| csi_data | Raw CSI data (I/Q interleaved) |
| csi_len | Length of CSI data |
| selected_subcarriers | Array of subcarrier indices |
| num_subcarriers | Number of selected subcarriers |
| rssi_dbm | Link RSSI for this packet, or INT8_MIN when unknown |
Reimplemented in espectre::HighAccuracyDetector, and espectre::LightweightDetector.
|
inline |
Supply the monotonic arrival timestamp consumed by time-binned features.
Definition at line 82 of file base_detector.h.
|
virtual |
Reset detector state.
Resets state machine but preserves buffer ("warm" restart).
Reimplemented in espectre::LightweightDetector.
|
inlinevirtual |
Get current motion state.
Definition at line 97 of file base_detector.h.
|
inlinevirtual |
Check if detector is ready (buffer filled).
Reimplemented in espectre::HighAccuracyDetector, and espectre::LightweightDetector.
Definition at line 102 of file base_detector.h.
|
virtual |
Advance packet-indexed feature rings for absent temporal slots.
Reimplemented in espectre::HighAccuracyDetector, and espectre::LightweightDetector.
|
inline |
Set the valid-slot occupancy floor used by is_ready().
Definition at line 111 of file base_detector.h.
|
inlinevirtual |
Get total packets processed.
Definition at line 119 of file base_detector.h.
|
pure virtual |
Update state machine (call at publish interval).
Subclasses implement their detection algorithm here.
Implemented in espectre::HighAccuracyDetector, and espectre::LightweightDetector.
|
inline |
Get current motion metric value.
Not virtual: every detector reported the same member through an identical accessor, and the two copies drifted on when they cleared it. Subclasses assign current_metric_ at the end of their update_state() instead.
Definition at line 141 of file base_detector.h.
|
pure virtual |
Set detection threshold.
| threshold | New threshold value |
Implemented in espectre::HighAccuracyDetector, and espectre::LightweightDetector.
|
inlinevirtual |
Apply a detector-specific startup-calibrated threshold.
Reimplemented in espectre::LightweightDetector.
Definition at line 152 of file base_detector.h.
|
pure virtual |
Get current threshold.
Implemented in espectre::HighAccuracyDetector, and espectre::LightweightDetector.
|
pure virtual |
Get detector name for logging.
Implemented in espectre::HighAccuracyDetector, and espectre::LightweightDetector.
|
inlinevirtual |
Get the detector-specific automatic startup multiplier.
threshold = threshold_metric x factor. Matches the Python runtime's detector STARTUP_THRESHOLD_FACTOR convention, where threshold_metric comes from the shared startup calibrator.
Reimplemented in espectre::LightweightDetector.
Definition at line 171 of file base_detector.h.
|
inlinevirtual |
Whether startup calibration uses the consistency gate (threshold.h).
Enabled only for detectors with a tight quiet floor (l1_delta). Matches the Python runtime's detector STARTUP_GATE convention.
Reimplemented in espectre::LightweightDetector.
Definition at line 179 of file base_detector.h.
|
inlinevirtual |
Hook called immediately before startup calibration begins.
Reimplemented in espectre::LightweightDetector.
Definition at line 182 of file base_detector.h.
|
inlinevirtual |
Hook called when startup calibration completes successfully.
Detectors can freeze session-specific state here before the runtime performs its warm clear between calibration and steady-state detection.
Reimplemented in espectre::LightweightDetector.
Definition at line 190 of file base_detector.h.
|
virtual |
Configure low-pass filter.
| enabled | Whether to enable the filter |
| cutoff_hz | Cutoff frequency (5.0-20.0 Hz) |
Reimplemented in espectre::HighAccuracyDetector, and espectre::LightweightDetector.
|
virtual |
Configure Hampel filter.
| enabled | Whether to enable the filter |
| window_size | Window size (3-11) |
| threshold | MAD multiplier threshold |
Reimplemented in espectre::HighAccuracyDetector, and espectre::LightweightDetector.
|
virtual |
Clear turbulence buffer (cold restart).
Virtual so detectors with additional state (e.g. L1-Delta profile rings) can extend the cold clear.
Reimplemented in espectre::HighAccuracyDetector, and espectre::LightweightDetector.
|
inline |
Get turbulence buffer pointer.
Definition at line 231 of file base_detector.h.
|
inline |
Get number of valid samples in buffer.
Definition at line 236 of file base_detector.h.
|
inline |
Definition at line 237 of file base_detector.h.
|
inline |
Get configured window size.
Definition at line 242 of file base_detector.h.
| float espectre::BaseDetector::get_last_turbulence | ( | ) | const |
Get last turbulence value.
|
inline |
Check if low-pass filter is enabled.
Definition at line 252 of file base_detector.h.
|
inline |
Check if Hampel filter is enabled.
Definition at line 257 of file base_detector.h.
|
inlineprotected |
Drop the last evaluation result.
Anything that invalidates the window must also invalidate what was derived from it, or the next publish ships a metric computed from samples the detector no longer holds. Owned here so a detector cannot clear one half and forget the other.
Definition at line 268 of file base_detector.h.
|
protected |
|
inlineprotected |
Definition at line 275 of file base_detector.h.
|
protected |
Add turbulence value to buffer (with filtering).
|
staticprotected |
Allocate a zeroed float buffer on the heap.
Shared by the detectors so no feature helper puts a window-sized array on the CSI callback stack.
|
protected |
View the turbulence ring in chronological order.
Returns the ring itself while it is still filling (already in order), and the base-owned reorder buffer once it wraps. Returns nullptr when there is nothing to read or the reorder buffer could not be allocated.
| count | Receives the number of valid samples |
|
protected |
Definition at line 306 of file base_detector.h.
|
protected |
Definition at line 307 of file base_detector.h.
|
protected |
Definition at line 308 of file base_detector.h.
|
protected |
Definition at line 309 of file base_detector.h.
|
protected |
Definition at line 310 of file base_detector.h.
|
protected |
Definition at line 311 of file base_detector.h.
|
protected |
Definition at line 312 of file base_detector.h.
|
protected |
Definition at line 316 of file base_detector.h.
|
protected |
Definition at line 317 of file base_detector.h.
|
protected |
Definition at line 318 of file base_detector.h.
|
protected |
Definition at line 319 of file base_detector.h.
|
protected |
Definition at line 320 of file base_detector.h.
|
protected |
Definition at line 321 of file base_detector.h.
|
protected |
Definition at line 324 of file base_detector.h.
|
protected |
Definition at line 325 of file base_detector.h.