Home IO Control
ESPHome add-on for IO-Homecontrol devices
Toggle main menu visibility
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
11
namespace
esphome
{
12
namespace
home_io_control
{
13
14
static
const
char
*
const
TAG
=
"home_io_control.radio"
;
15
16
namespace
{
17
18
constexpr
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
23
void
RadioDriver::reset_hardware_
() {
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
32
std::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
esphome::home_io_control::RadioDriver::rst_pin_
InternalGPIOPin * rst_pin_
Definition
radio_interface.h:495
esphome::home_io_control::RadioDriver::reset_hardware_
void reset_hardware_()
Shared hardware reset sequence for chips with an active-low RST pin.
Definition
radio_interface.cpp:23
esphome::home_io_control::RadioDriver::change_frequency
virtual void change_frequency(uint32_t freq_hz)=0
Change the carrier frequency using fast hop (no standby transition needed).
esphome::home_io_control::RadioDriver::cca_retune_logged_
bool cca_retune_logged_
The first clear-channel retune's cost has been logged.
Definition
radio_interface.h:500
esphome::home_io_control::RadioDriver::channel_busy_level_
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().
Definition
radio_interface.cpp:32
esphome::home_io_control::RadioDriver::read_rssi
virtual int16_t read_rssi()=0
Read instantaneous RSSI (in dBm) on the current channel, while in RX mode.
esphome::home_io_control::RadioDriver::current_freq_
uint32_t current_freq_
Definition
radio_interface.h:493
esphome::home_io_control
Definition
device_registry.cpp:15
esphome::home_io_control::TAG
static constexpr const char * TAG
Definition
device_registry.cpp:17
esphome::home_io_control::TAG
static const char *const TAG
Definition
radio_interface.cpp:14
esphome
Definition
device_registry.cpp:14
radio_interface.h
Radio abstraction layer for IO-Homecontrol.
esphome::home_io_control::RadioTxConfig
Configuration for transmitting a packet: carrier frequency, preamble length, wake-up level and clear-...
Definition
radio_interface.h:111
esphome::home_io_control::RadioTxConfig::freq_hz
uint32_t freq_hz
Carrier frequency in Hz.
Definition
radio_interface.h:112
esphome::home_io_control::RadioTxConfig::cca_threshold_dbm
std::optional< int16_t > cca_threshold_dbm
If set, send only if the energy on freq_hz, measured right before the first transmitted symbol,...
Definition
radio_interface.h:120
components
home_io_control
radio_interface.cpp
Generated by
1.18.0