diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap index 8497280b1a0949..5d4c6aea12ce51 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap @@ -1860,6 +1860,51 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "ActiveHardwareFaults", + "code": 5, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveRadioFaults", + "code": 6, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveNetworkFaults", + "code": 7, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "ClusterRevision", "code": 65533, diff --git a/examples/bridge-app/bridge-common/bridge-app.zap b/examples/bridge-app/bridge-common/bridge-app.zap index a0d18cf3fd4bc2..02124c3937d132 100644 --- a/examples/bridge-app/bridge-common/bridge-app.zap +++ b/examples/bridge-app/bridge-common/bridge-app.zap @@ -833,6 +833,51 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "ActiveHardwareFaults", + "code": 5, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveRadioFaults", + "code": 6, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveNetworkFaults", + "code": 7, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "ClusterRevision", "code": 65533, diff --git a/examples/lighting-app/lighting-common/lighting-app.zap b/examples/lighting-app/lighting-common/lighting-app.zap index 831f814711e313..cdc04a0e8af3ee 100644 --- a/examples/lighting-app/lighting-common/lighting-app.zap +++ b/examples/lighting-app/lighting-common/lighting-app.zap @@ -1719,6 +1719,51 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "ActiveHardwareFaults", + "code": 5, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveRadioFaults", + "code": 6, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveNetworkFaults", + "code": 7, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "ClusterRevision", "code": 65533, diff --git a/examples/lock-app/lock-common/lock-app.zap b/examples/lock-app/lock-common/lock-app.zap index 4bd1df6a269f25..019dd840fcbcae 100644 --- a/examples/lock-app/lock-common/lock-app.zap +++ b/examples/lock-app/lock-common/lock-app.zap @@ -1627,6 +1627,51 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "ActiveHardwareFaults", + "code": 5, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveRadioFaults", + "code": 6, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveNetworkFaults", + "code": 7, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "ClusterRevision", "code": 65533, diff --git a/examples/pump-app/pump-common/pump-app.zap b/examples/pump-app/pump-common/pump-app.zap index 5fe88120cc1de8..e85c3834e2018d 100644 --- a/examples/pump-app/pump-common/pump-app.zap +++ b/examples/pump-app/pump-common/pump-app.zap @@ -1541,6 +1541,51 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "ActiveHardwareFaults", + "code": 5, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveRadioFaults", + "code": 6, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveNetworkFaults", + "code": 7, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "ClusterRevision", "code": 65533, diff --git a/examples/pump-controller-app/pump-controller-common/pump-controller-app.zap b/examples/pump-controller-app/pump-controller-common/pump-controller-app.zap index fd2a6b65695624..bba6766a4a560d 100644 --- a/examples/pump-controller-app/pump-controller-common/pump-controller-app.zap +++ b/examples/pump-controller-app/pump-controller-common/pump-controller-app.zap @@ -1541,6 +1541,51 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "ActiveHardwareFaults", + "code": 5, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveRadioFaults", + "code": 6, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveNetworkFaults", + "code": 7, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "ClusterRevision", "code": 65533, diff --git a/examples/temperature-measurement-app/esp32/main/temperature-measurement.zap b/examples/temperature-measurement-app/esp32/main/temperature-measurement.zap index bdcaf6e9776f58..49e8e47faf2976 100644 --- a/examples/temperature-measurement-app/esp32/main/temperature-measurement.zap +++ b/examples/temperature-measurement-app/esp32/main/temperature-measurement.zap @@ -1203,6 +1203,51 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "ActiveHardwareFaults", + "code": 5, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveRadioFaults", + "code": 6, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveNetworkFaults", + "code": 7, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "ClusterRevision", "code": 65533, diff --git a/examples/thermostat/thermostat-common/thermostat.zap b/examples/thermostat/thermostat-common/thermostat.zap index 3de66b54fa60bf..32352b3ae1c6dd 100644 --- a/examples/thermostat/thermostat-common/thermostat.zap +++ b/examples/thermostat/thermostat-common/thermostat.zap @@ -1740,6 +1740,51 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "ActiveHardwareFaults", + "code": 5, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveRadioFaults", + "code": 6, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveNetworkFaults", + "code": 7, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "ClusterRevision", "code": 65533, diff --git a/examples/tv-app/tv-common/tv-app.zap b/examples/tv-app/tv-common/tv-app.zap index e92f1d46b36622..83f18932a7513a 100644 --- a/examples/tv-app/tv-common/tv-app.zap +++ b/examples/tv-app/tv-common/tv-app.zap @@ -1725,6 +1725,51 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "ActiveHardwareFaults", + "code": 5, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveRadioFaults", + "code": 6, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveNetworkFaults", + "code": 7, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "ClusterRevision", "code": 65533, diff --git a/examples/tv-casting-app/tv-casting-common/tv-casting-app.zap b/examples/tv-casting-app/tv-casting-common/tv-casting-app.zap index c7d64bf4a06e7e..bef667b934959d 100644 --- a/examples/tv-casting-app/tv-casting-common/tv-casting-app.zap +++ b/examples/tv-casting-app/tv-casting-common/tv-casting-app.zap @@ -1740,6 +1740,51 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "ActiveHardwareFaults", + "code": 5, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveRadioFaults", + "code": 6, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveNetworkFaults", + "code": 7, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "ClusterRevision", "code": 65533, diff --git a/examples/window-app/common/window-app.zap b/examples/window-app/common/window-app.zap index 725d3aa5bd01dc..32be5ce737aa7c 100644 --- a/examples/window-app/common/window-app.zap +++ b/examples/window-app/common/window-app.zap @@ -1289,6 +1289,51 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "ActiveHardwareFaults", + "code": 5, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveRadioFaults", + "code": 6, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveNetworkFaults", + "code": 7, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "ClusterRevision", "code": 65533, diff --git a/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp b/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp index 538fcff5252262..22ac84b2c16ca8 100644 --- a/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp +++ b/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp @@ -29,6 +29,7 @@ using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::GeneralDiagnostics::Attributes; +using namespace chip::DeviceLayer; using chip::DeviceLayer::ConnectivityMgr; using chip::DeviceLayer::PlatformManager; using chip::DeviceLayer::PlatformMgr; @@ -46,6 +47,10 @@ class GeneralDiagosticsAttrAccess : public AttributeAccessInterface private: template CHIP_ERROR ReadIfSupported(CHIP_ERROR (PlatformManager::*getter)(T &), AttributeValueEncoder & aEncoder); + + template + CHIP_ERROR ReadListIfSupported(CHIP_ERROR (PlatformManager::*getter)(T &), AttributeValueEncoder & aEncoder); + CHIP_ERROR ReadNetworkInterfaces(AttributeValueEncoder & aEncoder); }; @@ -67,6 +72,32 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (PlatformMana return aEncoder.Encode(data); } +template +CHIP_ERROR GeneralDiagosticsAttrAccess::ReadListIfSupported(CHIP_ERROR (PlatformManager::*getter)(T &), + AttributeValueEncoder & aEncoder) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + T faultList; + + if ((PlatformMgr().*getter)(faultList) == CHIP_NO_ERROR) + { + err = aEncoder.EncodeList([&faultList](const TagBoundEncoder & encoder) -> CHIP_ERROR { + for (auto fault : faultList) + { + ReturnErrorOnFailure(encoder.Encode(fault)); + } + + return CHIP_NO_ERROR; + }); + } + else + { + err = aEncoder.Encode(DataModel::List()); + } + + return err; +} + CHIP_ERROR GeneralDiagosticsAttrAccess::ReadNetworkInterfaces(AttributeValueEncoder & aEncoder) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -108,6 +139,15 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::Read(const ConcreteAttributePath & aPath case NetworkInterfaces::Id: { return ReadNetworkInterfaces(aEncoder); } + case ActiveHardwareFaults::Id: { + return ReadListIfSupported(&PlatformManager::GetActiveHardwareFaults, aEncoder); + } + case ActiveRadioFaults::Id: { + return ReadListIfSupported(&PlatformManager::GetActiveRadioFaults, aEncoder); + } + case ActiveNetworkFaults::Id: { + return ReadListIfSupported(&PlatformManager::GetActiveNetworkFaults, aEncoder); + } case RebootCount::Id: { return ReadIfSupported(&PlatformManager::GetRebootCount, aEncoder); } diff --git a/src/controller/data_model/controller-clusters.zap b/src/controller/data_model/controller-clusters.zap index 34446e5418489b..2b18418ac1a675 100644 --- a/src/controller/data_model/controller-clusters.zap +++ b/src/controller/data_model/controller-clusters.zap @@ -3087,6 +3087,51 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "ActiveHardwareFaults", + "code": 5, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveRadioFaults", + "code": 6, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ActiveNetworkFaults", + "code": 7, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "ClusterRevision", "code": 65533, diff --git a/src/include/platform/GeneralFaults.h b/src/include/platform/GeneralFaults.h new file mode 100644 index 00000000000000..596702f7e6dabb --- /dev/null +++ b/src/include/platform/GeneralFaults.h @@ -0,0 +1,139 @@ +/* + * + * Copyright (c) 2021 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. + */ + +/** + * @file + * General faults could be detected by the Node. + */ + +#pragma once + +#include + +namespace chip { +namespace DeviceLayer { + +static constexpr size_t kMaxHardwareFaults = 11; +static constexpr size_t kMaxRadioFaults = 7; +static constexpr size_t kMaxNetworkFaults = 4; + +template +class GeneralFaults +{ +public: + /* The iterator */ + class Iterator + { + public: + Iterator(const GeneralFaults * GeneralFaults, int index); + uint8_t operator*() const; + Iterator & operator++(); + bool operator!=(const Iterator & other) const; + + private: + const GeneralFaults * mGeneralFaultsPtr; + int mIndex = -1; + }; + +public: + GeneralFaults() = default; + ~GeneralFaults() { mSize = 0; } + + CHIP_ERROR add(const uint8_t value); + + int size() const; + uint8_t operator[](int index) const; + + Iterator begin() const; + Iterator end() const; + +private: + uint8_t mData[N]; + int mSize = 0; +}; + +/* + * GeneralFaults methods + **/ +template +inline CHIP_ERROR GeneralFaults::add(const uint8_t value) +{ + if (mSize == N) + { + return CHIP_ERROR_NO_MEMORY; + } + + // add the new element + mData[mSize] = value; + ++mSize; + return CHIP_NO_ERROR; +} + +template +inline int GeneralFaults::size() const +{ + return mSize; +} + +template +inline uint8_t GeneralFaults::operator[](int index) const +{ + VerifyOrDie(index < mSize); + return mData[index]; +} + +template +inline typename GeneralFaults::Iterator GeneralFaults::begin() const +{ + return GeneralFaults::Iterator{ this, 0 }; +} + +template +inline typename GeneralFaults::Iterator GeneralFaults::end() const +{ + return GeneralFaults::Iterator{ this, mSize }; +} + +/* + * Iterator methods + **/ +template +inline GeneralFaults::Iterator::Iterator(const GeneralFaults * pGeneralFaults, int index) : + mGeneralFaultsPtr(pGeneralFaults), mIndex(index) +{} + +template +inline uint8_t GeneralFaults::Iterator::operator*() const +{ + return mGeneralFaultsPtr->operator[](mIndex); +} + +template +inline typename GeneralFaults::Iterator & GeneralFaults::Iterator::operator++() +{ + ++mIndex; + return *this; +} + +template +inline bool GeneralFaults::Iterator::operator!=(const GeneralFaults::Iterator & other) const +{ + return mIndex != other.mIndex; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/include/platform/PlatformManager.h b/src/include/platform/PlatformManager.h index d5947c8f4a7a35..7c340ea6f8aa10 100644 --- a/src/include/platform/PlatformManager.h +++ b/src/include/platform/PlatformManager.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -204,6 +205,10 @@ class PlatformManager CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours); CHIP_ERROR GetBootReasons(uint8_t & bootReasons); + CHIP_ERROR GetActiveHardwareFaults(GeneralFaults & hardwareFaults); + CHIP_ERROR GetActiveRadioFaults(GeneralFaults & radioFaults); + CHIP_ERROR GetActiveNetworkFaults(GeneralFaults & networkFaults); + #if CHIP_STACK_LOCK_TRACKING_ENABLED bool IsChipStackLockedByCurrentThread() const; #endif @@ -495,5 +500,20 @@ inline CHIP_ERROR PlatformManager::GetBootReasons(uint8_t & bootReasons) return static_cast(this)->_GetBootReasons(bootReasons); } +inline CHIP_ERROR PlatformManager::GetActiveHardwareFaults(GeneralFaults & hardwareFaults) +{ + return static_cast(this)->_GetActiveHardwareFaults(hardwareFaults); +} + +inline CHIP_ERROR PlatformManager::GetActiveRadioFaults(GeneralFaults & radioFaults) +{ + return static_cast(this)->_GetActiveRadioFaults(radioFaults); +} + +inline CHIP_ERROR PlatformManager::GetActiveNetworkFaults(GeneralFaults & networkFaults) +{ + return static_cast(this)->_GetActiveNetworkFaults(networkFaults); +} + } // namespace DeviceLayer } // namespace chip diff --git a/src/include/platform/internal/GenericPlatformManagerImpl.h b/src/include/platform/internal/GenericPlatformManagerImpl.h index cf1ebc31fff05a..8a72d67a04ea9f 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl.h +++ b/src/include/platform/internal/GenericPlatformManagerImpl.h @@ -69,6 +69,10 @@ class GenericPlatformManagerImpl CHIP_ERROR _GetTotalOperationalHours(uint32_t & totalOperationalHours); CHIP_ERROR _GetBootReasons(uint8_t & bootReasons); + CHIP_ERROR _GetActiveHardwareFaults(GeneralFaults & hardwareFaults); + CHIP_ERROR _GetActiveRadioFaults(GeneralFaults & radioFaults); + CHIP_ERROR _GetActiveNetworkFaults(GeneralFaults & networkFaults); + // ===== Support methods that can be overridden by the implementation subclass. void DispatchEventToDeviceLayer(const ChipDeviceEvent * event); @@ -136,6 +140,25 @@ inline CHIP_ERROR GenericPlatformManagerImpl::_GetBootReasons(uint8_t return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } +template +inline CHIP_ERROR +GenericPlatformManagerImpl::_GetActiveHardwareFaults(GeneralFaults & hardwareFaults) +{ + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +} + +template +inline CHIP_ERROR GenericPlatformManagerImpl::_GetActiveRadioFaults(GeneralFaults & radioFaults) +{ + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +} + +template +inline CHIP_ERROR GenericPlatformManagerImpl::_GetActiveNetworkFaults(GeneralFaults & networkFaults) +{ + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +} + } // namespace Internal } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/Linux/PlatformManagerImpl.cpp b/src/platform/Linux/PlatformManagerImpl.cpp index badd1322cff65e..894d77c712ad69 100644 --- a/src/platform/Linux/PlatformManagerImpl.cpp +++ b/src/platform/Linux/PlatformManagerImpl.cpp @@ -402,6 +402,38 @@ CHIP_ERROR PlatformManagerImpl::_GetBootReasons(uint8_t & bootReasons) return err; } +CHIP_ERROR PlatformManagerImpl::_GetActiveHardwareFaults(GeneralFaults & hardwareFaults) +{ + // On Linux Simulation, set following hardware faults statically. + ReturnErrorOnFailure(hardwareFaults.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_RADIO)); + ReturnErrorOnFailure(hardwareFaults.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_SENSOR)); + ReturnErrorOnFailure(hardwareFaults.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_POWER_SOURCE)); + ReturnErrorOnFailure(hardwareFaults.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_USER_INTERFACE_FAULT)); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR PlatformManagerImpl::_GetActiveRadioFaults(GeneralFaults & radioFaults) +{ + // On Linux Simulation, set following radio faults statically. + ReturnErrorOnFailure(radioFaults.add(EMBER_ZCL_RADIO_FAULT_TYPE_WI_FI_FAULT)); + ReturnErrorOnFailure(radioFaults.add(EMBER_ZCL_RADIO_FAULT_TYPE_CELLULAR_FAULT)); + ReturnErrorOnFailure(radioFaults.add(EMBER_ZCL_RADIO_FAULT_TYPE_THREAD_FAULT)); + ReturnErrorOnFailure(radioFaults.add(EMBER_ZCL_RADIO_FAULT_TYPE_NFC_FAULT)); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR PlatformManagerImpl::_GetActiveNetworkFaults(GeneralFaults & networkFaults) +{ + // On Linux Simulation, set following radio faults statically. + ReturnErrorOnFailure(networkFaults.add(EMBER_ZCL_NETWORK_FAULT_TYPE_HARDWARE_FAILURE)); + ReturnErrorOnFailure(networkFaults.add(EMBER_ZCL_NETWORK_FAULT_TYPE_NETWORK_JAMMED)); + ReturnErrorOnFailure(networkFaults.add(EMBER_ZCL_NETWORK_FAULT_TYPE_CONNECTION_FAILED)); + + return CHIP_NO_ERROR; +} + void PlatformManagerImpl::HandleDeviceRebooted(intptr_t arg) { PlatformManagerDelegate * delegate = PlatformMgr().GetDelegate(); diff --git a/src/platform/Linux/PlatformManagerImpl.h b/src/platform/Linux/PlatformManagerImpl.h index 15d4666d558761..a1a865e531d7aa 100644 --- a/src/platform/Linux/PlatformManagerImpl.h +++ b/src/platform/Linux/PlatformManagerImpl.h @@ -72,6 +72,10 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener CHIP_ERROR _GetTotalOperationalHours(uint32_t & totalOperationalHours); CHIP_ERROR _GetBootReasons(uint8_t & bootReasons); + CHIP_ERROR _GetActiveHardwareFaults(GeneralFaults & hardwareFaults); + CHIP_ERROR _GetActiveRadioFaults(GeneralFaults & radioFaults); + CHIP_ERROR _GetActiveNetworkFaults(GeneralFaults & networkFaults); + // ===== Members for internal use by the following friends. friend PlatformManager & PlatformMgr(); diff --git a/src/platform/fake/PlatformManagerImpl.h b/src/platform/fake/PlatformManagerImpl.h index 84b0a1588d9e29..fa69fb892052cc 100644 --- a/src/platform/fake/PlatformManagerImpl.h +++ b/src/platform/fake/PlatformManagerImpl.h @@ -113,6 +113,10 @@ class PlatformManagerImpl final : public PlatformManager CHIP_ERROR _GetTotalOperationalHours(uint32_t & totalOperationalHours); CHIP_ERROR _GetBootReasons(uint8_t & bootReasons); + CHIP_ERROR _GetActiveHardwareFaults(GeneralFaults & hardwareFaults); + CHIP_ERROR _GetActiveRadioFaults(GeneralFaults & radioFaults); + CHIP_ERROR _GetActiveNetworkFaults(GeneralFaults & networkFaults); + // ===== Members for internal use by the following friends. friend PlatformManager & PlatformMgr();