Skip to content

Commit

Permalink
Merge branch 'feature/ble_anp' into 'master'
Browse files Browse the repository at this point in the history
feat(ble_anp): Add alert notification profile and examples

Closes AEG-621

See merge request ae_group/esp-iot-solution!760
  • Loading branch information
wujiangang committed Jan 22, 2024
2 parents 996917b + cf73876 commit 8f614a8
Show file tree
Hide file tree
Showing 24 changed files with 1,594 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/upload_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
directories: >
components/audio/pwm_audio;
components/bluetooth/ble_conn_mgr;
components/bluetooth/ble_profiles/std/ble_anp;
components/bluetooth/ble_profiles/std/ble_hrp;
components/bluetooth/ble_profiles/esp/ble_ota;
components/bootloader_support_plus;
Expand Down
13 changes: 13 additions & 0 deletions .gitlab/ci/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ build_example_bluetooth_ble_conn_mgr_ble_spp_server:
variables:
EXAMPLE_DIR: examples/bluetooth/ble_conn_mgr/ble_spp/spp_server

build_example_bluetooth_ble_anp:
extends:
- .build_examples_template
- .rules:build:example_bluetooth_ble_anp
parallel:
matrix:
- IMAGE: espressif/idf:release-v4.3
- IMAGE: espressif/idf:release-v4.4
- IMAGE: espressif/idf:release-v5.0
- IMAGE: espressif/idf:release-v5.1
variables:
EXAMPLE_DIR: examples/bluetooth/ble_profiles/ble_anp

build_example_bluetooth_ble_hrp:
extends:
- .build_examples_template
Expand Down
18 changes: 18 additions & 0 deletions .gitlab/ci/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
- "components/bluetooth/ble_conn_mgr/**/*"
- "components/tools/cmake_utilities/package_manager.cmake"

.patterns-components_bluetooth_ble_profiles_std_ble_anp: &patterns-components_bluetooth_ble_profiles_std_ble_anp
- "components/bluetooth/ble_profiles/std/ble_anp/**/*"
- "components/tools/cmake_utilities/package_manager.cmake"

.patterns-components_bluetooth_ble_profiles_std_ble_hrp: &patterns-components_bluetooth_ble_profiles_std_ble_hrp
- "components/bluetooth/ble_profiles/std/ble_hrp/**/*"
- "components/tools/cmake_utilities/package_manager.cmake"
Expand Down Expand Up @@ -251,6 +255,9 @@
.patterns-example_bluetooth_ble_conn_mgr: &patterns-example_bluetooth_ble_conn_mgr
- "examples/bluetooth/ble_conn_mgr/**/*"

.patterns-example_bluetooth_ble_anp: &patterns-example_bluetooth_ble_anp
- "examples/bluetooth/ble_anp/**/*"

.patterns-example_bluetooth_ble_hrp: &patterns-example_bluetooth_ble_hrp
- "examples/bluetooth/ble_hrp/**/*"

Expand Down Expand Up @@ -457,6 +464,17 @@
- <<: *if-dev-push
changes: *patterns-example_bluetooth_ble_conn_mgr

.rules:build:example_bluetooth_ble_anp:
rules:
- <<: *if-protected
- <<: *if-label-build
- <<: *if-dev-push
changes: *patterns-build_system
- <<: *if-dev-push
changes: *patterns-components_bluetooth_ble_profiles_std_ble_anp
- <<: *if-dev-push
changes: *patterns-example_bluetooth_ble_anp

