Skip to content

Commit 2b0679a

Browse files
authored
dynamic tv apps (project-chip#12125)
* draft - dynamic apps * sync to TOT * centralize commissioning logic in AppMain, add all clusters to the content apps * temp fix for integration tests * cleanup and prepare for moving app platform to common code * move ContentApp and ContentAppPlatform to common code * build fix * build fix * build fix * move DYNAMIC_ENDPOINT_COUNT to device config * fix CI test cases which assume dynamic endpoints * fix CI test cases * fix CI compiles * fix infineon compile * fix infineon compile * fix restyle
1 parent 1ad526b commit 2b0679a

29 files changed

+1476
-150
lines changed

config/standalone/CHIPProjectConfig.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969

7070
#define CHIP_CONFIG_DATA_MANAGEMENT_CLIENT_EXPERIMENTAL 1
7171

72-
#ifndef DYNAMIC_ENDPOINT_COUNT
73-
#define DYNAMIC_ENDPOINT_COUNT 4
72+
#ifndef CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT
73+
#define CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT 4
7474
#endif
7575

7676
#define CONFIG_IM_BUILD_FOR_UNIT_TEST 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
/**
20+
* @file
21+
* Example project configuration file for CHIP.
22+
*
23+
* This is a place to put application or project-specific overrides
24+
* to the default configuration values for general CHIP features.
25+
*
26+
*/
27+
28+
#pragma once
29+
30+
// overrides CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT in CHIPProjectConfig
31+
#define CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT 16
32+
33+
// include the CHIPProjectConfig from config/standalone
34+
#include <CHIPProjectConfig.h>

examples/bridge-app/esp32/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ set(EXTRA_COMPONENT_DIRS
2323
"${CMAKE_CURRENT_LIST_DIR}/../../common/QRCode"
2424
)
2525

26+
# TODO: add CHIPProjectAppConfig.h to esp32
2627
project(chip-bridge-app)
27-
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H;-DDYNAMIC_ENDPOINT_COUNT=16" APPEND)
28+
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H;-DCHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT=16" APPEND)
2829
idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND)
2930

3031
flashing_script()
31-

examples/bridge-app/esp32/main/main.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static const int kFixedLabelAttributeArraySize = 254;
5050

