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 this->mark_failed(LOG_STR(
"Radio driver selection/allocation failed (see earlier log for details)"));
97#ifdef IOHOME_LR1121_FIRMWARE_UPDATE
101 this->run_lr1121_boot_time_bootloader_read_();
104 if (!this->
radio_->init()) {
107#ifdef IOHOME_LR1121_FIRMWARE_UPDATE
111 this->cache_lr1121_flash_verdict_();
114 this->mark_failed(LOG_STR(
"Radio hardware initialization failed (see earlier log for details)"));
118#ifdef IOHOME_LR1121_FIRMWARE_UPDATE
119 this->cache_lr1121_flash_verdict_();
139 *chip_name_out =
"LR1121";
141 ESP_LOGE(
detail::TAG,
"LR1121 requires busy_pin and dio1_pin (dio1_pin carries the chip's DIO9 IRQ line)");
144 auto *radio =
new (std::nothrow)
146 if (radio ==
nullptr)
147 ESP_LOGE(
detail::TAG,
"Failed to allocate LR1121 radio driver");
152 *chip_name_out =
"SX1262";
154 ESP_LOGE(
detail::TAG,
"SX1262 requires busy_pin and dio1_pin");
160 if (radio ==
nullptr)
161 ESP_LOGE(
detail::TAG,
"Failed to allocate SX1262 radio driver");
166 *chip_name_out =
"SX1276";
171 auto *radio =
new (std::nothrow)
173 if (radio ==
nullptr)
174 ESP_LOGE(
detail::TAG,
"Failed to allocate SX1276 radio driver");
178 *chip_name_out =
"unknown";
191 if (this->
radio_ ==
nullptr)
204 if (param ==
nullptr) {
205 ESP_LOGW(
detail::TAG,
"Unknown tuning number parameter: %s", name.c_str());
221 if (param ==
nullptr) {
222 ESP_LOGW(
detail::TAG,
"Unknown tuning select parameter: %s", name.c_str());
239 if (param ==
nullptr) {
240 ESP_LOGW(
detail::TAG,
"Unknown tuning number parameter: %s", name.c_str());
254 if (param ==
nullptr) {
255 ESP_LOGW(
detail::TAG,
"Unknown tuning select parameter: %s", name.c_str());
292 this->
poll_policy_.set_interval(device_id, poll_interval_ms);
296 uint32_t
const now = millis();
297 uint32_t
const backoff_ms = this->
poll_policy_.on_exchange_failed(device_id, auth_like, now);
298 if (backoff_ms > 0) {
300 "Background status poll backoff for device %s: delay=%" PRIu32
301 " ms auth_like=%s status_failures=%u auth_failures=%u",
302 device_id.c_str(), backoff_ms, YESNO(auth_like), this->
poll_policy_.get_status_poll_failures(device_id),
303 this->poll_policy_.get_auth_poll_failures(device_id));
316 this->
registry_.set_dimmable(device_id, dimmable);
320 this->
registry_.set_silent(device_id, silent);
334 if (this->
radio_->check_for_packet(packet))
358#ifdef IOHOME_LOCK_CHANNEL_HZ
359 if (!this->
busy_ && this->
radio_ !=
nullptr && this->
radio_->get_current_freq() != IOHOME_LOCK_CHANNEL_HZ)
360 this->
radio_->change_frequency(IOHOME_LOCK_CHANNEL_HZ);
371 if (this->
radio_->get_current_freq() !=
FREQ_CH2 && !this->radio_->reception_in_progress())
396 LOG_PIN(
" RST Pin: ", this->
rst_pin_);
406 if (this->
registry_.linked_remote_count() > 0) {
408 this->
registry_.for_each_linked_remote([](
const std::string &remote_id,
const std::vector<std::string> &devices) {
409 for (
const auto &device_id : devices)
410 ESP_LOGCONFIG(
"home_io_control",
" - remote %s -> device %s", remote_id.c_str(), device_id.c_str());
416 if (this->
radio_ !=
nullptr)
417 this->
radio_->dump_debug();
419#ifdef IOHOME_LR1121_FIRMWARE_UPDATE
420 this->dump_lr1121_firmware_update_debug_();
435 detail::TAG,
" - %s: node %s%s, class 0x%02X, acei 0x%02X%s, broadcast %s%s", identity.id.c_str(),
436 node_id_to_string(identity.node_id).c_str(), identity.node_id_derived ?
" (derived)" :
"",
449 snprintf(byte_hex,
sizeof(byte_hex),
"%02X",
static_cast<unsigned>(c));
450 classes += classes.empty() ?
"0x" :
" 0x";
453 ESP_LOGCONFIG(
detail::TAG,
" enroll: VELUX KLI gesture, 0x30 sweep -> %s", classes.c_str());
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 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_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.
Abstract radio driver for IO-Homecontrol.
LR1121 implementation of RadioDriver.
SX1262 implementation of RadioDriver.
SX1276 implementation of RadioDriver.
Internal helpers shared by the hub implementation .cpp files.
constexpr const char * TAG
Shared log tag for hub-level messages.
static constexpr uint8_t NODE_ID_SIZE
Device/node addresses are 3 bytes (e.g., "123ABC").
DeviceType
Device type identifiers reported by IO‑Homecontrol products.
@ UNKNOWN
Unknown/unspecified device.
static constexpr const char * TAG
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.
static constexpr uint32_t FREQ_CH2
Channel 2: 868.95 MHz (1W and 2W, TX channel).
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 TuningNumberParam * find_tuning_number(const std::string &name)
Look up a numeric tuning parameter by name; returns nullptr if unknown.
static constexpr uint8_t AES_KEY_SIZE
AES-128 key size.
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.
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.
One numeric tuning parameter: its wire name plus accessors over TuningConfig.
float(* get)(const TuningConfig &)
Read the current value as a float.
bool applies_to_radio
True if changes must be re-applied to the radio.
void(* set)(TuningConfig &, float)
Write a new value (narrowed to the field type).
One select tuning parameter: its wire name plus string accessors over TuningConfig.
std::string(* get)(const TuningConfig &)
Read the current option string.
bool(* set)(TuningConfig &, const std::string &)
Parse/apply an option; false if unparseable.
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.