mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
LwipIntfDev - method end() to enable repeated begin (#9023)
This commit is contained in:
parent
c84fda145c
commit
74c04c88c5
@ -68,6 +68,7 @@ public:
|
|||||||
|
|
||||||
// default mac-address is inferred from esp8266's STA interface
|
// default mac-address is inferred from esp8266's STA interface
|
||||||
boolean begin(const uint8_t* macAddress = nullptr, const uint16_t mtu = DEFAULT_MTU);
|
boolean begin(const uint8_t* macAddress = nullptr, const uint16_t mtu = DEFAULT_MTU);
|
||||||
|
void end();
|
||||||
|
|
||||||
const netif* getNetIf() const
|
const netif* getNetIf() const
|
||||||
{
|
{
|
||||||
@ -170,6 +171,7 @@ protected:
|
|||||||
int8_t _intrPin;
|
int8_t _intrPin;
|
||||||
uint8_t _macAddress[6];
|
uint8_t _macAddress[6];
|
||||||
bool _started;
|
bool _started;
|
||||||
|
bool _scheduled;
|
||||||
bool _default;
|
bool _default;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -261,6 +263,7 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
|
|||||||
if (!netif_add(&_netif, ip_2_ip4(&ip_addr), ip_2_ip4(&netmask), ip_2_ip4(&gw), this,
|
if (!netif_add(&_netif, ip_2_ip4(&ip_addr), ip_2_ip4(&netmask), ip_2_ip4(&gw), this,
|
||||||
netif_init_s, ethernet_input))
|
netif_init_s, ethernet_input))
|
||||||
{
|
{
|
||||||
|
RawDev::end();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,10 +277,11 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ERR_IF:
|
case ERR_IF:
|
||||||
|
RawDev::end();
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
netif_remove(&_netif);
|
end();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -304,22 +308,41 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_intrPin < 0
|
if (_intrPin < 0 && !_scheduled)
|
||||||
&& !schedule_recurrent_function_us(
|
{
|
||||||
|
_scheduled = schedule_recurrent_function_us(
|
||||||
[&]()
|
[&]()
|
||||||
{
|
{
|
||||||
|
if (!_started)
|
||||||
|
{
|
||||||
|
_scheduled = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
this->handlePackets();
|
this->handlePackets();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
100))
|
100);
|
||||||
|
if (!_scheduled)
|
||||||
{
|
{
|
||||||
netif_remove(&_netif);
|
end();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class RawDev>
|
||||||
|
void LwipIntfDev<RawDev>::end()
|
||||||
|
{
|
||||||
|
netif_remove(&_netif);
|
||||||
|
ip_addr_copy(_netif.ip_addr, ip_addr_any); // to allow DHCP at next begin
|
||||||
|
ip_addr_copy(_netif.netmask, ip_addr_any);
|
||||||
|
ip_addr_copy(_netif.gw, ip_addr_any);
|
||||||
|
_started = false;
|
||||||
|
RawDev::end();
|
||||||
|
}
|
||||||
|
|
||||||
template<class RawDev>
|
template<class RawDev>
|
||||||
wl_status_t LwipIntfDev<RawDev>::status()
|
wl_status_t LwipIntfDev<RawDev>::status()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user