Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6664d55

Browse files
committedJan 29, 2025·
Decouple ember functions from ethernet diagnostics cluster
1 parent fb64160 commit 6664d55

File tree

5 files changed

+48
-112
lines changed

5 files changed

+48
-112
lines changed
 

‎scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/IMClusterCommandHandler.cpp

-44
Original file line numberDiff line numberDiff line change
@@ -445,47 +445,6 @@ Protocols::InteractionModel::Status DispatchServerCommand(CommandHandler * apCom
445445

446446
} // namespace DishwasherAlarm
447447

448-
namespace EthernetNetworkDiagnostics {
449-
450-
Protocols::InteractionModel::Status DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath,
451-
TLV::TLVReader & aDataTlv)
452-
{
453-
CHIP_ERROR TLVError = CHIP_NO_ERROR;
454-
bool wasHandled = false;
455-
{
456-
switch (aCommandPath.mCommandId)
457-
{
458-
case Commands::ResetCounts::Id: {
459-
Commands::ResetCounts::DecodableType commandData;
460-
TLVError = DataModel::Decode(aDataTlv, commandData);
461-
if (TLVError == CHIP_NO_ERROR)
462-
{
463-
wasHandled = emberAfEthernetNetworkDiagnosticsClusterResetCountsCallback(apCommandObj, aCommandPath, commandData);
464-
}
465-
break;
466-
}
467-
default: {
468-
// Unrecognized command ID, error status will apply.
469-
ChipLogError(Zcl, "Unknown command " ChipLogFormatMEI " for cluster " ChipLogFormatMEI,
470-
ChipLogValueMEI(aCommandPath.mCommandId), ChipLogValueMEI(aCommandPath.mClusterId));
471-
return Protocols::InteractionModel::Status::UnsupportedCommand;
472-
}
473-
}
474-
}
475-
476-
if (CHIP_NO_ERROR != TLVError || !wasHandled)
477-
{
478-
ChipLogProgress(Zcl, "Failed to dispatch command, TLVError=%" CHIP_ERROR_FORMAT, TLVError.Format());
479-
return Protocols::InteractionModel::Status::InvalidCommand;
480-
}
481-
482-
// We use success as a marker that no special handling is required
483-
// This is to avoid having a std::optional which uses slightly more code.
484-
return Protocols::InteractionModel::Status::Success;
485-
}
486-
487-
} // namespace EthernetNetworkDiagnostics
488-
489448
namespace FanControl {
490449

491450
Protocols::InteractionModel::Status DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath,
@@ -1866,9 +1825,6 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aCommandPath, TLV:
18661825
case Clusters::DishwasherAlarm::Id:
18671826
errorStatus = Clusters::DishwasherAlarm::DispatchServerCommand(apCommandObj, aCommandPath, aReader);
18681827
break;
1869-
case Clusters::EthernetNetworkDiagnostics::Id:
1870-
errorStatus = Clusters::EthernetNetworkDiagnostics::DispatchServerCommand(apCommandObj, aCommandPath, aReader);
1871-
break;
18721828
case Clusters::FanControl::Id:
18731829
errorStatus = Clusters::FanControl::DispatchServerCommand(apCommandObj, aCommandPath, aReader);
18741830
break;

‎scripts/tools/zap/tests/outputs/lighting-app/app-templates/IMClusterCommandHandler.cpp

-44
Original file line numberDiff line numberDiff line change
@@ -344,47 +344,6 @@ Protocols::InteractionModel::Status DispatchServerCommand(CommandHandler * apCom
344344

345345
} // namespace DiagnosticLogs
346346

347-
namespace EthernetNetworkDiagnostics {
348-
349-
Protocols::InteractionModel::Status DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath,
350-
TLV::TLVReader & aDataTlv)
351-
{
352-
CHIP_ERROR TLVError = CHIP_NO_ERROR;
353-
bool wasHandled = false;
354-
{
355-
switch (aCommandPath.mCommandId)
356-
{
357-
case Commands::ResetCounts::Id: {
358-
Commands::ResetCounts::DecodableType commandData;
359-
TLVError = DataModel::Decode(aDataTlv, commandData);
360-
if (TLVError == CHIP_NO_ERROR)
361-
{
362-
wasHandled = emberAfEthernetNetworkDiagnosticsClusterResetCountsCallback(apCommandObj, aCommandPath, commandData);
363-
}
364-
break;
365-
}
366-
default: {
367-
// Unrecognized command ID, error status will apply.
368-
ChipLogError(Zcl, "Unknown command " ChipLogFormatMEI " for cluster " ChipLogFormatMEI,
369-
ChipLogValueMEI(aCommandPath.mCommandId), ChipLogValueMEI(aCommandPath.mClusterId));
370-
return Protocols::InteractionModel::Status::UnsupportedCommand;
371-
}
372-
}
373-
}
374-
375-
if (CHIP_NO_ERROR != TLVError || !wasHandled)
376-
{
377-
ChipLogProgress(Zcl, "Failed to dispatch command, TLVError=%" CHIP_ERROR_FORMAT, TLVError.Format());
378-
return Protocols::InteractionModel::Status::InvalidCommand;
379-
}
380-
381-
// We use success as a marker that no special handling is required
382-
// This is to avoid having a std::optional which uses slightly more code.
383-
return Protocols::InteractionModel::Status::Success;
384-
}
385-
386-
} // namespace EthernetNetworkDiagnostics
387-
388347
namespace GroupKeyManagement {
389348

390349
Protocols::InteractionModel::Status DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath,
@@ -986,9 +945,6 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aCommandPath, TLV:
986945
case Clusters::DiagnosticLogs::Id:
987946
errorStatus = Clusters::DiagnosticLogs::DispatchServerCommand(apCommandObj, aCommandPath, aReader);
988947
break;
989-
case Clusters::EthernetNetworkDiagnostics::Id:
990-
errorStatus = Clusters::EthernetNetworkDiagnostics::DispatchServerCommand(apCommandObj, aCommandPath, aReader);
991-
break;
992948
case Clusters::GroupKeyManagement::Id:
993949
errorStatus = Clusters::GroupKeyManagement::DispatchServerCommand(apCommandObj, aCommandPath, aReader);
994950
break;

‎src/app/clusters/ethernet-network-diagnostics-server/ethernet-network-diagnostics-server.cpp

+47-18
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222
#include <app/AttributeAccessInterface.h>
2323
#include <app/AttributeAccessInterfaceRegistry.h>
2424
#include <app/CommandHandler.h>
25+
#include <app/CommandHandlerInterface.h>
26+
#include <app/CommandHandlerInterfaceRegistry.h>
2527
#include <app/ConcreteCommandPath.h>
2628
#include <app/util/attribute-storage.h>
2729
#include <lib/core/Optional.h>
2830
#include <platform/DiagnosticDataProvider.h>
31+
#include <zap-generated/gen_config.h>
2932

3033
using namespace chip;
3134
using namespace chip::app;
@@ -36,11 +39,15 @@ using chip::DeviceLayer::DiagnosticDataProvider;
3639

3740
namespace {
3841

39-
class EthernetDiagosticsAttrAccess : public AttributeAccessInterface
42+
class EthernetDiagosticsGlobalInstance : public AttributeAccessInterface, public CommandHandlerInterface
4043
{
4144
public:
4245
// Register for the EthernetNetworkDiagnostics cluster on all endpoints.
43-
EthernetDiagosticsAttrAccess() : AttributeAccessInterface(Optional<EndpointId>::Missing(), EthernetNetworkDiagnostics::Id) {}
46+
EthernetDiagosticsGlobalInstance(DiagnosticDataProvider & diagnosticProvider) :
47+
AttributeAccessInterface(Optional<EndpointId>::Missing(), EthernetNetworkDiagnostics::Id),
48+
CommandHandlerInterface(Optional<EndpointId>::Missing(), EthernetNetworkDiagnostics::Id),
49+
mDiagnosticProvider(diagnosticProvider)
50+
{}
4451

4552
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;
4653

@@ -51,11 +58,19 @@ class EthernetDiagosticsAttrAccess : public AttributeAccessInterface
5158
CHIP_ERROR ReadPHYRate(AttributeValueEncoder & aEncoder);
5259
CHIP_ERROR ReadFullDuplex(AttributeValueEncoder & aEncoder);
5360
CHIP_ERROR ReadCarrierDetect(AttributeValueEncoder & aEncoder);
61+
62+
void InvokeCommand(HandlerContext & ctx) override;
63+
64+
#ifdef ETHERNET_NETWORK_DIAGNOSTICS_ENABLE_RESET_COUNTS_CMD
65+
void HandleResetCounts(HandlerContext & ctx, const Commands::ResetCounts::DecodableType & commandData);
66+
#endif
67+
68+
DiagnosticDataProvider & mDiagnosticProvider;
5469
};
5570

5671
template <typename T>
57-
CHIP_ERROR EthernetDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &),
58-
AttributeValueEncoder & aEncoder)
72+
CHIP_ERROR EthernetDiagosticsGlobalInstance::ReadIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &),
73+
AttributeValueEncoder & aEncoder)
5974
{
6075
T data;
6176
CHIP_ERROR err = (DeviceLayer::GetDiagnosticDataProvider().*getter)(data);
@@ -71,7 +86,7 @@ CHIP_ERROR EthernetDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (DiagnosticD
7186
return aEncoder.Encode(data);
7287
}
7388

74-
CHIP_ERROR EthernetDiagosticsAttrAccess::ReadPHYRate(AttributeValueEncoder & aEncoder)
89+
CHIP_ERROR EthernetDiagosticsGlobalInstance::ReadPHYRate(AttributeValueEncoder & aEncoder)
7590
{
7691
Attributes::PHYRate::TypeInfo::Type pHYRate;
7792
auto value = app::Clusters::EthernetNetworkDiagnostics::PHYRateEnum::kRate10M;
@@ -90,7 +105,7 @@ CHIP_ERROR EthernetDiagosticsAttrAccess::ReadPHYRate(AttributeValueEncoder & aEn
90105
return aEncoder.Encode(pHYRate);
91106
}
92107

93-
CHIP_ERROR EthernetDiagosticsAttrAccess::ReadFullDuplex(AttributeValueEncoder & aEncoder)
108+
CHIP_ERROR EthernetDiagosticsGlobalInstance::ReadFullDuplex(AttributeValueEncoder & aEncoder)
94109
{
95110
Attributes::FullDuplex::TypeInfo::Type fullDuplex;
96111
bool value = false;
@@ -108,7 +123,7 @@ CHIP_ERROR EthernetDiagosticsAttrAccess::ReadFullDuplex(AttributeValueEncoder &
108123
return aEncoder.Encode(fullDuplex);
109124
}
110125

111-
CHIP_ERROR EthernetDiagosticsAttrAccess::ReadCarrierDetect(AttributeValueEncoder & aEncoder)
126+
CHIP_ERROR EthernetDiagosticsGlobalInstance::ReadCarrierDetect(AttributeValueEncoder & aEncoder)
112127
{
113128
Attributes::CarrierDetect::TypeInfo::Type carrierDetect;
114129
bool value = false;
@@ -127,9 +142,7 @@ CHIP_ERROR EthernetDiagosticsAttrAccess::ReadCarrierDetect(AttributeValueEncoder
127142
return aEncoder.Encode(carrierDetect);
128143
}
129144

130-
EthernetDiagosticsAttrAccess gAttrAccess;
131-
132-
CHIP_ERROR EthernetDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
145+
CHIP_ERROR EthernetDiagosticsGlobalInstance::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
133146
{
134147
if (aPath.mClusterId != EthernetNetworkDiagnostics::Id)
135148
{
@@ -172,19 +185,35 @@ CHIP_ERROR EthernetDiagosticsAttrAccess::Read(const ConcreteReadAttributePath &
172185
}
173186
return CHIP_NO_ERROR;
174187
}
175-
} // anonymous namespace
176188

177-
bool emberAfEthernetNetworkDiagnosticsClusterResetCountsCallback(app::CommandHandler * commandObj,
178-
const app::ConcreteCommandPath & commandPath,
179-
const Commands::ResetCounts::DecodableType & commandData)
189+
void EthernetDiagosticsGlobalInstance::InvokeCommand(HandlerContext & handlerContext)
180190
{
181-
DeviceLayer::GetDiagnosticDataProvider().ResetEthNetworkDiagnosticsCounts();
182-
commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::Success);
191+
switch (handlerContext.mRequestPath.mCommandId)
192+
{
193+
case Commands::ResetCounts::Id:
194+
#ifdef ETHERNET_NETWORK_DIAGNOSTICS_ENABLE_RESET_COUNTS_CMD
195+
CommandHandlerInterface::HandleCommand<Commands::ResetCounts::DecodableType>(
196+
handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleResetCounts(ctx, commandData); });
197+
break;
198+
#endif
199+
}
200+
}
183201

184-
return true;
202+
#ifdef ETHERNET_NETWORK_DIAGNOSTICS_ENABLE_RESET_COUNTS_CMD
203+
void EthernetDiagosticsGlobalInstance::HandleResetCounts(HandlerContext & ctx,
204+
const Commands::ResetCounts::DecodableType & commandData)
205+
{
206+
mDiagnosticProvider.ResetEthNetworkDiagnosticsCounts();
207+
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Protocols::InteractionModel::Status::Success);
185208
}
209+
#endif
210+
211+
EthernetDiagosticsGlobalInstance gEthernetDiagosticsInstance(DeviceLayer::GetDiagnosticDataProvider());
212+
213+
} // anonymous namespace
186214

187215
void MatterEthernetNetworkDiagnosticsPluginServerInitCallback()
188216
{
189-
AttributeAccessInterfaceRegistry::Instance().Register(&gAttrAccess);
217+
AttributeAccessInterfaceRegistry::Instance().Register(&gEthernetDiagosticsInstance);
218+
CommandHandlerInterfaceRegistry::Instance().RegisterCommandHandler(&gEthernetDiagosticsInstance);
190219
}

‎src/app/common/templates/config-data.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ CommandHandlerInterfaceOnlyClusters:
5353
- General Diagnostics
5454
- Software Diagnostics
5555
- Wi-Fi Network Diagnostics
56+
- Ethernet Network Diagnostics
5657

5758
# We need a more configurable way of deciding which clusters have which init functions....
5859
# See https://github.com/project-chip/connectedhomeip/issues/4369

‎zzz_generated/app-common/app-common/zap-generated/callback.h

-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)