mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 13:52:15 +01:00
fix: send socket events only from loop()
Every socket event is formatted into one static buffer by one shared formatter. setConnected() runs on the WiFi/Ethernet event task and sent memStatus, wifiStrength and ethernet, then ran sockEmit.loop(), while loop() could be building its own event. _safecat() checks the room and then writes at _len, so another task moving _len in between could write past the end of g_response. setConnected() now sends nothing. loop() broadcasts the status every STATUS_EMIT_MS (30 s): memStatus, then ethernet, or wifiStrength when it moved 3 dBm or changed channel. A client that connects still gets all of it at once from initClients(), so needsBroadcast and the 1.5 s tick go, and so does the 1.5 s memStatus for the config panel. SocketEmitter records loop()'s task in begin(). Off it, beginEmit() logs and hands out a formatter that writes nothing, and endEmit(), endEmitRoom() and loop() do nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
474c7c0f42
commit
25d548ef07
11 changed files with 153 additions and 117 deletions
|
|
@ -130,19 +130,21 @@ int Timestamp::tzOffset() {
|
|||
time(&now);
|
||||
return Timestamp::calcTZOffset(&now);
|
||||
}
|
||||
bool rssiNeedsEmit(int rssi, int lastRssi, int channel, int lastChannel, uint32_t sinceLastMs, int minDelta, uint32_t minMs) {
|
||||
bool rssiNeedsEmit(int rssi, int lastRssi, int channel, int lastChannel, int minDelta) {
|
||||
if(channel != lastChannel) return true;
|
||||
int delta = rssi > lastRssi ? rssi - lastRssi : lastRssi - rssi;
|
||||
return delta >= minDelta && sinceLastMs >= minMs;
|
||||
return delta >= minDelta;
|
||||
}
|
||||
bool RssiBroadcast::due(int rssi, int channel, uint32_t now, int minDelta, uint32_t minMs) const {
|
||||
return rssiNeedsEmit(rssi, this->rssi, channel, this->channel, now - this->at, minDelta, minMs);
|
||||
bool RssiBroadcast::due(int rssi, int channel, int minDelta) const {
|
||||
return rssiNeedsEmit(rssi, this->rssi, channel, this->channel, minDelta);
|
||||
}
|
||||
void RssiBroadcast::sent(bool broadcast, int rssi, int channel, uint32_t now) {
|
||||
void RssiBroadcast::sent(bool broadcast, int rssi, int channel) {
|
||||
if(!broadcast) return;
|
||||
this->rssi = rssi;
|
||||
this->channel = channel;
|
||||
this->at = now;
|
||||
}
|
||||
bool emitAllowed(const void *current, const void *owner) {
|
||||
return owner == nullptr || current == owner;
|
||||
}
|
||||
bool worthRoaming(bool connected, int currentRssi, int apRssi, int minGain) {
|
||||
return !connected || apRssi >= currentRssi + minGain;
|
||||
|
|
@ -179,11 +181,6 @@ const char *wifiAuthModeName(uint8_t authMode) {
|
|||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
heap_emit_t heapEmitTarget(uint8_t num, uint32_t sinceLastMs, uint32_t intervalMs, bool roomHasClients) {
|
||||
if(num != 255) return heap_emit_t::client;
|
||||
if(sinceLastMs >= intervalMs) return heap_emit_t::broadcast;
|
||||
return roomHasClients ? heap_emit_t::room : heap_emit_t::none;
|
||||
}
|
||||
void LoopStats::record(uint32_t passUs) {
|
||||
_passes++;
|
||||
if(passUs > _maxUs) _maxUs = passUs;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue