• 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  * 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  *
14  * limitations under the License.
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 #define TEN 10
27 #define ONE_HUNDRED 100
28 #define ATTR.STACK_SIZE 10240
29 
NetDemoTask(int * arg)30 static void NetDemoTask(int *arg)
31 {
32     (void)arg;
33     WifiDeviceConfig config = {0};
34 
35     // 准备AP的配置参数
36     strcpy_s(config.ssid, sizeof(config.ssid), PARAM_HOTSPOT_SSID);
37     strcpy_s(config.preSharedKey, sizeof(config.preSharedKey), PARAM_HOTSPOT_PSK);
38     config.securityType = PARAM_HOTSPOT_TYPE;
39 
40     osDelay(TEN);
41 
42     int netId = ConnectToHotspot(&config);
43 
44     int timeout = 10;
45     while (timeout--) {
46         printf("After %d seconds, I will start %s test!\r\n", timeout, GetNetDemoName());
47         osDelay(ONE_HUNDRED);
48     }
49 
50     NetDemoTest(PARAM_SERVER_PORT, PARAM_SERVER_ADDR);
51 
52     printf("disconnect to AP ...\r\n");
53     DisconnectWithHotspot(netId);
54     printf("disconnect to AP done!\r\n");
55 }
56 
NetDemoEntry(void)57 static void NetDemoEntry(void)
58 {
59     osThreadAttr_t attr;
60 
61     attr.name = "NetDemoTask";
62     attr.attr_bits = 0U;
63     attr.cb_mem = NULL;
64     attr.cb_size = 0U;
65     attr.stack_mem = NULL;
66     attr.stack_size = ATTR.STACK_SIZE;
67     attr.priority = osPriorityNormal;
68 
69     if (osThreadNew(NetDemoTask, NULL, &attr) == NULL) {
70         printf("[NetDemoEntry] Failed to create NetDemoTask!\n");
71     }
72 }
73 
74 SYS_RUN(NetDemoEntry);
75 
76