| 686 | } |
| 687 | |
| 688 | static void dispatchScan(std::shared_ptr<Wifi> wifi) { |
| 689 | LOGGER.info("dispatchScan()"); |
| 690 | auto lock = wifi->radioMutex.asScopedLock(); |
| 691 | |
| 692 | if (!lock.lock(10 / portTICK_PERIOD_MS)) { |
| 693 | LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED); |
| 694 | return; |
| 695 | } |
| 696 | |
| 697 | RadioState state = wifi->getRadioState(); |
| 698 | if (state != RadioState::On && state != RadioState::ConnectionActive && state != RadioState::ConnectionPending) { |
| 699 | LOGGER.warn("Scan unavailable: wifi not enabled"); |
| 700 | return; |
| 701 | } |
| 702 | |
| 703 | if (wifi->isScanActive()) { |
| 704 | LOGGER.warn("Scan already pending"); |
| 705 | return; |
| 706 | } |
| 707 | |
| 708 | // TODO: Thread safety |
| 709 | wifi->last_scan_time = tt::kernel::getTicks(); |
| 710 | |
| 711 | if (esp_wifi_scan_start(nullptr, false) != ESP_OK) { |
| 712 | LOGGER.info("Can't start scan"); |
| 713 | return; |
| 714 | } |
| 715 | |
| 716 | LOGGER.info("Starting scan"); |
| 717 | wifi->setScanActive(true); |
| 718 | publish_event(wifi, WifiEvent::ScanStarted); |
| 719 | } |
| 720 | |
| 721 | static void dispatchConnect(std::shared_ptr<Wifi> wifi) { |
| 722 | LOGGER.info("dispatchConnect()"); |
no test coverage detected