32constexpr uint32_t BLOCKING_WARNING_THRESHOLD_MS =
60 this->warn_if_blocking_over_ = BLOCKING_WARNING_THRESHOLD_MS;
61#ifdef IOHOME_UNSAFE_LOG_KEY_MATERIAL
65 ESP_LOGE(
detail::TAG,
"########################################");
66 ESP_LOGE(
detail::TAG,
"IOHOME_UNSAFE_LOG_KEY_MATERIAL IS ENABLED -- FRAME LOGS EXPOSE YOUR SYSTEM KEY");
67 ESP_LOGE(
detail::TAG,
"This build is NOT safe to run normally or share logs from. Rebuild without this");
68 ESP_LOGE(
detail::TAG,
"flag as soon as you are done capturing.");
69 ESP_LOGE(
detail::TAG,
"########################################");
75 this->mark_failed(LOG_STR(
"Invalid node_id or system_key configuration"));
89 const char *chip_name_for_log =
nullptr;
91 if (this->
radio_ ==
nullptr) {
93 "' (a required pin is missing, the type is unrecognized, or allocation failed)";
95 this->mark_failed(LOG_STR(
"Radio driver setup failed (see 'Radio setup failed' in the config dump)"));
99#ifdef IOHOME_LR1121_FIRMWARE_UPDATE
103 this->run_lr1121_boot_time_bootloader_read_();
110 driver_reason !=
nullptr ? driver_reason :
"driver init failed without a recorded cause";
113#ifdef IOHOME_LR1121_FIRMWARE_UPDATE
117 this->cache_lr1121_flash_verdict_();
120 this->mark_failed(LOG_STR(
"Radio hardware initialization failed (see 'Radio setup failed' in the config dump)"));
124#ifdef IOHOME_LR1121_FIRMWARE_UPDATE
125 this->cache_lr1121_flash_verdict_();
146 *chip_name_out =
"LR1121";
148 ESP_LOGE(
detail::TAG,
"LR1121 requires busy_pin and dio1_pin (dio1_pin carries the chip's DIO9 IRQ line)");
151 auto *radio =
new (std::nothrow)
153 if (radio ==
nullptr)
154 ESP_LOGE(
detail::TAG,
"Failed to allocate LR1121 radio driver");
159 *chip_name_out =
"SX1262";
161 ESP_LOGE(
detail::TAG,
"SX1262 requires busy_pin and dio1_pin");
164 auto *radio =
new (std::nothrow)
167 if (radio ==
nullptr)
168 ESP_LOGE(
detail::TAG,
"Failed to allocate SX1262 radio driver");
173 *chip_name_out =
"SX1276";
178 auto *radio =
new (std::nothrow)
180 if (radio ==
nullptr)
181 ESP_LOGE(
detail::TAG,
"Failed to allocate SX1276 radio driver");
185 *chip_name_out =
"unknown";
198 if (this->
radio_ ==
nullptr)
225 if (param ==
nullptr) {
226 ESP_LOGW(
detail::TAG,
"Unknown tuning number parameter: %s", name.c_str());
242 if (param ==
nullptr) {
243 ESP_LOGW(
detail::TAG,
"Unknown tuning select parameter: %s", name.c_str());
260 if (param ==
nullptr) {
261 ESP_LOGW(
detail::TAG,
"Unknown tuning number parameter: %s", name.c_str());
275 if (param ==
nullptr) {
276 ESP_LOGW(
detail::TAG,
"Unknown tuning select parameter: %s", name.c_str());
317 uint32_t
const now = millis();
319 if (backoff_ms > 0) {
321 "Background status poll backoff for device %s: delay=%" PRIu32
322 " ms auth_like=%s status_failures=%u auth_failures=%u",
324 this->poll_policy_.get_auth_poll_failures(device_id));
379#ifdef IOHOME_LOCK_CHANNEL_HZ
421 this->tuning_.normal_start_preamble_from_yaml ?
"set in YAML" :
"from the radio driver");
424#ifdef IOHOME_UNSAFE_LOG_KEY_MATERIAL
427 ESP_LOGE(
detail::TAG,
" IOHOME_UNSAFE_LOG_KEY_MATERIAL IS ENABLED -- FRAME LOGS EXPOSE YOUR SYSTEM KEY");
428 ESP_LOGE(
detail::TAG,
" Not safe to share logs from: rebuild without this flag as soon as you are done capturing.");
434 LOG_PIN(
" RST Pin: ", this->
rst_pin_);
445 ESP_LOGCONFIG(
detail::TAG,
" Low-power wake belief: %s",
451 for (
const auto &device_id : devices)
452 ESP_LOGCONFIG(
"home_io_control",
" - remote %s -> device %s", remote_id.c_str(), device_id.c_str());
458 if (this->
radio_ !=
nullptr) {
463 ESP_LOGE(
detail::TAG,
" Radio failed after setup: %s", reason !=
nullptr ? reason :
"no recorded cause");
469#ifdef IOHOME_LR1121_FIRMWARE_UPDATE
470 this->dump_lr1121_firmware_update_debug_();
489 detail::TAG,
" - %s: node %s%s, class 0x%02X, acei 0x%02X%s, broadcast %s%s, power %s%s",
490 identity.id.c_str(),
node_id_to_string(identity.node_id).c_str(), identity.node_id_derived ?
" (derived)" :
"",
505 snprintf(byte_hex,
sizeof(byte_hex),
"%02X",
static_cast<unsigned>(c));
506 classes += classes.empty() ?
"0x" :
" 0x";
509 ESP_LOGCONFIG(
detail::TAG,
" enroll: VELUX KLI gesture, 0x30 sweep -> %s", classes.c_str());
void set_dimmable(const std::string &device_id, bool dimmable)
Set a device's dimmable flag (see IoDevice::dimmable).
size_t linked_remote_count() const
void set_silent(const std::string &device_id, bool silent)
Select a device's travel profile.
void notify(const std::string &device_id)
Invoke all registered callbacks for device_id.
IoDevice * get(const std::string &device_id)
Retrieve a registered device by ID.
void for_each_linked_remote(const std::function< void(const std::string &, const std::vector< std::string > &)> &fn) const
Invoke fn(remote_id, device_id_list) for every linked-remote entry.
void add(const std::string &device_id)
Register a device by ID with default metadata (UNKNOWN type, subtype 0, not inverted).
void maybe_hop()
Hop only if the minimum dwell has elapsed and no frame is currently arriving on this channel — RadioD...
bool transmit_frame(const IoFrame &frame, uint32_t freq, uint16_t preamble)
Transmit a raw IoFrame with LBT and the given preamble length.
bool authenticate_request(const IoFrame &request, uint32_t freq)
Authenticate an inbound device command via 0x3C challenge / 0x3D HMAC.
ExchangeOutcome send_and_receive(const IoFrame &request, IoFrame &response, uint32_t freq, uint8_t max_tries=EXCHANGE_RETRY_COUNT, uint16_t request_preamble_override=0)
Execute an outbound authenticated exchange with retry.
void reset_hop_timestamp()
Reset the hop-timer (called after radio init in hub setup()).
void hop_frequency(uint32_t skip_freq=0)
Advance the receiver one step along the protocol's channel rotation (CH1→CH2→CH3→CH1).
InternalGPIOPin * fem_en_pin_
Front-end module enable.
InternalGPIOPin * fem_pa_pin_
Front-end module PA switch.
void dump_oneway_controllers_config_() const
Emit the 1W controller identities to the config dump — node, class, and the resolved ACEI / broadcast...
InternalGPIOPin * dio4_pin_
SX1276 DIO4 preamble detect (optional).
InternalGPIOPin * dio1_pin_
SX1262 DIO1 interrupt; also carries the LR1121's DIO9 IRQ line.
void dump_config() override
Dump configuration and radio debug info to the log.
void update_tuning_select(const std::string &name, const std::string &value)
Receive a select tuning update from a HA select entity.
InternalGPIOPin * rst_pin_
virtual IoDevice * get_device(const std::string &device_id)
Retrieve a device by ID; returns nullptr if not found.
virtual void queue_request_device_status(const std::string &device_id)
Queue an async status request; returns immediately, executed in loop().
void update_tuning_number(const std::string &name, float value)
Receive a numeric tuning update from a HA number entity.
virtual void add_device(const std::string &device_id)
Add a device to the registry by device ID only (undeclared/legacy path).
InternalGPIOPin * vfem_pin_
Front-end module power.
TuningConfig tuning_
Runtime tuning overrides.
ExchangeOutcome send_and_receive_(const IoFrame &request, IoFrame &response, uint32_t freq, uint8_t max_tries=EXCHANGE_RETRY_COUNT)
Main request/response exchange with retry and automatic authentication.
virtual void set_device_status_poll_interval(const std::string &device_id, uint32_t poll_interval_ms)
Configure the optional follow-up polling interval for a registered device.
void process_pending_operation_()
Pop next pending operation from the queue and execute it (set position, request status,...
StatusPollPolicy poll_policy_
void hop_frequency_()
Delegate channel hop to ExchangeEngine (which owns last_hop_us_).
virtual void set_device_dimmable(const std::string &device_id, bool dimmable)
Set a device's dimmable flag (see IoDevice::dimmable).
float get_tuning_number_value(const std::string &name) const
Current value of a numeric tuning parameter, used to seed a HA number entity on boot.
bool defer_background_poll_() const
Whether loop() should skip dispatching the queue this iteration because the pending work is a backgro...
void resolve_start_preamble_default_()
Resolve normal_start_preamble from the driver when YAML did not set it (ADR 0042).
void loop() override
Main loop: process pending operations and drive radio state machine.
void schedule_background_poll_backoff_(const std::string &device_id, bool auth_like)
Apply backoff after a failed background status poll and log the result.
OneWayTransmitter oneway_transmitter_
Owns the 1W controller identities, their rolling-sequence counters and the transmit burst.
std::string radio_failure_reason_
Why setup() gave up on the radio, or empty.
std::string radio_type_
"sx1276", "sx1262", or "lr1121"; required by the YAML schema.
uint8_t system_key_[AES_KEY_SIZE]
bool key_extraction_awaiting_reply_() const
True while the key-extraction responder is mid-attempt and still within its bounded CH2-hold window.
RadioDriver * select_and_construct_radio_(const char **chip_name_out)
Select and construct the radio driver named by the required radio_type config field.
bool transmit_frame_(const IoFrame &frame, uint32_t freq, uint16_t preamble)
Transmit a raw IoFrame on the current frequency with given preamble length.
bool radio_test_mode_
When true, loop() is suspended for loopback testing.
ExchangeEngine exchange_engine_
Owns all authenticated exchange and LBT/hop logic.
const OneWayControllerRegistry & oneway_controllers() const
virtual void set_device_silent(const std::string &device_id, bool silent)
Select a device's travel profile at runtime (see IOHomeCoverSilentSwitch).
InternalGPIOPin * dio0_pin_
SX1276 DIO0 interrupt.
std::vector< OneWayCommandReportFn > oneway_report_callbacks_
Subscribers to the per-command 1W report; one per "Last 1W Command" sensor.
void notify_device_update_(const std::string &id)
Fire all registered device update callbacks for the given device ID.
std::string system_key_str_
std::string get_tuning_select_value(const std::string &name) const
Current option string of a select tuning parameter, used to seed a HA select entity on boot.
void setup() override
Initialize hardware (radio and device registry).
uint8_t node_id_[NODE_ID_SIZE]
uint8_t tcxo_voltage_
SX1262/LR1121 TCXO voltage setting (default 1.8 V).
void process_received_packet_(const RadioRxPacket &packet)
Parse a received frame, merge supported device state or metadata, and notify callbacks.
bool authenticate_request_(const IoFrame &request, uint32_t freq)
Handle an inbound authenticated command from a device (status updates, etc.).
InternalGPIOPin * busy_pin_
SX1262/LR1121 BUSY pin.
void register_management_actions_()
Register hub-level Home Assistant actions; called from setup().
void apply_tuning_to_radio_()
Apply the current tuning configuration to the active radio driver.
FemProfile fem_profile_
Which FEM part fem_pa_pin_ belongs to, if any.
void setup()
Open each registered identity's persistent sequence counter.
void set_command_report_callback(OneWayCommandReportFn callback)
Register the callback that receives a report after every command attempt.
Abstract radio driver for IO-Homecontrol.
virtual void dump_front_end()
Optional board front-end-module (external PA/LNA) summary emitted from dump_config,...
uint32_t get_current_freq() const
Get the current RF frequency.
virtual uint16_t default_start_preamble() const
Default preamble for a directed start frame, when the user has not set normal_start_preamble in YAML.
virtual void change_frequency(uint32_t freq_hz)=0
Change the carrier frequency using fast hop (no standby transition needed).
const char * failure_reason() const
Short, human-readable reason the driver latched is_failed, or nullptr if it has not.
virtual bool is_failed() const
Returns true if the radio failed to initialize or encountered a fatal error.
virtual bool init()=0
Initialize the radio hardware. Returns true on success.
virtual void apply_tuning(const TuningConfig &tuning)
Apply runtime tuning parameters to the driver.
virtual void dump_debug()
Optional chip-specific diagnostics emitted from dump_config.
virtual bool check_for_packet(RadioRxPacket &packet)=0
Non-blocking check for a received packet.
RadioLR1121(SpiAccess *spi, InternalGPIOPin *rst_pin, InternalGPIOPin *irq_pin, InternalGPIOPin *busy_pin, uint8_t tx_power, uint8_t tcxo_voltage_code)
RadioSX1262(SpiAccess *spi, InternalGPIOPin *rst_pin, InternalGPIOPin *dio1_pin, InternalGPIOPin *busy_pin, uint8_t tx_power, uint8_t tcxo_voltage, InternalGPIOPin *fem_en_pin=nullptr, InternalGPIOPin *vfem_pin=nullptr, InternalGPIOPin *fem_pa_pin=nullptr, FemProfile fem_profile=FemProfile::NONE)
RadioSX1276(SpiAccess *spi, InternalGPIOPin *rst_pin, InternalGPIOPin *dio0_pin, InternalGPIOPin *dio4_pin, uint8_t tx_power, uint8_t pa_pin)
void set_interval(const std::string &device_id, uint32_t interval_ms)
Set the configured follow-up poll interval (ms; 0 = legacy one-shot settle only).
uint32_t on_exchange_failed(const std::string &device_id, bool auth_like, uint32_t now)
Record a failed background poll; apply backoff or clear tracking if the window expired.
uint8_t get_status_poll_failures(const std::string &device_id) const
std::optional< std::string > pop_due_device(uint32_t now)
Return and consume the first device whose next_update is overdue.
Helpers shared only by the hub's own implementation files (hub_*.cpp).
constexpr const char * TAG
Shared log tag for hub-level messages.
DeviceType
Device type identifiers reported by IO‑Homecontrol products.
@ UNKNOWN
Unknown/unspecified device.
static constexpr const char * TAG
OneWayPowerClass effective_power_class(const OneWayControllerIdentity &identity)
The burst shape this identity actually transmits with.
std::array< DeviceType, 3 > effective_enrollment_classes(const OneWayControllerIdentity &identity)
The device classes this identity's 0x30 enrollment sweep will actually target.
uint8_t effective_execute_acei(const OneWayControllerIdentity &identity)
The ACEI byte a given identity will put on air for a 1W EXECUTE frame.
ExchangeOutcome
Authenticated exchange engine — outbound and inbound protocol flows.
std::string tuning_config_full_snapshot(const TuningConfig &cfg)
Format the current tuning configuration as a full one-line snapshot.
const TuningSelectParam * find_tuning_select(const std::string &name)
Look up a select tuning parameter by name; returns nullptr if unknown.
std::string tuning_update_log_line(const std::string &name, const std::string &value)
Format a single tuning update for the log.
std::string node_id_to_string(const uint8_t id[NODE_ID_SIZE])
Format a 3‑byte node ID as a 6‑character uppercase hex string.
const char * oneway_power_class_name(OneWayPowerClass power_class)
Human-readable name for a OneWayPowerClass, as it appears in the boot log.
const TuningNumberParam * find_tuning_number(const std::string &name)
Look up a numeric tuning parameter by name; returns nullptr if unknown.
bool has_power_class_override(const OneWayControllerIdentity &identity)
Whether this identity's burst shape comes from an explicit low_power: rather than the profile.
OneWayWireProfile resolve_oneway_wire_profile(uint8_t manufacturer)
Resolve an identity's 1W wire profile from its manufacturer byte.
bool has_execute_acei_override(const OneWayControllerIdentity &identity)
Whether this identity's ACEI comes from an explicit execute_acei: rather than the profile.
bool hex_to_bytes(const std::string &hex, uint8_t *out, uint8_t len)
Convert a hex string (e.g., "123ABC") to a byte array.
static const char *const TAG
LR1121 radio driver for IO-Homecontrol.
SX1262 radio driver for IO-Homecontrol.
SX1276 radio driver for IO-Homecontrol.
YAML-declared device metadata for registration; defaults match an undeclared device.
Runtime state of a paired IO‑Homecontrol device.
Parsed IO‑Homecontrol frame (CTRL0/1 + addresses + command + data).
What a 1W command attempt did — the only feedback this feature can ever produce.
Vendor-divergent 1W wire settings for a controller identity.
bool profile_is_a_guess
true when manufacturer matched no known 1W wire profile.
EnrollGesture enroll_gesture
Which enrollment gesture this manufacturer's actuators expect.
Raw packet received from the radio.
bool active
True when the YAML tuning: block is present.
uint16_t normal_start_preamble
Preamble for a directed start frame to a non-low-power target.
bool low_power_wake_belief
Order a low_power device's start-frame tries by its wake belief (short preamble first when it is beli...
bool normal_start_preamble_from_yaml
True when normal_start_preamble: appeared in YAML.
One numeric tuning parameter: its wire name plus accessors over TuningConfig.
void(*) set(TuningConfig &, float)
Write a new value (narrowed to the field type).
bool applies_to_radio
True if changes must be re-applied to the radio.
float(*) get(const TuningConfig &)
Read the current value as a float.
One select tuning parameter: its wire name plus string accessors over TuningConfig.
bool(*) set(TuningConfig &, const std::string &)
Parse/apply an option; false if unparseable.
std::string(*) get(const TuningConfig &)
Read the current option string.
bool applies_to_radio
True if changes must be re-applied to the radio.
Runtime tuning configuration for pairing and radio diagnostics.
Table-driven registry of runtime tuning parameters.