XFusion API v1.3.0
载入中...
搜索中...
未找到
examples/protocols/iperf/softap/main/xf_main.c

wifi iperf 示例(softap)。

1
17/* ==================== [Includes] ========================================== */
18
19#include "xfconfig.h"
20
21#include "lwip/err.h"
22#include "lwip/sockets.h"
23#include "lwip/sys.h"
24#include "lwip/inet.h"
25
26#include "xf_utils.h"
27#include "xf_wifi.h"
28#include "xf_netif.h"
29#include "xf_osal.h"
30#include "xf_sys.h"
31
32#include "xf_iperf.h"
33
34#include "ex_easy_wifi.h"
35
36/* ==================== [Defines] =========================================== */
37
38/* ==================== [Typedefs] ========================================== */
39
40/* ==================== [Static Prototypes] ================================= */
41
42static void _example_thread(void *argument);
43
44/* ==================== [Static Variables] ================================== */
45
46static const char *TAG = "xf_main";
47
48static xf_osal_thread_t s_thread_hdl = NULL;
49#define EX_THREAD_NAME "ex_thread"
50#define EX_THREAD_PRIORITY XF_OSAL_PRIORITY_NORMOL
51#define EX_THREAD_STACK_SIZE (1024 * 4)
54 .priority = EX_THREAD_PRIORITY,
55 .stack_size = EX_THREAD_STACK_SIZE,
56};
57
58#ifdef CONFIG_EXAMPLE_IPERF_AUTO_TEST
59static const uint32_t s_iperf_test_item[] = {
64};
65#endif /* CONFIG_EXAMPLE_IPERF_AUTO_TEST */
66
67/* ==================== [Macros] ============================================ */
68
69/* ==================== [Global Functions] ================================== */
70
71void xf_main(void)
72{
74 if (s_thread_hdl == NULL) {
75 XF_LOGE(TAG, "xf_osal_thread_create error");
76 return;
77 }
78}
79
80/* ==================== [Static Functions] ================================== */
81
82static void _example_thread(void *argument)
83{
84 UNUSED(argument);
85
86 uint32_t test_idx = 0;
87
88 xf_ip4_addr_t dest_ip4 = {0};
89 xf_ip4_addr_t src_ip4 = {0};
90
94
95 XF_LOGI(TAG, "\n"
96 "src_ip4: " XF_IPSTR "\n"
97 "dest_ip4: " XF_IPSTR,
98 XF_IP2STR(&src_ip4),
99 XF_IP2STR(&dest_ip4));
100
102
103 for (test_idx = 0; test_idx < ARRAY_SIZE(s_iperf_test_item); ++test_idx) {
106
109 cfg.time = CONFIG_EXAMPLE_IPERF_TIME;
110 cfg.dip.u_addr.ip4.addr = dest_ip4.addr;
111 cfg.sip.u_addr.ip4.addr = src_ip4.addr;
112
113#ifdef CONFIG_EXAMPLE_IPERF_AUTO_TEST
114 if (s_iperf_test_item[test_idx] & IPERF_FLAG_CLIENT) {
115 /* 延迟一会,避免服务端还没建立 */
116 xf_osal_delay_ms(100);
117 }
118 cfg.flag = s_iperf_test_item[test_idx];
119#else
120# if defined(CONFIG_EXAMPLE_IPERF_SELECT_SERVER)
121 cfg.flag |= IPERF_FLAG_SERVER;
122# else
123 cfg.flag |= IPERF_FLAG_CLIENT;
124# endif
125# if defined(CONFIG_EXAMPLE_IPERF_SELECT_UDP)
126 cfg.flag |= IPERF_FLAG_UDP;
127# else
128 cfg.flag |= IPERF_FLAG_TCP;
129# endif
130#endif /* CONFIG_EXAMPLE_IPERF_AUTO_TEST */
131
132 XF_LOGI(TAG,
133 "mode=%s-%s "
134 "sip=" XF_IPSTR ":%d,"
135 "dip=" XF_IPSTR ":%d,"
136 "interval=%" PRId32 ", time=%" PRId32 "",
137 cfg.flag & IPERF_FLAG_TCP ? "tcp" : "udp",
138 cfg.flag & IPERF_FLAG_SERVER ? "server" : "client",
139 XF_IP2STR(&cfg.sip.u_addr.ip4), (int)cfg.sport,
140 XF_IP2STR(&cfg.dip.u_addr.ip4), (int)cfg.dport,
141 cfg.interval, cfg.time);
142
143 xf_iperf_start(&cfg, NULL, NULL);
144
145 while (xf_iperf_is_running()) {
146 xf_osal_delay_ms(100);
147 }
148 } /* for */
149
150 XF_LOGI(TAG, "test done!");
151
153}
154
155// /**
156// * @brief iperf 回调函数。
157// *
158// * 这是 iperf 回调示例,如果不需要 iperf 内部报告,
159// * 则需要修改 `xf_iperf_cfg_t.report_enabled = false;
160// * 并使用该回调 `xf_iperf_start(&cfg, _xf_iperf_cb, NULL);`
161// *
162// * @param event_id iperf 事件 id.
163// * @param hdl iperf 句柄。
164// * @param user_args 用户数据。
165// */
166// static void _xf_iperf_cb(
167// xf_iperf_event_id_t event_id, xf_iperf_t hdl, void *user_args)
168// {
169// UNUSED(user_args);
170// switch (event_id) {
171// case XF_IPERF_EVENT_START: {
172// XF_LOGI(TAG, "%16s %s", "Interval", "Bandwidth");
173// } break;
174// case XF_IPERF_EVENT_REPORT: {
175// XF_LOGI(TAG, "%4d-%4d sec %.2f Mbits/sec",
176// hdl->curr_time, hdl->curr_time + hdl->cfg.interval,
177// hdl->actual_bandwidth);
178// } break;
179// case XF_IPERF_EVENT_END: {
180// XF_LOGI(TAG, "%4d-%4d sec %.2f Mbits/sec",
181// 0, hdl->cfg.time, hdl->average_bandwidth);
182// } break;
183// default:
184// break;
185// }
186// }
xf_ip4_addr_t ex_easy_wifi_ap_get_onw_ip(void)
xf_ip4_addr_t ex_easy_wifi_ap_get_last_sta_ip(void)
#define EX_THREAD_PRIORITY
#define EX_THREAD_STACK_SIZE
#define EX_THREAD_NAME
xf_err_t ex_easy_wifi_ap(void)
void xf_main(void)
Definition xf_main.c:28
#define XF_IPSTR
#define XF_IP2STR(ipaddr)
#define XF_IPERF_DEFAULT_CONFIG()
默认 iperf 配置
Definition xf_iperf.h:165
xf_err_t xf_iperf_start(const xf_iperf_cfg_t *p_cfg, xf_iperf_cb_t cb_func, void *user_args)
启动 iperf.
Definition xf_iperf.c:81
#define IPERF_FLAG_SERVER
Definition xf_iperf.h:60
#define IPERF_SOCKET_RX_TIMEOUT_MS
Definition xf_iperf.h:84
#define IPERF_FLAG_CLIENT
Definition xf_iperf.h:59
#define IPERF_FLAG_TCP
Definition xf_iperf.h:61
#define IPERF_IP_TYPE_IPV4
Definition xf_iperf.h:51
bool xf_iperf_is_running(void)
检查 iperf 是否正在运行。
Definition xf_iperf.c:140
xf_err_t xf_iperf_stop(void)
停止 iperf.
Definition xf_iperf.c:126
#define IPERF_FLAG_UDP
Definition xf_iperf.h:62
xf_err_t xf_osal_thread_delete(xf_osal_thread_t thread)
终止线程的执行。
xf_osal_thread_t xf_osal_thread_create(xf_osal_thread_func_t func, void *argument, const xf_osal_thread_attr_t *attr)
创建一个线程并将其添加到活动线程中。
void * xf_osal_thread_t
线程句柄。
xf_err_t xf_osal_delay_ms(uint32_t ms)
(睡眠)等待超时,以 ms 为单位。
__weak xf_err_t xf_sys_watchdog_disable(void)
关闭看门狗
#define ARRAY_SIZE(arr)
ARRAY_SIZE - 获取数组 arr 中的元素数量。
Definition xf_predef.h:173
#define TAG
Definition xf_main.c:24
static const xf_osal_thread_attr_t s_thread_attr
Definition xf_main.c:57
static void _example_thread(void *argument)
Definition xf_main.c:78
static xf_osal_thread_t s_thread_hdl
Definition xf_main.c:53
union _xf_ip_addr::@10 u_addr
iperf 配置类型。
Definition xf_iperf.h:137
xf_ip_addr_t dip
Definition xf_iperf.h:141
xf_ip_addr_t sip
Definition xf_iperf.h:142
uint32_t flag
Definition xf_iperf.h:138
uint32_t time
Definition xf_iperf.h:147
线程的属性结构。
#define XF_LOGI(tag, format,...)
#define XF_LOGE(tag, format,...)
#define UNUSED(_x)
xf_wifi 包含 STA、AP 接口。