23constexpr size_t HEX_BYTE_STR_SIZE = 8;
25constexpr size_t HEX_ADDR_STR_SIZE = 16;
27constexpr size_t BANDWIDTH_STR_SIZE = 16;
67constexpr float SX1262_BW_FALLBACK_KHZ = 117.3F;
68constexpr float SX1276_BW_FALLBACK_KHZ = 41.7F;
69constexpr float LR1121_BW_FALLBACK_KHZ = 117.3F;
71template<
size_t N>
constexpr size_t bw_count(
const BandwidthOption (& )[N]) {
return N; }
76 for (
size_t i = 0; i < n; ++i) {
77 if (table[i].reg == reg)
84 char buf[BANDWIDTH_STR_SIZE];
85 snprintf(buf,
sizeof(buf),
"%.1f", khz);
86 return std::string(buf);
90 std::string normalized = value;
92 normalized.erase(std::remove_if(normalized.begin(), normalized.end(), ::isspace), normalized.end());
93 for (
char &c : normalized)
94 c =
static_cast<char>(std::tolower(
static_cast<unsigned char>(c)));
95 if (normalized.size() > 3 && normalized.ends_with(
"khz"))
96 normalized.resize(normalized.size() - 3);
98 for (
size_t i = 0; i < n; ++i) {
99 char one_decimal[BANDWIDTH_STR_SIZE];
100 char truncated[BANDWIDTH_STR_SIZE];
101 snprintf(one_decimal,
sizeof(one_decimal),
"%.1f", table[i].khz);
102 snprintf(truncated,
sizeof(truncated),
"%d",
static_cast<int>(table[i].khz));
103 if (normalized == one_decimal || normalized == truncated)
114 return bandwidth_to_khz(SX1262_BANDWIDTHS, bw_count(SX1262_BANDWIDTHS),
static_cast<uint8_t
>(bw),
115 SX1262_BW_FALLBACK_KHZ);
129 return bandwidth_to_khz(SX1276_BANDWIDTHS, bw_count(SX1276_BANDWIDTHS),
static_cast<uint8_t
>(bw),
130 SX1276_BW_FALLBACK_KHZ);
144 return bandwidth_to_khz(LR1121_BANDWIDTHS, bw_count(LR1121_BANDWIDTHS),
static_cast<uint8_t
>(bw),
145 LR1121_BW_FALLBACK_KHZ);
159 std::string normalized = value;
160 for (
char &c : normalized)
161 c =
static_cast<char>(std::tolower(
static_cast<unsigned char>(c)));
162 if (normalized ==
"0x28" || normalized ==
"discover")
164 if (normalized ==
"0x2a" || normalized ==
"discover_spe")
166 if (normalized ==
"0x2e" || normalized ==
"discover_alt")
172 char buf[HEX_BYTE_STR_SIZE];
173 snprintf(buf,
sizeof(buf),
"0x%02X",
static_cast<uint8_t
>(cmd));
174 return std::string(buf);
179 for (
size_t i = 0; i < commands.size(); ++i) {
193 if (!destination_auto)
209 if (destination_auto)
211 char buf[HEX_ADDR_STR_SIZE];
212 snprintf(buf,
sizeof(buf),
"0x%02X%02X%02X", destination[0], destination[1], destination[2]);
213 return std::string(buf);
217 if (!payload_enabled)
219 char buf[HEX_BYTE_STR_SIZE];
220 snprintf(buf,
sizeof(buf),
"0x%02X", payload);
221 return std::string(buf);
225 return "Tuning updated via HA: " + name +
"=" + value;
250 const float current = p->get(cfg);
251 if (current != p->get(DEFAULTS))
252 result +=
" " + std::string(p->name) +
"=" + std::to_string(
static_cast<int64_t
>(current));
266 result +=
" pairing_discovery_payload=" +
280 return "Tuning: defaults active";
281 return "Tuning overrides active:" + result;
BandwidthTableView lr1121_bandwidth_table()
The LR1121 RX-bandwidth option table (see sx1262_bandwidth_table()).
std::string discovery_commands_to_csv(const std::vector< DiscoveryCommand > &commands)
Format the ordered discovery command list as a UI/preset option string.
static constexpr uint8_t CMD_DISCOVER_REQ
Broadcast discovery request.
static constexpr uint8_t NODE_ID_SIZE
Device/node addresses are 3 bytes (e.g., "123ABC").
std::optional< LR1121RxBandwidth > lr1121_bandwidth_from_string(const std::string &value)
Convert a YAML LR1121 bandwidth string to the enum value.
SX1262RxBandwidth
Valid SX1262 RX bandwidth options (kHz register values).
@ BW_39_0_KHZ
39.0 kHz — narrowest; closest to the SX1276's validated 41.7 kHz.
@ BW_58_6_KHZ
58.6 kHz — default; the narrowest value validated on real hardware here.
@ BW_46_9_KHZ
46.9 kHz — narrow.
@ BW_78_2_KHZ
78.2 kHz — just above the ~77 kHz Carson figure for this waveform.
@ BW_117_3_KHZ
117.3 kHz — the former default.
@ BW_187_2_KHZ
187.2 kHz — widest selectable option.
const TuningNumberParam * tuning_number_params_end()
std::string discovery_payload_to_string(bool payload_enabled, uint8_t payload)
Format a payload option for YAML/logs.
std::optional< DiscoveryCommand > discovery_command_from_string(const std::string &value)
Parse a discovery command string (e.g., "0x28") into the enum.
static constexpr uint8_t CMD_DISCOVER_ALT_REQ
Alternate discovery.
LR1121RxBandwidth
Valid LR1121 RX bandwidth options (register values).
@ BW_39_0_KHZ
39.0 kHz — narrowest; close to SX1276's validated 41.7 kHz default.
@ BW_46_9_KHZ
46.9 kHz — narrow.
@ BW_156_2_KHZ
156.2 kHz — wider tolerance for LO offset.
@ BW_117_3_KHZ
117.3 kHz — default.
@ BW_187_2_KHZ
187.2 kHz — widest selectable option.
std::string lr1121_bandwidth_to_string(LR1121RxBandwidth bw)
Format an LR1121 bandwidth enum as its YAML/UI option string (bare kHz number).
std::string tuning_config_snapshot(const TuningConfig &cfg)
Format the current tuning configuration as a one-line YAML-compatible snapshot.
std::optional< SX1262RxBandwidth > sx1262_bandwidth_from_string(const std::string &value)
Convert a YAML bandwidth string to the enum value.
std::string sx1276_bandwidth_to_string(SX1276RxBandwidth bw)
Format an SX1276 bandwidth enum as its YAML/UI option string (bare kHz number).
float lr1121_bandwidth_to_khz(LR1121RxBandwidth bw)
Convert an LR1121 bandwidth enum to the numeric kHz value used in YAML/logs.
std::string discovery_commands_to_string(const std::vector< DiscoveryCommand > &commands)
Format the ordered discovery command list for logs.
std::string bandwidth_to_string(float khz)
Format a kHz value as its YAML/UI option string (bare number, one decimal, e.g. "117....
const TuningNumberParam * tuning_number_params_begin()
std::string tuning_config_full_snapshot(const TuningConfig &cfg)
Format the current tuning configuration as a full one-line snapshot.
float sx1262_bandwidth_to_khz(SX1262RxBandwidth bw)
Convert a bandwidth enum to the numeric kHz value used in YAML/logs.
static constexpr uint8_t CMD_DISCOVER_SPE_REQ
Broadcast roll-call answered by every device that already holds this controller's system key,...
std::string sx1262_bandwidth_to_string(SX1262RxBandwidth bw)
Format a bandwidth enum as its YAML/UI option string (bare kHz number, e.g.
BandwidthTableView sx1262_bandwidth_table()
The SX1262 RX-bandwidth option table.
std::string tuning_update_log_line(const std::string &name, const std::string &value)
Format a single tuning update for the log.
std::optional< uint8_t > bandwidth_from_string(const BandwidthOption *table, size_t n, const std::string &value)
Parse a YAML/UI bandwidth string against a table, returning the matching register byte.
DiscoveryCommand
Discovery request command codes.
@ DISCOVER_SPE
SPE roll-call request (self-authenticating; see CMD_DISCOVER_SPE_REQ).
@ DISCOVER
Standard broadcast discovery request (to 0x00003B).
@ DISCOVER_ALT
Alternate broadcast discovery (to 0x00003F), with optional payload byte.
float sx1276_bandwidth_to_khz(SX1276RxBandwidth bw)
Convert an SX1276 bandwidth enum to the numeric kHz value used in YAML/logs.
static constexpr uint8_t BROADCAST_DISCOVER[NODE_ID_SIZE]
Broadcast address for device discovery (0x00003B).
static constexpr uint8_t BROADCAST_DISCOVER_ALT[NODE_ID_SIZE]
Alternate discovery / 1W broadcast address (0x00003F).
std::string discovery_command_to_string(DiscoveryCommand cmd)
Format a discovery command enum for YAML/logs.
SX1276RxBandwidth
Valid SX1276 RX bandwidth options (RegRxBw register bytes).
@ BW_41_7_KHZ
41.7 kHz — default (validated against real devices).
@ BW_125_0_KHZ
125.0 kHz — widest selectable option.
@ BW_20_8_KHZ
20.8 kHz — narrowest; maximal noise rejection, least LO-offset tolerance.
std::optional< SX1276RxBandwidth > sx1276_bandwidth_from_string(const std::string &value)
Convert a YAML SX1276 bandwidth string to the enum value.
const uint8_t * resolve_discovery_destination(uint8_t command, bool destination_auto, const uint8_t destination[NODE_ID_SIZE])
Resolve the destination address for a discovery command.
BandwidthTableView sx1276_bandwidth_table()
The SX1276 RX-bandwidth option table (see sx1262_bandwidth_table()).
std::string discovery_destination_to_string(bool destination_auto, const uint8_t destination[NODE_ID_SIZE])
Format a destination option for YAML/logs.
float bandwidth_to_khz(const BandwidthOption *table, size_t n, uint8_t reg, float fallback)
Look up the kHz value for a register byte in a bandwidth table.
IO-Homecontrol command IDs, result codes and protocol enumerations.
One selectable RX bandwidth: the chip's register byte and its nominal kHz value.
A pointer/size view over one chip's RX-bandwidth option table.
All runtime tunable parameters for pairing and radio diagnostics.
bool pairing_discovery_destination_auto
When true, map commands to conventional addresses.
SX1276RxBandwidth sx1276_rx_bandwidth
SX1276 RX bandwidth selector.
SX1262RxBandwidth sx1262_rx_bandwidth
SX1262 RX bandwidth selector.
std::vector< uint8_t > pairing_discovery_destination
Destination when auto=false.
std::vector< DiscoveryCommand > pairing_discovery_commands
Ordered discovery commands.
bool pairing_discovery_low_power
Set LOW_POWER flag in discovery frames.
bool pairing_discovery_payload_enabled
Whether the optional payload is enabled.
LR1121RxBandwidth lr1121_rx_bandwidth
LR1121 RX bandwidth selector.
uint8_t pairing_discovery_payload
Optional payload byte (used for 0x2E).
One numeric tuning parameter: its wire name plus accessors over TuningConfig.
Runtime tuning configuration for pairing and radio diagnostics.
Table-driven registry of runtime tuning parameters.