#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 channelLoad(const std::vector& sightings) { std::array 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& load) { int best = 1; for (int ch : {6, 11}) if (load[ch] < load[best]) best = ch; return best; } } // namespace roro