Skip to content

Commit

Permalink
[Telink] Add resource monitoring app (#29157)
Browse files Browse the repository at this point in the history
* [Telink] add draft resource-monitoring app

* [Telink] add Telink-resource-monitoring example to github CI

* add compatibility with tlsr9528a_board

* [Telink] Minor chnages

* Restyled by whitespace

* Restyled by clang-format

* [Telink] Spelling error remove

* [Telink] Fix typo

---------

Co-authored-by: UR6LAL <ur6lal@gmail.com>
Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
3 people authored and pull[bot] committed Dec 5, 2023
1 parent 6f7ac83 commit 1099360
Show file tree
Hide file tree
Showing 15 changed files with 618 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .github/workflows/examples-telink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ jobs:
- name: clean out build output
run: rm -rf ./out

- name: Build example Telink (B91) Resource Monitoring App
run: |
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py --target 'telink-tlsr9518adk80d-resource-monitoring' build"
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
telink tlsr9518adk80d resource-monitoring-app \
out/telink-tlsr9518adk80d-resource-monitoring/zephyr/zephyr.elf \
/tmp/bloat_reports/
- name: clean out build output
run: rm -rf ./out

- name: Build example Telink (B91) Shell App
run: |
./scripts/run_in_build_env.sh \
Expand Down
1 change: 1 addition & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@
"telink-tlsr9518adk80d-ota-requestor",
"telink-tlsr9518adk80d-pump-app",
"telink-tlsr9518adk80d-pump-controller-app",
"telink-tlsr9518adk80d-resource-monitoring-app",
"telink-tlsr9518adk80d-shell",
"telink-tlsr9518adk80d-smoke-co-alarm-app",
"telink-tlsr9518adk80d-temperature-measurement",
Expand Down
1 change: 1 addition & 0 deletions examples/resource-monitoring-app/telink/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build/
91 changes: 91 additions & 0 deletions examples/resource-monitoring-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#
# Copyright (c) 2023 Project CHIP Authors
#
# 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.
#
cmake_minimum_required(VERSION 3.13.1)

get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connectedhomeip REALPATH)
get_filename_component(TELINK_COMMON ${CHIP_ROOT}/examples/platform/telink REALPATH)
get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH)

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD}.overlay")
set(LOCAL_DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD}.overlay")
else()
unset(LOCAL_DTC_OVERLAY_FILE)
endif()

if(EXISTS "${CHIP_ROOT}/src/platform/telink/${BOARD}.overlay")
set(GLOBAL_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BOARD}.overlay")
else()
unset(GLOBAL_DTC_OVERLAY_FILE)
endif()

if(DTC_OVERLAY_FILE)
set(DTC_OVERLAY_FILE
"${DTC_OVERLAY_FILE} ${GLOBAL_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE}"
CACHE STRING "" FORCE
)
else()
set(DTC_OVERLAY_FILE ${GLOBAL_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE})
endif()

set(CONF_FILE ${CHIP_ROOT}/config/telink/app/zephyr.conf prj.conf)

# Load NCS/Zephyr build system
list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/telink/chip-module)
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})

project(chip-telink-resource-monitoring-example)

include(${CHIP_ROOT}/config/telink/app/enable-gnu-std.cmake)
include(${CHIP_ROOT}/src/app/chip_data_model.cmake)

target_compile_options(app PRIVATE -fpermissive)

target_include_directories(app PRIVATE
include
${GEN_DIR}/app-common
${GEN_DIR}/resource-monitoring-app
${TELINK_COMMON}/common/include
${TELINK_COMMON}/util/include
${CMAKE_CURRENT_SOURCE_DIR}/../resource-monitoring-common/include
${CMAKE_CURRENT_SOURCE_DIR}/../resource-monitoring-common/include/delegates
)

add_definitions(
"-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib/address_resolve/AddressResolve_DefaultImpl.h>"
)

