Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_format_error' into 'master'
Browse files Browse the repository at this point in the history
examples: fix format errors, remove -Wno-format

Closes IDF-6433

See merge request espressif/esp-idf!21637
  • Loading branch information
jack0c committed Mar 21, 2023
2 parents 4c75ad9 + 9a05cc7 commit a39514a
Show file tree
Hide file tree
Showing 26 changed files with 109 additions and 117 deletions.
2 changes: 0 additions & 2 deletions examples/common_components/iperf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ idf_component_register(SRCS "iperf.c"
REQUIRES lwip
PRIV_REQUIRES esp_timer)

target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

if(CONFIG_SOC_WIFI_HE_SUPPORT)
idf_component_optional_requires(PRIVATE esp_wifi console)
endif()
18 changes: 12 additions & 6 deletions examples/common_components/iperf/iperf.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Iperf Example - iperf implementation
This example code is in the Public Domain (or CC0 licensed, at your option.)
/
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -11,6 +11,7 @@
#include <string.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_check.h"
Expand Down Expand Up @@ -86,14 +87,14 @@ static void iperf_report_task(void *arg)
while (!s_iperf_ctrl.finish) {
vTaskDelay(delay_interval);
actual_bandwidth = (s_iperf_ctrl.actual_len / coefficient[format] * 8) / interval;
printf("%4d-%4d sec %.2f %cbits/sec\n", cur, cur + interval,
printf("%4" PRIi32 "-%4" PRIi32 " sec %.2f %cbits/sec\n", cur, cur + interval,
actual_bandwidth, unit[format]);
cur += interval;
average = ((average * (k - 1) / k) + (actual_bandwidth / k));
k++;
s_iperf_ctrl.actual_len = 0;
if (cur >= time) {
printf("%4d-%4d sec %.2f %cbits/sec\n", 0, time,
printf("%4d-%4" PRIu32 " sec %.2f %cbits/sec\n", 0, time,
average, unit[format]);
break;
}
Expand Down Expand Up @@ -396,7 +397,7 @@ static esp_err_t IRAM_ATTR iperf_run_udp_server(void)

err = bind(listen_socket, (struct sockaddr *)&listen_addr6, sizeof(struct sockaddr_in6));
ESP_GOTO_ON_FALSE((err == 0), ESP_FAIL, exit, TAG, "Socket unable to bind: errno %d", errno);
ESP_LOGI(TAG, "Socket bound, port %d", listen_addr6.sin6_port);
ESP_LOGI(TAG, "Socket bound, port %" PRIu16, listen_addr6.sin6_port);

memcpy(&listen_addr, &listen_addr6, sizeof(listen_addr6));
} else if (s_iperf_ctrl.cfg.type == IPERF_IP_TYPE_IPV4) {
Expand Down Expand Up @@ -453,7 +454,7 @@ static esp_err_t iperf_run_udp_client(void)

client_socket = socket(AF_INET6, SOCK_DGRAM, IPPROTO_IPV6);
ESP_GOTO_ON_FALSE((client_socket >= 0), ESP_FAIL, exit, TAG, "Unable to create socket: errno %d", errno);
ESP_LOGI(TAG, "Socket created, sending to %s:%d", s_iperf_ctrl.cfg.destination_ip6, s_iperf_ctrl.cfg.dport);
ESP_LOGI(TAG, "Socket created, sending to %s:%" PRIu16, s_iperf_ctrl.cfg.destination_ip6, s_iperf_ctrl.cfg.dport);

setsockopt(client_socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
memcpy(&dest_addr, &dest_addr6, sizeof(dest_addr6));
Expand All @@ -464,7 +465,12 @@ static esp_err_t iperf_run_udp_client(void)

client_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
ESP_GOTO_ON_FALSE((client_socket >= 0), ESP_FAIL, exit, TAG, "Unable to create socket: errno %d", errno);
ESP_LOGI(TAG, "Socket created, sending to %d:%d", s_iperf_ctrl.cfg.destination_ip4, s_iperf_ctrl.cfg.dport);
ESP_LOGI(TAG, "Socket created, sending to %d.%d.%d.%d:%" PRIu16,
(uint16_t) s_iperf_ctrl.cfg.destination_ip4 & 0xFF,
(uint16_t) (s_iperf_ctrl.cfg.destination_ip4 >> 8) & 0xFF,
(uint16_t) (s_iperf_ctrl.cfg.destination_ip4 >> 16) & 0xFF,
(uint16_t) (s_iperf_ctrl.cfg.destination_ip4 >> 24) & 0xFF,
s_iperf_ctrl.cfg.dport);

setsockopt(client_socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
memcpy(&dest_addr, &dest_addr4, sizeof(dest_addr4));
Expand Down
48 changes: 21 additions & 27 deletions examples/common_components/iperf/wifi_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
* (1) esp_wifi_enable_rx_statistics(true, true);
* (2) esp_wifi_enable_tx_statistics(ESP_WIFI_ACI_BE, true);
*/
#define VAR2IPSTR(var) (uint16_t) var & 0xFF, \
(uint16_t) (var >> 8) & 0xFF, \
(uint16_t) (var >> 16) & 0xFF, \
(uint16_t) (var >> 24) & 0xFF


/*******************************************************
* Constants
Expand Down Expand Up @@ -258,12 +263,12 @@ static int wifi_cmd_reg_rw(int argc, char **argv)
}
if (reg_rw_args.read->count) {
addr = (uint32_t) reg_rw_args.read->dval[0];
ESP_LOGW(TAG, "reg read 0x%08x : 0x%08x\n", addr, REG_READ(addr));
ESP_LOGW(TAG, "reg read 0x%08lx : 0x%08lx\n", addr, REG_READ(addr));
} else if (reg_rw_args.write->count && (uint32_t) reg_rw_args.value->count) {
addr = (uint32_t) reg_rw_args.write->dval[0];
ESP_LOGW(TAG, "reg write 0x%8x : 0x%8x\n", addr, (uint32_t) reg_rw_args.value->dval[0]);
ESP_LOGW(TAG, "reg write 0x%8lx : 0x%8lx\n", addr, (uint32_t) reg_rw_args.value->dval[0]);
REG_WRITE(addr, (uint32_t ) reg_rw_args.value->dval[0]);
ESP_LOGW(TAG, "reg read 0x%08x : 0x%08x\n", addr, REG_READ(addr));
ESP_LOGW(TAG, "reg read 0x%08lx : 0x%08lx\n", addr, REG_READ(addr));
} else {
printf("Input Error\n");
}
Expand Down Expand Up @@ -360,7 +365,7 @@ static void cmd_ping_on_ping_success(esp_ping_handle_t hdl, void *args)
esp_ping_get_profile(hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof(target_addr));
esp_ping_get_profile(hdl, ESP_PING_PROF_SIZE, &recv_len, sizeof(recv_len));
esp_ping_get_profile(hdl, ESP_PING_PROF_TIMEGAP, &elapsed_time, sizeof(elapsed_time));
printf("%d bytes from %s icmp_seq=%d ttl=%d time=%d ms\n",
printf("%" PRIu32 " bytes from %s icmp_seq=%d ttl=%d time=%" PRIu32 " ms\n",
recv_len, inet_ntoa(target_addr.u_addr.ip4), seqno, ttl, elapsed_time);
}

Expand Down Expand Up @@ -389,7 +394,7 @@ static void cmd_ping_on_ping_end(esp_ping_handle_t hdl, void *args)
} else {
printf("\n--- %s ping statistics ---\n", inet6_ntoa(*ip_2_ip6(&target_addr)));
}
printf("%d packets transmitted, %d received, %d%% packet loss, time %dms\n",
printf("%" PRIu32 " packets transmitted, %" PRIu32 " received, %" PRIu32 "%% packet loss, time %" PRIu32 "ms\n",
transmitted, received, loss, total_time_ms);
// delete the ping sessions, so that we clean up all resources and can create a new ping session
// we don't have to call delete function in the callback, instead we can call delete function from other tasks
Expand Down Expand Up @@ -512,10 +517,8 @@ static int wifi_cmd_set_ip(int argc, char **argv)
/* set static IP settings */
esp_netif_set_static_ip(netif_sta, ip, gw, netmask);

ESP_LOGD(TAG, "ip:%d.%d.%d.%d, gateway:%d.%d.%d.%d, netmask:%d.%d.%d.%d,", ip & 0xFF,
(ip >> 8) & 0xFF, (ip >> 16) & 0xFF, (ip >> 24) & 0xFF, gw & 0xFF, (gw >> 8) & 0xFF,
(gw >> 16) & 0xFF, (gw >> 24) & 0xFF, netmask & 0xFF, (netmask >> 8) & 0xFF,
(netmask >> 16) & 0xFF, (netmask >> 24) & 0xFF);
ESP_LOGD(TAG, "ip:%d.%d.%d.%d, gateway:%d.%d.%d.%d, netmask:%d.%d.%d.%d,",
VAR2IPSTR(ip), VAR2IPSTR(gw), VAR2IPSTR(netmask));
return 0;
}

Expand Down Expand Up @@ -570,13 +573,9 @@ static int wifi_cmd_query(int argc, char **argv)
printf("\tap mac: "MACSTR, MAC2STR(mac));
printf("\n");
}
printf("\tip: %d.%d.%d.%d\n", ip_info.ip.addr & 0xFF, (ip_info.ip.addr >> 8) & 0xFF,
(ip_info.ip.addr >> 16) & 0xFF, (ip_info.ip.addr >> 24) & 0xFF);
printf("\tnetmask: %d.%d.%d.%d\n", ip_info.netmask.addr & 0xFF,
(ip_info.netmask.addr >> 8) & 0xFF, (ip_info.netmask.addr >> 16) & 0xFF,
(ip_info.netmask.addr >> 24) & 0xFF);
printf("\tgateway: %d.%d.%d.%d\n", ip_info.gw.addr & 0xFF, (ip_info.gw.addr >> 8) & 0xFF,
(ip_info.gw.addr >> 16) & 0xFF, (ip_info.gw.addr >> 24) & 0xFF);
printf("\tip: %d.%d.%d.%d\n", VAR2IPSTR(ip_info.ip.addr));
printf("\tnetmask: %d.%d.%d.%d\n", VAR2IPSTR(ip_info.netmask.addr));
printf("\tgateway: %d.%d.%d.%d\n", VAR2IPSTR(ip_info.gw.addr));
printf("\n");
} else if (WIFI_MODE_STA == mode) {
int bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0);
Expand Down Expand Up @@ -614,14 +613,9 @@ static int wifi_cmd_query(int argc, char **argv)
printf("\tsta mac: "MACSTR, MAC2STR(mac));
printf("\n");
}
printf("\tip: %d.%d.%d.%d\n", ip_info.ip.addr & 0xFF, (ip_info.ip.addr >> 8) & 0xFF,
(ip_info.ip.addr >> 16) & 0xFF, (ip_info.ip.addr >> 24) & 0xFF);
printf("\tnetmask: %d.%d.%d.%d\n", ip_info.netmask.addr & 0xFF,
(ip_info.netmask.addr >> 8) & 0xFF, (ip_info.netmask.addr >> 16) & 0xFF,
(ip_info.netmask.addr >> 24) & 0xFF);
printf("\tgateway: %d.%d.%d.%d\n", ip_info.gw.addr & 0xFF,
(ip_info.gw.addr >> 8) & 0xFF, (ip_info.gw.addr >> 16) & 0xFF,
(ip_info.gw.addr >> 24) & 0xFF);
printf("\tip: %d.%d.%d.%d\n", VAR2IPSTR(ip_info.ip.addr));
printf("\tnetmask: %d.%d.%d.%d\n", VAR2IPSTR(ip_info.netmask.addr));
printf("\tgateway: %d.%d.%d.%d\n", VAR2IPSTR(ip_info.gw.addr));
printf("\n");

} else {
Expand Down Expand Up @@ -721,7 +715,7 @@ static int wifi_cmd_inactive_time(int argc, char **argv)
if (err != ESP_OK) {
ESP_LOGW(TAG, "set softAP inactive time to %d seconds, err:0x%x\n", inactive_time_args.val->ival[0], err);
} else {
ESP_LOGI(TAG, "set softAP inactive time to %d seconds, err:0x%x\n", inactive_time_args.val->ival[0]);
ESP_LOGI(TAG, "set softAP inactive time to %d seconds\n", inactive_time_args.val->ival[0]);
}
}
//WIFI_MODE_STA or WIFI_MODE_APSTA
Expand All @@ -730,7 +724,7 @@ static int wifi_cmd_inactive_time(int argc, char **argv)
if (err != ESP_OK) {
ESP_LOGW(TAG, "set STA inactive time to %d seconds, err:0x%x\n", inactive_time_args.val->ival[0], err);
} else {
ESP_LOGI(TAG, "set STA inactive time to %d seconds, err:0x%x\n", inactive_time_args.val->ival[0]);
ESP_LOGI(TAG, "set STA inactive time to %d seconds\n", inactive_time_args.val->ival[0]);
}
}
uint16_t secs = 0;
Expand Down Expand Up @@ -816,7 +810,7 @@ static int wifi_cmd_set_tx_pwr(int argc, char **argv)
ESP_LOGW(TAG, "set MCS%d TX PWR to %d", tx_pwr_args.mcs->ival[0], tx_pwr_args.power->ival[0]);
} else if (tx_pwr_args.power->ival[0] == 0xff) {
esp_test_set_tx_mcs_pwr(tx_pwr_args.mcs->ival[0] + WIFI_PHY_RATE_MCS0_LGI, tx_pwr_args.power->ival[0]);
ESP_LOGW(TAG, "set MCS%d TX PWR to default value", tx_pwr_args.mcs->ival[0], tx_pwr_args.power->ival[0]);
ESP_LOGW(TAG, "set MCS%d TX PWR to default value", tx_pwr_args.mcs->ival[0]);
}
} else {
ESP_LOGW(TAG, "Set TX power fail, MCS should in range [0,9], power should in range [-13, 30] or set 0xFF for default");
Expand Down
Loading

0 comments on commit a39514a

Please sign in to comment.