diff --git a/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.cpp b/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.cpp index 44618a6..0e31da6 100644 --- a/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.cpp +++ b/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.cpp @@ -7,8 +7,19 @@ wifiHandlerSim::wifiHandlerSim() {} void wifiHandlerSim::begin() {} void wifiHandlerSim::connect(std::string ssid, std::string password) { - status.ssid = ssid; - mStatusUpdate->notify(wifiStatus(status)); + while (!mIsStatusThreadDone.load()) { + } + if (mFakeStatusThread.joinable()) { + mFakeStatusThread.join(); + } + mCurrentStatus.ssid = ssid; + mCurrentStatus.isConnected = true; + mIsStatusThreadDone = false; + mFakeStatusThread = std::thread([this] { + std::this_thread::sleep_for(std::chrono::seconds(1)); + mStatusUpdate->notify(mCurrentStatus); + mIsStatusThreadDone = true; + }); } static const WifiInfo wifis[] = { @@ -16,8 +27,17 @@ static const WifiInfo wifis[] = { WifiInfo("Low Signal Wifi", -65), WifiInfo("No Signal Wifi", -90)}; void wifiHandlerSim::scan() { - std::vector info = std::vector(std::begin(wifis), std::end(wifis)); - mScanNotification->notify(info); + while (!mIsScanThreadDone.load()) { + } + if (mFakeScanThread.joinable()) { + mFakeScanThread.join(); + } + mIsScanThreadDone = false; + mFakeScanThread = std::thread([this] { + std::vector info = + std::vector(std::begin(wifis), std::end(wifis)); + std::this_thread::sleep_for(std::chrono::seconds(2)); + mScanNotification->notify(info); + mIsScanThreadDone = true; + }); } - -bool wifiHandlerSim::isAvailable() { return false; } diff --git a/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.hpp b/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.hpp index 5f76b6b..439763d 100644 --- a/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.hpp +++ b/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.hpp @@ -1,24 +1,25 @@ #pragma once #include "Notification.hpp" #include "wifiHandlerInterface.h" +#include #include +#include class wifiHandlerSim : public wifiHandlerInterface { public: wifiHandlerSim(); - /** - * @brief Connect to the wifi using the provided credetials - */ + void begin() override; + void scan() override; void connect(std::string ssid, std::string password) override; - - /** - * @brief function to trigger asynchronous scan for wifi networks - */ - void scan(); - bool isAvailable(); - void begin(); + wifiStatus GetStatus() override { return mCurrentStatus; }; private: - wifiStatus status = wifiStatus(true, "172.0.0.1", "FakeNet"); + // Since they have not started consider them "done" + std::atomic mIsScanThreadDone = true; + std::atomic mIsStatusThreadDone = true; + + std::thread mFakeScanThread; + std::thread mFakeStatusThread; + wifiStatus mCurrentStatus = wifiStatus(true, "172.0.0.1", "FakeNet"); }; \ No newline at end of file