• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 WinnerMicro 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 
16 #include "ble_server_demo.h"
17 
18 #include <stdio.h>
19 #include "cmsis_os2.h"
20 #include "ohos_init.h"
21 #include "my_stdbool.h"
22 #include "ohos_bt_def.h"
23 #include "ohos_bt_gatt.h"
24 
25 #define BLE_DEMO_TASK_STACK_SIZE   2048
26 #define BLE_DEMO_TASK_PRIO         25
27 #define MS_1000     1000
28 
BLE_Task_Entry(const char * arg)29 void *BLE_Task_Entry(const char *arg)
30 {
31     int rc;
32     (void)arg;
33 
34     printf("Initialize BLE stack and running server demo.\r\n");
35 
36     /**Enable BLE stack*/
37     /* 启用BLE堆栈 */
38     rc = EnableBtStack();
39     if (rc != OHOS_BT_STATUS_SUCCESS) {
40         printf("ERR: enable ble stack failed, rc=%d\r\n", rc);
41         return NULL;
42     }
43 
44     /**Add BLE service and start Advertising*/
45     /* 添加BLE服务并开始广告 */
46     ble_server_demo();
47 
48     while (1) {
49         osDelay(MS_1000); /* 延时1000ms */
50     }
51 }
52 
BLE_Demo(void)53 void BLE_Demo(void)
54 {
55     osThreadAttr_t attr;
56 
57     attr.name       = "BLE_Demo_Task";
58     attr.attr_bits  = 0U;
59     attr.cb_mem     = NULL;
60     attr.cb_size    = 0U;
61     attr.stack_mem  = NULL;
62     attr.stack_size = BLE_DEMO_TASK_STACK_SIZE; /* 堆栈大小2048 */
63     attr.priority   = BLE_DEMO_TASK_PRIO;
64 
65     /* 创建线程监控是否创建蓝牙连接的任务 */
66     if (osThreadNew((osThreadFunc_t)BLE_Task_Entry, NULL, &attr) == NULL) {
67         printf("[BLEDemo] Failed to create BLE Demo Task!\n");
68     }
69 }
70 
71 SYS_RUN(BLE_Demo);
72