diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index 4a92fcfac91f9c..a7348127cbf692 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -38,6 +39,20 @@ namespace chip { namespace app { using Status = Protocols::InteractionModel::Status; +CHIP_ERROR ReadHandler::GetPublisherSelectedIntervalLimit(uint16_t & limit_s) +{ +#if CHIP_DEVICE_CONFIG_ENABLE_SED + uint32_t idle_interval_ms = 0; + EmberAfStatus status = + chip::app::Clusters::IcdManagement::Attributes::IdleModeInterval::Get(kRootEndpointId, &idle_interval_ms); + VerifyOrReturnError(EMBER_ZCL_STATUS_SUCCESS == status, CHIP_ERROR_INTERNAL); + limit_s = static_cast(idle_interval_ms / 1000); +#else + limit_s = kSubscriptionMaxIntervalPublisherLimit; +#endif + return CHIP_NO_ERROR; +} + ReadHandler::ReadHandler(ManagementCallback & apCallback, Messaging::ExchangeContext * apExchangeContext, InteractionType aInteractionType) : mExchangeCtx(*this), diff --git a/src/app/ReadHandler.h b/src/app/ReadHandler.h index f460188935223e..66a8eb1076e973 100644 --- a/src/app/ReadHandler.h +++ b/src/app/ReadHandler.h @@ -52,7 +52,7 @@ #include // https://github.com/CHIP-Specifications/connectedhomeip-spec/blob/61a9d19e6af12fdfb0872bcff26d19de6c680a1a/src/Ch02_Architecture.adoc#1122-subscribe-interaction-limits -constexpr uint16_t kSubscriptionMaxIntervalPublisherLimit = 3600; // 3600 seconds +constexpr uint16_t kSubscriptionMaxIntervalPublisherLimit = 3600; // seconds (60 minutes) namespace chip { namespace app { @@ -198,10 +198,11 @@ class ReadHandler : public Messaging::ExchangeDelegate */ CHIP_ERROR SetReportingIntervals(uint16_t aMaxInterval) { + uint16_t selected_interval_limit = 0; VerifyOrReturnError(IsIdle(), CHIP_ERROR_INCORRECT_STATE); + ReturnErrorOnFailure(GetPublisherSelectedIntervalLimit(selected_interval_limit)); VerifyOrReturnError(mMinIntervalFloorSeconds <= aMaxInterval, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(aMaxInterval <= std::max(kSubscriptionMaxIntervalPublisherLimit, mMaxInterval), - CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(aMaxInterval <= std::max(selected_interval_limit, mMaxInterval), CHIP_ERROR_INVALID_ARGUMENT); mMaxInterval = aMaxInterval; return CHIP_NO_ERROR; } @@ -209,6 +210,7 @@ class ReadHandler : public Messaging::ExchangeDelegate private: PriorityLevel GetCurrentPriority() const { return mCurrentPriority; } EventNumber & GetEventMin() { return mEventMin; } + CHIP_ERROR GetPublisherSelectedIntervalLimit(uint16_t & limit_s); enum class ReadHandlerFlags : uint8_t {