Skip to content

Commit

Permalink
P6 lock app changes addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenCY committed Jul 10, 2021
1 parent ae3b5db commit b64dba1
Show file tree
Hide file tree
Showing 75 changed files with 1,240 additions and 1,457 deletions.
1 change: 0 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
# Build the p6 lock app example.
enable_p6_lock_app_build = enable_p6_builds


# Build the qpgxxxx lock app example.
enable_qpg_lock_app_build = enable_qpg_builds && !is_debug

Expand Down
1 change: 0 additions & 1 deletion config/p6/toolchain/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ arm_toolchain("p6_lock_app") {
treat_warnings_as_errors = false
}
}

13 changes: 4 additions & 9 deletions examples/lock-app/p6/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020 Project CHIP Authors
# Copyright (c) 2021 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.
Expand Down Expand Up @@ -44,13 +44,9 @@ p6_sdk_sources("lock_app_sdk_sources") {
"CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}",
]

sources = [
"${p6_project_dir}/include/CHIPProjectConfig.h",
#"${p6_project_dir}/include/FreeRTOSConfig.h",
]
sources = [ "${p6_project_dir}/include/CHIPProjectConfig.h" ]

public_configs = ["${chip_root}/third_party/p6:p6_sdk_config"]
#public_configs += ["${chip_root}/third_party/p6:project_configs"]
public_configs = [ "${chip_root}/third_party/p6:p6_sdk_config" ]
}

