You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
2.0 KiB
C++
122 lines
2.0 KiB
C++
#ifndef MODULEWIFI_H
|
|
#define MODULEWIFI_H
|
|
|
|
#include <QObject>
|
|
#include <atomic>
|
|
#include <QTimer>
|
|
#include <QDebug>
|
|
|
|
class WifiBase
|
|
{
|
|
public:
|
|
WifiBase(){}
|
|
virtual ~WifiBase(){}
|
|
virtual WifiBase* run(WifiBase* p) = 0;
|
|
virtual bool state() = 0;
|
|
void connect(QString name, QString passwd);
|
|
void disconnect();
|
|
bool connectCheck();
|
|
int quality();
|
|
private:
|
|
int quality_val;
|
|
};
|
|
|
|
//已经断开连接
|
|
class WifiDisConnected : public WifiBase
|
|
{
|
|
public:
|
|
WifiDisConnected(){
|
|
qDebug("new WifiDisConnected");
|
|
}
|
|
~WifiDisConnected(){
|
|
qDebug("delete WifiDisConnected");
|
|
}
|
|
virtual WifiBase* run(WifiBase* p);
|
|
virtual bool state(){
|
|
return false;
|
|
}
|
|
};
|
|
//连接中
|
|
class WifiConnecting : public WifiBase
|
|
{
|
|
public:
|
|
WifiConnecting(){
|
|
qDebug("new WifiConnecting");
|
|
}
|
|
~WifiConnecting(){
|
|
qDebug("delete WifiConnecting");
|
|
}
|
|
virtual WifiBase* run(WifiBase* p);
|
|
virtual bool state(){
|
|
return false;
|
|
}
|
|
};
|
|
//已经连接
|
|
class WifiConnected : public WifiBase
|
|
{
|
|
public:
|
|
WifiConnected(){
|
|
qDebug("new WifiConnected");
|
|
}
|
|
~WifiConnected(){
|
|
qDebug("delete WifiConnected");
|
|
}
|
|
virtual WifiBase* run(WifiBase* p);
|
|
virtual bool state(){
|
|
return true;
|
|
}
|
|
};
|
|
|
|
class ModuleWifi : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit ModuleWifi(QObject *parent = nullptr);
|
|
~ModuleWifi();
|
|
|
|
signals:
|
|
|
|
void sigStateChanged(bool state);
|
|
|
|
public:
|
|
|
|
bool isConnected();
|
|
QString getName(){
|
|
return name;
|
|
}
|
|
QString getPasswd(){
|
|
return passwd;
|
|
}
|
|
int getquality();
|
|
|
|
|
|
public slots:
|
|
|
|
/**
|
|
* @brief 连接WIFI账户
|
|
* @param name 用户名
|
|
* @param passwd 密码
|
|
*/
|
|
void onConnect(QString name, QString passwd);
|
|
|
|
/**
|
|
* @brief 断开当前WIFI连接
|
|
*/
|
|
void onDisconnect();
|
|
|
|
|
|
private slots:
|
|
|
|
void onTimerTimeOutCheck();
|
|
|
|
private:
|
|
|
|
WifiBase * pWifi;
|
|
QString name;
|
|
QString passwd;
|
|
bool state;
|
|
|
|
};
|
|
|
|
#endif // MODULEWIFI_H
|