5151
static EndpointId gCurrentEndpointId;
5252
static EndpointId gFirstDynamicEndpointId;
53-
static Device * gDevices[DYNAMIC_ENDPOINT_COUNT]; // number of dynamic endpoints count
53+
static Device * gDevices[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; // number of dynamic endpoints count
5454

5555
// 4 Bridged devices
5656
static Device gLight1("Light 1", "Office");
@@ -116,7 +116,7 @@ DECLARE_DYNAMIC_ENDPOINT(bridgedLightEndpoint, bridgedLightClusters);
116116
CHIP_ERROR AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, uint16_t deviceType)
117117
{
118118
uint8_t index = 0;
119-
while (index < DYNAMIC_ENDPOINT_COUNT)
119+
while (index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
120120
{
121121
if (NULL == gDevices[index])
122122
{
@@ -144,7 +144,7 @@ CHIP_ERROR AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, uint16_t de
144144

145145
CHIP_ERROR RemoveDeviceEndpoint(Device * dev)
146146
{
147-
for (uint8_t index = 0; index < DYNAMIC_ENDPOINT_COUNT; index++)
147+
for (uint8_t index = 0; index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; index++)
148148
{
149149
if (gDevices[index] == dev)
150150
{
@@ -264,7 +264,7 @@ EmberAfStatus emberAfExternalAttributeReadCallback(EndpointId endpoint, ClusterI
264264
{
265265
uint16_t endpointIndex = emberAfGetDynamicIndexFromEndpoint(endpoint);
266266

267-
if ((endpointIndex < DYNAMIC_ENDPOINT_COUNT) && (gDevices[endpointIndex] != NULL))
267+
if ((endpointIndex < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT) && (gDevices[endpointIndex] != NULL))
268268
{
269269
Device * dev = gDevices[endpointIndex];
270270

@@ -291,7 +291,7 @@ EmberAfStatus emberAfExternalAttributeWriteCallback(EndpointId endpoint, Cluster
291291
{
292292
uint16_t endpointIndex = emberAfGetDynamicIndexFromEndpoint(endpoint);
293293

294-
if (endpointIndex < DYNAMIC_ENDPOINT_COUNT)
294+
if (endpointIndex < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
295295
{
296296
Device * dev = gDevices[endpointIndex];
297297

examples/bridge-app/linux/BUILD.gn

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ assert(chip_build_tools)
2020

2121
executable("chip-bridge-app") {
2222
sources = [
23+
"${chip_root}/examples/tv-app/tv-common/include/CHIPProjectAppConfig.h",
2324
"Device.cpp",
2425
"Options.cpp",
2526
"include/Device.h",
@@ -33,9 +34,6 @@ executable("chip-bridge-app") {
3334

3435
cflags = [ "-Wconversion" ]
3536

36-
# TODO: the definition of DYNAMIC_ENDPOINT_COUNT needs find a common home!
37-
cflags += [ "-DDYNAMIC_ENDPOINT_COUNT=16" ]
38-
3937
include_dirs = [ "include" ]
4038

4139
output_dir = root_out_dir

examples/bridge-app/linux/args.gni

+8
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@
1515
import("//build_overrides/chip.gni")
1616

1717
import("${chip_root}/config/standalone/args.gni")
18+
19+
chip_device_project_config_include = "<CHIPProjectAppConfig.h>"
20+
chip_project_config_include = "<CHIPProjectAppConfig.h>"
21+
chip_system_project_config_include = "<SystemProjectConfig.h>"
22+
23+
chip_project_config_include_dirs =
24+
[ "${chip_root}/examples/bridge-app/bridge-common/include" ]
25+
chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ]

examples/bridge-app/linux/main.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static const int kFixedLabelElementsOctetStringSize = 16;
5959

6060
static EndpointId gCurrentEndpointId;
6161
static EndpointId gFirstDynamicEndpointId;
62-
static Device * gDevices[DYNAMIC_ENDPOINT_COUNT];
62+
static Device * gDevices[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT];
6363

6464
// ENDPOINT DEFINITIONS:
6565
// =================================================================================
@@ -184,7 +184,7 @@ DECLARE_DYNAMIC_ENDPOINT(bridgedSwitchEndpoint, bridgedSwitchClusters);
184184
int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, uint16_t deviceType)
185185
{
186186
uint8_t index = 0;
187-
while (index < DYNAMIC_ENDPOINT_COUNT)
187+
while (index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
188188
{
189189
if (NULL == gDevices[index])
190190
{
@@ -219,7 +219,7 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, uint16_t deviceTyp
219219
int RemoveDeviceEndpoint(Device * dev)
220220
{
221221
uint8_t index = 0;
222-
while (index < DYNAMIC_ENDPOINT_COUNT)
222+
while (index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
223223
{
224224
if (gDevices[index] == dev)
225225
{
@@ -460,7 +460,7 @@ EmberAfStatus emberAfExternalAttributeReadCallback(EndpointId endpoint, ClusterI
460460

461461
EmberAfStatus ret = EMBER_ZCL_STATUS_FAILURE;
462462

463-
if ((endpointIndex < DYNAMIC_ENDPOINT_COUNT) && (gDevices[endpointIndex] != NULL))
463+
if ((endpointIndex < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT) && (gDevices[endpointIndex] != NULL))
464464
{
465465
Device * dev = gDevices[endpointIndex];
466466

@@ -496,7 +496,7 @@ EmberAfStatus emberAfExternalAttributeWriteCallback(EndpointId endpoint, Cluster
496496

497497
// ChipLogProgress(DeviceLayer, "emberAfExternalAttributeWriteCallback: ep=%d", endpoint);
498498

499-
if (endpointIndex < DYNAMIC_ENDPOINT_COUNT)
499+
if (endpointIndex < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
500500
{
501501
Device * dev = gDevices[endpointIndex];
502502

examples/platform/linux/AppMain.cpp

+117-1
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,122 @@ CHIP_ERROR ShutdownCommissioner()
274274
return CHIP_NO_ERROR;
275275
}
276276

277+
class PairingCommand : public chip::Controller::DevicePairingDelegate, public chip::Controller::DeviceAddressUpdateDelegate
278+
{
279+
/////////// DevicePairingDelegate Interface /////////
280+
void OnStatusUpdate(chip::Controller::DevicePairingDelegate::Status status) override;
281+
void OnPairingComplete(CHIP_ERROR error) override;
282+
void OnPairingDeleted(CHIP_ERROR error) override;
283+
void OnCommissioningComplete(NodeId deviceId, CHIP_ERROR error) override;
284+
285+
/////////// DeviceAddressUpdateDelegate Interface /////////
286+
void OnAddressUpdateComplete(NodeId nodeId, CHIP_ERROR error) override;
287+
288+
CHIP_ERROR UpdateNetworkAddress();
289+
};
290+
291+
PairingCommand gPairingCommand;
292+
NodeId gRemoteId = kTestDeviceNodeId;
293+
294+
CHIP_ERROR PairingCommand::UpdateNetworkAddress()
295+
{
296+
ChipLogProgress(AppServer, "Mdns: Updating NodeId: %" PRIx64 " ...", gRemoteId);
297+
return gCommissioner.UpdateDevice(gRemoteId);
298+
}
299+
300+
void PairingCommand::OnAddressUpdateComplete(NodeId nodeId, CHIP_ERROR err)
301+
{
302+
ChipLogProgress(AppServer, "OnAddressUpdateComplete: %s", ErrorStr(err));
303+
}
304+
305+
void PairingCommand::OnStatusUpdate(DevicePairingDelegate::Status status)
306+
{
307+
switch (status)
308+
{
309+
case DevicePairingDelegate::Status::SecurePairingSuccess:
310+
ChipLogProgress(AppServer, "Secure Pairing Success");
311+
break;
312+
case DevicePairingDelegate::Status::SecurePairingFailed:
313+
ChipLogError(AppServer, "Secure Pairing Failed");
314+
break;
315+
}
316+
}
317+
318+
void PairingCommand::OnPairingComplete(CHIP_ERROR err)
319+
{
320+
if (err == CHIP_NO_ERROR)
321+
{
322+
ChipLogProgress(AppServer, "Pairing Success");
323+
}
324+
else
325+
{
326+
ChipLogProgress(AppServer, "Pairing Failure: %s", ErrorStr(err));
327+
// For some devices, it may take more time to appear on the network and become discoverable
328+
// over DNS-SD, so don't give up on failure and restart the address update. Note that this
329+
// will not be repeated endlessly as each chip-tool command has a timeout (in the case of
330+
// the `pairing` command it equals 120s).
331+
// UpdateNetworkAddress();
332+
}
333+
}
334+
335+
void PairingCommand::OnPairingDeleted(CHIP_ERROR err)
336+
{
337+
if (err == CHIP_NO_ERROR)
338+
{
339+
ChipLogProgress(AppServer, "Pairing Deleted Success");
340+
}
341+
else
342+
{
343+
ChipLogProgress(AppServer, "Pairing Deleted Failure: %s", ErrorStr(err));
344+
}
345+
}
346+
347+
void PairingCommand::OnCommissioningComplete(NodeId nodeId, CHIP_ERROR err)
348+
{
349+
if (err == CHIP_NO_ERROR)
350+
{
351+
ChipLogProgress(AppServer, "Device commissioning completed with success");
352+
}
353+
else
354+
{
355+
ChipLogProgress(AppServer, "Device commissioning Failure: %s", ErrorStr(err));
356+
}
357+
}
358+
359+
CHIP_ERROR CommissionerPairOnNetwork(uint32_t pincode, uint16_t disc, chip::Transport::PeerAddress address)
360+
{
361+
RendezvousParameters params = RendezvousParameters().SetSetupPINCode(pincode).SetDiscriminator(disc).SetPeerAddress(address);
362+
363+
gCommissioner.RegisterDeviceAddressUpdateDelegate(&gPairingCommand);
364+
gCommissioner.RegisterPairingDelegate(&gPairingCommand);
365+
gCommissioner.PairDevice(gRemoteId, params);
366+
367+
return CHIP_NO_ERROR;
368+
}
369+
370+
CHIP_ERROR CommissionerPairUDC(uint32_t pincode, size_t index)
371+
{
372+
UDCClientState * state = gCommissioner.GetUserDirectedCommissioningServer()->GetUDCClients().GetUDCClientState(index);
373+
if (state == nullptr)
374+
{
375+
ChipLogProgress(AppServer, "udc client[%ld] null \r\n", index);
376+
return CHIP_ERROR_KEY_NOT_FOUND;
377+
}
378+
else
379+
{
380+
Transport::PeerAddress peerAddress = state->GetPeerAddress();
381+
382+
state->SetUDCClientProcessingState(UDCClientProcessingState::kCommissioningNode);
383+
384+
return CommissionerPairOnNetwork(pincode, state->GetLongDiscriminator(), peerAddress);
385+
}
386+
}
387+
388+
DeviceCommissioner * GetDeviceCommissioner()
389+
{
390+
return &gCommissioner;
391+
}
392+
277393
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
278394

279395
void ChipLinuxAppMainLoop()
@@ -307,7 +423,7 @@ void ChipLinuxAppMainLoop()
307423
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
308424
InitCommissioner();
309425
#if defined(ENABLE_CHIP_SHELL)
310-
chip::Shell::RegisterControllerCommands(&gCommissioner);
426+
chip::Shell::RegisterControllerCommands();
311427
#endif // defined(ENABLE_CHIP_SHELL)
312428
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
313429

examples/platform/linux/AppMain.h

+21
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,26 @@
1818

1919
#pragma once
2020

21+
#include <iostream>
22+
#include <thread>
23+
24+
#include <controller/CHIPDeviceController.h>
25+
#include <lib/core/CHIPError.h>
26+
#include <platform/CHIPDeviceLayer.h>
27+
#include <platform/PlatformManager.h>
28+
#include <transport/TransportMgr.h>
29+
2130
int ChipLinuxAppInit(int argc, char ** argv);
2231
void ChipLinuxAppMainLoop();
32+
33+
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
34+
35+
using namespace chip::Transport;
36+
using namespace ::chip::Controller;
37+
38+
CHIP_ERROR CommissionerPairOnNetwork(uint32_t pincode, uint16_t disc, chip::Transport::PeerAddress address);
39+
CHIP_ERROR CommissionerPairUDC(uint32_t pincode, size_t index);
40+
41+
DeviceCommissioner * GetDeviceCommissioner();
42+
43+
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE

0 commit comments

Comments
 (0)