Skip to content

Commit bab75e6

Browse files
authored
[Ameba] Support BLE & IP commissioning functions (project-chip#10841)
* Support commissioning over BLE * Revise files * Update files to match B1021 * Fix restyled errors * Remove outdated comments * Update README.md and wordlist * Rename mDNS abstract layer to DNS-SD for Ameba * Minor fixes on the typos * Update for the review questions
1 parent 55f3ee3 commit bab75e6

38 files changed

+3340
-138
lines changed

.github/.wordlist.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ attrMask
5858
attSizeBytes
5959
attType
6060
ATW
61+
ATWC
6162
AudioOutput
6263
auth
6364
autoconnect
@@ -138,13 +139,15 @@ CHIPCryptoPALHsm
138139
CHIPDeviceController
139140
ChipDeviceCtrl
140141
CHIPDeviceEvent
142+
CHIPDevicePlatformConfig
141143
CHIPDevicePlatformEvent
142144
ChipEchoRequester
143145
ChipEchoResponder
144146
ChipImInitiator
145147
ChipImResponder
146148
ChipLight
147149
ChipMessageLayer
150+
CHIPOBLE
148151
CHIPTest
149152
CHIPTool
150153
chmod
@@ -797,9 +800,9 @@ ScriptBinding
797800
SDC
798801
SDHC
799802
SDK
800-
SDK's
801803
sdkconfig
802804
SDKs
805+
SDK's
803806
SDKTARGETSYSROOT
804807
sdl
805808
segger

config/ameba/args.gni

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ chip_ble_project_config_include = ""
2424
mbedtls_target = "//mbedtls:mbedtls"
2525
lwip_platform = "external"
2626

27-
chip_build_tests = true
27+
chip_build_tests = false
2828

2929
chip_inet_config_enable_tcp_endpoint = true
3030
chip_inet_config_enable_udp_endpoint = true
3131

32-
chip_bypass_rendezvous = true
33-
chip_config_network_layer_ble = false
32+
chip_bypass_rendezvous = false
33+
chip_config_network_layer_ble = true
34+
chip_ip_commissioning = true
35+
chip_use_clusters_for_ip_commissioning = true
3436

3537
custom_toolchain = "//third_party/connectedhomeip/config/ameba/toolchain:ameba"

config/ameba/chip.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ list(
2626
-DCONFIG_FUNCION_O0_OPTIMIZE
2727
-DDM_ODM_SUPPORT_TYPE=32
2828
-DCHIP_DEVICE_LAYER_TARGET=Ameba
29-
-DMBEDTLS_CONFIG_FILE=\\\"mbedtls_config.h\\\"
29+
-DMBEDTLS_CONFIG_FILE=<mbedtls_config.h>
30+
-D_POSIX_REALTIME_SIGNALS
3031
)
3132

3233
list(
@@ -96,7 +97,6 @@ string(APPEND CHIP_GN_ARGS "ameba_ar = \"arm-none-eabi-ar\"\n")
9697
string(APPEND CHIP_GN_ARGS "ameba_cc = \"arm-none-eabi-gcc\"\n")
9798
string(APPEND CHIP_GN_ARGS "ameba_cxx = \"arm-none-eabi-c++\"\n")
9899
string(APPEND CHIP_GN_ARGS "ameba_cpu = \"ameba\"\n")
99-
string(APPEND CHIP_GN_ARGS "chip_build_tests = false\n")
100100

101101
file(GENERATE OUTPUT ${CHIP_OUTPUT}/args.gn CONTENT ${CHIP_GN_ARGS})
102102

examples/all-clusters-app/ameba/.gitignore

100644100755
File mode changed.

examples/all-clusters-app/ameba/README.md

+85-19
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ control.
1010
- [Building the Example Application](#building-the-example-application)
1111
- [Commissioning and cluster control](#commissioning-and-cluster-control)
1212
- [Commissioning](#commissioning)
13+
- [Bypass mode](#bypass-mode)
14+
- [BLE mode](#ble-mode)
15+
- [IP mode](#ip-mode)
1316
- [Cluster control](#cluster-control)
1417

1518
---
@@ -40,36 +43,99 @@ The CHIP demo application is supported on
4043
The output image files are stored in
4144
`out/ameba-amebad-all-clusters/asdk/image` folder.
4245

46+
The bootloader image files are stored in
47+
`out/ameba-amebad-all-clusters/asdk/bootloader` folder.
48+
4349
- After building the application, **Ameba Image Tool** is used to flash it to
4450
Ameba board.
4551

46-
1. Connect your device via USB and open Ameba Image Tool.
47-
2. Select correct serial port and set baudrate as **115200**.
48-
3. Browse and add the corresponding image files in the Flash Download list to
49-
the correct locations
50-
4. Click **Download** button.
52+
1. Connect your device via USB and open Ameba Image Tool.
53+
2. Select correct serial port and set baudrate as **115200**.
54+
3. Browse and add the corresponding image files in the Flash Download list to
55+
the correct locations
56+
4. Click **Download** button.
5157

5258
## Commissioning and Cluster Control
5359

54-
### Commissioning
60+
## Commissioning
61+
62+
There are three commissioning modes supported by Ameba platform:
63+
64+
### Bypass mode
65+
66+
1. In "connectedhomeip/config/ameba/args.gni"
67+
68+
- set `chip_bypass_rendezvous = true`
69+
- Set `chip_ip_commissioning = false`
70+
- Set `chip_use_clusters_for_ip_commissioning = false`
71+
- Set `chip_config_network_layer_ble = false`
72+
73+
2. In "connectedhomeip/src/platform/Ameba/CHIPDevicePlatformConfig.h"
74+
75+
- Set `#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0`
76+
77+
3. Build and Flash
78+
4. Use ATS\$ command to run all-cluster example.
79+
5. Connect to AP using `ATW0, ATW1, ATWC` commands
80+
6. Test with
81+
[Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool)
82+
or
83+
[Python Controller](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/python_chip_controller_building.md).
84+
85+
### BLE mode
86+
87+
1. In "connectedhomeip/config/ameba/args.gni"
5588

56-
The commissioning is carried out via WiFi.
89+
- set `chip_bypass_rendezvous = false`
90+
- Set `chip_ip_commissioning = false`
91+
- Set `chip_use_clusters_for_ip_commissioning = false`
92+
- Set `chip_config_network_layer_ble = true`
5793

58-
1. After download all-cluster example to Ameba board, boot up the board by
59-
pressing the reset button.
60-
2. Use ATW commands to setup network.
61-
3. Use ATS\$ command to run all-cluster example.
62-
4. Use
63-
[standalone chip-tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool)
64-
to communicate with the device.
94+
2. In "connectedhomeip/src/platform/Ameba/CHIPDevicePlatformConfig.h"
6595

66-
$ ./chip-tool pairing bypass ${NODE_ID_TO_ASSIGN} 192.168.xx.xxx 5540
96+
- Set `#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1`
6797

68-
### Cluster Control
98+
3. Build and Flash
99+
4. Use ATS\$ command to run all-cluster example.
100+
5. Test with
101+
[Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool)
102+
or
103+
[Python Controller](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/python_chip_controller_building.md).
69104

70-
- After successful commissioning, use the OnOff cluster command to control the
71-
OnOff attribute. This allows you to toggle a parameter implemented by the
72-
device to be On or Off.
105+
### IP mode
106+
107+
1. In "connectedhomeip/config/ameba/args.gni"
108+
109+
- set `chip_bypass_rendezvous = false`
110+
- Set `chip_ip_commissioning = true`
111+
- Set `chip_use_clusters_for_ip_commissioning = true`
112+
- Set `chip_config_network_layer_ble = false`
113+
114+
2. In "connectedhomeip/src/platform/Ameba/CHIPDevicePlatformConfig.h"
115+
116+
- Set `#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0`
117+
118+
3. Build and Flash
119+
4. Use ATS\$ command to run all-cluster example.
120+
5. Connect to AP using `ATW0, ATW1, ATWC` commands
121+
6. Test with
122+
[Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool)
123+
or
124+
[Python Controller](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/python_chip_controller_building.md).
125+
126+
## Cluster Control
127+
128+
After successful commissioning, use the OnOff cluster command to control the
129+
OnOff attribute. This allows you to toggle a parameter implemented by the device
130+
to be On or Off.
131+
132+
- Via
133+
[Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool#using-the-client-to-send-matter-commands)
73134

74135
$ ./chip-tool onoff on 1
75136
$ ./chip-tool onoff off 1
137+
138+
- Via
139+
[Python Controller](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/python_chip_controller_building.md#step-8-control-application-zcl-clusters)
140+
141+
$ chip-device-ctrl > zcl OnOff Toggle 1234 1 0

examples/all-clusters-app/ameba/chip_main.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ list(
3838
${chip_dir}/examples/all-clusters-app/ameba/main/chipinterface.cpp
3939
${chip_dir}/examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp
4040
${chip_dir}/examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp
41+
${chip_dir}/examples/all-clusters-app/ameba/main/Globals.cpp
42+
${chip_dir}/examples/all-clusters-app/ameba/main/LEDWidget.cpp
4143
)
4244

4345
add_library(
@@ -81,6 +83,7 @@ list(
8183
-DCHIP_DEVICE_LAYER_TARGET=Ameba
8284
-DUSE_ZAP_CONFIG
8385
-DCHIP_HAVE_CONFIG_H
86+
-DMBEDTLS_CONFIG_FILE=<mbedtls_config.h>
8487
)
8588

8689
list(

examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb)
5858
err = PlatformMgr().InitChipStack();
5959
SuccessOrExit(err);
6060

61+
if (CONFIG_NETWORK_LAYER_BLE)
62+
{
63+
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
64+
}
65+
6166
err = Platform::MemoryInit();
6267
SuccessOrExit(err);
6368

examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp

+72-7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
#include <support/logging/CHIPLogging.h>
3838
#include <support/logging/Constants.h>
3939

40+
#include "Globals.h"
41+
#include "LEDWidget.h"
42+
4043
static const char * TAG = "app-devicecallbacks";
4144

4245
using namespace ::chip;
@@ -51,29 +54,91 @@ constexpr uint32_t kIdentifyTimerDelayMS = 250;
5154

5255
void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg)
5356
{
54-
// TODO
55-
// Add callback functions for different ChipDeviceEvent Types
57+
switch (event->Type)
58+
{
59+
case DeviceEventType::kInternetConnectivityChange:
60+
OnInternetConnectivityChange(event);
61+
break;
62+
63+
case DeviceEventType::kSessionEstablished:
64+
OnSessionEstablished(event);
65+
break;
66+
case DeviceEventType::kInterfaceIpAddressChanged:
67+
if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) ||
68+
(event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned))
69+
{
70+
// MDNS server restart on any ip assignment: if link local ipv6 is configured, that
71+
// will not trigger a 'internet connectivity change' as there is no internet
72+
// connectivity. MDNS still wants to refresh its listening interfaces to include the
73+
// newly selected address.
74+
chip::app::DnssdServer::Instance().StartServer();
75+
}
76+
break;
77+
}
5678
}
5779

5880
void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, ClusterId clusterId, AttributeId attributeId, uint8_t mask,
5981
uint8_t type, uint16_t size, uint8_t * value)
6082
{
61-
ChipLogProgress(DeviceLayer,
62-
"[%s] PostAttributeChangeCallback - Cluster ID: 0x%04x, EndPoint ID: 0x%02x, Attribute ID: 0x%04x\r\n", TAG,
63-
clusterId, endpointId, attributeId);
64-
6583
switch (clusterId)
6684
{
85+
case ZCL_ON_OFF_CLUSTER_ID:
86+
OnOnOffPostAttributeChangeCallback(endpointId, attributeId, value);
87+
break;
88+
6789
case ZCL_IDENTIFY_CLUSTER_ID:
6890
OnIdentifyPostAttributeChangeCallback(endpointId, attributeId, value);
6991
break;
7092

7193
default:
72-
ChipLogProgress(DeviceLayer, "[%s] Unhandled cluster ID: 0x%04x\r\n", TAG, clusterId);
7394
break;
7495
}
7596
}
7697

98+
void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event)
99+
{
100+
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
101+
{
102+
ChipLogProgress(DeviceLayer, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT);
103+
chip::app::DnssdServer::Instance().StartServer();
104+
}
105+
else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost)
106+
{
107+
ChipLogProgress(DeviceLayer, "Lost IPv4 connectivity...");
108+
}
109+
if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established)
110+
{
111+
ChipLogProgress(DeviceLayer, "IPv6 Server ready...");
112+
chip::app::DnssdServer::Instance().StartServer();
113+
}
114+
else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost)
115+
{
116+
ChipLogProgress(DeviceLayer, "Lost IPv6 connectivity...");
117+
}
118+
}
119+
120+
void DeviceCallbacks::OnSessionEstablished(const ChipDeviceEvent * event)
121+
{
122+
if (event->SessionEstablished.IsCommissioner)
123+
{
124+
ChipLogProgress(DeviceLayer, "Commissioner detected!");
125+
}
126+
}
127+
128+
void DeviceCallbacks::OnOnOffPostAttributeChangeCallback(EndpointId endpointId, AttributeId attributeId, uint8_t * value)
129+
{
130+
VerifyOrExit(attributeId == ZCL_ON_OFF_ATTRIBUTE_ID,
131+
ChipLogError(DeviceLayer, TAG, "Unhandled Attribute ID: '0x%04x", attributeId));
132+
VerifyOrExit(endpointId == 1 || endpointId == 2,
133+
ChipLogError(DeviceLayer, TAG, "Unexpected EndPoint ID: `0x%02x'", endpointId));
134+
135+
// At this point we can assume that value points to a bool value.
136+
statusLED1.Set(*value);
137+
138+
exit:
139+
return;
140+
}
141+
77142
void IdentifyTimerHandler(Layer * systemLayer, void * appState, CHIP_ERROR error)
78143
{
79144
if (identifyTimerCount)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
*
3+
* Copyright (c) 2020 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "Globals.h"
20+
21+
LEDWidget statusLED1;

0 commit comments

Comments
 (0)