Skip to content
New issue

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

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

Already on GitHub? # to your account

migrate from astyle to clang-format, add tests/ #8455

Closed
wants to merge 15 commits into from
Prev Previous commit
Next Next commit
tuning
  • Loading branch information
d-a-v committed Jan 20, 2022
commit 242b3405e04ed7f48718f47fc792cfa0e7a5ee4c
2 changes: 1 addition & 1 deletion cores/esp8266/LwipDhcpServer-NonOS.cpp
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
extern netif netif_git[2];

// global DHCP instance for softAP interface
DhcpServer dhcpSoftAP(&netif_git[SOFTAP_IF]);
DhcpServer dhcpSoftAP(&netif_git[SOFTAP_IF]);

extern "C"
{
40 changes: 20 additions & 20 deletions cores/esp8266/LwipDhcpServer.cpp
Original file line number Diff line number Diff line change
@@ -175,9 +175,9 @@ const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
#define LWIP_IS_OK(what, err) ((err) == ERR_OK)
#endif

const uint32 DhcpServer::magic_cookie = 0x63538263; // https://tools.ietf.org/html/rfc1497
const uint32 DhcpServer::magic_cookie = 0x63538263; // https://tools.ietf.org/html/rfc1497

int fw_has_started_softap_dhcps = 0;
int fw_has_started_softap_dhcps = 0;

////////////////////////////////////////////////////////////////////////////////////

@@ -210,7 +210,7 @@ DhcpServer::DhcpServer(netif* netif) :
// wifi_softap_set_station_info is missing in user_interface.h:
extern "C" void wifi_softap_set_station_info(uint8_t* mac, struct ipv4_addr*);

void DhcpServer::dhcps_set_dns(int num, const ipv4_addr_t* dns)
void DhcpServer::dhcps_set_dns(int num, const ipv4_addr_t* dns)
{
(void)num;
if (!ip4_addr_isany(dns))
@@ -278,7 +278,7 @@ void DhcpServer::node_remove_from_list(list_node** phead, list_node* pdelete)
{
list_node* plist = nullptr;

plist = *phead;
plist = *phead;
if (plist == nullptr)
{
*phead = nullptr;
@@ -316,8 +316,8 @@ bool DhcpServer::add_dhcps_lease(uint8* macaddr)
struct dhcps_pool* pdhcps_pool = nullptr;
list_node* pback_node = nullptr;

uint32 start_ip = dhcps_lease.start_ip.addr;
uint32 end_ip = dhcps_lease.end_ip.addr;
uint32 start_ip = dhcps_lease.start_ip.addr;
uint32 end_ip = dhcps_lease.end_ip.addr;

for (pback_node = plist; pback_node != nullptr; pback_node = pback_node->pnext)
{
@@ -503,12 +503,12 @@ void DhcpServer::create_msg(struct dhcps_msg* m)

client.addr = client_address.addr;

m->op = DHCP_REPLY;
m->htype = DHCP_HTYPE_ETHERNET;
m->hlen = 6;
m->hops = 0;
m->secs = 0;
m->flags = htons(BOOTP_BROADCAST);
m->op = DHCP_REPLY;
m->htype = DHCP_HTYPE_ETHERNET;
m->hlen = 6;
m->hops = 0;
m->secs = 0;
m->flags = htons(BOOTP_BROADCAST);

memcpy((char*)m->yiaddr, (char*)&client.addr, sizeof(m->yiaddr));
memset((char*)m->ciaddr, 0, sizeof(m->ciaddr));
@@ -539,7 +539,7 @@ void DhcpServer::send_offer(struct dhcps_msg* m)
end = add_offer_options(end);
end = add_end(end);

p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM);
p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM);
#if DHCPS_DEBUG
os_printf("udhcp: send_offer>>p->ref = %d\n", p->ref);
#endif
@@ -602,7 +602,7 @@ void DhcpServer::send_nak(struct dhcps_msg* m)
end = add_msg_type(&m->options[4], DHCPNAK);
end = add_end(end);

p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM);
p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM);
#if DHCPS_DEBUG
os_printf("udhcp: send_nak>>p->ref = %d\n", p->ref);
#endif
@@ -661,7 +661,7 @@ void DhcpServer::send_ack(struct dhcps_msg* m)
end = add_offer_options(end);
end = add_end(end);

p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM);
p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM);
#if DHCPS_DEBUG
os_printf("udhcp: send_ack>>p->ref = %d\n", p->ref);
#endif
@@ -724,10 +724,10 @@ uint8_t DhcpServer::parse_options(uint8_t* optptr, sint16_t len)

