use threads in wifi handler sim to simulate a bit of delay in the notifications like on hardware.
This commit is contained in:
parent
45160ceac5
commit
29f58d406f
2 changed files with 38 additions and 17 deletions
|
@ -7,8 +7,19 @@ wifiHandlerSim::wifiHandlerSim() {}
|
||||||
void wifiHandlerSim::begin() {}
|
void wifiHandlerSim::begin() {}
|
||||||
|
|
||||||
void wifiHandlerSim::connect(std::string ssid, std::string password) {
|
void wifiHandlerSim::connect(std::string ssid, std::string password) {
|
||||||
status.ssid = ssid;
|
while (!mIsStatusThreadDone.load()) {
|
||||||
mStatusUpdate->notify(wifiStatus(status));
|
}
|
||||||
|
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[] = {
|
static const WifiInfo wifis[] = {
|
||||||
|
@ -16,8 +27,17 @@ static const WifiInfo wifis[] = {
|
||||||
WifiInfo("Low Signal Wifi", -65), WifiInfo("No Signal Wifi", -90)};
|
WifiInfo("Low Signal Wifi", -65), WifiInfo("No Signal Wifi", -90)};
|
||||||
|
|
||||||
void wifiHandlerSim::scan() {
|
void wifiHandlerSim::scan() {
|
||||||
std::vector<WifiInfo> info = std::vector(std::begin(wifis), std::end(wifis));
|
while (!mIsScanThreadDone.load()) {
|
||||||
mScanNotification->notify(info);
|
}
|
||||||
|
if (mFakeScanThread.joinable()) {
|
||||||
|
mFakeScanThread.join();
|
||||||
|
}
|
||||||
|
mIsScanThreadDone = false;
|
||||||
|
mFakeScanThread = std::thread([this] {
|
||||||
|
std::vector<WifiInfo> 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; }
|
|
||||||
|
|
|
@ -1,24 +1,25 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Notification.hpp"
|
#include "Notification.hpp"
|
||||||
#include "wifiHandlerInterface.h"
|
#include "wifiHandlerInterface.h"
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
class wifiHandlerSim : public wifiHandlerInterface {
|
class wifiHandlerSim : public wifiHandlerInterface {
|
||||||
public:
|
public:
|
||||||
wifiHandlerSim();
|
wifiHandlerSim();
|
||||||
|
|
||||||
/**
|
void begin() override;
|
||||||
* @brief Connect to the wifi using the provided credetials
|
void scan() override;
|
||||||
*/
|
|
||||||
void connect(std::string ssid, std::string password) override;
|
void connect(std::string ssid, std::string password) override;
|
||||||
|
wifiStatus GetStatus() override { return mCurrentStatus; };
|
||||||
/**
|
|
||||||
* @brief function to trigger asynchronous scan for wifi networks
|
|
||||||
*/
|
|
||||||
void scan();
|
|
||||||
bool isAvailable();
|
|
||||||
void begin();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wifiStatus status = wifiStatus(true, "172.0.0.1", "FakeNet");
|
// Since they have not started consider them "done"
|
||||||
|
std::atomic<bool> mIsScanThreadDone = true;
|
||||||
|
std::atomic<bool> mIsStatusThreadDone = true;
|
||||||
|
|
||||||
|
std::thread mFakeScanThread;
|
||||||
|
std::thread mFakeStatusThread;
|
||||||
|
wifiStatus mCurrentStatus = wifiStatus(true, "172.0.0.1", "FakeNet");
|
||||||
};
|
};
|
Loading…
Add table
Reference in a new issue