• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2022 Talkweb Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <stdio.h>
16 #include "cmsis_os2.h"
17 #include "app_ethernet.h"
18 #include "ohos_run.h"
19 
20 osThreadId_t iperf_test_id = NULL;
21 static unsigned char iperf_run_flag = 0;
22 
23 #define LOCAL_PORT        1234
24 
25 EthLinkInfo gEthLinkInfo;
26 
iperf_test(void * arg)27 void iperf_test(void *arg)
28 {
29     (void *)arg;
30     get_ethernet_link_info(&gEthLinkInfo);
31     printf("lwiperf_start_tcp_server IP:%s port:%d\n", ipaddr_ntoa(&gEthLinkInfo.ipaddr), LOCAL_PORT);
32     lwiperf_start_tcp_server(&gEthLinkInfo.ipaddr, LOCAL_PORT, NULL, NULL);
33     printf("lwiperf tcp_server is running...\n");
34     iperf_run_flag = 1;
35     while (iperf_run_flag) {
36         osDelay(1000);
37     }
38 }
39 
eth_enable_state_callBack(EthLinkState state)40 static void eth_enable_state_callBack(EthLinkState state)
41 {
42     static int net_init_finish = 0;
43     if (state == STATE_UPDATE_LINK_DOWN) {
44         iperf_run_flag = 0;
45         osThreadTerminate(iperf_test_id);
46         iperf_test_id = NULL;
47         printf("ETH LINK STATE: DisConnected!\r\n");
48     } else if (state == STATE_UPDATE_LINK_UP) {
49         printf("ETH LINK STATE: Connected!\r\n");
50         if (net_init_finish == 0) {
51             osThreadAttr_t attr;
52             attr.name = "iperf_test";
53             attr.attr_bits = 0U;
54             attr.cb_mem = NULL;
55             attr.cb_size = 0U;
56             attr.stack_mem = NULL;
57             attr.stack_size = 1024 * 4;
58             attr.priority = 25;
59             iperf_test_id = osThreadNew((osThreadFunc_t)iperf_test, NULL, &attr);
60             if (iperf_test_id == NULL) {
61                 printf("Failed to create iperf_test thread!\n");
62             }
63             net_init_finish = 1;
64         }
65     }
66 }
67 
iperf_test_example(void)68 void iperf_test_example(void)
69 {
70     ethernet_enable(eth_enable_state_callBack);
71 }
72 
73 OHOS_APP_RUN(iperf_test_example);