Skip to content

Commit

Permalink
dynamic tv apps (#12125)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
chrisdecenzo authored and pull[bot] committed Jan 11, 2022
1 parent 11958f3 commit 4382625
Show file tree
Hide file tree
Showing 29 changed files with 1,476 additions and 150 deletions.
4 changes: 2 additions & 2 deletions config/standalone/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@

#define CHIP_CONFIG_DATA_MANAGEMENT_CLIENT_EXPERIMENTAL 1

#ifndef DYNAMIC_ENDPOINT_COUNT
#define DYNAMIC_ENDPOINT_COUNT 4
#ifndef CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT
#define CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT 4
#endif

#define CONFIG_IM_BUILD_FOR_UNIT_TEST 1
Expand Down
34 changes: 34 additions & 0 deletions examples/bridge-app/bridge-common/include/CHIPProjectAppConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
*
* Copyright (c) 2020 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.
*/

/**
* @file
* Example project configuration file for CHIP.
*
* This is a place to put application or project-specific overrides
* to the default configuration values for general CHIP features.
*
*/

#pragma once

// overrides CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT in CHIPProjectConfig
#define CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT 16

// include the CHIPProjectConfig from config/standalone
#include <CHIPProjectConfig.h>
4 changes: 2 additions & 2 deletions examples/bridge-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ set(EXTRA_COMPONENT_DIRS
"${CMAKE_CURRENT_LIST_DIR}/../../common/QRCode"
)

# TODO: add CHIPProjectAppConfig.h to esp32
project(chip-bridge-app)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H;-DDYNAMIC_ENDPOINT_COUNT=16" APPEND)
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)
idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND)

flashing_script()

10 changes: 5 additions & 5 deletions examples/bridge-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static const int kFixedLabelAttributeArraySize = 254;

