1 /*
2 * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
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
16 #include <stdio.h>
17 #include <string.h>
18 #include <unistd.h>
19
20 #include "ohos_init.h"
21 #include "cmsis_os2.h"
22
23 #include "net_demo.h"
24 #include "net_params.h"
25 #include "wifi_connecter.h"
26
NetDemoTask(void)27 static void NetDemoTask(void)
28 {
29 int netId = ConnectToHotspot();
30
31 int timeout = 10; /* timeout 10ms */
32 while (timeout--) {
33 printf("After %d seconds, I will start lwip test!\r\n", timeout);
34 osDelay(100); /* 延时100ms */
35 }
36
37 NetDemoTest(PARAM_SERVER_PORT, PARAM_SERVER_ADDR);
38
39 printf("disconnect to AP ...\r\n");
40 DisconnectWithHotspot(netId);
41 printf("disconnect to AP done!\r\n");
42 }
43
NetDemoEntry(void)44 static void NetDemoEntry(void)
45 {
46 osThreadAttr_t attr;
47
48 attr.name = "NetDemoTask";
49 attr.attr_bits = 0U;
50 attr.cb_mem = NULL;
51 attr.cb_size = 0U;
52 attr.stack_mem = NULL;
53 attr.stack_size = 10240; /* 堆栈大小为10240 */
54 attr.priority = osPriorityNormal;
55
56 if (osThreadNew(NetDemoTask, NULL, &attr) == NULL) {
57 printf("[NetDemoEntry] Failed to create NetDemoTask!\n");
58 }
59 }
60
61 SYS_RUN(NetDemoEntry);