Skip to content

Commit

Permalink
[Telink] Implement OnSubscriptionRequested callback for SED examples (#…
Browse files Browse the repository at this point in the history
…26650)

* [Telink] Add OnSubscriptionRequested callback

* [Telink] Enable CHIP_ICD_SUBSCRIPTION_HANDLING for all SED devices

* [Telink] Move build ICDUtil into libCHIP & CHIP_ICD_SUBSCRIPTION_HANDLING default if PM

* Restyled by gn

* [Telink] Move ICDUtil.h include into cpp file

* Restyled by clang-format

* [Telink] Move ICDUtil.* to src/platform/telink

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Sep 5, 2023
1 parent 64c1029 commit 1101892
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
20 changes: 20 additions & 0 deletions config/telink/chip-module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,23 @@ config CHIP_OPENTHREAD_TX_POWER
config SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE
int
default 255 if SHELL_BACKEND_SERIAL

config CHIP_ICD_SUBSCRIPTION_HANDLING
bool "Enables platform specific handling of ICD subscriptions"
default PM
help
Enables platform specific implementation that handles ICD subscription requests
and selects subscription report interval value considering maximum interval preferred
by the publisher.

config CHIP_MAX_PREFERRED_SUBSCRIPTION_REPORT_INTERVAL
int "Maximum preferred interval of sending subscription reports (s)"
default 60
help
Provides maximum preferred interval to be used by a publisher for negotiation
of the final maximum subscription report interval, after receiving a subscription
request from the initiator. This value should be selected as a compromise between
keeping the power consumption low due to not sending reports too often, and allowing
the initiator device to detect the publisher absence reasonably fast due to not sending
the reports too rarely. The current algorithm is to select bigger value from the one
requested by the initiator and the one preferred by the publisher.
9 changes: 9 additions & 0 deletions examples/platform/telink/common/src/AppTaskCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
#include "OTAUtil.h"
#endif

#ifdef CONFIG_CHIP_ICD_SUBSCRIPTION_HANDLING
#include "ICDUtil.h"
#include <app/InteractionModelEngine.h>
#endif

LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL);

namespace {
Expand Down Expand Up @@ -229,6 +234,10 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void)
emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false);
#endif

#ifdef CONFIG_CHIP_ICD_SUBSCRIPTION_HANDLING
chip::app::InteractionModelEngine::GetInstance()->RegisterReadHandlerAppCallback(&GetICDUtil());
#endif

// Add CHIP event handler and start CHIP thread.
// Note that all the initialization code should happen prior to this point to avoid data races
// between the main and the CHIP threads.
Expand Down
3 changes: 3 additions & 0 deletions src/platform/telink/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static_library("telink") {
"ConfigurationManagerImpl.h",
"ConnectivityManagerImpl.cpp",
"ConnectivityManagerImpl.h",
"ICDUtil.cpp",
"InetPlatformConfig.h",
"KeyValueStoreManagerImpl.h",
"PlatformManagerImpl.h",
Expand All @@ -57,6 +58,8 @@ static_library("telink") {

public_deps = [ "${chip_root}/src/platform:platform_base" ]

defines = [ "CHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib/address_resolve/AddressResolve_DefaultImpl.h>" ]

if (chip_enable_factory_data) {
sources += [
"FactoryDataParser.c",
Expand Down
40 changes: 40 additions & 0 deletions src/platform/telink/ICDUtil.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
*
* 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.
*/

#include "ICDUtil.h"

ICDUtil ICDUtil::sICDUtil;

CHIP_ERROR ICDUtil::OnSubscriptionRequested(chip::app::ReadHandler & aReadHandler, chip::Transport::SecureSession & aSecureSession)
{
uint16_t agreedMaxInterval = CONFIG_CHIP_MAX_PREFERRED_SUBSCRIPTION_REPORT_INTERVAL;
uint16_t requestedMinInterval = 0;
uint16_t requestedMaxInterval = 0;
aReadHandler.GetReportingIntervals(requestedMinInterval, requestedMaxInterval);

if (requestedMaxInterval > agreedMaxInterval)
{
agreedMaxInterval = requestedMaxInterval;
}
else if (agreedMaxInterval > kSubscriptionMaxIntervalPublisherLimit)
{
agreedMaxInterval = kSubscriptionMaxIntervalPublisherLimit;
}

return aReadHandler.SetReportingIntervals(agreedMaxInterval);
}
33 changes: 33 additions & 0 deletions src/platform/telink/ICDUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
*
* 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.
*/

#pragma once

#include <app/ReadHandler.h>

class ICDUtil : public chip::app::ReadHandler::ApplicationCallback
{
CHIP_ERROR OnSubscriptionRequested(chip::app::ReadHandler & aReadHandler,
chip::Transport::SecureSession & aSecureSession) override;
friend ICDUtil & GetICDUtil();
static ICDUtil sICDUtil;
};

inline ICDUtil & GetICDUtil()
{
return ICDUtil::sICDUtil;
}

0 comments on commit 1101892

Please sign in to comment.