static EndpointId gCurrentEndpointId;
static EndpointId gFirstDynamicEndpointId;
static Device * gDevices[DYNAMIC_ENDPOINT_COUNT]; // number of dynamic endpoints count
static Device * gDevices[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; // number of dynamic endpoints count

// 4 Bridged devices
static Device gLight1("Light 1", "Office");
Expand Down Expand Up @@ -116,7 +116,7 @@ DECLARE_DYNAMIC_ENDPOINT(bridgedLightEndpoint, bridgedLightClusters);
CHIP_ERROR AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, uint16_t deviceType)
{
uint8_t index = 0;
while (index < DYNAMIC_ENDPOINT_COUNT)
while (index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
{
if (NULL == gDevices[index])
{
Expand Down Expand Up @@ -144,7 +144,7 @@ CHIP_ERROR AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, uint16_t de

CHIP_ERROR RemoveDeviceEndpoint(Device * dev)
{
for (uint8_t index = 0; index < DYNAMIC_ENDPOINT_COUNT; index++)
for (uint8_t index = 0; index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; index++)
{
if (gDevices[index] == dev)
{
Expand Down Expand Up @@ -264,7 +264,7 @@ EmberAfStatus emberAfExternalAttributeReadCallback(EndpointId endpoint, ClusterI
{
uint16_t endpointIndex = emberAfGetDynamicIndexFromEndpoint(endpoint);

if ((endpointIndex < DYNAMIC_ENDPOINT_COUNT) && (gDevices[endpointIndex] != NULL))
if ((endpointIndex < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT) && (gDevices[endpointIndex] != NULL))
{
Device * dev = gDevices[endpointIndex];

Expand All @@ -291,7 +291,7 @@ EmberAfStatus emberAfExternalAttributeWriteCallback(EndpointId endpoint, Cluster
{
uint16_t endpointIndex = emberAfGetDynamicIndexFromEndpoint(endpoint);

if (endpointIndex < DYNAMIC_ENDPOINT_COUNT)
if (endpointIndex < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
{
Device * dev = gDevices[endpointIndex];

Expand Down
4 changes: 1 addition & 3 deletions examples/bridge-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ assert(chip_build_tools)

executable("chip-bridge-app") {
sources = [
"${chip_root}/examples/tv-app/tv-common/include/CHIPProjectAppConfig.h",
"Device.cpp",
"Options.cpp",
"include/Device.h",
Expand All @@ -33,9 +34,6 @@ executable("chip-bridge-app") {

cflags = [ "-Wconversion" ]

# TODO: the definition of DYNAMIC_ENDPOINT_COUNT needs find a common home!
cflags += [ "-DDYNAMIC_ENDPOINT_COUNT=16" ]

include_dirs = [ "include" ]

output_dir = root_out_dir
Expand Down
8 changes: 8 additions & 0 deletions examples/bridge-app/linux/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@
import("//build_overrides/chip.gni")

import("${chip_root}/config/standalone/args.gni")

chip_device_project_config_include = "<CHIPProjectAppConfig.h>"
chip_project_config_include = "<CHIPProjectAppConfig.h>"
chip_system_project_config_include = "<SystemProjectConfig.h>"

chip_project_config_include_dirs =
[ "${chip_root}/examples/bridge-app/bridge-common/include" ]
chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ]
10 changes: 5 additions & 5 deletions examples/bridge-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static const int kFixedLabelElementsOctetStringSize = 16;

static EndpointId gCurrentEndpointId;
static EndpointId gFirstDynamicEndpointId;
static Device * gDevices[DYNAMIC_ENDPOINT_COUNT];
static Device * gDevices[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT];

// ENDPOINT DEFINITIONS:
// =================================================================================
Expand Down Expand Up @@ -184,7 +184,7 @@ DECLARE_DYNAMIC_ENDPOINT(bridgedSwitchEndpoint, bridgedSwitchClusters);
int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, uint16_t deviceType)
{
uint8_t index = 0;
while (index < DYNAMIC_ENDPOINT_COUNT)
while (index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
{
if (NULL == gDevices[index])
{
Expand Down Expand Up @@ -219,7 +219,7 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, uint16_t deviceTyp
int RemoveDeviceEndpoint(Device * dev)
{
uint8_t index = 0;
while (index < DYNAMIC_ENDPOINT_COUNT)
while (index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
{
if (gDevices[index] == dev)
{
Expand Down Expand Up @@ -460,7 +460,7 @@ EmberAfStatus emberAfExternalAttributeReadCallback(EndpointId endpoint, ClusterI

EmberAfStatus ret = EMBER_ZCL_STATUS_FAILURE;

if ((endpointIndex < DYNAMIC_ENDPOINT_COUNT) && (gDevices[endpointIndex] != NULL))
if ((endpointIndex < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT) && (gDevices[endpointIndex] != NULL))
{
Device * dev = gDevices[endpointIndex];

Expand Down Expand Up @@ -496,7 +496,7 @@ EmberAfStatus emberAfExternalAttributeWriteCallback(EndpointId endpoint, Cluster

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

if (endpointIndex < DYNAMIC_ENDPOINT_COUNT)
if (endpointIndex < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
{
Device * dev = gDevices[endpointIndex];

Expand Down
118 changes: 117 additions & 1 deletion examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,122 @@ CHIP_ERROR ShutdownCommissioner()
return CHIP_NO_ERROR;
}

class PairingCommand : public chip::Controller::DevicePairingDelegate, public chip::Controller::DeviceAddressUpdateDelegate
{
/////////// DevicePairingDelegate Interface /////////
void OnStatusUpdate(chip::Controller::DevicePairingDelegate::Status status) override;
void OnPairingComplete(CHIP_ERROR error) override;
void OnPairingDeleted(CHIP_ERROR error) override;
void OnCommissioningComplete(NodeId deviceId, CHIP_ERROR error) override;

/////////// DeviceAddressUpdateDelegate Interface /////////
void OnAddressUpdateComplete(NodeId nodeId, CHIP_ERROR error) override;

CHIP_ERROR UpdateNetworkAddress();
};

PairingCommand gPairingCommand;
NodeId gRemoteId = kTestDeviceNodeId;

CHIP_ERROR PairingCommand::UpdateNetworkAddress()
{
ChipLogProgress(AppServer, "Mdns: Updating NodeId: %" PRIx64 " ...", gRemoteId);
return gCommissioner.UpdateDevice(gRemoteId);
}

void PairingCommand::OnAddressUpdateComplete(NodeId nodeId, CHIP_ERROR err)
{
ChipLogProgress(AppServer, "OnAddressUpdateComplete: %s", ErrorStr(err));
}

void PairingCommand::OnStatusUpdate(DevicePairingDelegate::Status status)
{
switch (status)
{
case DevicePairingDelegate::Status::SecurePairingSuccess:
ChipLogProgress(AppServer, "Secure Pairing Success");
break;
case DevicePairingDelegate::Status::SecurePairingFailed:
ChipLogError(AppServer, "Secure Pairing Failed");
break;
}
}

void PairingCommand::OnPairingComplete(CHIP_ERROR err)
{
if (err == CHIP_NO_ERROR)
{
ChipLogProgress(AppServer, "Pairing Success");
}
else
{
ChipLogProgress(AppServer, "Pairing Failure: %s", ErrorStr(err));
// For some devices, it may take more time to appear on the network and become discoverable
// over DNS-SD, so don't give up on failure and restart the address update. Note that this
// will not be repeated endlessly as each chip-tool command has a timeout (in the case of
// the `pairing` command it equals 120s).
// UpdateNetworkAddress();
}
}

void PairingCommand::OnPairingDeleted(CHIP_ERROR err)
{
if (err == CHIP_NO_ERROR)
{
ChipLogProgress(AppServer, "Pairing Deleted Success");
}
else
{
ChipLogProgress(AppServer, "Pairing Deleted Failure: %s", ErrorStr(err));
}
}

void PairingCommand::OnCommissioningComplete(NodeId nodeId, CHIP_ERROR err)
{
if (err == CHIP_NO_ERROR)
{
ChipLogProgress(AppServer, "Device commissioning completed with success");
}
else
{
ChipLogProgress(AppServer, "Device commissioning Failure: %s", ErrorStr(err));
}
}

CHIP_ERROR CommissionerPairOnNetwork(uint32_t pincode, uint16_t disc, chip::Transport::PeerAddress address)
{
RendezvousParameters params = RendezvousParameters().SetSetupPINCode(pincode).SetDiscriminator(disc).SetPeerAddress(address);

gCommissioner.RegisterDeviceAddressUpdateDelegate(&gPairingCommand);
gCommissioner.RegisterPairingDelegate(&gPairingCommand);
gCommissioner.PairDevice(gRemoteId, params);

return CHIP_NO_ERROR;
}

CHIP_ERROR CommissionerPairUDC(uint32_t pincode, size_t index)
{
UDCClientState * state = gCommissioner.GetUserDirectedCommissioningServer()->GetUDCClients().GetUDCClientState(index);
if (state == nullptr)
{
ChipLogProgress(AppServer, "udc client[%ld] null \r\n", index);
return CHIP_ERROR_KEY_NOT_FOUND;
}
else
{
Transport::PeerAddress peerAddress = state->GetPeerAddress();

state->SetUDCClientProcessingState(UDCClientProcessingState::kCommissioningNode);

return CommissionerPairOnNetwork(pincode, state->GetLongDiscriminator(), peerAddress);
}
}

DeviceCommissioner * GetDeviceCommissioner()
{
return &gCommissioner;
}

#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE

void ChipLinuxAppMainLoop()
Expand Down Expand Up @@ -307,7 +423,7 @@ void ChipLinuxAppMainLoop()
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
InitCommissioner();
#if defined(ENABLE_CHIP_SHELL)
chip::Shell::RegisterControllerCommands(&gCommissioner);
chip::Shell::RegisterControllerCommands();
#endif // defined(ENABLE_CHIP_SHELL)
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE

Expand Down
21 changes: 21 additions & 0 deletions examples/platform/linux/AppMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,26 @@

#pragma once

#include <iostream>
#include <thread>

#include <controller/CHIPDeviceController.h>
#include <lib/core/CHIPError.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/PlatformManager.h>
#include <transport/TransportMgr.h>

int ChipLinuxAppInit(int argc, char ** argv);
void ChipLinuxAppMainLoop();

#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE

using namespace chip::Transport;
using namespace ::chip::Controller;

CHIP_ERROR CommissionerPairOnNetwork(uint32_t pincode, uint16_t disc, chip::Transport::PeerAddress address);
CHIP_ERROR CommissionerPairUDC(uint32_t pincode, size_t index);

DeviceCommissioner * GetDeviceCommissioner();

#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
Loading

0 comments on commit 4382625

Please sign in to comment.