1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Migrate from astyle to clang-format (#8464)

This commit is contained in:
Maxim Prokhorov
2022-02-20 19:23:33 +03:00
committed by Max Prokhorov
parent 46190b61f1
commit 19b7a29720
241 changed files with 15925 additions and 16197 deletions

View File

@ -25,7 +25,7 @@
#ifndef STASSID
#define STASSID "your-ssid"
#define STAPSK "your-password"
#define STAPSK "your-password"
#endif
#define LOGGERBAUD 115200
@ -34,18 +34,15 @@
#define NAPT 200
#define NAPT_PORT 3
#define RX 13 // d1mini D7
#define TX 15 // d1mini D8
#define RX 13 // d1mini D7
#define TX 15 // d1mini D8
SoftwareSerial ppplink(RX, TX);
HardwareSerial& logger = Serial;
PPPServer ppp(&ppplink);
void PPPConnectedCallback(netif* nif) {
logger.printf("ppp: ip=%s/mask=%s/gw=%s\n",
IPAddress(&nif->ip_addr).toString().c_str(),
IPAddress(&nif->netmask).toString().c_str(),
IPAddress(&nif->gw).toString().c_str());
logger.printf("ppp: ip=%s/mask=%s/gw=%s\n", IPAddress(&nif->ip_addr).toString().c_str(), IPAddress(&nif->netmask).toString().c_str(), IPAddress(&nif->gw).toString().c_str());
logger.printf("Heap before: %d\n", ESP.getFreeHeap());
err_t ret = ip_napt_init(NAPT, NAPT_PORT);
@ -53,9 +50,7 @@ void PPPConnectedCallback(netif* nif) {
if (ret == ERR_OK) {
ret = ip_napt_enable_no(nif->num, 1);
logger.printf("ip_napt_enable(nif): ret=%d (OK=%d)\n", (int)ret, (int)ERR_OK);
if (ret == ERR_OK) {
logger.printf("PPP client is NATed\n");
}
if (ret == ERR_OK) { logger.printf("PPP client is NATed\n"); }
// could not make this work yet,
// but packets are arriving on ppp client (= linux host)
@ -64,9 +59,7 @@ void PPPConnectedCallback(netif* nif) {
logger.printf("redirect443=%d\n", ip_portmap_add(IP_PROTO_TCP, ip_2_ip4(&nif->ip_addr)->addr, 443, ip_2_ip4(&nif->gw)->addr, 443));
}
logger.printf("Heap after napt init: %d\n", ESP.getFreeHeap());
if (ret != ERR_OK) {
logger.printf("NAPT initialization failed\n");
}
if (ret != ERR_OK) { logger.printf("NAPT initialization failed\n"); }
}
void setup() {
@ -79,10 +72,7 @@ void setup() {
logger.print('.');
delay(500);
}
logger.printf("\nSTA: %s (dns: %s / %s)\n",
WiFi.localIP().toString().c_str(),
WiFi.dnsIP(0).toString().c_str(),
WiFi.dnsIP(1).toString().c_str());
logger.printf("\nSTA: %s (dns: %s / %s)\n", WiFi.localIP().toString().c_str(), WiFi.dnsIP(0).toString().c_str(), WiFi.dnsIP(1).toString().c_str());
ppplink.begin(PPPLINKBAUD);
ppplink.enableIntTx(true);
@ -107,5 +97,4 @@ void setup() {
#endif
void loop() {
}
void loop() {}

View File

@ -2,8 +2,8 @@
// This is still beta / a work in progress
// testing on linux:
// sudo /usr/sbin/pppd /dev/ttyUSB1 38400 noipdefault nocrtscts local defaultroute noauth nodetach debug dump
// sudo /usr/sbin/pppd /dev/ttyUSB1 38400 noipdefault nocrtscts local defaultroute noauth
// sudo /usr/sbin/pppd /dev/ttyUSB1 38400 noipdefault nocrtscts local defaultroute noauth nodetach
// debug dump sudo /usr/sbin/pppd /dev/ttyUSB1 38400 noipdefault nocrtscts local defaultroute noauth
// proxy arp is needed but we don't have it
// http://lwip.100.n7.nabble.com/PPP-proxy-arp-support-tp33286p33345.html
@ -16,9 +16,7 @@
#include "PPPServer.h"
PPPServer::PPPServer(Stream* sio): _sio(sio), _cb(netif_status_cb_s), _enabled(false)
{
}
PPPServer::PPPServer(Stream* sio) : _sio(sio), _cb(netif_status_cb_s), _enabled(false) { }
bool PPPServer::handlePackets()
{
@ -38,15 +36,15 @@ bool PPPServer::handlePackets()
void PPPServer::link_status_cb_s(ppp_pcb* pcb, int err_code, void* ctx)
{
bool stop = true;
netif* nif = ppp_netif(pcb);
bool stop = true;
netif* nif = ppp_netif(pcb);
switch (err_code)
{
case PPPERR_NONE: /* No error. */
case PPPERR_NONE: /* No error. */
{
#if LWIP_DNS
const ip_addr_t *ns;
const ip_addr_t* ns;
#endif /* LWIP_DNS */
ets_printf("ppp_link_status_cb: PPPERR_NONE\n\r");
#if LWIP_IPV4
@ -68,54 +66,54 @@ void PPPServer::link_status_cb_s(ppp_pcb* pcb, int err_code, void* ctx)
ets_printf(" our6_ipaddr = %s\n\r", ip6addr_ntoa(netif_ip6_addr(nif, 0)));
#endif /* PPP_IPV6_SUPPORT */
}
stop = false;
break;
stop = false;
break;
case PPPERR_PARAM: /* Invalid parameter. */
case PPPERR_PARAM: /* Invalid parameter. */
ets_printf("ppp_link_status_cb: PPPERR_PARAM\n");
break;
case PPPERR_OPEN: /* Unable to open PPP session. */
case PPPERR_OPEN: /* Unable to open PPP session. */
ets_printf("ppp_link_status_cb: PPPERR_OPEN\n");
break;
case PPPERR_DEVICE: /* Invalid I/O device for PPP. */
case PPPERR_DEVICE: /* Invalid I/O device for PPP. */
ets_printf("ppp_link_status_cb: PPPERR_DEVICE\n");
break;
case PPPERR_ALLOC: /* Unable to allocate resources. */
case PPPERR_ALLOC: /* Unable to allocate resources. */
ets_printf("ppp_link_status_cb: PPPERR_ALLOC\n");
break;
case PPPERR_USER: /* User interrupt. */
case PPPERR_USER: /* User interrupt. */
ets_printf("ppp_link_status_cb: PPPERR_USER\n");
break;
case PPPERR_CONNECT: /* Connection lost. */
case PPPERR_CONNECT: /* Connection lost. */
ets_printf("ppp_link_status_cb: PPPERR_CONNECT\n");
break;
case PPPERR_AUTHFAIL: /* Failed authentication challenge. */
case PPPERR_AUTHFAIL: /* Failed authentication challenge. */
ets_printf("ppp_link_status_cb: PPPERR_AUTHFAIL\n");
break;
case PPPERR_PROTOCOL: /* Failed to meet protocol. */
case PPPERR_PROTOCOL: /* Failed to meet protocol. */
ets_printf("ppp_link_status_cb: PPPERR_PROTOCOL\n");
break;
case PPPERR_PEERDEAD: /* Connection timeout. */
case PPPERR_PEERDEAD: /* Connection timeout. */
ets_printf("ppp_link_status_cb: PPPERR_PEERDEAD\n");
break;
case PPPERR_IDLETIMEOUT: /* Idle Timeout. */
case PPPERR_IDLETIMEOUT: /* Idle Timeout. */
ets_printf("ppp_link_status_cb: PPPERR_IDLETIMEOUT\n");
break;
case PPPERR_CONNECTTIME: /* PPPERR_CONNECTTIME. */
case PPPERR_CONNECTTIME: /* PPPERR_CONNECTTIME. */
ets_printf("ppp_link_status_cb: PPPERR_CONNECTTIME\n");
break;
case PPPERR_LOOPBACK: /* Connection timeout. */
case PPPERR_LOOPBACK: /* Connection timeout. */
ets_printf("ppp_link_status_cb: PPPERR_LOOPBACK\n");
break;
@ -165,22 +163,24 @@ bool PPPServer::begin(const IPAddress& ourAddress, const IPAddress& peer)
ppp_set_ipcp_ouraddr(_ppp, ip_2_ip4((const ip_addr_t*)ourAddress));
ppp_set_ipcp_hisaddr(_ppp, ip_2_ip4((const ip_addr_t*)peer));
//ip4_addr_t addr;
//IP4_ADDR(&addr, 10,0,1,254);
//ppp_set_ipcp_dnsaddr(_ppp, 0, &addr);
// ip4_addr_t addr;
// IP4_ADDR(&addr, 10,0,1,254);
// ppp_set_ipcp_dnsaddr(_ppp, 0, &addr);
//ppp_set_auth(_ppp, PPPAUTHTYPE_ANY, "login", "password");
//ppp_set_auth_required(_ppp, 1);
// ppp_set_auth(_ppp, PPPAUTHTYPE_ANY, "login", "password");
// ppp_set_auth_required(_ppp, 1);
ppp_set_silent(_ppp, 1);
ppp_listen(_ppp);
netif_set_status_callback(&_netif, _cb);
_enabled = true;
if (!schedule_recurrent_function_us([&]()
{
return this->handlePackets();
}, 1000))
if (!schedule_recurrent_function_us(
[&]()
{
return this->handlePackets();
},
1000))
{
netif_remove(&_netif);
return false;

View File

@ -27,7 +27,6 @@
*/
#ifndef __PPPSERVER_H
#define __PPPSERVER_H
@ -40,7 +39,6 @@
class PPPServer
{
public:
PPPServer(Stream* sio);
bool begin(const IPAddress& ourAddress, const IPAddress& peer = IPAddress(172, 31, 255, 254));
@ -56,22 +54,20 @@ public:
}
protected:
static constexpr size_t _bufsize = 128;
Stream* _sio;
ppp_pcb* _ppp;
netif _netif;
Stream* _sio;
ppp_pcb* _ppp;
netif _netif;
void (*_cb)(netif*);
uint8_t _buf[_bufsize];
bool _enabled;
bool _enabled;
// feed ppp from stream - to call on a regular basis or on interrupt
bool handlePackets();
static u32_t output_cb_s(ppp_pcb* pcb, u8_t* data, u32_t len, void* ctx);
static void link_status_cb_s(ppp_pcb* pcb, int err_code, void* ctx);
static void netif_status_cb_s(netif* nif);
static void link_status_cb_s(ppp_pcb* pcb, int err_code, void* ctx);
static void netif_status_cb_s(netif* nif);
};
#endif // __PPPSERVER_H
#endif // __PPPSERVER_H