| 1474 | } |
| 1475 | |
| 1476 | void WBLink::perform_channel_analyze(int channels_to_scan) { |
| 1477 | const auto analyze_begin = std::chrono::steady_clock::now(); |
| 1478 | struct AnalyzeResult { |
| 1479 | int frequency; |
| 1480 | int n_foreign_packets; |
| 1481 | }; |
| 1482 | const WiFiCard& card = m_broadcast_cards.at(0); |
| 1483 | const auto channels_to_analyze = |
| 1484 | openhd::wb::get_analyze_channels_frequencies(card, channels_to_scan); |
| 1485 | auto stats_current = openhd::LinkActionHandler::instance().get_link_stats(); |
| 1486 | stats_current.gnd_operating_mode.operating_mode = 2; |
| 1487 | openhd::LinkActionHandler::instance().update_link_stats(stats_current); |
| 1488 | std::vector<AnalyzeResult> results{}; |
| 1489 | for (int i = 0; i < channels_to_analyze.size(); i++) { |
| 1490 | const auto channel = channels_to_analyze[i]; |
| 1491 | // We use fixed 40Mhz during analyze. |
| 1492 | const int channel_width = 40; |
| 1493 | // set new frequency, reset the packet count, sleep, then check if any |
| 1494 | // openhd packets have been received |
| 1495 | apply_frequency_and_channel_width(channel.frequency, channel_width, 20); |
| 1496 | // Disable injection during analyze |
| 1497 | m_wb_txrx->set_passive_mode(true); |
| 1498 | // Sleep a bit to give the card time to switch |
| 1499 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 1500 | m_console->debug("Analyzing [{}] {}Mhz@{}Mhz", channel.channel, |
| 1501 | channel.frequency, channel_width); |
| 1502 | reset_all_rx_stats(); |
| 1503 | std::this_thread::sleep_for(std::chrono::seconds(4)); |
| 1504 | const auto stats = m_wb_txrx->get_rx_stats(); |
| 1505 | const auto n_foreign_packets = stats.count_p_any - stats.count_p_valid; |
| 1506 | m_console->debug("Got {} foreign packets {}:{}", n_foreign_packets, |
| 1507 | stats.count_p_any, stats.count_p_valid); |
| 1508 | results.push_back( |
| 1509 | AnalyzeResult{(int)channel.frequency, (int)n_foreign_packets}); |
| 1510 | |
| 1511 | openhd::LinkActionHandler::AnalyzeChannelsResult tmp{}; |
| 1512 | for (int j = 0; j < 30; j++) { |
| 1513 | if (j < results.size()) { |
| 1514 | tmp.channels_mhz[j] = results[j].frequency; |
| 1515 | tmp.foreign_packets[j] = results[j].n_foreign_packets; |
| 1516 | } else { |
| 1517 | tmp.channels_mhz[j] = 0; |
| 1518 | tmp.foreign_packets[j] = 0; |
| 1519 | } |
| 1520 | } |
| 1521 | tmp.progress = OHDUtil::calculate_progress_perc( |
| 1522 | i + 1, (int)channels_to_analyze.size()); |
| 1523 | openhd::LinkActionHandler::instance().add_analyze_result(tmp); |
| 1524 | } |
| 1525 | /*std::stringstream ss; |
| 1526 | for(int i=0;i<results.size();i++){ |
| 1527 | ss<<results[i].frequency<<"@"<<results[i].n_foreign_packets<<"\n"; |
| 1528 | } |
| 1529 | m_console->debug("{}",ss.str().c_str());*/ |
| 1530 | re_enable_injection_unless_user_passive_mode_enabled(); |
| 1531 | m_console->debug( |
| 1532 | "Done analyzing, took:{}", |
| 1533 | MyTimeHelper::R(std::chrono::steady_clock::now() - analyze_begin)); |
nothing calls this directly
no test coverage detected