Files
roro9stack/lib/wifi/src/channel_occupancy.cpp
T
twislaandClaude Opus 5.5 4cd6a63498 M1 step 6: Wi-Fi Tools from ordinary scans
- lib/wifi (host-tested): channel occupancy (neighbour spill, signal
  weighting, quietest of 1/6/11) and a signal tracker (history, lost
  detection, click interval)
- WifiService: scan results carry BSSID, channel and security; a scan
  can target one channel for quick tracker refreshes; endListScans()
  turns the radio back off when Wi-Fi is disabled
- Wi-Fi Tools App: networks nearby, channel occupancy bars, signal
  tracker with clicks (m to mute)
- M1 plan: Monitoring-mode views and captures deferred

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
2026-10-02 16:33:11 +02:00

36 lines
947 B
C++

#include "channel_occupancy.h"
namespace roro {
namespace {
// -90 dBm (barely there) -> 0.1, -40 dBm and stronger -> 1.
float weight(int rssi) {
float w = (rssi + 90) / 50.0f;
if (w < 0.1f) w = 0.1f;
if (w > 1.0f) w = 1.0f;
return w;
}
const float kSpill[] = {1.0f, 0.5f, 0.2f}; // same channel, one away, two away
} // namespace
std::array<float, 14> channelLoad(const std::vector<ChannelSighting>& sightings) {
std::array<float, 14> load{};
for (auto& s : sightings) {
if (s.channel < 1 || s.channel > 13) continue;
for (int d = -2; d <= 2; d++) {
int ch = s.channel + d;
if (ch >= 1 && ch <= 13) load[ch] += weight(s.rssi) * kSpill[d < 0 ? -d : d];
}
}
return load;
}
int quietestChannel(const std::array<float, 14>& load) {
int best = 1;
for (int ch : {6, 11})
if (load[ch] < load[best]) best = ch;
return best;
}
} // namespace roro