Apply busy radio settings and recover service starts automatically
Save valid busy RX, fast-switch and Companion tuple changes once, then apply the latest accepted intent at a safe radio gap. Preserve checked-save rollback, runtime RXEN intent, TempRadio ownership and exact remote reply delivery. Repair failed preamble compensation without hiding uncertain saves. Retry WebConfig, MQTT and NimBLE startup failures automatically. Preserve explicit off choices, OTA ownership and the latest WiFi credentials through cooperative shutdown. Add regression coverage and update command guides. Validation: focused host transaction, rollback, ownership and lifecycle suites; Full RAK4631, Heltec V4 R8 TFT and RC32 packages; representative room, sensor, LR1110, LR2021, SX1276, STM32WL and ESP-NOW builds. Linked RAK crypto and OTA workspace checks pass; its complete OTA image uses 712644/712704 bytes.
This commit is contained in:
1 parent
fb73e3afac
commit
73c5f572eb
89 files changed
+2978
-816
No files matched your search
@@ -32,7 +32,8 @@ public:
|
||||
if (the_mesh.isWebConfigActive()) mask |= mesh::wireless::WiFi;
|
||||
#endif
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
if (the_mesh.isMqttBridgeRunning()) mask |= mesh::wireless::WiFi;
|
||||
if (the_mesh.isMqttBridgeRunning() || the_mesh.isMqttBridgeStartPending())
|
||||
mask |= mesh::wireless::WiFi;
|
||||
#endif
|
||||
#ifdef WITH_UDP_BRIDGE
|
||||
if (the_mesh.isUDPBridgeNetworkEnabled()) mask |= mesh::wireless::WiFi;
|
||||
@@ -74,7 +75,8 @@ public:
|
||||
resume_web_ = the_mesh.isWebConfigActive();
|
||||
#endif
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
resume_mqtt_ = the_mesh.isMqttBridgeRunning();
|
||||
resume_mqtt_ = the_mesh.isMqttBridgeRunning()
|
||||
|| the_mesh.isMqttBridgeStartPending();
|
||||
#endif
|
||||
#ifdef WITH_UDP_BRIDGE
|
||||
resume_udp_ = the_mesh.isUDPBridgeConfigured();
|
||||
|
||||
+293
-342
File diff suppressed because it is too large.
Load diff
@@ -30,6 +30,7 @@
|
||||
#include "DataStore.h"
|
||||
#include <helpers/RadioProfileCLI.h>
|
||||
#include <helpers/MorseReplyHandoff.h>
|
||||
#include <helpers/TempRadioReplyBarrier.h>
|
||||
#include <helpers/MeshtextConfig.h>
|
||||
#if MESH_ENABLE_ETHERNET_TUNNEL
|
||||
#include <helpers/EthernetTunnelSettings.h>
|
||||
@@ -221,6 +222,7 @@ public:
|
||||
void begin(bool has_display, bool radio_available = true,
|
||||
mesh::ui::StartupScreen* startup_screen = nullptr);
|
||||
void activateRadio();
|
||||
void servicePendingLocalRadioSettings();
|
||||
bool isRadioReady() const { return _radio_available; }
|
||||
void startInterface(BaseSerialInterface &serial);
|
||||
void cancelSerialResponseStream(BaseSerialInterface* route = NULL);
|
||||
@@ -273,6 +275,7 @@ public:
|
||||
void stopWebConfig();
|
||||
void serviceWebConfig();
|
||||
bool isWebConfigActiveOrStopping() const;
|
||||
bool isWebConfigWiFiTransitionActive() const;
|
||||
bool isWebConfigSetupActive() const;
|
||||
bool isWebConfigWiFiRecoveryActive() const;
|
||||
|
||||
@@ -678,7 +681,7 @@ private:
|
||||
bool applyAndSaveFemRxGain(bool enabled);
|
||||
bool applyAndSaveFemTxGain(bool enabled);
|
||||
bool applyAndSaveRxBoostedGain(bool enabled);
|
||||
enum class RadioSettingResult { Saved, RadioRejected, SaveFailed };
|
||||
enum class RadioSettingResult { Saved, RadioRejected, SaveFailed, SaveUnconfirmed };
|
||||
RadioSettingResult applyAndSaveTxPower(int8_t power);
|
||||
void servicePendingTxPower();
|
||||
bool handleCadCommand(const char* command, char* reply, size_t reply_size);
|
||||
@@ -750,12 +753,11 @@ private:
|
||||
mesh::RadioParamApplyResult tryApplyRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, bool temporary = false, uint16_t preamble = 0);
|
||||
bool applySavedRadioParams();
|
||||
void configureRadioFromPrefs();
|
||||
void finishRadioParamApply(float freq, float bw, uint8_t sf, uint8_t cr,
|
||||
uint8_t repeat,
|
||||
BaseSerialInterface* route = nullptr);
|
||||
void deferRadioCommand();
|
||||
void cancelPendingRadioParamApply();
|
||||
void servicePendingRadioParamApply();
|
||||
void queueSavedRadioApply();
|
||||
void finishPrimaryRadioReply(bool delivered);
|
||||
bool applyRxPowerSavingRfRxDisabled(const char* value, char* reply, size_t capacity);
|
||||
RadioSettingResult applyAndSaveRadioParams(float freq, float bw, uint8_t sf,
|
||||
uint8_t cr, uint8_t repeat, uint16_t preamble, bool remote = false);
|
||||
void servicePendingSerialReply();
|
||||
void servicePendingSerialReply(uint32_t now);
|
||||
bool beginPendingRequest(mesh::CompanionDelayedReplies::Kind kind,
|
||||
@@ -807,6 +809,8 @@ private:
|
||||
#endif
|
||||
mesh::MorseReplyHandoff _morse_reply;
|
||||
bool _morse_reply_admission = false;
|
||||
mesh::TempRadioReplyBarrier _primary_radio_reply;
|
||||
bool _primary_radio_blocked = false, _primary_radio_reply_admission = false;
|
||||
#if MESH_ENABLE_MESHTEXT_CHAT
|
||||
mesh::mt::Region _mt_region = mesh::mt::Region::Unset;
|
||||
uint32_t _mt_slot = 0, _mt_node = 0, _mt_packet_id = 0;
|
||||
@@ -913,20 +917,14 @@ private:
|
||||
uint8_t _morse_terminal_pending_chars = 0;
|
||||
bool _morse_terminal_was_receiving = false;
|
||||
#endif
|
||||
int8_t rf_rx_disable_pending = -1;
|
||||
uint32_t rf_rx_retry_at = 0;
|
||||
bool saved_radio_apply_pending;
|
||||
bool _radio_available;
|
||||
bool tx_power_apply_pending = false;
|
||||
uint32_t tx_power_apply_retry_at = 0;
|
||||
unsigned long radio_apply_retry_at;
|
||||
uint8_t radio_apply_failures;
|
||||
bool command_radio_apply_pending;
|
||||
float command_radio_freq;
|
||||
float command_radio_bw;
|
||||
uint8_t command_radio_sf;
|
||||
uint8_t command_radio_cr;
|
||||
uint8_t command_radio_repeat;
|
||||
unsigned long command_radio_apply_deadline;
|
||||
BaseSerialInterface* command_radio_reply_route;
|
||||
// Deferred so USB/TCP terminals can transmit the acknowledgement before
|
||||
// the transport disappears. Also used by USB interface changes.
|
||||
unsigned long _scheduled_reboot_at;
|
||||
|
||||
@@ -2625,7 +2625,7 @@ void halt() {
|
||||
}
|
||||
if (companionWiFiBackgroundSuspended()) return;
|
||||
#ifdef WITH_WEBCONFIG
|
||||
if (the_mesh.isWebConfigActiveOrStopping()) return;
|
||||
if (the_mesh.isWebConfigWiFiTransitionActive()) return;
|
||||
#endif
|
||||
// Retain the pending reload until the operator's OTA/setup AP closes.
|
||||
if (!mesh::wifi::stationMutationAllowed()) return;
|
||||
|
||||
@@ -4387,6 +4387,9 @@ void MyMesh::onSendComplete(mesh::Packet* packet) {
|
||||
if (_cli.fleetChannel()) _cli.fleetChannel()->complete(packet, _cli.radioProfiles());
|
||||
#endif
|
||||
if (temp_radio_reply_barrier.complete(packet) && !temp_radio_reply_barrier.waiting()) finishRadioReply(true);
|
||||
_cli.servicePendingRxSettings();
|
||||
_cli.radioProfiles().servicePendingTuning();
|
||||
processScheduledRadioSettings(true);
|
||||
if (packet == pending_battery_alert_packet) {
|
||||
pending_battery_alert_packet = NULL;
|
||||
battery_alert_sent = true;
|
||||
@@ -5129,9 +5132,9 @@ void MyMesh::serviceFleetScheduleReply() {
|
||||
}
|
||||
#endif
|
||||
|
||||
void MyMesh::processScheduledRadioSettings() {
|
||||
void MyMesh::processScheduledRadioSettings(bool tx_gap) {
|
||||
#if MESH_ENABLE_FLEET_CONTROL
|
||||
serviceFleetScheduleReply();
|
||||
if (!tx_gap) serviceFleetScheduleReply();
|
||||
#endif
|
||||
const uint64_t current_uptime_millis =
|
||||
uptime_millis + (uint32_t)(millis() - last_millis);
|
||||
@@ -5175,7 +5178,8 @@ void MyMesh::processScheduledRadioSettings() {
|
||||
// changes retain their existing bounded retry behavior.
|
||||
if (scheduled_radio_retry_at
|
||||
&& !millisHasNowPassed(scheduled_radio_retry_at)
|
||||
&& !hard_temp_end_due) return;
|
||||
&& !hard_temp_end_due
|
||||
&& !(tx_gap && scheduled_radio_retry_failures == 0)) return;
|
||||
|
||||
const bool schedule_check_due = next_scheduled_radio_time != 0
|
||||
&& (next_scheduled_radio_check_at == 0
|
||||
@@ -5193,7 +5197,7 @@ void MyMesh::processScheduledRadioSettings() {
|
||||
|
||||
// Never touch modulation registers while a packet is still on air. Back off
|
||||
// this check too; a long packet should not make the scheduler poll every loop.
|
||||
if (hasOutbound()) {
|
||||
if (!tx_gap && hasOutbound()) {
|
||||
scheduled_radio_retry_at = futureMillis(RADIO_APPLY_RETRY_INTERVAL_MILLIS);
|
||||
return;
|
||||
}
|
||||
@@ -5908,6 +5912,14 @@ bool MyMesh::setRxPowerSaving(bool enable, uint32_t rx_us, uint32_t sleep_us) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool MyMesh::supportsRxPowerSaving() const {
|
||||
return radio_driver.supportsRxPowerSaving();
|
||||
}
|
||||
|
||||
mesh::RadioParamApplyResult MyMesh::trySetRxPowerSaving(bool enable, uint32_t rx_us, uint32_t sleep_us) {
|
||||
return radio_driver.trySetRxPowerSaving(enable, rx_us, sleep_us);
|
||||
}
|
||||
|
||||
bool MyMesh::supportsRxPowerSavingRfRxDisable() const {
|
||||
return radio_driver.supportsRxPowerSavingRfRxDisable();
|
||||
}
|
||||
@@ -5924,6 +5936,10 @@ bool MyMesh::isRxPowerSavingRfRxDisabled() const {
|
||||
return radio_driver.isRxPowerSavingRfRxDisabled();
|
||||
}
|
||||
|
||||
mesh::RadioParamApplyResult MyMesh::trySetRxPowerSavingRfRxDisabled(bool disabled) {
|
||||
return radio_driver.trySetRxPowerSavingRfRxDisabled(disabled);
|
||||
}
|
||||
|
||||
void MyMesh::getRxPsWatchdogCounts(uint32_t* soft, uint32_t* hard) {
|
||||
*soft = radio_driver.getRxPsWatchdogSoftCount();
|
||||
*hard = radio_driver.getRxPsWatchdogHardCount();
|
||||
@@ -5933,10 +5949,22 @@ bool MyMesh::setRxBoostedGain(bool enable) {
|
||||
return radio_driver.setRxBoostedGainMode(enable);
|
||||
}
|
||||
|
||||
bool MyMesh::supportsRxBoostedGain() const {
|
||||
return radio_driver.supportsRxBoostedGainMode();
|
||||
}
|
||||
|
||||
mesh::RadioParamApplyResult MyMesh::trySetRxBoostedGain(bool enable) {
|
||||
return radio_driver.trySetRxBoostedGainMode(enable);
|
||||
}
|
||||
|
||||
#if defined(USE_LR2021)
|
||||
bool MyMesh::configSideDetectors(const uint8_t sideDetSFs[], uint8_t num, float bw) {
|
||||
return radio_driver.configSideDetectors(sideDetSFs, num, bw);
|
||||
}
|
||||
|
||||
mesh::RadioParamApplyResult MyMesh::tryConfigSideDetectors(const uint8_t sideDetSFs[], uint8_t num, float bw) {
|
||||
return radio_driver.tryConfigSideDetectors(sideDetSFs, num, bw);
|
||||
}
|
||||
#endif
|
||||
|
||||
void MyMesh::formatNeighborsReply(char *reply) {
|
||||
@@ -11652,12 +11680,11 @@ bool MyMesh::startWebConfigImpl(bool force_ap, char* reply, bool automatic_setup
|
||||
strcpy(reply, "Err: OTA server is running - 'stop ota' first");
|
||||
return true;
|
||||
}
|
||||
if (_webconfig && (_webconfig->isRunning() || _webconfig->isStopping())) {
|
||||
if (_webconfig && _webconfig->isRunning()) {
|
||||
if (!automatic_setup && !_webconfig->isStopping()) {
|
||||
_webconfig->requestNetworkAccess();
|
||||
}
|
||||
strcpy(reply, _webconfig->isStopping() ? "Err: webconfig still stopping, retry shortly"
|
||||
: "Err: webconfig already running");
|
||||
strcpy(reply, "Err: webconfig already running");
|
||||
return true;
|
||||
}
|
||||
if (mesh::wireless::control().blocked(mesh::wireless::WiFi)) {
|
||||
@@ -11710,9 +11737,9 @@ bool MyMesh::startWebConfigImpl(bool force_ap, char* reply, bool automatic_setup
|
||||
#endif
|
||||
bool started;
|
||||
if (force_ap) {
|
||||
started = _webconfig->startSetupMode(reply);
|
||||
started = _webconfig->requestStart(true, reply);
|
||||
} else {
|
||||
started = _webconfig->startAutoMode(reply);
|
||||
started = _webconfig->requestStart(false, reply);
|
||||
}
|
||||
if (!started) {
|
||||
// A failed portal must not consume a live operator-started transport.
|
||||
@@ -11734,7 +11761,8 @@ bool MyMesh::startWebConfigImpl(bool force_ap, char* reply, bool automatic_setup
|
||||
}
|
||||
|
||||
bool MyMesh::stopWebConfig(char* reply) {
|
||||
if (!_webconfig || !_webconfig->isRunning()) {
|
||||
if (!_webconfig || (!_webconfig->isRunning() && !_webconfig->isStopping()
|
||||
&& !_webconfig->isStartPending())) {
|
||||
strcpy(reply, "Err: webconfig not running");
|
||||
return true;
|
||||
}
|
||||
@@ -11749,7 +11777,7 @@ bool MyMesh::setWebUIEnabled(bool enabled, char* reply) {
|
||||
return true;
|
||||
}
|
||||
if (enabled) {
|
||||
if (_webconfig && (_webconfig->isRunning() || _webconfig->isStopping())) {
|
||||
if (_webconfig && _webconfig->isRunning()) {
|
||||
strcpy(reply, "OK - webui on (already active)");
|
||||
} else {
|
||||
startWebConfig(false, reply);
|
||||
@@ -11760,7 +11788,7 @@ bool MyMesh::setWebUIEnabled(bool enabled, char* reply) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (_webconfig && _webconfig->isRunning()) _webconfig->requestStop();
|
||||
if (_webconfig) _webconfig->requestStop();
|
||||
strcpy(reply, "OK - webui off");
|
||||
}
|
||||
return true;
|
||||
@@ -11801,24 +11829,30 @@ bool MyMesh::getWiFiCLI(char* reply) const {
|
||||
|
||||
bool MyMesh::setWiFiSSID(const char* value, char* reply) {
|
||||
if (WebConfigServer::setStandaloneWiFiSSID(value, reply, 160, canonicalWiFiLegacyPrefs())) {
|
||||
const bool was_running = _webconfig && _webconfig->isRunning();
|
||||
if (was_running) _webconfig->requestStop();
|
||||
if (_webconfig) _webconfig->reloadStandaloneWiFi();
|
||||
if (was_running) {
|
||||
strcpy(reply, "OK - WiFi SSID saved; WebConfig stopping, start again to apply");
|
||||
if (_webconfig) {
|
||||
_webconfig->reloadStandaloneWiFi();
|
||||
_webconfig->requestRestart();
|
||||
}
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
if (_prefs.bridge_enabled && mqtt_bridge
|
||||
&& !_cli.getBoard()->isOTAUpdateRunning()) mqtt_bridge->requestRestart();
|
||||
#endif
|
||||
strcpy(reply, "OK - WiFi SSID saved; reconnect scheduled");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MyMesh::setWiFiPassword(const char* value, char* reply) {
|
||||
if (WebConfigServer::setStandaloneWiFiPassword(value, reply, 160, canonicalWiFiLegacyPrefs())) {
|
||||
const bool was_running = _webconfig && _webconfig->isRunning();
|
||||
if (was_running) _webconfig->requestStop();
|
||||
if (_webconfig) _webconfig->reloadStandaloneWiFi();
|
||||
if (was_running) {
|
||||
strcpy(reply, "OK - WiFi password saved; WebConfig stopping, start again to apply");
|
||||
if (_webconfig) {
|
||||
_webconfig->reloadStandaloneWiFi();
|
||||
_webconfig->requestRestart();
|
||||
}
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
if (_prefs.bridge_enabled && mqtt_bridge
|
||||
&& !_cli.getBoard()->isOTAUpdateRunning()) mqtt_bridge->requestRestart();
|
||||
#endif
|
||||
strcpy(reply, "OK - WiFi password saved; reconnect scheduled");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -13858,7 +13892,7 @@ void __attribute__((noinline)) MyMesh::servicePostMeshLoop() {
|
||||
#endif
|
||||
#if defined(WITH_MQTT_BRIDGE)
|
||||
// MQTT owns TLS on Core 0; the radio loop only reaps an acknowledged stop.
|
||||
if (mqtt_bridge && mqtt_bridge->isRunning()) mqtt_bridge->loop();
|
||||
if (mqtt_bridge) mqtt_bridge->loop();
|
||||
#endif
|
||||
#if defined(WITH_ESPNOW_BRIDGE)
|
||||
// ESP-NOW remains cooperative, including in the
|
||||
@@ -13960,7 +13994,8 @@ void __attribute__((noinline)) MyMesh::servicePostMeshLoop() {
|
||||
if (_webconfig) {
|
||||
_webconfig->updateWiFiOwnership(webConfigOwnsWiFi());
|
||||
_webconfig->tick(millis());
|
||||
if (!_webconfig->isRunning() && !_webconfig->isStopping()) {
|
||||
if (!_webconfig->isRunning() && !_webconfig->isStopping()
|
||||
&& !_webconfig->isStartPending()) {
|
||||
delete _webconfig;
|
||||
_webconfig = nullptr;
|
||||
}
|
||||
@@ -14813,7 +14848,7 @@ mesh::powerdiag::Mask MyMesh::pendingWorkReason() const {
|
||||
if (_local_cli_output.busy()) return mask(Reason::SerialIO);
|
||||
#endif
|
||||
if (deferred_cli_command.pending || pending_self_advert || _cli.hasActiveUserGpioTimer()
|
||||
|| _cli.hasPendingTxPower()) return mask(Reason::Scheduled);
|
||||
|| _cli.hasPendingRadioSettings()) return mask(Reason::Scheduled);
|
||||
#if defined(WITH_BRIDGE)
|
||||
const AbstractBridge* active_bridge = activeBridge();
|
||||
if (active_bridge && active_bridge->isRunning()) {
|
||||
|
||||
@@ -930,7 +930,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks
|
||||
bool applySavedRadioParams();
|
||||
void queueSavedRadioApply();
|
||||
void refreshScheduledRadioState();
|
||||
void processScheduledRadioSettings();
|
||||
void processScheduledRadioSettings(bool tx_gap = false);
|
||||
bool isMillisTimerDue(unsigned long timestamp) const;
|
||||
bool floodChannelDataHopApplies(const mesh::Packet* packet) const;
|
||||
bool loadFloodPacketFilters();
|
||||
@@ -1287,8 +1287,11 @@ public:
|
||||
bool isTxPowerApplied(int8_t power_dbm) const override;
|
||||
#endif
|
||||
bool setRxPowerSaving(bool enable, uint32_t rx_us, uint32_t sleep_us) override;
|
||||
bool supportsRxPowerSaving() const override;
|
||||
mesh::RadioParamApplyResult trySetRxPowerSaving(bool enable, uint32_t rx_us, uint32_t sleep_us) override;
|
||||
bool supportsRxPowerSavingRfRxDisable() const override;
|
||||
bool setRxPowerSavingRfRxDisabled(bool disabled) override;
|
||||
mesh::RadioParamApplyResult trySetRxPowerSavingRfRxDisabled(bool disabled) override;
|
||||
bool isRxPowerSavingRfRxDisabled() const override;
|
||||
void getRxPsWatchdogCounts(uint32_t* soft, uint32_t* hard) override;
|
||||
void formatNeighborsReply(char *reply) override;
|
||||
@@ -1360,7 +1363,7 @@ public:
|
||||
#endif
|
||||
bool canRecoverUsbLogging() const {
|
||||
return dirty_contacts_expiry == 0 && !hasOutbound() && !isAnyTempRadioActive()
|
||||
&& !hasPendingOtaApply() && !saved_radio_apply_pending && !_cli.hasPendingTxPower()
|
||||
&& !hasPendingOtaApply() && !saved_radio_apply_pending && !_cli.hasPendingRadioSettings()
|
||||
&& !temp_radio_handoff_pending && _ota_update_at == 0;
|
||||
}
|
||||
#if MESH_ENABLE_FLOOD_RULE_ENGINE
|
||||
@@ -1612,11 +1615,14 @@ public:
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
bool setMqttBridgeState(bool enable) override {
|
||||
if (!enable) {
|
||||
if (mqtt_bridge && mqtt_bridge->isRunning()) mqtt_bridge->end();
|
||||
if (mqtt_bridge) mqtt_bridge->end();
|
||||
_alerter.setBridge(nullptr);
|
||||
return !mqtt_bridge || !mqtt_bridge->isRunning();
|
||||
}
|
||||
if (mqtt_bridge && mqtt_bridge->isStopping()) return false;
|
||||
if (mqtt_bridge && mqtt_bridge->isStopping()) {
|
||||
mqtt_bridge->begin();
|
||||
return mqtt_bridge->isStartPending();
|
||||
}
|
||||
// Give the WiFi station to MQTT while it associates. ESP-NOW is restarted
|
||||
// after the AP channel is known, which avoids a raw ESP-NOW-only session
|
||||
// pinning the station to a different channel.
|
||||
@@ -1652,7 +1658,7 @@ public:
|
||||
_alerter.setBridge(mqtt_bridge);
|
||||
}
|
||||
if (_prefs.espnow_bridge_enabled) startSharedEspNowBridgeIfReady();
|
||||
return mqtt_bridge->isRunning();
|
||||
return mqtt_bridge->isRunning() || mqtt_bridge->isStartPending();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1706,7 +1712,11 @@ public:
|
||||
|
||||
bool setBridgeState(bool enable) override {
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
if (enable && mqtt_bridge && mqtt_bridge->isStopping()) return false;
|
||||
if (!enable && mqtt_bridge && mqtt_bridge->isStartPending()) mqtt_bridge->end();
|
||||
if (enable && mqtt_bridge && mqtt_bridge->isStopping()) {
|
||||
mqtt_bridge->begin();
|
||||
return mqtt_bridge->isStartPending();
|
||||
}
|
||||
#endif
|
||||
#if defined(WITH_MQTT_BRIDGE) && defined(WITH_ESPNOW_BRIDGE)
|
||||
if (!enable) {
|
||||
@@ -1785,7 +1795,11 @@ public:
|
||||
#else
|
||||
configureBridgeFilter(active_bridge);
|
||||
active_bridge->begin();
|
||||
const bool started = active_bridge->isRunning();
|
||||
const bool started = active_bridge->isRunning()
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
|| mqtt_bridge->isStartPending()
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
_alerter.setBridge(mqtt_bridge);
|
||||
@@ -1967,6 +1981,12 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
bool isMqttBridgeStartPending() override {
|
||||
return mqtt_bridge && mqtt_bridge->isStartPending();
|
||||
}
|
||||
#endif
|
||||
|
||||
bool syncMqttNtp() override {
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
if (!mqtt_bridge || !mqtt_bridge->isRunning()) return false;
|
||||
@@ -2020,7 +2040,8 @@ public:
|
||||
bool setWiFiPowerSave(const char* value, char* reply) override;
|
||||
bool setWiFiCLI(const char* value, char* reply) override;
|
||||
bool isWebConfigActive() const override {
|
||||
return _webconfig && (_webconfig->isRunning() || _webconfig->isStopping());
|
||||
return _webconfig && (_webconfig->isRunning() || _webconfig->isStopping()
|
||||
|| _webconfig->isStartPending());
|
||||
}
|
||||
void getNodeSnapshot(WebConfigServer::NodeSnapshot& snapshot) override;
|
||||
void execCommand(char* cmd, char* reply) override { handleCommand(0, cmd, reply); }
|
||||
@@ -2071,10 +2092,13 @@ public:
|
||||
mesh::powerdiag::Mask pendingWorkReason() const;
|
||||
|
||||
bool setRxBoostedGain(bool enable) override;
|
||||
bool supportsRxBoostedGain() const override;
|
||||
mesh::RadioParamApplyResult trySetRxBoostedGain(bool enable) override;
|
||||
void recalibrateNoiseFloor() override { _radio->recalibrateNoiseFloor(); }
|
||||
|
||||
#if defined(USE_LR2021)
|
||||
virtual bool configSideDetectors(const uint8_t sideDetSFs[], uint8_t num, float bw) override;
|
||||
mesh::RadioParamApplyResult tryConfigSideDetectors(const uint8_t sideDetSFs[], uint8_t num, float bw) override;
|
||||
#endif
|
||||
|
||||
};
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "MyMesh.h"
|
||||
#include <helpers/ui/DisplayNightLocation.h>
|
||||
#if defined(USE_LR2021)
|
||||
#include <helpers/radiolib/LR2021SideDetectorConfig.h>
|
||||
#endif
|
||||
#include <helpers/DefaultPasswordWarning.h>
|
||||
#if defined(HELTEC_V4_R8_TFT) && defined(HELTEC_TFT_RUNTIME_ROTATION) \
|
||||
&& HELTEC_TFT_RUNTIME_ROTATION == 1
|
||||
@@ -2427,6 +2430,73 @@ void MyMesh::onGroupPacketRecv(mesh::Packet* packet) {
|
||||
_clock_sync.observeGroupPacket(packet);
|
||||
}
|
||||
|
||||
void MyMesh::servicePendingPrimaryRadioSettings(bool tx_gap) {
|
||||
const bool revert_radio_due = revert_radio_at && millisHasNowPassed(revert_radio_at);
|
||||
const bool radio_apply_ready = !radio_apply_retry_at || millisHasNowPassed(radio_apply_retry_at);
|
||||
bool radio_apply_failed = false;
|
||||
if (revert_radio_due && !temp_radio_applied) {
|
||||
// The temporary window ended before it could be applied. Drop both timers
|
||||
// so a previously busy radio cannot switch to the expired channel later.
|
||||
set_radio_at = revert_radio_at = 0;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
MESH_DEBUG_PRINTLN("Temp radio params expired before apply");
|
||||
} else if (revert_radio_due && !hasOutbound() && radio_apply_ready) {
|
||||
if (applySavedRadioParams()) {
|
||||
set_radio_at = revert_radio_at = 0;
|
||||
temp_radio_applied = false;
|
||||
saved_radio_apply_pending = false;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
MESH_DEBUG_PRINTLN("Radio params restored");
|
||||
} else {
|
||||
radio_apply_failed = true;
|
||||
}
|
||||
} else if (set_radio_at && millisHasNowPassed(set_radio_at) && !hasOutbound()
|
||||
&& radio_apply_ready) {
|
||||
uint32_t rx_us = _prefs.rx_ps_rx_us;
|
||||
uint32_t sleep_us = _prefs.rx_ps_sleep_us;
|
||||
bool timing_ok = true;
|
||||
if (_prefs.rx_powersaving_enabled && _prefs.rx_ps_level != 0) {
|
||||
uint32_t preamble = _prefs.rx_ps_preamble ? _prefs.rx_ps_preamble
|
||||
: rxPowerSavingPreambleForParams(pending_sf, pending_bw);
|
||||
timing_ok = CommonCLI::calculateRxPowerSavingLevel(
|
||||
_prefs.rx_ps_level, pending_sf, pending_bw, preamble, &rx_us, &sleep_us);
|
||||
}
|
||||
uint32_t timings[2] = {rx_us, sleep_us};
|
||||
const uint32_t* applied_timings = _prefs.rx_powersaving_enabled
|
||||
&& radio_driver.supportsRxPowerSaving() ? timings : NULL;
|
||||
if (timing_ok && _cli.radioProfiles().applyPrimary(
|
||||
pending_freq, pending_bw, pending_sf, pending_cr, true, pending_preamble, applied_timings) == mesh::RadioParamApplyResult::APPLIED) {
|
||||
set_radio_at = 0;
|
||||
active_cr = pending_cr;
|
||||
temp_radio_applied = true;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
MESH_DEBUG_PRINTLN("Temp radio params");
|
||||
} else {
|
||||
// A failed setParams() may have applied only a prefix of the tuple.
|
||||
// Ensure expiry restores the complete saved configuration.
|
||||
saved_radio_apply_pending = true;
|
||||
radio_apply_failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (saved_radio_apply_pending && !temp_radio_applied && (tx_gap || !hasOutbound())
|
||||
&& radio_apply_ready && !radio_apply_failed) {
|
||||
if (applySavedRadioParams()) {
|
||||
saved_radio_apply_pending = false;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
} else {
|
||||
radio_apply_failed = true;
|
||||
}
|
||||
}
|
||||
if (radio_apply_failed) {
|
||||
radio_apply_retry_at = futureMillis(nextRadioApplyRetryDelay(radio_apply_failures));
|
||||
}
|
||||
}
|
||||
|
||||
void MyMesh::onSendComplete(mesh::Packet* packet) {
|
||||
mesh::Mesh::onSendComplete(packet);
|
||||
_cli.servicePendingTxPower();
|
||||
@@ -2434,6 +2504,9 @@ void MyMesh::onSendComplete(mesh::Packet* packet) {
|
||||
#if MESH_ENABLE_FLEET_CONTROL
|
||||
if (_cli.fleetChannel()) _cli.fleetChannel()->complete(packet, _cli.radioProfiles());
|
||||
#endif
|
||||
_cli.servicePendingRxSettings();
|
||||
_cli.radioProfiles().servicePendingTuning();
|
||||
servicePendingPrimaryRadioSettings(true);
|
||||
}
|
||||
|
||||
void MyMesh::onSendFail(mesh::Packet* packet) {
|
||||
@@ -2872,6 +2945,19 @@ void MyMesh::begin(FILESYSTEM *fs) {
|
||||
}
|
||||
|
||||
bool MyMesh::applySavedRadioParams() {
|
||||
#if defined(USE_LR2021)
|
||||
uint8_t extra_sf_count = 0;
|
||||
const auto* profiles = radio_driver.profiles();
|
||||
const bool side_detectors_allowed = !profiles || !profiles->enabled();
|
||||
if (!mesh::lr2021::storedSideDetectorCount(_prefs.extra_sf, extra_sf_count)
|
||||
|| !mesh::lr2021::validateSideDetectorSFs(
|
||||
_prefs.extra_sf, extra_sf_count, _prefs.sf, _prefs.bw)) {
|
||||
if (side_detectors_allowed && !radio_driver.configSideDetectors(nullptr, 0, _prefs.bw)) return false;
|
||||
memset(_prefs.extra_sf, 0, sizeof(_prefs.extra_sf));
|
||||
extra_sf_count = 0;
|
||||
savePrefs();
|
||||
}
|
||||
#endif
|
||||
// Each setter can defer while the radio is busy. Keep recovery pending
|
||||
// until the complete saved configuration has been accepted.
|
||||
if (radio_driver.supportsRxBoostedGainMode()
|
||||
@@ -2885,6 +2971,10 @@ bool MyMesh::applySavedRadioParams() {
|
||||
return false;
|
||||
}
|
||||
active_cr = _prefs.cr;
|
||||
#if defined(USE_LR2021)
|
||||
if (side_detectors_allowed
|
||||
&& !radio_driver.configSideDetectors(_prefs.extra_sf, extra_sf_count, _prefs.bw)) return false;
|
||||
#endif
|
||||
return radio_driver.setTxPower(_prefs.tx_power_dbm);
|
||||
}
|
||||
|
||||
@@ -3209,6 +3299,26 @@ bool MyMesh::isTxPowerApplied(int8_t power_dbm) const {
|
||||
bool MyMesh::setRxPowerSaving(bool enable, uint32_t rx_us, uint32_t sleep_us) {
|
||||
return radio_driver.setRxPowerSaving(enable, rx_us, sleep_us);
|
||||
}
|
||||
|
||||
bool MyMesh::supportsRxPowerSaving() const {
|
||||
return radio_driver.supportsRxPowerSaving();
|
||||
}
|
||||
|
||||
mesh::RadioParamApplyResult MyMesh::trySetRxPowerSaving(bool enable, uint32_t rx_us, uint32_t sleep_us) {
|
||||
return radio_driver.trySetRxPowerSaving(enable, rx_us, sleep_us);
|
||||
}
|
||||
|
||||
bool MyMesh::supportsRxPowerSavingRfRxDisable() const {
|
||||
return radio_driver.supportsRxPowerSavingRfRxDisable();
|
||||
}
|
||||
|
||||
mesh::RadioParamApplyResult MyMesh::trySetRxPowerSavingRfRxDisabled(bool disabled) {
|
||||
return radio_driver.trySetRxPowerSavingRfRxDisabled(disabled);
|
||||
}
|
||||
|
||||
bool MyMesh::isRxPowerSavingRfRxDisabled() const {
|
||||
return radio_driver.isRxPowerSavingRfRxDisabled();
|
||||
}
|
||||
void MyMesh::getRxPsWatchdogCounts(uint32_t* soft, uint32_t* hard) {
|
||||
*soft = radio_driver.getRxPsWatchdogSoftCount();
|
||||
*hard = radio_driver.getRxPsWatchdogHardCount();
|
||||
@@ -3218,6 +3328,20 @@ bool MyMesh::setRxBoostedGain(bool enable) {
|
||||
return radio_driver.setRxBoostedGainMode(enable);
|
||||
}
|
||||
|
||||
bool MyMesh::supportsRxBoostedGain() const {
|
||||
return radio_driver.supportsRxBoostedGainMode();
|
||||
}
|
||||
|
||||
mesh::RadioParamApplyResult MyMesh::trySetRxBoostedGain(bool enable) {
|
||||
return radio_driver.trySetRxBoostedGainMode(enable);
|
||||
}
|
||||
|
||||
#if defined(USE_LR2021)
|
||||
mesh::RadioParamApplyResult MyMesh::tryConfigSideDetectors(const uint8_t sideDetSFs[], uint8_t num, float bw) {
|
||||
return radio_driver.tryConfigSideDetectors(sideDetSFs, num, bw);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool MyMesh::saveIdentity(const mesh::LocalIdentity &new_id) {
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
IdentityStore store(*_fs, "");
|
||||
@@ -3351,12 +3475,11 @@ bool MyMesh::startWebConfigImpl(bool force_ap, char* reply, bool automatic_setup
|
||||
strcpy(reply, "Err: OTA server is running - 'stop ota' first");
|
||||
return true;
|
||||
}
|
||||
if (_webconfig && (_webconfig->isRunning() || _webconfig->isStopping())) {
|
||||
if (_webconfig && _webconfig->isRunning()) {
|
||||
if (!automatic_setup && !_webconfig->isStopping()) {
|
||||
_webconfig->requestNetworkAccess();
|
||||
}
|
||||
strcpy(reply, _webconfig->isStopping() ? "Err: webconfig still stopping, retry shortly"
|
||||
: "Err: webconfig already running");
|
||||
strcpy(reply, "Err: webconfig already running");
|
||||
return true;
|
||||
}
|
||||
if (mesh::wireless::control().blocked(mesh::wireless::WiFi)) {
|
||||
@@ -3406,9 +3529,9 @@ bool MyMesh::startWebConfigImpl(bool force_ap, char* reply, bool automatic_setup
|
||||
|
||||
bool started;
|
||||
if (force_ap) {
|
||||
started = _webconfig->startSetupMode(reply);
|
||||
started = _webconfig->requestStart(true, reply);
|
||||
} else {
|
||||
started = _webconfig->startAutoMode(reply);
|
||||
started = _webconfig->requestStart(false, reply);
|
||||
}
|
||||
if (!started) {
|
||||
_unconfigured_setup_espnow_suspended = setup_was_suspended;
|
||||
@@ -3433,7 +3556,7 @@ bool MyMesh::setWebUIEnabled(bool enabled, char* reply) {
|
||||
return true;
|
||||
}
|
||||
if (enabled) {
|
||||
if (_webconfig && (_webconfig->isRunning() || _webconfig->isStopping())) {
|
||||
if (_webconfig && _webconfig->isRunning()) {
|
||||
strcpy(reply, "OK - webui on (already active)");
|
||||
} else {
|
||||
startWebConfig(false, reply);
|
||||
@@ -3444,7 +3567,7 @@ bool MyMesh::setWebUIEnabled(bool enabled, char* reply) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (_webconfig && _webconfig->isRunning()) _webconfig->requestStop();
|
||||
if (_webconfig) _webconfig->requestStop();
|
||||
strcpy(reply, "OK - webui off");
|
||||
}
|
||||
return true;
|
||||
@@ -3485,24 +3608,30 @@ bool MyMesh::getWiFiCLI(char* reply) const {
|
||||
|
||||
bool MyMesh::setWiFiSSID(const char* value, char* reply) {
|
||||
if (WebConfigServer::setStandaloneWiFiSSID(value, reply, 160, canonicalWiFiLegacyPrefs())) {
|
||||
const bool was_running = _webconfig && _webconfig->isRunning();
|
||||
if (was_running) _webconfig->requestStop();
|
||||
if (_webconfig) _webconfig->reloadStandaloneWiFi();
|
||||
if (was_running) {
|
||||
strcpy(reply, "OK - WiFi SSID saved; WebConfig stopping, start again to apply");
|
||||
if (_webconfig) {
|
||||
_webconfig->reloadStandaloneWiFi();
|
||||
_webconfig->requestRestart();
|
||||
}
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
if (_prefs.bridge_enabled && bridge
|
||||
&& !_cli.getBoard()->isOTAUpdateRunning()) bridge->requestRestart();
|
||||
#endif
|
||||
strcpy(reply, "OK - WiFi SSID saved; reconnect scheduled");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MyMesh::setWiFiPassword(const char* value, char* reply) {
|
||||
if (WebConfigServer::setStandaloneWiFiPassword(value, reply, 160, canonicalWiFiLegacyPrefs())) {
|
||||
const bool was_running = _webconfig && _webconfig->isRunning();
|
||||
if (was_running) _webconfig->requestStop();
|
||||
if (_webconfig) _webconfig->reloadStandaloneWiFi();
|
||||
if (was_running) {
|
||||
strcpy(reply, "OK - WiFi password saved; WebConfig stopping, start again to apply");
|
||||
if (_webconfig) {
|
||||
_webconfig->reloadStandaloneWiFi();
|
||||
_webconfig->requestRestart();
|
||||
}
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
if (_prefs.bridge_enabled && bridge
|
||||
&& !_cli.getBoard()->isOTAUpdateRunning()) bridge->requestRestart();
|
||||
#endif
|
||||
strcpy(reply, "OK - WiFi password saved; reconnect scheduled");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -3521,7 +3650,8 @@ bool MyMesh::setWiFiCLI(const char* value, char* reply) {
|
||||
}
|
||||
|
||||
bool MyMesh::stopWebConfig(char* reply) {
|
||||
if (!_webconfig || !_webconfig->isRunning()) {
|
||||
if (!_webconfig || (!_webconfig->isRunning() && !_webconfig->isStopping()
|
||||
&& !_webconfig->isStartPending())) {
|
||||
strcpy(reply, "Err: webconfig not running");
|
||||
return true;
|
||||
}
|
||||
@@ -4127,7 +4257,7 @@ void MyMesh::loop() {
|
||||
#endif
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
// TLS runs on Core 0; the radio loop reaps only an acknowledged CLI stop.
|
||||
if (bridge && bridge->isRunning()) bridge->loop();
|
||||
if (bridge) bridge->loop();
|
||||
#endif
|
||||
#ifdef WITH_ESPNOW_BRIDGE
|
||||
if (espnow_bridge.isRunning()) espnow_bridge.loop();
|
||||
@@ -4150,70 +4280,7 @@ void MyMesh::loop() {
|
||||
updateAdvertTimer(); // schedule next local advert
|
||||
}
|
||||
|
||||
const bool revert_radio_due = revert_radio_at && millisHasNowPassed(revert_radio_at);
|
||||
const bool radio_apply_ready = !radio_apply_retry_at || millisHasNowPassed(radio_apply_retry_at);
|
||||
bool radio_apply_failed = false;
|
||||
if (revert_radio_due && !temp_radio_applied) {
|
||||
// The temporary window ended before it could be applied. Drop both timers
|
||||
// so a previously busy radio cannot switch to the expired channel later.
|
||||
set_radio_at = revert_radio_at = 0;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
MESH_DEBUG_PRINTLN("Temp radio params expired before apply");
|
||||
} else if (revert_radio_due && !hasOutbound() && radio_apply_ready) {
|
||||
if (applySavedRadioParams()) {
|
||||
set_radio_at = revert_radio_at = 0;
|
||||
temp_radio_applied = false;
|
||||
saved_radio_apply_pending = false;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
MESH_DEBUG_PRINTLN("Radio params restored");
|
||||
} else {
|
||||
radio_apply_failed = true;
|
||||
}
|
||||
} else if (set_radio_at && millisHasNowPassed(set_radio_at) && !hasOutbound()
|
||||
&& radio_apply_ready) {
|
||||
uint32_t rx_us = _prefs.rx_ps_rx_us;
|
||||
uint32_t sleep_us = _prefs.rx_ps_sleep_us;
|
||||
bool timing_ok = true;
|
||||
if (_prefs.rx_powersaving_enabled && _prefs.rx_ps_level != 0) {
|
||||
uint32_t preamble = _prefs.rx_ps_preamble ? _prefs.rx_ps_preamble
|
||||
: rxPowerSavingPreambleForParams(pending_sf, pending_bw);
|
||||
timing_ok = CommonCLI::calculateRxPowerSavingLevel(
|
||||
_prefs.rx_ps_level, pending_sf, pending_bw, preamble, &rx_us, &sleep_us);
|
||||
}
|
||||
uint32_t timings[2] = {rx_us, sleep_us};
|
||||
const uint32_t* applied_timings = _prefs.rx_powersaving_enabled
|
||||
&& radio_driver.supportsRxPowerSaving() ? timings : NULL;
|
||||
if (timing_ok && _cli.radioProfiles().applyPrimary(
|
||||
pending_freq, pending_bw, pending_sf, pending_cr, true, pending_preamble, applied_timings) == mesh::RadioParamApplyResult::APPLIED) {
|
||||
set_radio_at = 0;
|
||||
active_cr = pending_cr;
|
||||
temp_radio_applied = true;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
MESH_DEBUG_PRINTLN("Temp radio params");
|
||||
} else {
|
||||
// A failed setParams() may have applied only a prefix of the tuple.
|
||||
// Ensure expiry restores the complete saved configuration.
|
||||
saved_radio_apply_pending = true;
|
||||
radio_apply_failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (saved_radio_apply_pending && !temp_radio_applied && !hasOutbound()
|
||||
&& radio_apply_ready && !radio_apply_failed) {
|
||||
if (applySavedRadioParams()) {
|
||||
saved_radio_apply_pending = false;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
} else {
|
||||
radio_apply_failed = true;
|
||||
}
|
||||
}
|
||||
if (radio_apply_failed) {
|
||||
radio_apply_retry_at = futureMillis(nextRadioApplyRetryDelay(radio_apply_failures));
|
||||
}
|
||||
servicePendingPrimaryRadioSettings();
|
||||
|
||||
#ifdef WITH_WEBCONFIG
|
||||
if (_webconfig) {
|
||||
@@ -4222,7 +4289,8 @@ void MyMesh::loop() {
|
||||
|| (!bridge->isRunning() && !bridge->isStopping()));
|
||||
#endif
|
||||
_webconfig->tick(millis());
|
||||
if (!_webconfig->isRunning() && !_webconfig->isStopping()) {
|
||||
if (!_webconfig->isRunning() && !_webconfig->isStopping()
|
||||
&& !_webconfig->isStartPending()) {
|
||||
delete _webconfig;
|
||||
_webconfig = nullptr;
|
||||
}
|
||||
@@ -4510,7 +4578,7 @@ mesh::powerdiag::Mask MyMesh::pendingWorkReason() const {
|
||||
using mesh::powerdiag::Reason;
|
||||
if (!canIdleDualRadio()) return mask(Reason::DualRadio);
|
||||
if (hasPendingOtaApply()) return mask(Reason::Ota);
|
||||
if (_cli.hasPendingTxPower()) return mask(Reason::Scheduled);
|
||||
if (_cli.hasPendingRadioSettings()) return mask(Reason::Scheduled);
|
||||
#if defined(ESP32_PLATFORM)
|
||||
if (mesh::wifi::networkPower().foregroundActive()) return mask(Reason::Network);
|
||||
#endif
|
||||
|
||||
@@ -410,6 +410,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks,
|
||||
|
||||
bool addPost(ClientInfo* client, const char* postData);
|
||||
bool applySavedRadioParams();
|
||||
void servicePendingPrimaryRadioSettings(bool tx_gap = false);
|
||||
bool storePost(const mesh::Identity& author, const char* postData);
|
||||
bool snapshotRoomHistory();
|
||||
void loadRoomHistory();
|
||||
@@ -625,9 +626,19 @@ public:
|
||||
bool isTxPowerApplied(int8_t power_dbm) const override;
|
||||
#endif
|
||||
bool setRxPowerSaving(bool enable, uint32_t rx_us, uint32_t sleep_us) override;
|
||||
bool supportsRxPowerSaving() const override;
|
||||
mesh::RadioParamApplyResult trySetRxPowerSaving(bool enable, uint32_t rx_us, uint32_t sleep_us) override;
|
||||
bool supportsRxPowerSavingRfRxDisable() const override;
|
||||
mesh::RadioParamApplyResult trySetRxPowerSavingRfRxDisabled(bool disabled) override;
|
||||
bool isRxPowerSavingRfRxDisabled() const override;
|
||||
void recalibrateNoiseFloor() override { _radio->recalibrateNoiseFloor(); }
|
||||
void getRxPsWatchdogCounts(uint32_t* soft, uint32_t* hard) override;
|
||||
bool setRxBoostedGain(bool enable) override;
|
||||
bool supportsRxBoostedGain() const override;
|
||||
mesh::RadioParamApplyResult trySetRxBoostedGain(bool enable) override;
|
||||
#if defined(USE_LR2021)
|
||||
mesh::RadioParamApplyResult tryConfigSideDetectors(const uint8_t sideDetSFs[], uint8_t num, float bw) override;
|
||||
#endif
|
||||
|
||||
void formatNeighborsReply(char *reply) override;
|
||||
void removeNeighbor(const uint8_t* pubkey, int key_len) override;
|
||||
@@ -704,7 +715,7 @@ public:
|
||||
#endif
|
||||
bool canRecoverUsbLogging() const {
|
||||
return dirty_contacts_expiry == 0 && !hasOutbound() && !isAnyTempRadioActive()
|
||||
&& !hasPendingOtaApply() && !saved_radio_apply_pending && !_cli.hasPendingTxPower()
|
||||
&& !hasPendingOtaApply() && !saved_radio_apply_pending && !_cli.hasPendingRadioSettings()
|
||||
&& set_radio_at == 0 && _ota_update_at == 0;
|
||||
}
|
||||
#if MESH_ENABLE_ROOM_FLOOD_RULE_ENGINE
|
||||
@@ -767,11 +778,14 @@ public:
|
||||
|
||||
bool setMqttBridgeState(bool enable) override {
|
||||
if (!enable) {
|
||||
if (bridge && bridge->isRunning()) bridge->end();
|
||||
if (bridge) bridge->end();
|
||||
_alerter.setBridge(nullptr);
|
||||
return !bridge || !bridge->isRunning();
|
||||
}
|
||||
if (bridge && bridge->isStopping()) return false;
|
||||
if (bridge && bridge->isStopping()) {
|
||||
bridge->begin();
|
||||
return bridge->isStartPending();
|
||||
}
|
||||
// Give the WiFi station to MQTT while it associates. ESP-NOW is restarted
|
||||
// after the AP channel is known, which avoids a raw ESP-NOW-only session
|
||||
// pinning the station to a different channel.
|
||||
@@ -814,7 +828,7 @@ public:
|
||||
_alerter.setBridge(bridge);
|
||||
}
|
||||
if (_prefs.espnow_bridge_enabled) startSharedEspNowBridgeIfReady();
|
||||
return bridge->isRunning();
|
||||
return bridge->isRunning() || bridge->isStartPending();
|
||||
}
|
||||
|
||||
bool setEspNowBridgeState(bool enable) override {
|
||||
@@ -872,7 +886,11 @@ public:
|
||||
|
||||
bool setBridgeState(bool enable) override {
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
if (enable && bridge && bridge->isStopping()) return false;
|
||||
if (!enable && bridge && bridge->isStartPending()) bridge->end();
|
||||
if (enable && bridge && bridge->isStopping()) {
|
||||
bridge->begin();
|
||||
return bridge->isStartPending();
|
||||
}
|
||||
#endif
|
||||
#if defined(WITH_MQTT_BRIDGE) && defined(WITH_ESPNOW_BRIDGE)
|
||||
if (!enable) return setEspNowBridgeState(false) && setMqttBridgeState(false);
|
||||
@@ -936,7 +954,8 @@ public:
|
||||
_alerter.setBridge(nullptr);
|
||||
#endif
|
||||
}
|
||||
return enable ? bridge->isRunning() : !bridge->isRunning();
|
||||
return enable ? (bridge->isRunning() || bridge->isStartPending())
|
||||
: !bridge->isRunning();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -970,7 +989,7 @@ public:
|
||||
#endif
|
||||
configureBridgeFilter(bridge);
|
||||
bridge->begin();
|
||||
return bridge->isRunning();
|
||||
return bridge->isRunning() || bridge->isStartPending();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1031,6 +1050,10 @@ public:
|
||||
return bridge && bridge->isStopping();
|
||||
}
|
||||
|
||||
bool isMqttBridgeStartPending() override {
|
||||
return bridge && bridge->isStartPending();
|
||||
}
|
||||
|
||||
bool syncMqttNtp() override {
|
||||
if (!bridge || !bridge->isRunning()) return false;
|
||||
// Queue the sync onto the MQTT task (Core 0) without blocking: this runs on
|
||||
@@ -1076,7 +1099,8 @@ public:
|
||||
bool setWiFiPowerSave(const char* value, char* reply) override;
|
||||
bool setWiFiCLI(const char* value, char* reply) override;
|
||||
bool isWebConfigActive() const override {
|
||||
return _webconfig && (_webconfig->isRunning() || _webconfig->isStopping());
|
||||
return _webconfig && (_webconfig->isRunning() || _webconfig->isStopping()
|
||||
|| _webconfig->isStartPending());
|
||||
}
|
||||
void getNodeSnapshot(WebConfigServer::NodeSnapshot& snapshot) override;
|
||||
void execCommand(char* cmd, char* reply) override { handleCommand(0, cmd, reply); }
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "SensorMesh.h"
|
||||
#include <helpers/ui/DisplayNightLocation.h>
|
||||
#if defined(USE_LR2021)
|
||||
#include <helpers/radiolib/LR2021SideDetectorConfig.h>
|
||||
#endif
|
||||
#include <helpers/CLICommandUtils.h>
|
||||
#include <helpers/ClientACLCLI.h>
|
||||
#include <helpers/ClientACLResponse.h>
|
||||
@@ -1112,11 +1115,80 @@ bool SensorMesh::handleIncomingMsg(ClientInfo& from, uint32_t timestamp, uint8_t
|
||||
return false;
|
||||
}
|
||||
|
||||
void SensorMesh::servicePendingPrimaryRadioSettings(bool tx_gap) {
|
||||
const bool revert_radio_due = revert_radio_at && millisHasNowPassed(revert_radio_at);
|
||||
const bool radio_apply_ready = !radio_apply_retry_at || millisHasNowPassed(radio_apply_retry_at);
|
||||
bool radio_apply_failed = false;
|
||||
if (revert_radio_due && !temp_radio_applied) {
|
||||
// Never apply a temporary channel after its window has already ended.
|
||||
set_radio_at = revert_radio_at = 0;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
MESH_DEBUG_PRINTLN("Temp radio params expired before apply");
|
||||
} else if (revert_radio_due && !hasOutbound() && radio_apply_ready) {
|
||||
if (applySavedRadioParams()) {
|
||||
set_radio_at = revert_radio_at = 0;
|
||||
temp_radio_applied = false;
|
||||
saved_radio_apply_pending = false;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
MESH_DEBUG_PRINTLN("Radio params restored");
|
||||
} else {
|
||||
radio_apply_failed = true;
|
||||
}
|
||||
} else if (set_radio_at && millisHasNowPassed(set_radio_at) && !hasOutbound()
|
||||
&& radio_apply_ready) {
|
||||
uint32_t rx_us = _prefs.rx_ps_rx_us;
|
||||
uint32_t sleep_us = _prefs.rx_ps_sleep_us;
|
||||
bool timing_ok = true;
|
||||
if (_prefs.rx_powersaving_enabled && _prefs.rx_ps_level != 0) {
|
||||
uint32_t preamble = _prefs.rx_ps_preamble ? _prefs.rx_ps_preamble
|
||||
: rxPowerSavingPreambleForParams(pending_sf, pending_bw);
|
||||
timing_ok = CommonCLI::calculateRxPowerSavingLevel(
|
||||
_prefs.rx_ps_level, pending_sf, pending_bw, preamble, &rx_us, &sleep_us);
|
||||
}
|
||||
uint32_t timings[2] = {rx_us, sleep_us};
|
||||
const uint32_t* applied_timings = _prefs.rx_powersaving_enabled
|
||||
&& radio_driver.supportsRxPowerSaving() ? timings : NULL;
|
||||
if (timing_ok && _cli.radioProfiles().applyPrimary(
|
||||
pending_freq, pending_bw, pending_sf, pending_cr, true, pending_preamble, applied_timings) == mesh::RadioParamApplyResult::APPLIED) {
|
||||
set_radio_at = 0;
|
||||
active_cr = pending_cr;
|
||||
temp_radio_applied = true;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
MESH_DEBUG_PRINTLN("Temp radio params");
|
||||
} else {
|
||||
// A failed setParams() may have applied only a prefix of the tuple.
|
||||
// Ensure expiry restores the complete saved configuration.
|
||||
saved_radio_apply_pending = true;
|
||||
radio_apply_failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (saved_radio_apply_pending && !temp_radio_applied && (tx_gap || !hasOutbound())
|
||||
&& radio_apply_ready && !radio_apply_failed) {
|
||||
if (applySavedRadioParams()) {
|
||||
saved_radio_apply_pending = false;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
} else {
|
||||
radio_apply_failed = true;
|
||||
}
|
||||
}
|
||||
if (radio_apply_failed) {
|
||||
radio_apply_retry_at = futureMillis(nextRadioApplyRetryDelay(radio_apply_failures));
|
||||
}
|
||||
}
|
||||
|
||||
#if !MESH_ENABLE_SENSOR_TRACKER
|
||||
void SensorMesh::onSendComplete(mesh::Packet* packet) {
|
||||
mesh::Mesh::onSendComplete(packet);
|
||||
_cli.servicePendingTxPower();
|
||||
_cli.morseReply().complete(packet);
|
||||
_cli.servicePendingRxSettings();
|
||||
_cli.radioProfiles().servicePendingTuning();
|
||||
servicePendingPrimaryRadioSettings(true);
|
||||
}
|
||||
|
||||
void SensorMesh::onSendFail(mesh::Packet* packet) {
|
||||
@@ -1339,8 +1411,23 @@ void SensorMesh::begin(FILESYSTEM* fs) {
|
||||
}
|
||||
|
||||
bool SensorMesh::applySavedRadioParams() {
|
||||
#if defined(USE_LR2021)
|
||||
uint8_t extra_sf_count = 0;
|
||||
const auto* profiles = radio_driver.profiles();
|
||||
const bool side_detectors_allowed = !profiles || !profiles->enabled();
|
||||
if (!mesh::lr2021::storedSideDetectorCount(_prefs.extra_sf, extra_sf_count)
|
||||
|| !mesh::lr2021::validateSideDetectorSFs(
|
||||
_prefs.extra_sf, extra_sf_count, _prefs.sf, _prefs.bw)) {
|
||||
if (side_detectors_allowed && !radio_driver.configSideDetectors(nullptr, 0, _prefs.bw)) return false;
|
||||
memset(_prefs.extra_sf, 0, sizeof(_prefs.extra_sf));
|
||||
extra_sf_count = 0;
|
||||
savePrefs();
|
||||
}
|
||||
#endif
|
||||
// A busy radio can accept the tuple before deferring TX power. Recovery
|
||||
// is complete only after both saved settings have been accepted.
|
||||
if (radio_driver.supportsRxBoostedGainMode()
|
||||
&& !radio_driver.setRxBoostedGainMode(_prefs.rx_boosted_gain)) return false;
|
||||
uint32_t timings[2] = {_prefs.rx_ps_rx_us, _prefs.rx_ps_sleep_us};
|
||||
const uint32_t* applied_timings = _prefs.rx_powersaving_enabled
|
||||
&& radio_driver.supportsRxPowerSaving() ? timings : NULL;
|
||||
@@ -1350,6 +1437,10 @@ bool SensorMesh::applySavedRadioParams() {
|
||||
return false;
|
||||
}
|
||||
active_cr = _prefs.cr;
|
||||
#if defined(USE_LR2021)
|
||||
if (side_detectors_allowed
|
||||
&& !radio_driver.configSideDetectors(_prefs.extra_sf, extra_sf_count, _prefs.bw)) return false;
|
||||
#endif
|
||||
return radio_driver.setTxPower(_prefs.tx_power_dbm);
|
||||
}
|
||||
|
||||
@@ -1479,6 +1570,40 @@ bool SensorMesh::isTxPowerApplied(int8_t power_dbm) const {
|
||||
bool SensorMesh::setRxPowerSaving(bool enable, uint32_t rx_us, uint32_t sleep_us) {
|
||||
return radio_driver.setRxPowerSaving(enable, rx_us, sleep_us);
|
||||
}
|
||||
|
||||
bool SensorMesh::supportsRxPowerSaving() const {
|
||||
return radio_driver.supportsRxPowerSaving();
|
||||
}
|
||||
|
||||
mesh::RadioParamApplyResult SensorMesh::trySetRxPowerSaving(bool enable, uint32_t rx_us, uint32_t sleep_us) {
|
||||
return radio_driver.trySetRxPowerSaving(enable, rx_us, sleep_us);
|
||||
}
|
||||
|
||||
bool SensorMesh::supportsRxPowerSavingRfRxDisable() const {
|
||||
return radio_driver.supportsRxPowerSavingRfRxDisable();
|
||||
}
|
||||
|
||||
mesh::RadioParamApplyResult SensorMesh::trySetRxPowerSavingRfRxDisabled(bool disabled) {
|
||||
return radio_driver.trySetRxPowerSavingRfRxDisabled(disabled);
|
||||
}
|
||||
|
||||
bool SensorMesh::isRxPowerSavingRfRxDisabled() const {
|
||||
return radio_driver.isRxPowerSavingRfRxDisabled();
|
||||
}
|
||||
|
||||
bool SensorMesh::supportsRxBoostedGain() const {
|
||||
return radio_driver.supportsRxBoostedGainMode();
|
||||
}
|
||||
|
||||
mesh::RadioParamApplyResult SensorMesh::trySetRxBoostedGain(bool enable) {
|
||||
return radio_driver.trySetRxBoostedGainMode(enable);
|
||||
}
|
||||
|
||||
#if defined(USE_LR2021)
|
||||
mesh::RadioParamApplyResult SensorMesh::tryConfigSideDetectors(const uint8_t sideDetSFs[], uint8_t num, float bw) {
|
||||
return radio_driver.tryConfigSideDetectors(sideDetSFs, num, bw);
|
||||
}
|
||||
#endif
|
||||
void SensorMesh::getRxPsWatchdogCounts(uint32_t* soft, uint32_t* hard) {
|
||||
*soft = radio_driver.getRxPsWatchdogSoftCount();
|
||||
*hard = radio_driver.getRxPsWatchdogHardCount();
|
||||
@@ -1551,69 +1676,7 @@ void SensorMesh::loop() {
|
||||
updateAdvertTimer(); // schedule next local advert
|
||||
}
|
||||
|
||||
const bool revert_radio_due = revert_radio_at && millisHasNowPassed(revert_radio_at);
|
||||
const bool radio_apply_ready = !radio_apply_retry_at || millisHasNowPassed(radio_apply_retry_at);
|
||||
bool radio_apply_failed = false;
|
||||
if (revert_radio_due && !temp_radio_applied) {
|
||||
// Never apply a temporary channel after its window has already ended.
|
||||
set_radio_at = revert_radio_at = 0;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
MESH_DEBUG_PRINTLN("Temp radio params expired before apply");
|
||||
} else if (revert_radio_due && !hasOutbound() && radio_apply_ready) {
|
||||
if (applySavedRadioParams()) {
|
||||
set_radio_at = revert_radio_at = 0;
|
||||
temp_radio_applied = false;
|
||||
saved_radio_apply_pending = false;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
MESH_DEBUG_PRINTLN("Radio params restored");
|
||||
} else {
|
||||
radio_apply_failed = true;
|
||||
}
|
||||
} else if (set_radio_at && millisHasNowPassed(set_radio_at) && !hasOutbound()
|
||||
&& radio_apply_ready) {
|
||||
uint32_t rx_us = _prefs.rx_ps_rx_us;
|
||||
uint32_t sleep_us = _prefs.rx_ps_sleep_us;
|
||||
bool timing_ok = true;
|
||||
if (_prefs.rx_powersaving_enabled && _prefs.rx_ps_level != 0) {
|
||||
uint32_t preamble = _prefs.rx_ps_preamble ? _prefs.rx_ps_preamble
|
||||
: rxPowerSavingPreambleForParams(pending_sf, pending_bw);
|
||||
timing_ok = CommonCLI::calculateRxPowerSavingLevel(
|
||||
_prefs.rx_ps_level, pending_sf, pending_bw, preamble, &rx_us, &sleep_us);
|
||||
}
|
||||
uint32_t timings[2] = {rx_us, sleep_us};
|
||||
const uint32_t* applied_timings = _prefs.rx_powersaving_enabled
|
||||
&& radio_driver.supportsRxPowerSaving() ? timings : NULL;
|
||||
if (timing_ok && _cli.radioProfiles().applyPrimary(
|
||||
pending_freq, pending_bw, pending_sf, pending_cr, true, pending_preamble, applied_timings) == mesh::RadioParamApplyResult::APPLIED) {
|
||||
set_radio_at = 0;
|
||||
active_cr = pending_cr;
|
||||
temp_radio_applied = true;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
MESH_DEBUG_PRINTLN("Temp radio params");
|
||||
} else {
|
||||
// A failed setParams() may have applied only a prefix of the tuple.
|
||||
// Ensure expiry restores the complete saved configuration.
|
||||
saved_radio_apply_pending = true;
|
||||
radio_apply_failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (saved_radio_apply_pending && !temp_radio_applied && !hasOutbound()
|
||||
&& radio_apply_ready && !radio_apply_failed) {
|
||||
if (applySavedRadioParams()) {
|
||||
saved_radio_apply_pending = false;
|
||||
radio_apply_retry_at = 0;
|
||||
radio_apply_failures = 0;
|
||||
} else {
|
||||
radio_apply_failed = true;
|
||||
}
|
||||
}
|
||||
if (radio_apply_failed) {
|
||||
radio_apply_retry_at = futureMillis(nextRadioApplyRetryDelay(radio_apply_failures));
|
||||
}
|
||||
servicePendingPrimaryRadioSettings();
|
||||
|
||||
uint32_t curr = getRTCClock()->getCurrentTime();
|
||||
if (curr >= last_read_time + SENSOR_READ_INTERVAL_SECS) {
|
||||
@@ -1751,7 +1814,7 @@ mesh::powerdiag::Mask SensorMesh::pendingWorkReason() const {
|
||||
#endif
|
||||
if (!canIdleDualRadio()) return mask(Reason::DualRadio);
|
||||
if (hasPendingOtaApply()) return mask(Reason::Ota);
|
||||
if (_cli.hasActiveUserGpioTimer() || _cli.hasPendingTxPower()) return mask(Reason::Scheduled);
|
||||
if (_cli.hasActiveUserGpioTimer() || _cli.hasPendingRadioSettings()) return mask(Reason::Scheduled);
|
||||
if (radio_driver.isWatchdogObserving()) return mask(Reason::RadioWatchdog);
|
||||
uint32_t noise_floor_delay_ms;
|
||||
if (getNextNoiseFloorWakeDelay(noise_floor_delay_ms) && noise_floor_delay_ms == 0)
|
||||
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
void loop();
|
||||
bool canRecoverUsbLogging() const {
|
||||
return dirty_contacts_expiry == 0 && !hasOutbound() && !isAnyTempRadioActive()
|
||||
&& !hasPendingOtaApply() && !saved_radio_apply_pending && !_cli.hasPendingTxPower()
|
||||
&& !hasPendingOtaApply() && !saved_radio_apply_pending && !_cli.hasPendingRadioSettings()
|
||||
&& set_radio_at == 0;
|
||||
}
|
||||
void handleCommand(uint32_t sender_timestamp, char* command, char* reply,
|
||||
@@ -120,6 +120,16 @@ public:
|
||||
bool isTxPowerApplied(int8_t power_dbm) const override;
|
||||
#endif
|
||||
bool setRxPowerSaving(bool enable, uint32_t rx_us, uint32_t sleep_us) override;
|
||||
bool supportsRxPowerSaving() const override;
|
||||
mesh::RadioParamApplyResult trySetRxPowerSaving(bool enable, uint32_t rx_us, uint32_t sleep_us) override;
|
||||
bool supportsRxPowerSavingRfRxDisable() const override;
|
||||
mesh::RadioParamApplyResult trySetRxPowerSavingRfRxDisabled(bool disabled) override;
|
||||
bool isRxPowerSavingRfRxDisabled() const override;
|
||||
bool supportsRxBoostedGain() const override;
|
||||
mesh::RadioParamApplyResult trySetRxBoostedGain(bool enable) override;
|
||||
#if defined(USE_LR2021)
|
||||
mesh::RadioParamApplyResult tryConfigSideDetectors(const uint8_t sideDetSFs[], uint8_t num, float bw) override;
|
||||
#endif
|
||||
void recalibrateNoiseFloor() override { _radio->recalibrateNoiseFloor(); }
|
||||
void getRxPsWatchdogCounts(uint32_t* soft, uint32_t* hard) override;
|
||||
void formatNeighborsReply(char *reply) override {
|
||||
@@ -303,6 +313,7 @@ private:
|
||||
uint8_t radio_apply_failures;
|
||||
|
||||
bool applySavedRadioParams();
|
||||
void servicePendingPrimaryRadioSettings(bool tx_gap = false);
|
||||
bool isMillisTimerDue(unsigned long timestamp) const;
|
||||
uint32_t limitSleepToMillisTimer(unsigned long timestamp,
|
||||
uint32_t sleep_ms) const;
|
||||
|
||||
@@ -83,7 +83,7 @@ bool SensorMesh::trackerNeedsRadio() const {
|
||||
|| board.isRadioTestActive() || mesh::isUsbLoggingWatchdogArmed()
|
||||
|| isAnyTempRadioActive() || hasPendingOtaApply() || isDualRadioActive()
|
||||
|| set_radio_at || revert_radio_at || saved_radio_apply_pending
|
||||
|| _cli.hasActiveUserGpioTimer() || _cli.hasPendingTxPower()
|
||||
|| _cli.hasActiveUserGpioTimer() || _cli.hasPendingRadioSettings()
|
||||
|| hasOutbound() || _mgr->getOutboundTotal() != 0)
|
||||
return true;
|
||||
uint32_t delay;
|
||||
@@ -272,6 +272,9 @@ void SensorMesh::onSendComplete(mesh::Packet* packet) {
|
||||
mesh::Mesh::onSendComplete(packet);
|
||||
_cli.servicePendingTxPower();
|
||||
_cli.morseReply().complete(packet);
|
||||
_cli.servicePendingRxSettings();
|
||||
_cli.radioProfiles().servicePendingTuning();
|
||||
servicePendingPrimaryRadioSettings(true);
|
||||
if (!tracker_pending || !packet || packet->getPayloadType() != PAYLOAD_TYPE_REQ) return;
|
||||
uint8_t hash[MAX_HASH_SIZE];
|
||||
packet->calculatePacketHash(hash);
|
||||
|
||||
Reference in new issue
Block a user