Skip to content

Commit 3bbaccd

Browse files
exporting Network stack synchronization to lwipClient
1 parent 0207e39 commit 3bbaccd

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

libraries/lwIpWrapper/src/CNetIf.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,11 @@ int CNetIf::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress &gw)
342342
this->dhcpStart();
343343

344344

345-
CLwipIf::getInstance().sync_timer();
345+
CLwipIf::getInstance().syncTimer();
346346
while(!this->isDhcpAcquired()) {
347347
CLwipIf::getInstance().task();
348348
}
349-
CLwipIf::getInstance().enable_timer();
349+
CLwipIf::getInstance().enableTimer();
350350
}
351351

352352
#endif
@@ -638,9 +638,9 @@ int CWifiStation::connectToAP(const char* ssid, const char *passphrase) {
638638
time_num++;
639639
}
640640

641-
CLwipIf::getInstance().sync_timer();
641+
CLwipIf::getInstance().syncTimer();
642642
rv = CEspControl::getInstance().setWifiMode(WIFI_MODE_STA);
643-
CLwipIf::getInstance().enable_timer();
643+
CLwipIf::getInstance().enableTimer();
644644

645645
if((rv=this->scanForAp()) != WL_SCAN_COMPLETED) {
646646
rv = -2;
@@ -668,7 +668,7 @@ int CWifiStation::connectToAP(const char* ssid, const char *passphrase) {
668668
memset(ap.bssid, 0x00, BSSID_LENGTH);
669669
memcpy(ap.bssid, access_points[best_index].bssid, BSSID_LENGTH);
670670

671-
CLwipIf::getInstance().sync_timer();
671+
CLwipIf::getInstance().syncTimer();
672672
rv=CEspControl::getInstance().connectAccessPoint(ap);
673673

674674
if (rv == ESP_CONTROL_OK) {
@@ -680,7 +680,7 @@ int CWifiStation::connectToAP(const char* ssid, const char *passphrase) {
680680
} else {
681681
wifi_status = WL_CONNECT_FAILED;
682682
}
683-
CLwipIf::getInstance().enable_timer();
683+
CLwipIf::getInstance().enableTimer();
684684
}
685685

686686
exit:
@@ -690,10 +690,10 @@ int CWifiStation::connectToAP(const char* ssid, const char *passphrase) {
690690
int CWifiStation::scanForAp() {
691691
access_points.clear();
692692

693-
CLwipIf::getInstance().sync_timer();
693+
CLwipIf::getInstance().syncTimer();
694694

695695
int res = CEspControl::getInstance().getAccessPointScanList(access_points);
696-
CLwipIf::getInstance().enable_timer();
696+
CLwipIf::getInstance().enableTimer();
697697

698698
if (res == ESP_CONTROL_OK) {
699699
wifi_status = WL_SCAN_COMPLETED;
@@ -707,11 +707,11 @@ int CWifiStation::scanForAp() {
707707

708708
// disconnect
709709
int CWifiStation::disconnectFromAp() {
710-
CLwipIf::getInstance().sync_timer();
710+
CLwipIf::getInstance().syncTimer();
711711

712712
auto res = CEspControl::getInstance().disconnectAccessPoint();
713713

714-
CLwipIf::getInstance().enable_timer();
714+
CLwipIf::getInstance().enableTimer();
715715

716716
return res;
717717
}
@@ -942,9 +942,9 @@ int CWifiSoftAp::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress
942942
time_num++;
943943
}
944944

945-
CLwipIf::getInstance().sync_timer();
945+
CLwipIf::getInstance().syncTimer();
946946
res = CEspControl::getInstance().setWifiMode(WIFI_MODE_AP);
947-
CLwipIf::getInstance().enable_timer();
947+
CLwipIf::getInstance().enableTimer();
948948

949949
CNetIf::begin(
950950
default_dhcp_server_ip,
@@ -958,7 +958,7 @@ int CWifiSoftAp::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress
958958
// TODO scan the other access point first and then set the channel if 0
959959
// TODO there are requirements for ssid and password
960960
int CWifiSoftAp::startSoftAp(const char* ssid, const char* passphrase, uint8_t channel) {
961-
CLwipIf::getInstance().sync_timer();
961+
CLwipIf::getInstance().syncTimer();
962962
SoftApCfg_t cfg;
963963

964964
strncpy((char*)cfg.ssid, ssid, SSID_LENGTH);
@@ -991,7 +991,7 @@ int CWifiSoftAp::startSoftAp(const char* ssid, const char* passphrase, uint8_t c
991991
// wifi_status = WL_AP_FAILED;
992992
}
993993

994-
CLwipIf::getInstance().enable_timer();
994+
CLwipIf::getInstance().enableTimer();
995995
return rv;
996996
}
997997

@@ -1131,17 +1131,17 @@ uint8_t CWifiSoftAp::getChannel() {
11311131
}
11321132

11331133
int CWifiSoftAp::setLowPowerMode() {
1134-
CLwipIf::getInstance().sync_timer();
1134+
CLwipIf::getInstance().syncTimer();
11351135
auto res = CEspControl::getInstance().setPowerSaveMode(1);
1136-
CLwipIf::getInstance().enable_timer();
1136+
CLwipIf::getInstance().enableTimer();
11371137

11381138
return res;
11391139
}
11401140

11411141
int CWifiSoftAp::resetLowPowerMode() {
1142-
CLwipIf::getInstance().sync_timer();
1142+
CLwipIf::getInstance().syncTimer();
11431143
auto res = CEspControl::getInstance().setPowerSaveMode(1);
1144-
CLwipIf::getInstance().enable_timer();
1144+
CLwipIf::getInstance().enableTimer();
11451145

11461146
return res;
11471147
}

libraries/lwIpWrapper/src/CNetIf.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -432,24 +432,24 @@ class CLwipIf {
432432
friend class CNetIf;
433433
friend class CWifiSoftAp;
434434
friend class CWifiStation;
435-
435+
public:
436436
#ifdef LWIP_USE_TIMER
437437
FspTimer timer;
438438

439-
inline void sync_timer() {
439+
inline void syncTimer() {
440440
timer.disable_overflow_irq();
441441
this->task();
442442
}
443443

444-
inline void enable_timer() {
444+
inline void enableTimer() {
445445
timer.enable_overflow_irq();
446446
}
447447
#else // LWIP_USE_TIMER
448-
inline void sync_timer() {
448+
inline void syncTimer() {
449449
this->task();
450450
}
451451

452-
inline void enable_timer() { }
452+
inline void enableTimer() { }
453453
#endif // LWIP_USE_TIMER
454454
};
455455

libraries/lwIpWrapper/src/lwipClient.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ int lwipClient::connect(IPAddress ip, uint16_t port) {
101101

102102
// the connect method is only connected when trying to connect a client to a server
103103
// and not when a client is created out of a listening socket
104+
CLwipIf::getInstance().syncTimer();
104105
this->tcp_info->pcb = tcp_new();
105106

106107
if(this->tcp_info->pcb == nullptr) {
@@ -124,7 +125,13 @@ int lwipClient::connect(IPAddress ip, uint16_t port) {
124125
this->tcp_info->pcb, &this->_ip, port, // FIXME check if _ip gets copied
125126
_lwip_tcp_connected_callback // FIXME we need to define a static private function
126127
);
127-
return err;
128+
129+
while(!connected()) {
130+
CLwipIf::getInstance().task();
131+
}
132+
CLwipIf::getInstance().enableTimer();
133+
134+
return err == ERR_OK? 1: -err;
128135
}
129136

130137
err_t _lwip_tcp_connected_callback(void* arg, struct tcp_pcb* tpcb, err_t err) {

0 commit comments

Comments
 (0)