client.addr = client_address.addr;

u8_t* end = optptr + len;
u16_t type = 0;
u8_t* end = optptr + len;
u16_t type = 0;

s.state = DHCPS_STATE_IDLE;
s.state = DHCPS_STATE_IDLE;

while (optptr < end)
{
@@ -830,7 +830,7 @@ sint16_t DhcpServer::parse_msg(struct dhcps_msg* m, u16_t len)
memcpy(&ip.addr, m->ciaddr, sizeof(ip.addr));
client_address.addr = dhcps_client_update(m->chaddr, &ip);

sint16_t ret = parse_options(&m->options[4], len);
sint16_t ret = parse_options(&m->options[4], len);

if (ret == DHCPS_STATE_RELEASE)
{
@@ -1071,7 +1071,7 @@ void DhcpServer::end()

udp_disconnect(pcb_dhcps);
udp_remove(pcb_dhcps);
pcb_dhcps = nullptr;
pcb_dhcps = nullptr;

//udp_remove(pcb_dhcps);
list_node* pnode = nullptr;
46 changes: 23 additions & 23 deletions cores/esp8266/LwipDhcpServer.h
Original file line number Diff line number Diff line change
@@ -39,11 +39,11 @@ class DhcpServer
DhcpServer(netif* netif);
~DhcpServer();

void setDns(int num, const ipv4_addr_t* dns);
void setDns(int num, const ipv4_addr_t* dns);

bool begin(ip_info* info);
void end();
bool isRunning();
bool begin(ip_info* info);
void end();
bool isRunning();

// this is the C interface encapsulated in a class
// (originally dhcpserver.c in lwIP-v1.4 in NonOS-SDK)
@@ -61,7 +61,7 @@ class DhcpServer
uint32 get_dhcps_lease_time(void);
bool add_dhcps_lease(uint8* macaddr);

void dhcps_set_dns(int num, const ipv4_addr_t* dns);
void dhcps_set_dns(int num, const ipv4_addr_t* dns);

protected:
// legacy C structure and API to eventually turn into C++
@@ -93,24 +93,24 @@ class DhcpServer
struct pbuf* p,
const ip_addr_t* addr,
uint16_t port);
void kill_oldest_dhcps_pool(void);
void dhcps_coarse_tmr(void); // CURRENTLY NOT CALLED
void dhcps_client_leave(u8* bssid, struct ipv4_addr* ip, bool force);
uint32 dhcps_client_update(u8* bssid, struct ipv4_addr* ip);

netif* _netif;

struct udp_pcb* pcb_dhcps;
ip_addr_t broadcast_dhcps;
struct ipv4_addr server_address;
struct ipv4_addr client_address;
struct ipv4_addr dns_address;
uint32 dhcps_lease_time;

struct dhcps_lease dhcps_lease;
list_node* plist;
uint8 offer;
bool renew;
void kill_oldest_dhcps_pool(void);
void dhcps_coarse_tmr(void); // CURRENTLY NOT CALLED
void dhcps_client_leave(u8* bssid, struct ipv4_addr* ip, bool force);
uint32 dhcps_client_update(u8* bssid, struct ipv4_addr* ip);

netif* _netif;

struct udp_pcb* pcb_dhcps;
ip_addr_t broadcast_dhcps;
struct ipv4_addr server_address;
struct ipv4_addr client_address;
struct ipv4_addr dns_address;
uint32 dhcps_lease_time;

struct dhcps_lease dhcps_lease;
list_node* plist;
uint8 offer;
bool renew;

static const uint32 magic_cookie;
};
4 changes: 2 additions & 2 deletions cores/esp8266/LwipIntf.h
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@ class LwipIntf
static bool ipAddressReorder(const IPAddress& local_ip, const IPAddress& arg1, const IPAddress& arg2, const IPAddress& arg3,
IPAddress& gateway, IPAddress& netmask, IPAddress& dns1);

String hostname();
bool hostname(const String& aHostname)
String hostname();
bool hostname(const String& aHostname)
{
return hostname(aHostname.c_str());
}
2 changes: 1 addition & 1 deletion cores/esp8266/LwipIntfCB.cpp
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
static int netifStatusChangeListLength = 0;
LwipIntf::CBType netifStatusChangeList[NETIF_STATUS_CB_SIZE];

