35 SUB_NUMBER(motion_on_hits)
36 SUB_NUMBER(motion_off_hits)
39 SUB_SELECT(traffic_mode)
40 SUB_SELECT(detection_algorithm)
41 SUB_SELECT(csi_sample_spacing)
48 void setup()
override;
50 void dump_config()
override;
51 void on_shutdown()
override;
55 void set_detection_algorithm(::espectre::DetectionAlgorithm
value) {
56 this->runtime_.config().detection_algorithm =
value;
58 void set_csi_capture_profile(::espectre::CsiCapturePolicy
value) {
59 this->runtime_.config().csi_capture_policy =
value;
61 void set_traffic_generator_mode(::espectre::TrafficGeneratorMode
value) {
62 this->runtime_.config().traffic_generator_mode =
value;
64 void set_traffic_generator_target_ip(
const std::string &
value) {
65 this->runtime_.config().traffic_generator_target_ip =
value;
67 void set_traffic_generator_target_mac(
const std::string &
value) {
68 this->runtime_.config().traffic_generator_target_mac =
value;
70 void set_csi_sample_spacing(::espectre::TemporalCsiSpacing
value) {
71 this->runtime_.config().csi_sample_spacing =
value;
73 void set_csi_traffic_multicast_group(
const std::string &
value) {
74 this->runtime_.config().csi_traffic_multicast_group =
value;
76 void set_motion_on_hits(uint8_t
value) { this->runtime_.config().motion_on_hits =
value; }
77 void set_motion_off_hits(uint8_t
value) { this->runtime_.config().motion_off_hits =
value; }
78 void set_window_size_ms(
uint32_t value) { this->runtime_.config().window_size_ms =
value; }
79 void set_csi_target_pps(
uint32_t value) { this->runtime_.config().csi_target_pps =
value; }
80 void set_evaluation_interval_ms(
uint32_t value) { this->runtime_.config().evaluation_interval_ms =
value; }
81 void set_lowpass_enabled(
bool value) { this->runtime_.config().lowpass_enabled =
value; }
82 void set_lowpass_cutoff(
float value) { this->runtime_.config().lowpass_cutoff =
value; }
83 void set_hampel_enabled(
bool value) { this->runtime_.config().hampel_enabled =
value; }
84 void set_hampel_window(uint8_t
value) { this->runtime_.config().hampel_window =
value; }
85 void set_hampel_threshold(
float value) { this->runtime_.config().hampel_threshold =
value; }
86 void set_wifi_band_policy(::espectre::WifiBandPolicy
value) { this->runtime_.config().wifi_band_policy =
value; }
88 void recalibrate() { this->recalibrate_pending_ =
true; }
90 void request_threshold(
float value) { this->pending_threshold_ =
value; }
91 void request_motion_on_hits(
float value) { this->pending_motion_on_hits_ =
static_cast<uint8_t
>(std::lround(
value)); }
92 void request_motion_off_hits(
float value) {
93 this->pending_motion_off_hits_ =
static_cast<uint8_t
>(std::lround(
value));
97 void request_traffic_generator_mode(::espectre::TrafficGeneratorMode
mode) { this->pending_traffic_mode_ =
mode; }
99 void request_traffic_generator_mode(
const char *name);
101 void request_detection_algorithm(
const char *name);
103 void request_csi_sample_spacing(
const char *name);
106 void request_sensing(
bool enabled) { this->pending_sensing_ = enabled; }
109#ifdef USE_BINARY_SENSOR
110 SUB_BINARY_SENSOR(motion)
111 SUB_BINARY_SENSOR(calibrating)
117 const ::espectre::RuntimeDiagnosticsSample *diagnostics_sample()
const {
return this->runtime_.diagnostics_sample(); }
121 void on_live_telemetry(const ::espectre::RuntimeSnapshot &snapshot)
override { this->movement_pending_ =
true; }
122 void on_calibration_finished(const ::espectre::RuntimeSnapshot &snapshot,
bool success)
override;
123 void on_runtime_fault(
const char *
message)
override;
124 void start_runtime_();
125 void schedule_restart_();
126 void invalidate_sensing_();
129 void apply_pending_traffic_mode_();
130 void publish_traffic_mode_();
133 void restore_controls_();
134 void apply_pending_controls_();
135 void publish_controls_();
137 static constexpr uint32_t RESTART_DELAY_MS = 30000;
139 ::espectre::RuntimeFrontendController runtime_;
144 float pending_threshold_{NAN};
146 uint8_t pending_motion_on_hits_{0};
147 uint8_t pending_motion_off_hits_{0};
153 optional<::espectre::TrafficGeneratorMode> pending_traffic_mode_;
154 optional<::espectre::DetectionAlgorithm> pending_detection_algorithm_;
155 optional<::espectre::TemporalCsiSpacing> pending_csi_sample_spacing_;
158 optional<bool> pending_sensing_;
160 bool recalibrate_pending_{
false};
161 bool movement_pending_{
false};
163 bool motion_state_{
false};
164 bool calibrating_state_{
false};
165 bool calibrating_published_{
false};
166 bool runtime_fault_{
false};
167 bool running_{
false};
168 bool restart_pending_{
false};
169 bool calibrated_{
false};
170 bool roaming_suppressed_{
false};