target_sources(app PRIVATE
src/AppTask.cpp
src/ZclCallbacks.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../resource-monitoring-common/src/ReplacementProductListManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../resource-monitoring-common/src/delegates/ActivatedCarbonFilterMonitoring.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../resource-monitoring-common/src/delegates/HepaFilterMonitoring.cpp
${TELINK_COMMON}/common/src/mainCommon.cpp
${TELINK_COMMON}/common/src/AppTaskCommon.cpp
${TELINK_COMMON}/util/src/LEDWidget.cpp
${TELINK_COMMON}/util/src/ButtonManager.cpp
${TELINK_COMMON}/util/src/ThreadUtil.cpp
${TELINK_COMMON}/util/src/PWMDevice.cpp
)

chip_configure_data_model(app
INCLUDE_SERVER
ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../resource-monitoring-common/resource-monitoring-app.zap
)

if(CONFIG_CHIP_OTA_REQUESTOR)
target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp)
endif()
175 changes: 175 additions & 0 deletions examples/resource-monitoring-app/telink/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Matter Telink Resource Monitoring Example Application

You can use this example as a reference for creating your own application.

![Telink B91 EVK](http://wiki.telink-semi.cn/wiki/assets/Hardware/B91_Generic_Starter_Kit_Hardware_Guide/connection_chart.png)

## Build and flash

1. Pull docker image from repository:

```bash
$ docker pull ghcr.io/project-chip/chip-build-telink:10
```

2. Run docker container:

```bash
$ docker run -it --rm -v ${CHIP_BASE}:/root/chip -v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule "c 189:* rmw" ghcr.io/project-chip/chip-build-telink:10
```

here `${CHIP_BASE}` is directory which contains CHIP repo files **!!!Pay
attention that OUTPUT_DIR should contains ABSOLUTE path to output dir**

3. Activate the build environment:

```bash
$ source ./scripts/activate.sh
```

4. In the example dir run (replace _<build_target>_ with your board name, for
example, `tlsr9518adk80d` or `tlsr9528a`):

```bash
$ west build -b <build_target>
```

5. Flash binary:

```
$ west flash --erase
```

## Usage

### UART

To get output from device, connect UART to following pins:

| Name | Pin |
| :--: | :---------------------------- |
| RX | PB3 (pin 17 of J34 connector) |
| TX | PB2 (pin 16 of J34 connector) |
| GND | GND |

### Buttons

The following buttons are available on **tlsr9518adk80d** board:

| Name | Function | Description |
| :------- | :--------------------- | :----------------------------------------------------------------------------------------------------- |
| Button 1 | Factory reset | Perform factory reset to forget currently commissioned Thread network and back to uncommissioned state |
| Button 2 | NA | NA |
| Button 3 | Thread start | Commission thread with static credentials and enables the Thread on device |
| Button 4 | Open commission window | The button is opening commissioning window to perform commissioning over BLE |

### LEDs

#### Indicate current state of Thread network

**Red** LED indicates current state of Thread network. It is able to be in
following states:

| State | Description |
| :-------------------------- | :--------------------------------------------------------------------------- |
| Blinks with short pulses | Device is not commissioned to Thread, Thread is disabled |
| Blinks with frequent pulses | Device is commissioned, Thread enabled. Device trying to JOIN thread network |
| Blinks with wide pulses | Device commissioned and joined to thread network as CHILD |

#### Indicate identify of device

**Green** LED used to identify the device. The LED starts blinking when the
Identify command of the Identify cluster is received. The command's argument can
be used to specify the the effect. It is able to be in following effects:
| Effect | Description |
| :------------------------------ | :--------------------------------------------------------------------------- |
| Blinks (200 ms on/200 ms off) | Blink (`Clusters::Identify::EffectIdentifierEnum::kBlink`) |
| Breathe (during 1000 ms) | Breathe (`Clusters::Identify::EffectIdentifierEnum::kBreathe`) |
| Blinks (50 ms on/950 ms off) | Okay (`Clusters::Identify::EffectIdentifierEnum::kOkay`) |
| Blinks (1000 ms on/1000 ms off) | Channel Change ( `Clusters::Identify::EffectIdentifierEnum::kChannelChange`) |
| Blinks (950 ms on/50 ms off) | Finish ( `Clusters::Identify::EffectIdentifierEnum::kFinishEffect`) |
| LED off | Stop (`Clusters::Identify::EffectIdentifierEnum::kStopEffect`) |
### CHIP tool commands
1. Build
[chip-tool cli](https://github.com/project-chip/connectedhomeip/blob/master/examples/chip-tool/README.md)
2. Pair with device
```
${CHIP_TOOL_DIR}/chip-tool pairing ble-thread ${NODE_ID} hex:${DATASET} ${PIN_CODE} ${DISCRIMINATOR}
```
Example:
```
./chip-tool pairing ble-thread 1234 hex:0e080000000000010000000300000f35060004001fffe0020811111111222222220708fd61f77bd3df233e051000112233445566778899aabbccddeeff030e4f70656e54687265616444656d6f010212340410445f2b5ca6f2a93a55ce570a70efeecb0c0402a0fff8 20202021 3840
```
### OTA with Linux OTA Provider
OTA feature enabled by default only for ota-requestor-app example. To enable OTA
feature for another Telink example:
- set CONFIG_CHIP_OTA_REQUESTOR=y in corresponding "prj.conf" configuration
file.
After build application with enabled OTA feature, use next binary files:
- zephyr.bin - main binary to flash PCB (Use 2MB PCB).
- zephyr-ota.bin - binary for OTA Provider
All binaries has the same SW version. To test OTA “zephyr-ota.bin” should have
higher SW version than base SW. Set CONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 in
corresponding “prj.conf” configuration file.
Usage of OTA:
- Build the [Linux OTA Provider](../../ota-provider-app/linux)
```
./scripts/examples/gn_build_example.sh examples/ota-provider-app/linux out/ota-provider-app chip_config_network_layer_ble=false
```
- Run the Linux OTA Provider with OTA image.
```
./chip-ota-provider-app -f zephyr-ota.bin
```
- Provision the Linux OTA Provider using chip-tool
```
./chip-tool pairing onnetwork ${OTA_PROVIDER_NODE_ID} 20202021
```
here:
- \${OTA_PROVIDER_NODE_ID} is the node id of Linux OTA Provider
- Configure the ACL of the ota-provider-app to allow access
```
./chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null}, {"fabricIndex": 1, "privilege": 3, "authMode": 2, "subjects": null, "targets": null}]' ${OTA_PROVIDER_NODE_ID} 0
```
here:
- \${OTA_PROVIDER_NODE_ID} is the node id of Linux OTA Provider
- Use the chip-tool to announce the ota-provider-app to start the OTA process
```
./chip-tool otasoftwareupdaterequestor announce-otaprovider ${OTA_PROVIDER_NODE_ID} 0 0 0 ${DEVICE_NODE_ID} 0
```
here:
- \${OTA_PROVIDER_NODE_ID} is the node id of Linux OTA Provider
- \${DEVICE_NODE_ID} is the node id of paired device
Once the transfer is complete, OTA requestor sends ApplyUpdateRequest command to
OTA provider for applying the image. Device will restart on successful
application of OTA image.
27 changes: 27 additions & 0 deletions examples/resource-monitoring-app/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* 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

// ---- Air Quality Example App Config ----

#define APP_USE_EXAMPLE_START_BUTTON 0
#define APP_USE_THREAD_START_BUTTON 0
#define APP_SET_DEVICE_INFO_PROVIDER 1
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0
#define APP_USE_IDENTIFY_PWM 1
37 changes: 37 additions & 0 deletions examples/resource-monitoring-app/telink/include/AppTask.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* 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 "AppTaskCommon.h"

class AppTask : public AppTaskCommon
{
private:
friend AppTask & GetAppTask(void);
friend class AppTaskCommon;

CHIP_ERROR Init(void);

static AppTask sAppTask;
};

inline AppTask & GetAppTask(void)
{
return AppTask::sAppTask;
}
Loading

0 comments on commit 1099360

Please sign in to comment.