[realtek-ambz] Better handle WiFi events

This commit is contained in:
Kuba Szczodrzyński
2022-06-06 21:45:18 +02:00
parent 03ab020dc8
commit bbf8e0b6b6
3 changed files with 24 additions and 6 deletions

View File

@@ -3,6 +3,11 @@
#include "WiFi.h"
#include "WiFiPriv.h"
typedef struct {
int count;
rtw_mac_t mac_list[AP_STA_NUM];
} client_info_t;
bool WiFiClass::softAP(const char *ssid, const char *passphrase, int channel, bool ssidHidden, int maxClients) {
if (!enableAP(true))
return false;
@@ -61,6 +66,8 @@ bool WiFiClass::softAP(const char *ssid, const char *passphrase, int channel, bo
);
}
wifi_indication(WIFI_EVENT_CONNECT, NULL, ARDUINO_EVENT_WIFI_AP_START, -2);
if (ret < 0) {
LT_E("SoftAP failed; ret=%d", ret);
return false;
@@ -109,9 +116,11 @@ bool WiFiClass::softAPdisconnect(bool wifiOff) {
}
uint8_t WiFiClass::softAPgetStationNum() {
// TODO
// the struct is at wifi_conf.c:2576
return 0;
client_info_t info;
info.count = AP_STA_NUM;
wifi_get_associated_client_list(&info, sizeof(info));
return info.count;
}
IPAddress WiFiClass::softAPIP() {

View File

@@ -145,10 +145,6 @@ void WiFiClass::handleRtwEvent(uint16_t event, char *data, int len, int flags) {
memset(&eventInfo, 0, sizeof(EventInfo));
switch (event) {
case WIFI_EVENT_CONNECT:
eventId = ARDUINO_EVENT_WIFI_STA_START;
break;
case WIFI_EVENT_DISCONNECT:
case WIFI_EVENT_RECONNECTION_FAIL:
eventId = ARDUINO_EVENT_WIFI_STA_DISCONNECTED;
@@ -189,6 +185,7 @@ void WiFiClass::handleRtwEvent(uint16_t event, char *data, int len, int flags) {
memcpy(eventInfo.wifi_ap_stadisconnected.mac, (const char *)data, 6);
break;
// case WIFI_EVENT_CONNECT:
// case WIFI_EVENT_SCAN_RESULT_REPORT:
// case WIFI_EVENT_SEND_ACTION_DONE:
// case WIFI_EVENT_RX_MGNT:

View File

@@ -45,6 +45,18 @@ bool WiFiClass::mode(WiFiMode mode) {
LT_E("Error while changing mode(%u)", mode);
return false;
}
// send STA start/stop events and AP stop event (start is handled in softAP())
if ((mode & WIFI_MODE_STA) != (currentMode & WIFI_MODE_STA)) {
if (mode & WIFI_MODE_STA)
wifi_indication(WIFI_EVENT_CONNECT, NULL, ARDUINO_EVENT_WIFI_STA_START, -2);
else
wifi_indication(WIFI_EVENT_CONNECT, NULL, ARDUINO_EVENT_WIFI_STA_STOP, -2);
}
if (!(mode & WIFI_MODE_AP) && (currentMode & WIFI_MODE_AP)) {
wifi_indication(WIFI_EVENT_CONNECT, NULL, ARDUINO_EVENT_WIFI_AP_STOP, -2);
}
LT_HEAP_I();
return true;
}