MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / perform_channel_scan

Method perform_channel_scan

OpenHD/ohd_interface/src/wb_link.cpp:1336–1474  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1334}
1335
1336void WBLink::perform_channel_scan(
1337 const openhd::LinkActionHandler::ScanChannelsParam& scan_channels_params) {
1338 const WiFiCard& card = m_broadcast_cards.at(0);
1339 const auto channels_to_scan = openhd::wb::get_scan_channels_frequencies(
1340 card, scan_channels_params.channels_to_scan);
1341 if (channels_to_scan.empty()) {
1342 m_console->warn("No channels to scan, return early");
1343 return;
1344 }
1345 // const auto channel_widths_to_scan=
1346 // openhd::wb::get_scan_channels_bandwidths(scan_channels_params.check_20Mhz_channel_width_if_card_supports,
1347 // scan_channels_params.check_40Mhz_channel_width_if_card_supports);
1348 // if(channel_widths_to_scan.empty()){
1349 // m_console->warn("No channel_widths to scan, return early");
1350 // return;
1351 // }
1352 // We only scan 40Mhz, this way we get both 20Mhz and 40Mhz air unit(s)
1353 const std::vector<uint16_t> channel_widths_to_scan = {40};
1354
1355 auto stats_current = openhd::LinkActionHandler::instance().get_link_stats();
1356 stats_current.gnd_operating_mode.operating_mode = 1;
1357 openhd::LinkActionHandler::instance().update_link_stats(stats_current);
1358
1359 struct ScanResult {
1360 bool success = false;
1361 int frequency = 0;
1362 int channel_width = 0;
1363 };
1364 ScanResult result{false, 0, 0};
1365 // Note: We intentionally do not modify the persistent settings here
1366 m_console->debug(
1367 "Channel scan N channels to scan:{} N channel widths to scan:{}",
1368 channels_to_scan.size(), channel_widths_to_scan.size());
1369 bool done_early = false;
1370 // We need to loop through all possible channels
1371 for (int i = 0; i < channels_to_scan.size(); i++) {
1372 const auto& channel = channels_to_scan[i];
1373 if (done_early) break;
1374 // and all possible channel widths (20 or 40Mhz only right now)
1375 for (const auto& channel_width : channel_widths_to_scan) {
1376 // Return early in some cases (e.g. when we have a low loss and are quite
1377 // certain about a frequency)
1378 if (done_early) break;
1379 // Skip channels / frequencies the card doesn't support anyways
1380 if (!openhd::wb::any_card_support_frequency(
1381 channel.frequency, m_broadcast_cards, m_console)) {
1382 continue;
1383 }
1384 // set new frequency, reset the packet count, sleep, then check if any
1385 // openhd packets have been received
1386 const bool freq_success = apply_frequency_and_channel_width(
1387 channel.frequency, channel_width, 20);
1388 if (!freq_success) {
1389 m_console->warn("Cannot scan [{}] {}Mhz@{}Mhz", channel.channel,
1390 channel.frequency, channel_width);
1391 continue;
1392 }
1393 openhd::LinkActionHandler::ScanChannelsProgress tmp{};

Callers

nothing calls this directly

Calls 6

get_link_statsMethod · 0.80
update_link_statsMethod · 0.80
debugMethod · 0.80
sizeMethod · 0.80
persistMethod · 0.80

Tested by

no test coverage detected