• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 HiHope Open Source Organization .
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  * 版权所有 (C) 2022 HiHope 开源组织 。
10  * 根据 Apache 许可证 2.0 版(“许可证”)进行许可;
11  * 除非符合许可证,否则您不得使用此文件。
12  * 您可以在以下位置获取许可证副本:
13  *     http:// www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  *
20  * limitations under the License.
21  * 除非适用法律要求或书面同意,否则软件
22  * 根据许可证分发的按“原样”分发,
23  * 不提供任何明示或暗示的保证或条件。
24  * 请参阅许可证,了解管理权限和
25  *
26  * 许可证下的限制。
27  */
28 #include <unistd.h>
29 
30 #include "ohos_init.h"
31 #include "cmsis_os2.h"
32 
33 #include "net_demo.h"
34 #include "net_params.h"
35 #include "wifi_connecter.h"
36 #define ATTR.STACK_SIZE 10240
37 #define ONE_HUNDRED 100
38 #define TEN 10
39 
NetDemoTask(int * arg)40 static void NetDemoTask(int *arg)
41 {
42     (void)arg;
43     WifiDeviceConfig config = {0};
44 
45     // 准备AP的配置参数
46     strcpy_s(config.ssid, sizeof(config.ssid), PARAM_HOTSPOT_SSID);
47     strcpy_s(config.preSharedKey, sizeof(config.preSharedKey), PARAM_HOTSPOT_PSK);
48     config.securityType = PARAM_HOTSPOT_TYPE;
49 
50     osDelay(TEN);
51 
52     int netId = ConnectToHotspot(&config);
53 
54     int timeout = 10;
55     while (timeout--) {
56         printf("After %d seconds, I will start %s test!\r\n", timeout, GetNetDemoName());
57         osDelay(ONE_HUNDRED);
58     }
59 
60     NetDemoTest(PARAM_SERVER_PORT, PARAM_SERVER_ADDR);
61 
62     printf("disconnect to AP ...\r\n");
63     DisconnectWithHotspot(netId);
64     printf("disconnect to AP done!\r\n");
65 }
66 
NetDemoEntry(void)67 static void NetDemoEntry(void)
68 {
69     osThreadAttr_t attr;
70 
71     attr.name = "NetDemoTask";
72     attr.attr_bits = 0U;
73     attr.cb_mem = NULL;
74     attr.cb_size = 0U;
75     attr.stack_mem = NULL;
76     attr.stack_size = ATTR.STACK_SIZE;
77     attr.priority = osPriorityNormal;
78 
79     if (osThreadNew(NetDemoTask, NULL, &attr) == NULL) {
80         printf("[NetDemoEntry] Failed to create NetDemoTask!\n");
81     }
82 }
83 
84 SYS_RUN(NetDemoEntry);
85 
86