Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NXP] Add multiple ble connections support #35645

Merged
merged 12 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/contact-sensor-app/nxp/k32w1/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ mcxw71_k32w1_executable("contact_sensor_app") {
"${common_example_dir}/low_power/include",
"${common_example_dir}/operational_keystore/include",
"${common_example_dir}/ui_feedback/include",
"${common_example_dir}/app_ble/include",
]

sources += [
"${common_example_dir}/app_ble/source/BLEApplicationManagerEmpty.cpp",
"${common_example_dir}/app_task/source/AppTaskBase.cpp",
"${common_example_dir}/app_task/source/AppTaskFreeRTOS.cpp",
"${common_example_dir}/clusters/source/ZclCallbacks.cpp",
Expand Down
2 changes: 2 additions & 0 deletions examples/contact-sensor-app/nxp/mcxw71/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ mcxw71_k32w1_executable("contact_sensor_app") {
"${common_example_dir}/low_power/include",
"${common_example_dir}/operational_keystore/include",
"${common_example_dir}/ui_feedback/include",
"${common_example_dir}/app_ble/include",
]

sources += [
"${common_example_dir}/app_ble/source/BLEApplicationManagerEmpty.cpp",
"${common_example_dir}/app_task/source/AppTaskBase.cpp",
"${common_example_dir}/app_task/source/AppTaskFreeRTOS.cpp",
"${common_example_dir}/clusters/source/ZclCallbacks.cpp",
Expand Down
2 changes: 2 additions & 0 deletions examples/lighting-app/nxp/k32w1/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ mcxw71_k32w1_executable("light_app") {
"${common_example_dir}/operational_keystore/include",
"${common_example_dir}/rpc/include",
"${common_example_dir}/ui_feedback/include",
"${common_example_dir}/app_ble/include",
]

sources += [
"${common_example_dir}/app_ble/source/BLEApplicationManagerEmpty.cpp",
"${common_example_dir}/app_task/source/AppTaskBase.cpp",
"${common_example_dir}/app_task/source/AppTaskFreeRTOS.cpp",
"${common_example_dir}/clusters/source/ZclCallbacks.cpp",
Expand Down
2 changes: 2 additions & 0 deletions examples/lighting-app/nxp/mcxw71/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ mcxw71_k32w1_executable("light_app") {
"${common_example_dir}/operational_keystore/include",
"${common_example_dir}/rpc/include",
"${common_example_dir}/ui_feedback/include",
"${common_example_dir}/app_ble/include",
]

sources += [
"${common_example_dir}/app_ble/source/BLEApplicationManagerEmpty.cpp",
"${common_example_dir}/app_task/source/AppTaskBase.cpp",
"${common_example_dir}/app_task/source/AppTaskFreeRTOS.cpp",
"${common_example_dir}/clusters/source/ZclCallbacks.cpp",
Expand Down
4 changes: 4 additions & 0 deletions examples/lock-app/nxp/common/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include "AppTask.h"
#include "BLEApplicationManager.h"
#include "CHIPDeviceManager.h"
#include "LockManager.h"
#include <app-common/zap-generated/attributes/Accessors.h>
Expand Down Expand Up @@ -115,6 +116,9 @@ static CHIP_ERROR cliDoorLock(int argc, char * argv[])
void LockApp::AppTask::PreInitMatterStack()
{
ChipLogProgress(DeviceLayer, "Welcome to NXP Lock Demo App");

/* BLEApplicationManager implemented per platform or left blank */
chip::NXP::App::BleAppMgr().Init();
}

void LockApp::AppTask::PostInitMatterStack()
Expand Down
18 changes: 18 additions & 0 deletions examples/lock-app/nxp/k32w1/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ mcxw71_k32w1_sdk("sdk") {
"${example_platform_dir}/board/peripherals.h",
]
}

if (nxp_multiple_ble_connections) {
include_dirs += [ "${example_platform_dir}/app_ble/include" ]
defines += [
"EXTRA_GATT_DB_HEADER=\"extra_gatt_db.h\"",
"EXTRA_GATT_UUID_HEADER=\"extra_gatt_uuid128.h\"",
]
}
}

mcxw71_k32w1_executable("lock_app") {
Expand Down Expand Up @@ -140,6 +148,7 @@ mcxw71_k32w1_executable("lock_app") {
"${common_example_dir}/low_power/include",
"${common_example_dir}/operational_keystore/include",
"${common_example_dir}/ui_feedback/include",
"${common_example_dir}/app_ble/include",
]

sources += [
Expand Down Expand Up @@ -189,6 +198,15 @@ mcxw71_k32w1_executable("lock_app") {
deps += [ "${chip_root}/src/platform/nxp:nxp_ota" ]
}

if (nxp_multiple_ble_connections) {
sources +=
[ "${example_platform_dir}/app_ble/source/BLEApplicationManager.cpp" ]
} else {
sources += [
"${common_example_dir}/app_ble/source/BLEApplicationManagerEmpty.cpp",
]
}

if (chip_with_diag_logs_demo) {
sources += [
"${common_example_dir}/diagnostic_logs/source/DiagnosticLogsDemo.cpp",
Expand Down
13 changes: 13 additions & 0 deletions examples/lock-app/nxp/k32w1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For generic information related to door lock application, please see the
- [Flashing the host image](#flashing-the-host-image)
- [Debugging](#debugging)
- [OTA](#ota)
- [Multiple BLE connections](#multiple-ble-connections)

## Introduction

Expand Down Expand Up @@ -163,3 +164,15 @@ Run -> Debug Configurations... -> C/C++ Application

Please see
[k32w1 OTA guide](../../../../docs/guides/nxp/nxp_mcxw71_ota_guide.md).

## Multiple BLE connections

To compile with the Multiple BLE connections support demo example add the gn
argument `nxp_multiple_ble_connections=true`.

The application will accept multiple BLE connections after commissioning, by
pressing the BLE advertise button again. Once discovered by a BLE central, a
custom GATT service will be visible on the device.

The user can change the default behavior by implementing the class defined in
[BLEApplicationManager.h](../../../platform/nxp/common/app_ble/include/BLEApplicationManager.h)
18 changes: 18 additions & 0 deletions examples/lock-app/nxp/mcxw71/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ mcxw71_k32w1_sdk("sdk") {
"${example_platform_dir}/board/peripherals.h",
]
}

if (nxp_multiple_ble_connections) {
include_dirs += [ "${example_platform_dir}/app_ble/include" ]
defines += [
"EXTRA_GATT_DB_HEADER=\"extra_gatt_db.h\"",
"EXTRA_GATT_UUID_HEADER=\"extra_gatt_uuid128.h\"",
]
}
}

mcxw71_k32w1_executable("lock_app") {
Expand Down Expand Up @@ -140,6 +148,7 @@ mcxw71_k32w1_executable("lock_app") {
"${common_example_dir}/low_power/include",
"${common_example_dir}/operational_keystore/include",
"${common_example_dir}/ui_feedback/include",
"${common_example_dir}/app_ble/include",
]

sources += [
Expand Down Expand Up @@ -189,6 +198,15 @@ mcxw71_k32w1_executable("lock_app") {
deps += [ "${chip_root}/src/platform/nxp:nxp_ota" ]
}

if (nxp_multiple_ble_connections) {
sources +=
[ "${example_platform_dir}/app_ble/source/BLEApplicationManager.cpp" ]
} else {
sources += [
"${common_example_dir}/app_ble/source/BLEApplicationManagerEmpty.cpp",
]
}

if (chip_with_diag_logs_demo) {
sources += [
"${common_example_dir}/diagnostic_logs/source/DiagnosticLogsDemo.cpp",
Expand Down
13 changes: 13 additions & 0 deletions examples/lock-app/nxp/mcxw71/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For generic information related to door lock application, please see the
- [Flashing the host image](#flashing-the-host-image)
- [Debugging](#debugging)
- [OTA](#ota)
- [Multiple BLE connections](#multiple-ble-connections)

## Introduction

Expand Down Expand Up @@ -195,3 +196,15 @@ Run -> Debug Configurations... -> C/C++ Application

Please see
[mcxw71 OTA guide](../../../../docs/guides/nxp/nxp_mcxw71_ota_guide.md).

## Multiple BLE connections

To compile with the Multiple BLE connections support demo example add the gn
argument `nxp_multiple_ble_connections=true`.

The application will accept multiple BLE connections after commissioning, by
pressing the BLE advertise button again. Once discovered by a BLE central, a
custom GATT service will be visible on the device.

The user can change the default behavior by implementing the class defined in
[BLEApplicationManager.h](../../../platform/nxp/common/app_ble/include/BLEApplicationManager.h)
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* Copyright 2024 NXP
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <stdint.h>

namespace chip::NXP::App {

/**
* @brief This class describes a manager for extra application BLE-related
* functionality (e.g multiple BLE connections).
*
*/
class BLEApplicationManager
{
public:
void Init();
void EnableMultipleConnectionsHandler();

private:
static void EnableMultipleConnections(intptr_t arg);

friend BLEApplicationManager & BleAppMgr();
static BLEApplicationManager sInstance;
};

inline BLEApplicationManager & BleAppMgr()
{
return BLEApplicationManager::sInstance;
}

} // namespace chip::NXP::App
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* Copyright 2024 NXP
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "BLEApplicationManager.h"

using namespace ::chip::NXP::App;

BLEApplicationManager BLEApplicationManager::sInstance;

void BLEApplicationManager::Init(void)
{
/*Empty implementation. Intentionally left blank */
}

void BLEApplicationManager::EnableMultipleConnectionsHandler(void)
{
/*Empty implementation. Intentionally left blank */
}

void BLEApplicationManager::EnableMultipleConnections(intptr_t arg)
{
/*Empty implementation. Intentionally left blank */
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PRIMARY_SERVICE_UUID128(service_wireless_uart, uuid_service_wireless_uart)
CHARACTERISTIC_UUID128(char_uart_stream, uuid_uart_stream, (gGattCharPropWriteWithoutRsp_c))
VALUE_UUID128_VARLEN(value_uart_stream, uuid_uart_stream, (gPermissionFlagWritable_c), gAttMaxWriteDataSize_d(gAttMaxMtu_c), 1,
0x00)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Declare all custom 128-bit UUIDs here using the format:
*
* UUID128(name, bytes)
*
* where:
* -name : an unique tag for the newly defined UUID;
will be used to reference this UUID when defining
services and characteristics in <<gattDb.h>>
* -bytes: 16 bytes representing the 128-bit value
*
* One definition per line. No semicolon required after each definition.
*
* example:
* UUID128(uuid_service_robot_characteristics, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB,
0xCD, 0xEF)
* UUID128(uuid_char_robot_direction, 0x12, 0x34, 0x50, 0x00, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD,
0xEF)
*/
/* Services */

UUID128(uuid_service_wireless_uart, 0xE0, 0x1C, 0x4B, 0x5E, 0x1E, 0xEB, 0xA1, 0x5C, 0xEE, 0xF4, 0x5E, 0xBA, 0x00, 0x01, 0xFF, 0x01)
UUID128(uuid_uart_stream, 0xE0, 0x1C, 0x4B, 0x5E, 0x1E, 0xEB, 0xA1, 0x5C, 0xEE, 0xF4, 0x5E, 0xBA, 0x01, 0x01, 0xFF, 0x01)
Loading
Loading