Improve:wifi hal init ap mode.
This commit is contained in:
parent
cc493b6c3d
commit
61df3be654
|
@ -36,6 +36,10 @@ StatusCode VWifiHal::OpenApMode(void)
|
||||||
{
|
{
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
}
|
}
|
||||||
|
StatusCode VWifiHal::CloseApMode(void)
|
||||||
|
{
|
||||||
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
}
|
||||||
void VCameraHalMonitor::ReportEvent(const CameraReportEvent &event)
|
void VCameraHalMonitor::ReportEvent(const CameraReportEvent &event)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,7 @@ public:
|
||||||
VWifiHal() = default;
|
VWifiHal() = default;
|
||||||
virtual ~VWifiHal() = default;
|
virtual ~VWifiHal() = default;
|
||||||
virtual StatusCode OpenApMode(void);
|
virtual StatusCode OpenApMode(void);
|
||||||
|
virtual StatusCode CloseApMode(void);
|
||||||
};
|
};
|
||||||
class VCameraHalMonitor
|
class VCameraHalMonitor
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,12 +20,16 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
WifiHal::WifiHal() : mInitRunning(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
StatusCode WifiHal::OpenApMode(void)
|
StatusCode WifiHal::OpenApMode(void)
|
||||||
{
|
{
|
||||||
LogInfo("OpenApMode. \n");
|
LogInfo("OpenApMode. \n");
|
||||||
constexpr int SLEEP_TIME_MS = 5;
|
constexpr int SLEEP_TIME_MS = 5;
|
||||||
constexpr int WAITING_TIME_MS = 1000 * 10;
|
constexpr int WAITING_TIME_MS = 1000 * 10;
|
||||||
unsigned int sleepingTime_ms = 0;
|
unsigned int sleepingTime_ms = 0;
|
||||||
|
mInitRunning = true;
|
||||||
while (CheckWlan0IfExist() == false) {
|
while (CheckWlan0IfExist() == false) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
|
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
|
||||||
sleepingTime_ms += SLEEP_TIME_MS;
|
sleepingTime_ms += SLEEP_TIME_MS;
|
||||||
|
@ -33,6 +37,10 @@ StatusCode WifiHal::OpenApMode(void)
|
||||||
LogError("wlan0 not found. \n");
|
LogError("wlan0 not found. \n");
|
||||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||||
}
|
}
|
||||||
|
if (false == mInitRunning) {
|
||||||
|
LogError("Open ap mode stop. \n");
|
||||||
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
LogInfo("wlan0 ok. \n");
|
LogInfo("wlan0 ok. \n");
|
||||||
fx_system("ifconfig wlan0 192.168.169.1 netmask 255.255.255.0");
|
fx_system("ifconfig wlan0 192.168.169.1 netmask 255.255.255.0");
|
||||||
|
@ -41,6 +49,17 @@ StatusCode WifiHal::OpenApMode(void)
|
||||||
fx_system("udhcpd -f /etc/udhcpd.conf &");
|
fx_system("udhcpd -f /etc/udhcpd.conf &");
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
|
StatusCode WifiHal::CloseApMode(void)
|
||||||
|
{
|
||||||
|
mInitRunning = false;
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
||||||
|
void WifiHal::Init(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void WifiHal::UnInit(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
bool WifiHal::CheckWlan0IfExist(void)
|
bool WifiHal::CheckWlan0IfExist(void)
|
||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
|
|
|
@ -18,11 +18,17 @@
|
||||||
class WifiHal : public VWifiHal
|
class WifiHal : public VWifiHal
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WifiHal() = default;
|
WifiHal();
|
||||||
virtual ~WifiHal() = default;
|
virtual ~WifiHal() = default;
|
||||||
StatusCode OpenApMode(void) override;
|
StatusCode OpenApMode(void) override;
|
||||||
|
StatusCode CloseApMode(void) override;
|
||||||
|
void Init(void);
|
||||||
|
void UnInit(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool CheckWlan0IfExist(void);
|
bool CheckWlan0IfExist(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool mInitRunning;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -19,28 +19,34 @@
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include "TcpModule.h"
|
#include "TcpModule.h"
|
||||||
#include "WebServer.h"
|
#include "WebServer.h"
|
||||||
AppManager::AppManager()
|
AppManager::AppManager() : mTcpServer(nullptr), mInitRuning(false)
|
||||||
{
|
{
|
||||||
mTcpServer = nullptr;
|
|
||||||
}
|
}
|
||||||
const StatusCode AppManager::Init(const AppParam ¶m)
|
const StatusCode AppManager::Init(const AppParam ¶m)
|
||||||
{
|
{
|
||||||
std::shared_ptr<VWifiHal> wifi;
|
auto initThread = [](std::shared_ptr<AppManager> appManager, const AppParam param) {
|
||||||
IHalCpp::GetInstance()->GetWifiHal(wifi);
|
LogInfo("WifiApModeInit started.\n");
|
||||||
if (!wifi) {
|
appManager->WifiApModeInit(param);
|
||||||
LogError("Get wifi hal failed.\n");
|
};
|
||||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
mInitThread = std::thread(initThread, shared_from_this(), param);
|
||||||
}
|
|
||||||
wifi->OpenApMode();
|
|
||||||
std::shared_ptr<IAppProtocolHandle> protocolHandle;
|
|
||||||
AppManagerMakePtr::GetInstance()->CreateProtocolHandle(protocolHandle);
|
|
||||||
IAppProtocolHandle::GetInstance(&protocolHandle);
|
|
||||||
HttpServerStart(param);
|
|
||||||
TcpServerStart(param);
|
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
const StatusCode AppManager::UnInit(void)
|
const StatusCode AppManager::UnInit(void)
|
||||||
{
|
{
|
||||||
|
if (true == mInitRuning) {
|
||||||
|
std::shared_ptr<VWifiHal> wifi;
|
||||||
|
IHalCpp::GetInstance()->GetWifiHal(wifi);
|
||||||
|
if (!wifi) {
|
||||||
|
LogWarning("Get wifi hal failed.\n");
|
||||||
|
goto GOAHEAD;
|
||||||
|
}
|
||||||
|
wifi->CloseApMode();
|
||||||
|
}
|
||||||
|
GOAHEAD:
|
||||||
|
mInitRuning = false;
|
||||||
|
if (mInitThread.joinable()) {
|
||||||
|
mInitThread.join();
|
||||||
|
}
|
||||||
HttpServerStop();
|
HttpServerStop();
|
||||||
TcpServerStop();
|
TcpServerStop();
|
||||||
std::shared_ptr<IAppProtocolHandle> protocolHandle = std::make_shared<IAppProtocolHandle>();
|
std::shared_ptr<IAppProtocolHandle> protocolHandle = std::make_shared<IAppProtocolHandle>();
|
||||||
|
@ -156,4 +162,28 @@ void AppManager::TcpServerStop(void)
|
||||||
if (nullptr != mTcpServer) {
|
if (nullptr != mTcpServer) {
|
||||||
FreeTcpServer(mTcpServer);
|
FreeTcpServer(mTcpServer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
void AppManager::WifiApModeInit(const AppParam ¶m)
|
||||||
|
{
|
||||||
|
mInitRuning = true;
|
||||||
|
std::shared_ptr<VWifiHal> wifi;
|
||||||
|
IHalCpp::GetInstance()->GetWifiHal(wifi);
|
||||||
|
if (!wifi) {
|
||||||
|
LogError("Get wifi hal failed.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief This interface depends on hardware and may block. It is necessary to ensure that hardware interface
|
||||||
|
* blocking does not cause the main thread to block.
|
||||||
|
*/
|
||||||
|
wifi->OpenApMode();
|
||||||
|
if (false == mInitRuning) {
|
||||||
|
LogWarning("AppManager init stop.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::shared_ptr<IAppProtocolHandle> protocolHandle;
|
||||||
|
AppManagerMakePtr::GetInstance()->CreateProtocolHandle(protocolHandle);
|
||||||
|
IAppProtocolHandle::GetInstance(&protocolHandle);
|
||||||
|
HttpServerStart(param);
|
||||||
|
TcpServerStart(param);
|
||||||
}
|
}
|
|
@ -41,12 +41,17 @@ private:
|
||||||
void TcpServerStart(const AppParam ¶m);
|
void TcpServerStart(const AppParam ¶m);
|
||||||
void TcpServerStop(void);
|
void TcpServerStop(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void WifiApModeInit(const AppParam ¶m);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::thread mHttpSever;
|
std::thread mHttpSever;
|
||||||
std::shared_ptr<IAppProtocolHandle> mProtocolHandle;
|
std::shared_ptr<IAppProtocolHandle> mProtocolHandle;
|
||||||
void *mTcpServer;
|
void *mTcpServer;
|
||||||
std::shared_ptr<VAppMonitor> mAppMonitor;
|
std::shared_ptr<VAppMonitor> mAppMonitor;
|
||||||
std::map<void *, std::shared_ptr<VAppClient>> mAppClients;
|
std::map<void *, std::shared_ptr<VAppClient>> mAppClients;
|
||||||
|
bool mInitRuning;
|
||||||
|
std::thread mInitThread;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user