WiFi接口析构时自动销毁ssid/pass

This commit is contained in:
大石头X2 2017-03-01 01:19:22 +08:00
parent 29202abaa7
commit c156bc9d34
3 changed files with 22 additions and 17 deletions

View File

@ -50,20 +50,19 @@ Esp8266::Esp8266(COM idx, Pin power, Pin rst)
Esp8266::~Esp8266() Esp8266::~Esp8266()
{ {
delete SSID; RemoveLed();
delete Pass;
} }
void Esp8266::Init(ITransport* port, Pin power, Pin rst) void Esp8266::Init(ITransport* port, Pin power, Pin rst)
{ {
Name = "Esp8266"; Name = "Esp8266";
Speed = 54; Speed = 54;
Port = port; Port = port;
if(Port) if (Port)
{ {
if(MinSize) MinSize = Port->MinSize; if (MinSize) MinSize = Port->MinSize;
if(MaxSize) MaxSize = Port->MaxSize; if (MaxSize) MaxSize = Port->MaxSize;
Port->Register(OnPortReceive, this); Port->Register(OnPortReceive, this);
} }
@ -71,16 +70,16 @@ void Esp8266::Init(ITransport* port, Pin power, Pin rst)
_power.Init(power, false); _power.Init(power, false);
if (rst != P0) _rst.Init(rst, true); if (rst != P0) _rst.Init(rst, true);
_task = 0; _task = 0;
Led = nullptr; Led = nullptr;
_Expect = nullptr; _Expect = nullptr;
Buffer(_sockets, 5 * 4).Clear(); Buffer(_sockets, 5 * 4).Clear();
Mode = NetworkType::STA_AP; Mode = NetworkType::STA_AP;
WorkMode= NetworkType::STA_AP; WorkMode = NetworkType::STA_AP;
InitConfig(); InitConfig();
LoadConfig(); LoadConfig();
@ -100,10 +99,10 @@ void Esp8266::SetLed(Pin led)
void Esp8266::SetLed(OutputPort& led) void Esp8266::SetLed(OutputPort& led)
{ {
auto fp = new FlushPort(); auto fp = new FlushPort();
fp->Port = &led; fp->Port = &led;
fp->Start(); fp->Start();
Led = fp; Led = fp;
} }
void Esp8266::RemoveLed() void Esp8266::RemoveLed()
@ -463,7 +462,7 @@ void ParseFail(cstring name, const Buffer& bs)
uint Esp8266::OnPortReceive(ITransport* sender, Buffer& bs, void* param, void* param2) uint Esp8266::OnPortReceive(ITransport* sender, Buffer& bs, void* param, void* param2)
{ {
auto esp = (Esp8266*)param; auto esp = (Esp8266*)param;
return esp->OnReceive(bs, param2); return esp->OnReceive(bs, param2);
} }

View File

@ -289,6 +289,12 @@ WiFiInterface::WiFiInterface() : NetworkInterface()
Pass = nullptr; Pass = nullptr;
} }
WiFiInterface::~WiFiInterface()
{
delete SSID;
delete Pass;
}
bool WiFiInterface::IsStation() const bool WiFiInterface::IsStation() const
{ {
return Mode == NetworkType::Station || Mode == NetworkType::STA_AP; return Mode == NetworkType::Station || Mode == NetworkType::STA_AP;

View File

@ -113,7 +113,7 @@ public:
String* Pass; // 无线密码 String* Pass; // 无线密码
WiFiInterface(); WiFiInterface();
virtual ~WiFiInterface() { } virtual ~WiFiInterface();
bool IsStation() const; bool IsStation() const;
bool IsAP() const; bool IsAP() const;