extern "C" void netif_status_changed(struct netif* netif)
extern "C" void netif_status_changed(struct netif* netif)
{
// override the default empty weak function
for (int i = 0; i < netifStatusChangeListLength; i++)
26 changes: 13 additions & 13 deletions cores/esp8266/LwipIntfDev.h
Original file line number Diff line number Diff line change
@@ -39,10 +39,10 @@ class LwipIntfDev : public LwipIntf, public RawDev
memset(&_netif, 0, sizeof(_netif));
}

boolean config(const IPAddress& local_ip, const IPAddress& arg1, const IPAddress& arg2, const IPAddress& arg3 = IPADDR_NONE, const IPAddress& dns2 = IPADDR_NONE);
boolean config(const IPAddress& local_ip, const IPAddress& arg1, const IPAddress& arg2, const IPAddress& arg3 = IPADDR_NONE, const IPAddress& dns2 = IPADDR_NONE);

// 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);

const netif* getNetIf() const
{
@@ -75,25 +75,25 @@ class LwipIntfDev : public LwipIntf, public RawDev
wl_status_t status();

protected:
err_t netif_init();
void netif_status_callback();
err_t netif_init();
void netif_status_callback();

static err_t netif_init_s(netif* netif);
static err_t linkoutput_s(netif* netif, struct pbuf* p);
static void netif_status_callback_s(netif* netif);

// called on a regular basis or on interrupt
err_t handlePackets();
err_t handlePackets();

// members

netif _netif;
netif _netif;

uint16_t _mtu;
int8_t _intrPin;
uint8_t _macAddress[6];
bool _started;
bool _default;
uint16_t _mtu;
int8_t _intrPin;
uint8_t _macAddress[6];
bool _started;
bool _default;
};

template <class RawDev>
@@ -286,11 +286,11 @@ err_t LwipIntfDev<RawDev>::netif_init()
// lwIP's doc: This function typically first resolves the hardware
// address, then sends the packet. For ethernet physical layer, this is
// usually lwIP's etharp_output()
_netif.output = etharp_output;
_netif.output = etharp_output;

// lwIP's doc: This function outputs the pbuf as-is on the link medium
// (this must points to the raw ethernet driver, meaning: us)
_netif.linkoutput = linkoutput_s;
_netif.linkoutput = linkoutput_s;

_netif.status_callback = netif_status_callback_s;

12 changes: 6 additions & 6 deletions cores/esp8266/StreamSend.cpp
Original file line number Diff line number Diff line change
@@ -61,8 +61,8 @@ size_t Stream::SendGenericPeekBuffer(Print* to, const ssize_t len, const int rea
// "neverExpires (default, impossible)" is translated to default timeout
esp8266::polledTimeout::oneShotFastMs timedOut(timeoutMs >= esp8266::polledTimeout::oneShotFastMs::neverExpires ? getTimeout() : timeoutMs);
// len==-1 => maxLen=0 <=> until starvation
const size_t maxLen = std::max((ssize_t)0, len);
size_t written = 0;
const size_t maxLen = std::max((ssize_t)0, len);
size_t written = 0;

while (!maxLen || written < maxLen)
{
@@ -151,8 +151,8 @@ size_t Stream::SendGenericRegularUntil(Print* to, const ssize_t len, const int r
// "neverExpires (default, impossible)" is translated to default timeout
esp8266::polledTimeout::oneShotFastMs timedOut(timeoutMs >= esp8266::polledTimeout::oneShotFastMs::neverExpires ? getTimeout() : timeoutMs);
// len==-1 => maxLen=0 <=> until starvation
const size_t maxLen = std::max((ssize_t)0, len);
size_t written = 0;
const size_t maxLen = std::max((ssize_t)0, len);
size_t written = 0;

while (!maxLen || written < maxLen)
{
@@ -227,8 +227,8 @@ size_t Stream::SendGenericRegular(Print* to, const ssize_t len, const esp8266::p
// "neverExpires (default, impossible)" is translated to default timeout
esp8266::polledTimeout::oneShotFastMs timedOut(timeoutMs >= esp8266::polledTimeout::oneShotFastMs::neverExpires ? getTimeout() : timeoutMs);
// len==-1 => maxLen=0 <=> until starvation
const size_t maxLen = std::max((ssize_t)0, len);
size_t written = 0;
const size_t maxLen = std::max((ssize_t)0, len);
size_t written = 0;

while (!maxLen || written < maxLen)
{
Loading