.rules:build:example_bluetooth_ble_hrp:
rules:
- <<: *if-protected
Expand Down
1 change: 0 additions & 1 deletion components/bluetooth/ble_conn_mgr/src/esp_nimble.c
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,6 @@ static int esp_ble_conn_gap_event(struct ble_gap_event *event, void *arg)
struct ble_hs_adv_fields fields;
rc = ble_hs_adv_parse_fields(&fields, event->disc.data, event->disc.length_data);
if (rc != ESP_OK) {
ESP_LOGE(TAG, "");
return 0;
} else {
/* Try to connect to the advertiser if it looks interesting. */
Expand Down
6 changes: 6 additions & 0 deletions components/bluetooth/ble_profiles/std/ble_anp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## v0.1.0

This is the first release version for Alert Notification Profile component in Espressif Component Registry, more detailed descriptions about the project, please refer to [User_Guide](https://docs.espressif.com/projects/espressif-esp-iot-solution/en/latest/bluetooth/ble_profiles.html).

Features:
- ANP: Support Alert Notification Profile.
16 changes: 16 additions & 0 deletions components/bluetooth/ble_profiles/std/ble_anp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
set(srcs "")
set(req "")
set(include "")
set(priv_includes "")
set(priv_req "ble_conn_mgr")

if(CONFIG_BLE_ALERT_NOTIFICATION_PROFILES)
list(APPEND srcs "src/esp_anp.c")
list(APPEND include "include")
endif()

idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "${include}"
PRIV_INCLUDE_DIRS "${priv_includes}"
REQUIRES "${req}"
PRIV_REQUIRES "${priv_req}")
7 changes: 7 additions & 0 deletions components/bluetooth/ble_profiles/std/ble_anp/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
menu "BLE Profile: Alert Notification"
config BLE_ALERT_NOTIFICATION_PROFILES
bool "Enable Alert Notification Profile"
default n
help
Enable support for Alert Notification Profile.
endmenu
50 changes: 50 additions & 0 deletions components/bluetooth/ble_profiles/std/ble_anp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## Alert Notification Profile Component

[![Component Registry](https://components.espressif.com/components/espressif/ble_anp/badge.svg)](https://components.espressif.com/components/espressif/ble_anp)

- [User Guide](https://docs.espressif.com/projects/espressif-esp-iot-solution/en/latest/bluetooth/ble_profiles.html)

``ble_anp`` is a component which provide a simplified API interface for accessing the commonly used BLE alert notification profile functionality on a GATT Client.

### Add component to your project

Please use the component manager command `add-dependency` to add the `ble_anp` to your project's dependency, during the `CMake` step the component will be downloaded automatically

```
idf.py add-dependency "espressif/ble_anp=*"
```

### Examples

Please use the component manager command `create-project-from-example` to create the project from example template

```
idf.py create-project-from-example "espressif/ble_anp=*:ble_anp"
```

Then the example will be downloaded in current folder, you can check into it for build and flash.

> You can use this command to download other examples. Or you can download examples from esp-iot-solution repository:
1. [ble_anp](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_profiles/ble_anp)

### Q&A

Q1. I encountered the following problems when using the package manager

```
HINT: Please check manifest file of the following component(s): main
ERROR: Because project depends on esp-now (2.*) which doesn't match any
versions, version solving failed.
```

A1. For the examples downloaded by using this command, you need to comment out the override_path line in the main/idf_component.yml of each example.

Q2. I encountered the following problems when using the package manager

```
Executing action: create-project-from-example
CMakeLists.txt not found in project directory /home/username
```

A2. This is because an older version packege manager was used, please run `pip install -U idf-component-manager` in ESP-IDF environment to update.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "0.1.0"
description: BLE standard profile support Alert Notification
url: https://github.com/espressif/esp-iot-solution/tree/master/components/bluetooth/ble_profiles/std/ble_anp
issues: https://github.com/espressif/esp-iot-solution/issues
examples:
- path: ../../../../../examples/bluetooth/ble_profiles
184 changes: 184 additions & 0 deletions components/bluetooth/ble_profiles/std/ble_anp/include/esp_anp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/*
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "esp_event.h"

#ifdef __cplusplus
extern "C"
{
#endif

/** @cond **/
/* BLE ANP EVENTS BASE */
ESP_EVENT_DECLARE_BASE(BLE_ANP_EVENTS);
/** @endcond **/

/* 16 Bit Alert Notification Service UUID */
#define BLE_ANP_UUID16 0x1811

/* 16 Bit Alert Notification Service Characteristic UUIDs */
#define BLE_ANP_CHR_UUID16_SUP_NEW_ALERT_CAT 0x2A47
#define BLE_ANP_CHR_UUID16_NEW_ALERT 0x2A46
#define BLE_ANP_CHR_UUID16_SUP_UNR_ALERT_CAT 0x2A48
#define BLE_ANP_CHR_UUID16_UNR_ALERT_STAT 0x2A45
#define BLE_ANP_CHR_UUID16_ALERT_NOT_CTRL_PT 0x2A44

/* Alert Notification Service Category ID Bit Masks
*
* TODO: Add remaining 2 optional categories */
#define BLE_ANP_CAT_BM_NONE 0x00
#define BLE_ANP_CAT_BM_SIMPLE_ALERT 0x01
#define BLE_ANP_CAT_BM_EMAIL 0x02
#define BLE_ANP_CAT_BM_NEWS 0x04
#define BLE_ANP_CAT_BM_CALL 0x08
#define BLE_ANP_CAT_BM_MISSED_CALL 0x10
#define BLE_ANP_CAT_BM_SMS 0x20
#define BLE_ANP_CAT_BM_VOICE_MAIL 0x40
#define BLE_ANP_CAT_BM_SCHEDULE 0x80

/* Alert Notification Service Category IDs
*
* TODO: Add remaining 2 optional categories */
#define BLE_ANP_CAT_ID_SIMPLE_ALERT 0
#define BLE_ANP_CAT_ID_EMAIL 1
#define BLE_ANP_CAT_ID_NEWS 2
#define BLE_ANP_CAT_ID_CALL 3
#define BLE_ANP_CAT_ID_MISSED_CALL 4
#define BLE_ANP_CAT_ID_SMS 5
#define BLE_ANP_CAT_ID_VOICE_MAIL 6
#define BLE_ANP_CAT_ID_SCHEDULE 7

/* Number of valid ANS categories
*
* TODO: Add remaining 2 optional categories */
#define BLE_ANP_CAT_NUM 8

/* Alert Notification Control Point Command IDs */
#define BLE_ANP_CMD_EN_NEW_ALERT_CAT 0
#define BLE_ANP_CMD_EN_UNR_ALERT_CAT 1
#define BLE_ANP_CMD_DIS_NEW_ALERT_CAT 2
#define BLE_ANP_CMD_DIS_UNR_ALERT_CAT 3
#define BLE_ANP_CMD_NOT_NEW_ALERT_IMMEDIATE 4
#define BLE_ANP_CMD_NOT_UNR_ALERT_IMMEDIATE 5

/* Max length of new alert info string */
#define BLE_ANP_INFO_STR_MAX_LEN 18

/* Max length of a new alert notification, max string length + 2 bytes for category ID and count. */
#define BLE_ANP_NEW_ALERT_MAX_LEN (BLE_ANP_INFO_STR_MAX_LEN + 2)

/**
* @brief The status of the new or unread alert
*/
typedef struct {
union {
struct {
uint8_t cat_id; /*!< The predefined categories of unread alerts and messages */
uint8_t count; /*!< The number of unread alerts in the server ranging from 0 to 255 */
} unr_alert_stat; /*!< The status of unread alerts */

struct {
uint8_t cat_id; /*!< The predefined categories of new alerts and messages */
uint8_t count; /*!< The number of new alerts in the server ranging from 0 to 255 */
uint8_t cat_info[BLE_ANP_INFO_STR_MAX_LEN]; /*!< The brief text information for the last alert */
} new_alert_val; /*!< The status of new alerts */
}; /*!< Alert notification status */
} esp_ble_anp_data_t;

/**
* @brief The option of the new or unread alert
*/
typedef enum {
BLE_ANP_OPT_ENABLE,
BLE_ANP_OPT_DISABLE,
BLE_ANP_OPT_RECOVER,
} esp_ble_anp_option_t;

/**
* @brief Read the value of or check supported new alert category.
*
* @attention 1. When cat_id is 0xFF, read the value of supported new alert category.
* @attention 2. When cat_id isn't 0xFF, check supported new alert category is enable or disable.
*
* @param[in] cat_id The ID of the category to read or check
* @param[out] cat_val The value of read or check supported new alert category
*
* @return
* - ESP_OK on successful
* - ESP_ERR_INVALID_ARG on wrong category of the alert
*/
esp_err_t esp_ble_anp_get_new_alert(uint8_t cat_id, uint8_t *cat_val);

/**
* @brief Request or recovery supported new alert notification to the given category.
*
* @attention 1. When cat_id is 0xFF, recover for all supported new alert category to get the current message counts.
* @attention 2. When cat_id isn't 0xFF, request for a supported new alert category to get the current message counts.
*
* @param[in] cat_id The ID of the category to request or recover the notification to
* @param[in] option Disable or enable supported new alert category
*
* @return
* - ESP_OK on successful
* - ESP_ERR_INVALID_ARG on wrong category of the alert
*/
esp_err_t esp_ble_anp_set_new_alert(uint8_t cat_id, esp_ble_anp_option_t option);

/**
* @brief Read the value of or check supported unread alert status category.
*
* @attention 1. When cat_id is 0xFF, read the value of supported unread alert status category.
* @attention 2. When cat_id isn't 0xFF, check supported unread alert status category is enable or disable.
*
* @param[in] cat_id The ID of the category to read or check
* @param[out] cat_val The value of read or check supported unread alert status category
*
* @return
* - ESP_OK on successful
* - ESP_ERR_INVALID_ARG on wrong category of the alert
*/
esp_err_t esp_ble_anp_get_unr_alert(uint8_t cat_id, uint8_t *cat_val);

/**
* @brief Request or recovery supported unread alert status notification to the given category.
*
* @attention 1. When cat_id is 0xFF, recover for all supported unread alert status category to get the current message counts.
* @attention 2. When cat_id isn't 0xFF, request for an supported unread alert status category to get the current message counts.
*
* @param[in] cat_id The ID of the category to request or recover the notification to
* @param[in] option Disable or enable supported unread alert status category
*
* @return
* - ESP_OK on successful
* - ESP_ERR_INVALID_ARG on wrong category of the alert
*/
esp_err_t esp_ble_anp_set_unr_alert(uint8_t cat_id, esp_ble_anp_option_t option);

/**
* @brief Initialization GATT Alert Notification Profile
*
* @return
* - ESP_OK on successful
* - ESP_ERR_INVALID_ARG on wrong initialization
* - ESP_FAIL on error
*/
esp_err_t esp_ble_anp_init(void);

/**
* @brief Deinitialization GATT Alert Notification Profile
*
* @return
* - ESP_OK on successful
* - ESP_ERR_INVALID_ARG on wrong initialization
* - ESP_FAIL on error
*/
esp_err_t esp_ble_anp_deinit(void);

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit 8f614a8

Please sign in to comment.