Skip to content

Revert "Allman now" #6090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 52 additions & 121 deletions cores/esp8266/AddrList.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
/*
AddrList.h - cycle through lwIP netif's ip addresses like a c++ list
Copyright (c) 2018 david gauchard. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
AddrList.h - cycle through lwIP netif's ip addresses like a c++ list
Copyright (c) 2018 david gauchard. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

/*
This class allows to explore all configured IP addresses
in lwIP netifs, with that kind of c++ loop:
This class allows to explore all configured IP addresses
in lwIP netifs, with that kind of c++ loop:

for (auto a: addrList)
for (auto a: addrList)
out.printf("IF='%s' index=%d legacy=%d IPv4=%d local=%d hostname='%s' addr= %s\n",
a.iface().c_str(),
a.ifnumber(),
Expand All @@ -31,14 +31,14 @@
a.hostname().c_str(),
a.addr().toString().c_str());

This loop:
This loop:

while (WiFi.status() != WL_CONNECTED()) {
Serial.print('.');
delay(500);
}

can be replaced by:
can be replaced by:

for (bool configured = false; !configured; ) {
for (auto iface: addrList)
Expand All @@ -48,7 +48,7 @@
delay(500);
}

waiting for an IPv6 global address:
waiting for an IPv6 global address:

for (bool configured = false; !configured; ) {
for (auto iface: addrList)
Expand All @@ -59,7 +59,7 @@
delay(500);
}

waiting for an IPv6 global address, on a specific interface:
waiting for an IPv6 global address, on a specific interface:

for (bool configured = false; !configured; ) {
for (auto iface: addrList)
Expand Down Expand Up @@ -94,8 +94,8 @@ namespace AddressListImplementation

struct netifWrapper
{
netifWrapper(netif* netif) : _netif(netif), _num(-1) {}
netifWrapper(const netifWrapper& o) : _netif(o._netif), _num(o._num) {}
netifWrapper (netif* netif) : _netif(netif), _num(-1) {}
netifWrapper (const netifWrapper& o) : _netif(o._netif), _num(o._num) {}

netifWrapper& operator= (const netifWrapper& o)
{
Expand All @@ -110,64 +110,25 @@ struct netifWrapper
}

// address properties
IPAddress addr() const
{
return ipFromNetifNum();
}
bool isLegacy() const
{
return _num == 0;
}
bool isLocal() const
{
return addr().isLocal();
}
bool isV4() const
{
return addr().isV4();
}
bool isV6() const
{
return !addr().isV4();
}
String toString() const
{
return addr().toString();
}
IPAddress addr () const { return ipFromNetifNum(); }
bool isLegacy () const { return _num == 0; }
bool isLocal () const { return addr().isLocal(); }
bool isV4 () const { return addr().isV4(); }
bool isV6 () const { return !addr().isV4(); }
String toString() const { return addr().toString(); }

// related to legacy address (_num=0, ipv4)
IPAddress ipv4() const
{
return _netif->ip_addr;
}
IPAddress netmask() const
{
return _netif->netmask;
}
IPAddress gw() const
{
return _netif->gw;
}
IPAddress ipv4 () const { return _netif->ip_addr; }
IPAddress netmask () const { return _netif->netmask; }
IPAddress gw () const { return _netif->gw; }

// common to all addresses of this interface
String ifname() const
{
return String(_netif->name[0]) + _netif->name[1];
}
const char* ifhostname() const
{
return _netif->hostname ? : emptyString.c_str();
}
const char* ifmac() const
{
return (const char*)_netif->hwaddr;
}
int ifnumber() const
{
return _netif->num;
}
String ifname () const { return String(_netif->name[0]) + _netif->name[1]; }
const char* ifhostname () const { return _netif->hostname?: emptyString.c_str(); }
const char* ifmac () const { return (const char*)_netif->hwaddr; }
int ifnumber () const { return _netif->num; }

const ip_addr_t* ipFromNetifNum() const
const ip_addr_t* ipFromNetifNum () const
{
#if LWIP_IPV6
return _num ? &_netif->ip6_addr[_num - 1] : &_netif->ip_addr;
Expand All @@ -189,8 +150,8 @@ struct netifWrapper
class AddressListIterator
{
public:
AddressListIterator(const netifWrapper& o) : netIf(o) {}
AddressListIterator(netif* netif) : netIf(netif)
AddressListIterator (const netifWrapper& o) : netIf(o) {}
AddressListIterator (netif* netif) : netIf(netif)
{
// This constructor is called with lwIP's global netif_list, or
// nullptr. operator++() is designed to loop through _configured_
Expand All @@ -199,29 +160,13 @@ class AddressListIterator
(void)operator++();
}

const netifWrapper& operator* () const
{
return netIf;
}
const netifWrapper* operator-> () const
{
return &netIf;
}
const netifWrapper& operator* () const { return netIf; }
const netifWrapper* operator-> () const { return &netIf; }

bool operator== (AddressListIterator& o)
{
return netIf.equal(*o);
}
bool operator!= (AddressListIterator& o)
{
return !netIf.equal(*o);
}
bool operator== (AddressListIterator& o) { return netIf.equal(*o); }
bool operator!= (AddressListIterator& o) { return !netIf.equal(*o); }

AddressListIterator& operator= (const AddressListIterator& o)
{
netIf = o.netIf;
return *this;
}
AddressListIterator& operator= (const AddressListIterator& o) { netIf = o.netIf; return *this; }

AddressListIterator operator++ (int)
{
Expand All @@ -243,9 +188,7 @@ class AddressListIterator
}
if (!ip_addr_isany(netIf.ipFromNetifNum()))
// found an initialized address
{
break;
}
}
return *this;
}
Expand All @@ -257,27 +200,15 @@ class AddressListIterator
class AddressList
{
public:
using const_iterator = const AddressListIterator;
using const_iterator = const AddressListIterator;

const_iterator begin() const
{
return const_iterator(netif_list);
}
const_iterator end() const
{
return const_iterator(nullptr);
}
const_iterator begin () const { return const_iterator(netif_list); }
const_iterator end () const { return const_iterator(nullptr); }

};

inline AddressList::const_iterator begin(const AddressList& a)
{
return a.begin();
}
inline AddressList::const_iterator end(const AddressList& a)
{
return a.end();
}
inline AddressList::const_iterator begin (const AddressList& a) { return a.begin(); }
inline AddressList::const_iterator end (const AddressList& a) { return a.end(); }


} // AddressListImplementation
Expand Down
39 changes: 19 additions & 20 deletions cores/esp8266/Arduino.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/*
Arduino.h - Main include file for the Arduino SDK
Copyright (c) 2005-2013 Arduino Team. All right reserved.
Arduino.h - Main include file for the Arduino SDK
Copyright (c) 2005-2013 Arduino Team. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef Arduino_h
#define Arduino_h
Expand Down Expand Up @@ -86,11 +86,10 @@ extern "C" {
#define EXTERNAL 0

//timer dividers
enum TIM_DIV_ENUM
{
TIM_DIV1 = 0, //80MHz (80 ticks/us - 104857.588 us max)
TIM_DIV16 = 1, //5MHz (5 ticks/us - 1677721.4 us max)
TIM_DIV256 = 3 //312.5Khz (1 tick = 3.2us - 26843542.4 us max)
enum TIM_DIV_ENUM {
TIM_DIV1 = 0, //80MHz (80 ticks/us - 104857.588 us max)
TIM_DIV16 = 1, //5MHz (5 ticks/us - 1677721.4 us max)
TIM_DIV256 = 3 //312.5Khz (1 tick = 3.2us - 26843542.4 us max)
};


Expand Down Expand Up @@ -296,7 +295,7 @@ long secureRandom(long, long);
long map(long, long, long, long, long);

extern "C" void configTime(long timezone, int daylightOffset_sec,
const char* server1, const char* server2 = nullptr, const char* server3 = nullptr);
const char* server1, const char* server2 = nullptr, const char* server3 = nullptr);

#endif

Expand Down
Loading