p6_executable("lock_app") {
Expand Down Expand Up @@ -80,14 +76,13 @@ p6_executable("lock_app") {

sources = [
"${examples_plat_dir}/LEDWidget.cpp",
"${examples_plat_dir}/Service.cpp",
"${examples_plat_dir}/init_p6Platform.cpp",
"${p6_project_dir}/include/CHIPProjectConfig.h",
"src/AppTask.cpp",
"src/BoltLockManager.cpp",
"src/ButtonHandler.cpp",
"src/ZclCallbacks.cpp",
"src/main.cpp",
"${p6_project_dir}/include/CHIPProjectConfig.h",
]

output_dir = root_out_dir
Expand Down
58 changes: 31 additions & 27 deletions examples/lock-app/p6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,24 @@ An example showing the use of Matter on the Infineon CY8CKIT-062S2-43012 board.
## Introduction

The P6 lock example provides a demonstration of a door lock control device,
built using Matter and the Infineon Modustoolbox SDK. It can be controlled by
a Matter controller over Wi-Fi network.
built using Matter and the Infineon Modustoolbox SDK. It can be controlled by a
Matter controller over Wi-Fi network.

The P6 device can be commissioned over Bluetooth Low Energy where the device
and the Matter controller will exchange security information with the Rendezvous
procedure. Wi-Fi Network credentials are then provided to the P6 device
which will then join the network.
The P6 device can be commissioned over Bluetooth Low Energy where the device and
the Matter controller will exchange security information with the Rendezvous
procedure. Wi-Fi Network credentials are then provided to the P6 device which
will then join the network.

<a name="building"></a>

## Building

- Download [Modustoolbox Software](https://www.cypress.com/products/modustoolbox)
- Install some additional tools (likely already present for Matter developers):
$ sudo apt install gcc g++ clang ninja-build python python3-venv libssl-dev libavahi-client-dev libglib2.0-dev git cmake python3-pip
- Download
[Modustoolbox Software](https://www.cypress.com/products/modustoolbox)
- Install some additional tools (likely already present for Matter
developers): \$ sudo apt install gcc g++ clang ninja-build python
python3-venv libssl-dev libavahi-client-dev libglib2.0-dev git cmake
python3-pip

- Supported hardware:
[CY8CKIT-062S2-43012](https://www.cypress.com/CY8CKIT-062S2-43012)
Expand All @@ -50,30 +53,31 @@ which will then join the network.
$ cd ~/connectedhomeip
$ rm -rf out/


<a name="flashing"></a>

## Flashing the Application

- Put CY8CKIT-062S2-43012 board on KitProg3 CMSIS-DAP Mode by pressing the `MODE SELECT`
button. `KITPROG3 STATUS` LED is ON confirms board is in proper mode.
- Put CY8CKIT-062S2-43012 board on KitProg3 CMSIS-DAP Mode by pressing the
`MODE SELECT` button. `KITPROG3 STATUS` LED is ON confirms board is in
proper mode.

- On the command line:

$ cd ~/connectedhomeip
$ python3 out/debug/p6_lock_app/chip-p6-lock-example.flash.py

<a name="Commissioning and cluster control"></a>

## Commissioning and cluster control

Commissioning can be carried out using BLE.

<a name="Setting up Python Controller"></a>

### Setting up Python Controller

Once P6 is up and running, we need to set up a device controller on Raspberry Pi 4 to perform
commissioning and cluster control.
Once P6 is up and running, we need to set up a device controller on Raspberry Pi
4 to perform commissioning and cluster control.

- Set up python controller.

Expand All @@ -84,7 +88,7 @@ commissioning and cluster control.

$ source ./out/python_env/bin/activate
$ chip-device-ctrl

<a name="Commissioning over BLE"></a>

### Commissioning over BLE
Expand All @@ -104,9 +108,9 @@ commissioning and cluster control.
We have chosen a random node ID which is 1234.

- Add credentials of the Wi-Fi network you want the P6 to connect to, using
the `AddWiFiNetwork` command and then enable the P6 to connect to it
using `EnableWiFiNetwork` command. In this example, we have used `WIFI_SSID`
and `WIFI_PASSWORD` as the SSID and passphrase respectively.
the `AddWiFiNetwork` command and then enable the P6 to connect to it using
`EnableWiFiNetwork` command. In this example, we have used `WIFI_SSID` and
`WIFI_PASSWORD` as the SSID and passphrase respectively.

- chip-device-ctrl > zcl NetworkCommissioning AddWiFiNetwork 1234 0 0 ssid=str:WIFI_SSID credentials=str:WIFI_PASSWORD breadcrumb=0 timeoutMs=1000

Expand All @@ -123,8 +127,9 @@ commissioning and cluster control.
<a name="Notes"></a>

#### Notes
Raspberry Pi 4 BLE connection issues can be avoided by running the following commands.
These power cycle the BlueTooth hardware and disable BR/EDR mode.

Raspberry Pi 4 BLE connection issues can be avoided by running the following
commands. These power cycle the BlueTooth hardware and disable BR/EDR mode.

$ sudo btmgmt -i hci0 power off
$ sudo btmgmt -i hci0 bredr off
Expand All @@ -141,9 +146,8 @@ These power cycle the BlueTooth hardware and disable BR/EDR mode.

`chip-device-ctrl > zcl OnOff On 1234 1 0`

- Cluster OnOff can also be done using the `USER_BTN1` button on the board. This
button is configured with `APP_LOCK_BUTTON` in `include/AppConfig.h`. Press
`USER_BTN1` on the board to toggle between lock and unlock states. The
Lock/Unlock status of door can be observed with 'LED9' on the board. This LED
is configured with `LOCK_STATE_LED` in `include/AppConfig.h`.

- Cluster OnOff can also be done using the `USER_BTN1` button on the board.
This button is configured with `APP_LOCK_BUTTON` in `include/AppConfig.h`.
Press `USER_BTN1` on the board to toggle between lock and unlock states. The
Lock/Unlock status of door can be observed with 'LED9' on the board. This
LED is configured with `LOCK_STATE_LED` in `include/AppConfig.h`.
4 changes: 2 additions & 2 deletions examples/lock-app/p6/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ import("//build_overrides/chip.gni")
import("//build_overrides/pigweed.gni")
import("${chip_root}/src/platform/P6/args.gni")

p6_target_project = get_label_info(":lock_app_sdk_sources", "label_no_toolchain")

p6_target_project =
get_label_info(":lock_app_sdk_sources", "label_no_toolchain")
4 changes: 2 additions & 2 deletions examples/lock-app/p6/include/AppConfig.h
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2021 Project CHIP Authors
* Copyright (c) 2019 Google LLC.
* All rights reserved.
*
Expand Down Expand Up @@ -58,7 +58,7 @@ extern "C" {

void appError(int err);
void P6Log(const char * aFormat, ...);
#define P6_LOG(...) P6Log(__VA_ARGS__)
#define P6_LOG(...) P6Log(__VA_ARGS__)

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/p6/include/AppEvent.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2021 Project CHIP Authors
* Copyright (c) 2018 Nest Labs, Inc.
* All rights reserved.
*
Expand Down
5 changes: 2 additions & 3 deletions examples/lock-app/p6/include/AppTask.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2021 Project CHIP Authors
* Copyright (c) 2019 Google LLC.
* All rights reserved.
*
Expand Down Expand Up @@ -41,6 +41,7 @@ class AppTask
void PostEvent(const AppEvent * event);

void ButtonEventHandler(uint8_t btnIdx, uint8_t btnAction);
void UpdateClusterState(void);

private:
friend AppTask & GetAppTask(void);
Expand All @@ -59,8 +60,6 @@ class AppTask
static void LockActionEventHandler(AppEvent * aEvent);
static void TimerEventHandler(TimerHandle_t xTimer);

static void UpdateClusterState(void);

void StartTimer(uint32_t aTimeoutMs);

enum Function_t
Expand Down
1 change: 1 addition & 0 deletions examples/lock-app/p6/include/BoltLockManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
* Copyright (c) 2019 Google LLC.
* All rights reserved.
*
Expand Down
7 changes: 4 additions & 3 deletions examples/lock-app/p6/include/ButtonHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
#include <stdint.h>

#include "FreeRTOS.h"
#include "cyhal.h"
#include "timers.h" // provides FreeRTOS timer support

#define GPIO_INTERRUPT_PRIORITY (5)
#define GPIO_INTERRUPT_PRIORITY (5)

class ButtonHandler
{
Expand All @@ -32,7 +33,7 @@ class ButtonHandler

private:
static void GpioInit(void);
static void lockbuttonIsr(void *handler_arg, cyhal_gpio_event_t event);
static void functionbuttonIsr(void *handler_arg, cyhal_gpio_event_t event);
static void lockbuttonIsr(void * handler_arg, cyhal_gpio_event_t event);
static void functionbuttonIsr(void * handler_arg, cyhal_gpio_event_t event);
static void TimerCallback(TimerHandle_t xTimer);
};
2 changes: 1 addition & 1 deletion examples/lock-app/p6/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2021 Project CHIP Authors
* Copyright (c) 2019 Google LLC.
* All rights reserved.
*
Expand Down
33 changes: 11 additions & 22 deletions examples/lock-app/p6/src/AppTask.cpp
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2019 Google LLC.
* Copyright (c) 2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -25,25 +24,19 @@
#include "LEDWidget.h"
#include "OnboardingCodesUtil.h"
#include "Server.h"
#include "Service.h"
#include "qrcodegen.h"
#include <app/common/gen/attribute-id.h>
#include <app/common/gen/attribute-type.h>
#include <app/common/gen/cluster-id.h>
#include <app/server/Mdns.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <app/util/attribute-storage.h>
#include <assert.h>
#include <cy_wcm.h>
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>
#include <platform/CHIPDeviceLayer.h>
#if CHIP_ENABLE_OPENTHREAD
#include <platform/P6/ThreadStackManagerImpl.h>
#include <platform/OpenThread/OpenThreadUtils.h>
#include <platform/ThreadStackManager.h>
#endif
#include <cy_wcm.h>
#include <app/server/Mdns.h>

#define FACTORY_RESET_TRIGGER_TIMEOUT 3000
#define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000
Expand All @@ -52,7 +45,7 @@
#define APP_EVENT_QUEUE_SIZE 10

namespace {

TimerHandle_t sFunctionTimer; // FreeRTOS app sw timer.

static TaskHandle_t sAppTaskHandle;
Expand All @@ -69,7 +62,7 @@ static bool sHaveServiceConnectivity = false;

StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)];
StaticTask_t appTaskStruct;
}
} // namespace
using namespace chip::TLV;
using namespace ::chip::DeviceLayer;

Expand All @@ -96,8 +89,6 @@ int AppTask::StartAppTask()
return err;
}



int AppTask::Init()
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down Expand Up @@ -172,7 +163,6 @@ void AppTask::AppTaskMain(void * pvParameter)
}

P6_LOG("App Task started");
SetDeviceName("P6LockDemo._chip._udp.local.");

while (true)
{
Expand Down Expand Up @@ -217,8 +207,7 @@ void AppTask::AppTaskMain(void * pvParameter)
{
sStatusLED.Set(true);
}
else if (sIsWiFiStationEnabled && sIsWiFiStationProvisioned &&
(!sIsWiFiStationConnected || !sHaveServiceConnectivity))
else if (sIsWiFiStationEnabled && sIsWiFiStationProvisioned && (!sIsWiFiStationConnected || !sHaveServiceConnectivity))
{
sStatusLED.Blink(950, 50);
}
Expand Down Expand Up @@ -461,7 +450,7 @@ void AppTask::ActionCompleted(BoltLockManager::Action_t aAction)

if (sAppTask.mSyncClusterToButtonAction)
{
UpdateClusterState();
sAppTask.UpdateClusterState();
sAppTask.mSyncClusterToButtonAction = false;
}
}
Expand Down Expand Up @@ -504,8 +493,8 @@ void AppTask::UpdateClusterState(void)
uint8_t newValue = !BoltLockMgr().IsUnlocked();

// write the new on/off value
EmberAfStatus status = emberAfWriteAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, CLUSTER_MASK_SERVER,
(uint8_t *) &newValue, ZCL_BOOLEAN_ATTRIBUTE_TYPE);
EmberAfStatus status = emberAfWriteAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, &newValue,
ZCL_BOOLEAN_ATTRIBUTE_TYPE);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
P6_LOG("ERR: updating on/off %x", status);
Expand All @@ -518,5 +507,5 @@ void vApplicationStackOverflowHook(TaskHandle_t pxTask, char * pcTaskName)
/* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
function is called if a stack overflow is detected. */
printf( "ERROR: stack overflow with task %s\r\n", pcTaskName );
printf("ERROR: stack overflow with task %s\r\n", pcTaskName);
}
5 changes: 2 additions & 3 deletions examples/lock-app/p6/src/BoltLockManager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2021 Project CHIP Authors
* Copyright (c) 2019 Google LLC.
* All rights reserved.
*
Expand Down Expand Up @@ -219,8 +219,7 @@ void BoltLockManager::ActuatorMovementTimerEventHandler(AppEvent * aEvent)

lock->mAutoLockTimerArmed = true;

P6_LOG("Auto Re-lock enabled. Will be triggered in %lu seconds",
lock->mAutoLockDuration);
P6_LOG("Auto Re-lock enabled. Will be triggered in %lu seconds", lock->mAutoLockDuration);
}
}
}
Loading

0 comments on commit b64dba1

Please sign in to comment.