Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
radio_interface.cpp
Go to the documentation of this file.
1/// @file radio_interface.cpp
2/// @brief Implementation of non-inline RadioDriver methods.
3/// @ingroup hioc_radio
4
5#include "radio_interface.h"
6#include "esphome/core/application.h"
7#include "esphome/core/log.h"
8
9#include <cinttypes>
10
11namespace esphome {
12namespace home_io_control {
13
14static const char *const TAG = "home_io_control.radio";
15
16namespace {
17
18constexpr uint32_t RADIO_RESET_PULSE_DELAY_MS =
19 10; ///< Reset low/high pulse used by both radio drivers during hardware reset.
20
21} // namespace
22
24 if (this->rst_pin_ != nullptr) {
25 this->rst_pin_->digital_write(false);
26 delay(RADIO_RESET_PULSE_DELAY_MS);
27 this->rst_pin_->digital_write(true);
28 delay(RADIO_RESET_PULSE_DELAY_MS);
29 }
30}
31
32std::optional<int16_t> RadioDriver::channel_busy_level_(const RadioTxConfig &tx_config, uint32_t settle_us) {
33 if (!tx_config.cca_threshold_dbm.has_value())
34 return std::nullopt;
35 // The idle receiver hops, so it is usually on another channel than the one about to be used:
36 // measure where the frame will go, not where the receiver happens to be.
37 if (this->current_freq_ != tx_config.freq_hz) {
38 uint32_t const start_us = micros();
39 this->change_frequency(tx_config.freq_hz);
40 delayMicroseconds(settle_us);
41 if (!this->cca_retune_logged_) {
42 this->cca_retune_logged_ = true;
43 ESP_LOGD(TAG, "Clear-channel check retuned to %" PRIu32 " Hz: %" PRIu32 " us including %" PRIu32 " us settle",
44 tx_config.freq_hz, micros() - start_us, settle_us);
45 }
46 }
47 int16_t const level = this->read_rssi();
48 if (level >= *tx_config.cca_threshold_dbm)
49 return level;
50 return std::nullopt;
51}
52
53} // namespace home_io_control
54} // namespace esphome
void reset_hardware_()
Shared hardware reset sequence for chips with an active-low RST pin.
virtual void change_frequency(uint32_t freq_hz)=0
Change the carrier frequency using fast hop (no standby transition needed).
bool cca_retune_logged_
The first clear-channel retune's cost has been logged.
std::optional< int16_t > channel_busy_level_(const RadioTxConfig &tx_config, uint32_t settle_us)
The clear-channel check a driver runs at the top of send_packet().
virtual int16_t read_rssi()=0
Read instantaneous RSSI (in dBm) on the current channel, while in RX mode.
static constexpr const char * TAG
static const char *const TAG
Radio abstraction layer for IO-Homecontrol.
Configuration for transmitting a packet: carrier frequency, preamble length, wake-up level and clear-...
uint32_t freq_hz
Carrier frequency in Hz.
std::optional< int16_t > cca_threshold_dbm
If set, send only if the energy on freq_hz, measured right before the first transmitted symbol,...