esp_wifi: fix pre commit issue

This commit is contained in:
muhaidong 2023-02-21 19:07:15 +08:00
parent 3f544d76ff
commit 610cc41847
13 changed files with 53 additions and 179 deletions

64
a.diff
View File

@ -1,64 +0,0 @@
diff --git a/examples/wifi/antenna/components/antenna_soft_switch/antenna_switch.c b/examples/wifi/antenna/components/antenna_soft_switch/antenna_switch.c
index ffcf0fa927..8dc0a991e8 100644
--- a/examples/wifi/antenna/components/antenna_soft_switch/antenna_switch.c
+++ b/examples/wifi/antenna/components/antenna_soft_switch/antenna_switch.c
@@ -11,6 +11,7 @@
#include "freertos/queue.h"
#include "esp_wifi.h"
#include "esp_log.h"
+#include "esp_check.h"
#include "antenna_switch.h"
@@ -43,11 +44,6 @@ static void antenna_switch_function(const wifi_antenna_auto_switch_config_t *con
wifi_ap_record_t wifi_ap_record;
int16_t rssi_ant0 = INT16_MIN, rssi_ant1 = INT16_MIN, rssi_ant2 = INT16_MIN, rssi_max, rssi_min;
- if(config->ant_num < 2 || config->ant_num > 3) {
- ESP_LOGE(TAG, "wifi_antenna_auto_switch_config_t parameter error");
- abort();
- }
-
/**< Monitor antenna zero signal strength*/
wifi_ant_config.rx_ant_mode = WIFI_ANT_MODE_ANT0;
wifi_ant_config.rx_ant_default = WIFI_ANT_MODE_ANT0;
@@ -103,7 +99,7 @@ static void antenna_switch_function(const wifi_antenna_auto_switch_config_t *con
rssi_ant1 = rssi_ant1 - rssi_max - rssi_min;
ESP_LOGD(TAG, "The signal strength of the antenna one :%d", rssi_ant1);
- if(config->ant_num == 3) {
+ if(config->ant_num == ANT_TOTAL_THREE) {
/**< Monitor antenna two signal strength*/
wifi_ant_config.rx_ant_mode = WIFI_ANT_MODE_ANT1;
wifi_ant_config.tx_ant_mode = WIFI_ANT_MODE_ANT1;
@@ -275,6 +271,7 @@ esp_err_t esp_wifi_set_ant_soft_switch(const wifi_antenna_auto_switch_config_t
{
BaseType_t ret;
+ ESP_RETURN_ON_FALSE(config->ant_num < ANT_TOTAL_MAX, ESP_ERR_INVALID_ARG, TAG, "antenna nunmbers error!");
/**< Refresh configuration parameters*/
wifi_three_ant_auto_get_config = *config;
/**< Select the optimal antenna*/
diff --git a/examples/wifi/antenna/components/antenna_soft_switch/include/antenna_switch.h b/examples/wifi/antenna/components/antenna_soft_switch/include/antenna_switch.h
index d3aa655b19..42f89c1c06 100644
--- a/examples/wifi/antenna/components/antenna_soft_switch/include/antenna_switch.h
+++ b/examples/wifi/antenna/components/antenna_soft_switch/include/antenna_switch.h
@@ -11,12 +11,17 @@
extern "C" {
#endif
+typedef enum {
+ ANT_TOTAL_TWO, /**< TWO antennas participate in the switch */
+ ANT_TOTAL_THREE, /**< Three antennas participate in the switch */
+ ANT_TOTAL_MAX
+} ant_mun_t;
/**
* @brief WiFi antenna auto switch configuration
*
*/
typedef struct {
- uint8_t ant_num; /**< WiFi use antenna numbers 2 or 3*/
+ ant_mun_t ant_num; /**< WiFi use antenna numbers 2 or 3*/
uint8_t ant_zero; /**< WiFi antenna zero select*/
uint8_t ant_one; /**< WiFi antenna one select*/
uint8_t ant_two; /**< WiFi antenna two select*/

2
examples/wifi/antenna/CMakeLists.txt Executable file → Normal file
View File

@ -3,4 +3,4 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(wifi_station)
project(wifi_antenna)

65
examples/wifi/antenna/README.md Executable file → Normal file
View File

@ -32,15 +32,18 @@ Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.
See the Getting Started Guide for all the steps to configure and use the ESP-IDF to build projects.
* [ESP-IDF Getting Started Guide on ESP32](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html)
* [ESP-IDF Getting Started Guide on ESP32-S2](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/get-started/index.html)
* [ESP-IDF Getting Started Guide on ESP32-C2](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c2/get-started/index.html)
* [ESP-IDF Getting Started Guide on ESP32-C3](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/get-started/index.html)
* [ESP-IDF Getting Started Guide on ESP32-C6](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c6/get-started/index.html)
* [ESP-IDF Getting Started Guide on ESP32-S2](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/get-started/index.html)
* [ESP-IDF Getting Started Guide on ESP32-S3](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/get-started/index.html)
## Example Output
Note that the output, in particular the order of the output, may vary depending on the environment.
Console output if station connects to AP successfully:
```
I (589) wifi station: ESP_WIFI_MODE_STA
I (589) multi-antenna example: ESP_WIFI_MODE_STA
I (599) wifi: wifi driver task: 3ffc08b4, prio:23, stack:3584, core=0
I (599) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (599) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
@ -56,7 +59,7 @@ I (649) wifi: Init static rx buffer num: 10
I (659) wifi: Init dynamic rx buffer num: 32
I (759) phy: phy_version: 4180, cb3948e, Sep 12 2019, 16:39:13, 0, 0
I (769) wifi: mode : sta (30:ae:a4:d9:bc:c4)
I (769) wifi station: wifi_init_sta finished.
I (769) multi-antenna example: wifi_init_sta finished.
I (889) wifi: new:<6,0>, old:<1,0>, ap:<255,255>, sta:<6,0>, prof:1
I (889) wifi: state: init -> auth (b0)
I (899) wifi: state: auth -> assoc (0)
@ -67,25 +70,25 @@ I (949) wifi: pm start, type: 1
I (1029) wifi: AP's beacon interval = 102400 us, DTIM period = 3
I (2089) esp_netif_handlers: sta ip: 192.168.77.89, mask: 255.255.255.0, gw: 192.168.77.1
I (2089) wifi station: got ip:192.168.77.89
I (2089) wifi station: connected to ap SSID:myssid password:mypassword
I (12268) wifi station: GPIO: [0].pin = 21, [1].pin = 22
I (18568) wifi station: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (19068) wifi station: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (19568) wifi station: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (20068) wifi station: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (20568) wifi station: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (21068) wifi station: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (21568) wifi station: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (22068) wifi station: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (22568) wifi station: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (23068) wifi station: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (23568) wifi station: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (2089) multi-antenna example: got ip:192.168.77.89
I (2089) multi-antenna example: connected to ap SSID:myssid password:mypassword
I (12268) multi-antenna example: GPIO: [0].pin = 21, [1].pin = 22
I (18568) multi-antenna example: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (19068) multi-antenna example: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (19568) multi-antenna example: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (20068) multi-antenna example: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (20568) multi-antenna example: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (21068) multi-antenna example: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (21568) multi-antenna example: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (22068) multi-antenna example: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (22568) multi-antenna example: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (23068) multi-antenna example: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
I (23568) multi-antenna example: rx mode = 1, tx mode = 1, ant0_en = 0, ant1_en = 1
```
Console output if the station failed to connect to AP:
```
I (589) wifi station: ESP_WIFI_MODE_STA
I (589) multi-antenna example: ESP_WIFI_MODE_STA
I (599) wifi: wifi driver task: 3ffc08b4, prio:23, stack:3584, core=0
I (599) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (599) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
@ -101,31 +104,31 @@ I (649) wifi: Init static rx buffer num: 10
I (659) wifi: Init dynamic rx buffer num: 32
I (759) phy: phy_version: 4180, cb3948e, Sep 12 2019, 16:39:13, 0, 0
I (759) wifi: mode : sta (30:ae:a4:d9:bc:c4)
I (769) wifi station: wifi_init_sta finished.
I (769) multi-antenna example: wifi_init_sta finished.
I (889) wifi: new:<6,0>, old:<1,0>, ap:<255,255>, sta:<6,0>, prof:1
I (889) wifi: state: init -> auth (b0)
I (1889) wifi: state: auth -> init (200)
I (1889) wifi: new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1
I (1889) wifi station: retry to connect to the AP
I (1899) wifi station: connect to the AP fail
I (3949) wifi station: retry to connect to the AP
I (3949) wifi station: connect to the AP fail
I (1889) multi-antenna example: retry to connect to the AP
I (1899) multi-antenna example: connect to the AP fail
I (3949) multi-antenna example: retry to connect to the AP
I (3949) multi-antenna example: connect to the AP fail
I (4069) wifi: new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1
I (4069) wifi: state: init -> auth (b0)
I (5069) wifi: state: auth -> init (200)
I (5069) wifi: new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1
I (5069) wifi station: retry to connect to the AP
I (5069) wifi station: connect to the AP fail
I (7129) wifi station: retry to connect to the AP
I (7129) wifi station: connect to the AP fail
I (5069) multi-antenna example: retry to connect to the AP
I (5069) multi-antenna example: connect to the AP fail
I (7129) multi-antenna example: retry to connect to the AP
I (7129) multi-antenna example: connect to the AP fail
I (7249) wifi: new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1
I (7249) wifi: state: init -> auth (b0)
I (8249) wifi: state: auth -> init (200)
I (8249) wifi: new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1
I (8249) wifi station: retry to connect to the AP
I (8249) wifi station: connect to the AP fail
I (10299) wifi station: connect to the AP fail
I (10299) wifi station: Failed to connect to SSID:myssid, password:mypassword
I (8249) multi-antenna example: retry to connect to the AP
I (8249) multi-antenna example: connect to the AP fail
I (10299) multi-antenna example: connect to the AP fail
I (10299) multi-antenna example: Failed to connect to SSID:myssid, password:mypassword
```
## Troubleshooting

View File

View File

@ -1,3 +1,8 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
/* Antenna soft switching Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
@ -199,7 +204,7 @@ static void antenna_soft_switching_task(void *arg)
while(true) {
while(ESP_OK != esp_wifi_sta_get_ap_info(&wifi_ap_record)) {
/**< can't find AP*/
/**< Can't find AP*/
vTaskDelay(100/portTICK_PERIOD_MS);
}
/**< Filter the current rssi*/

View File

@ -1,4 +0,0 @@
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

View File

@ -1,3 +1,8 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
/*
* Design of antenna soft switching : 2023.02.21
*
@ -12,7 +17,7 @@ extern "C" {
#endif
typedef enum {
ANT_TOTAL_TWO, /**< TWO antennas participate in the switch */
ANT_TOTAL_TWO, /**< Two antennas participate in the switch */
ANT_TOTAL_THREE, /**< Three antennas participate in the switch */
ANT_TOTAL_MAX
} ant_mun_t;
@ -21,7 +26,7 @@ typedef enum {
*
*/
typedef struct {
ant_mun_t ant_num; /**< WiFi use antenna numbers 2 or 3*/
ant_mun_t ant_num; /**< WiFi use antenna numbers 2 or 3*/
uint8_t ant_zero; /**< WiFi antenna zero select*/
uint8_t ant_one; /**< WiFi antenna one select*/
uint8_t ant_two; /**< WiFi antenna two select*/

1
examples/wifi/antenna/main/CMakeLists.txt Executable file → Normal file
View File

@ -1,3 +1,2 @@
idf_component_register(SRCS "antenna_switch_example_main.c"
REQUIRES nvs_flash esp_wifi antenna_soft_switch)

0
examples/wifi/antenna/main/Kconfig.projbuild Executable file → Normal file
View File

View File

@ -1,3 +1,8 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
/* WiFi station Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
@ -60,7 +65,6 @@ static const char *TAG = "multi-antenna example";
static int s_retry_num = 0;
static void event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{

View File

@ -1,70 +0,0 @@
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0
import os.path
from typing import Tuple
import pytest
from pytest_embedded_idf.dut import IdfDut
# @pytest.mark.supported_targets
# This test should support all targets, even between different target types
# For now our CI only support multi dut with esp32
# If you want to enable different target type, please use the following param
# @pytest.mark.parametrize(
# 'count, app_path, target', [
# (2,
# f'{os.path.join(os.path.dirname(__file__), "softAP")}|{os.path.join(os.path.dirname(__file__), "station")}',
# 'esp32|esp32s2'),
# ],
# indirect=True,
# )
@pytest.mark.esp32
@pytest.mark.esp32c3
@pytest.mark.esp32s3
@pytest.mark.wifi_two_dut
@pytest.mark.parametrize(
'count, app_path', [
(2,
f'{os.path.join(os.path.dirname(__file__), "softAP")}|{os.path.join(os.path.dirname(__file__), "station")}'),
], indirect=True
)
def test_wifi_getting_started(dut: Tuple[IdfDut, IdfDut]) -> None:
softap = dut[0]
station = dut[1]
ssid = softap.app.sdkconfig.get('ESP_WIFI_SSID')
password = softap.app.sdkconfig.get('ESP_WIFI_PASSWORD')
assert station.app.sdkconfig.get('ESP_WIFI_SSID') == ssid
assert station.app.sdkconfig.get('ESP_WIFI_PASSWORD') == password
tag = 'wifi station'
station.expect(f'{tag}: got ip:', timeout=60)
station.expect(f'{tag}: connected to ap SSID:{ssid} password:{password}', timeout=60)
softap.expect('station .+ join, AID=', timeout=60)
@pytest.mark.esp32c2
@pytest.mark.wifi_two_dut
@pytest.mark.xtal_26mhz
@pytest.mark.parametrize(
'count, config, baud, app_path', [
(2, 'esp32c2_xtal26m', '74880',
f'{os.path.join(os.path.dirname(__file__), "softAP")}|{os.path.join(os.path.dirname(__file__), "station")}'),
], indirect=True
)
def test_wifi_getting_started_esp32c2_xtal_26mhz(dut: Tuple[IdfDut, IdfDut]) -> None:
softap = dut[0]
station = dut[1]
ssid = softap.app.sdkconfig.get('ESP_WIFI_SSID')
password = softap.app.sdkconfig.get('ESP_WIFI_PASSWORD')
assert station.app.sdkconfig.get('ESP_WIFI_SSID') == ssid
assert station.app.sdkconfig.get('ESP_WIFI_PASSWORD') == password
tag = 'wifi station'
station.expect(f'{tag}: got ip:', timeout=60)
station.expect(f'{tag}: connected to ap SSID:{ssid} password:{password}', timeout=60)
softap.expect('station .+ join, AID=', timeout=60)

View File

@ -1,2 +0,0 @@
CONFIG_ESP_WIFI_SSID="ssid_${IDF_TARGET}_${CI_PIPELINE_ID}"
CONFIG_ESP_WIFI_PASSWORD="password_${IDF_TARGET}_${CI_PIPELINE_ID}"

View File

@ -1,2 +0,0 @@
CONFIG_IDF_TARGET="esp32c2"
CONFIG_XTAL_FREQ_26=y