mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 22:02:17 +01:00
fix: swap restored radio config under the radio lock
Restoring a backup wrote the transceiver config in place from the async task while the radio task could be transmitting with it. Read the record into a copy and swap it in through the new Transceiver::setConfig, which Transceiver::fromJSON now uses as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
352f36e478
commit
00a084048f
3 changed files with 15 additions and 7 deletions
|
|
@ -4812,17 +4812,21 @@ bool Transceiver::toJSON(JsonObject& obj) {
|
|||
bool Transceiver::fromJSON(JsonObject& obj) {
|
||||
if (!obj["config"].isNull()) {
|
||||
JsonObject objConfig = obj["config"];
|
||||
// Parse into a copy so the radio task never sees a half updated config,
|
||||
// then swap it in once any transmission in flight has stopped. Queued
|
||||
// jobs are kept and go out with the new settings.
|
||||
// Parse into a copy so the radio task never sees a half updated config.
|
||||
transceiver_config_t cfg = this->config;
|
||||
cfg.fromJSON(objConfig);
|
||||
RadioLock lock(portMAX_DELAY, true);
|
||||
if(this->config.enabled && this->config.TXPin != cfg.TXPin) pinMode(this->config.TXPin, INPUT);
|
||||
this->config = cfg;
|
||||
this->setConfig(cfg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void Transceiver::setConfig(const transceiver_config_t &cfg) {
|
||||
// Swap the whole config in once any transmission in flight has stopped so the
|
||||
// radio task never sees a half updated one. Queued jobs are kept and go out
|
||||
// with the new settings.
|
||||
RadioLock lock(portMAX_DELAY, true);
|
||||
if(this->config.enabled && this->config.TXPin != cfg.TXPin) pinMode(this->config.TXPin, INPUT);
|
||||
this->config = cfg;
|
||||
}
|
||||
bool Transceiver::usesPin(uint8_t pin) {
|
||||
if(this->config.enabled) {
|
||||
if(this->config.SCKPin == pin ||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue