Skip to content

Commit dd87462

Browse files
committed
Meter Identification server added
1 parent b56134c commit dd87462

File tree

7 files changed

+455
-0
lines changed

7 files changed

+455
-0
lines changed

scripts/build/build/targets.py

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def BuildHostTarget():
194194
target.AppendModifier('rpc', enable_rpcs=True)
195195
target.AppendModifier('with-ui', imgui_ui=True)
196196
target.AppendModifier('evse-test-event', enable_test_event_triggers=['EVSE']).OnlyIfRe('-energy-management')
197+
target.AppendModifier('mtrid-test-event', enable_test_event_triggers=['MTRID']).OnlyIfRe('-meter-identification')
197198
target.AppendModifier('enable-dnssd-tests', enable_dnssd_tests=True).OnlyIfRe('-tests')
198199
target.AppendModifier('disable-dnssd-tests', enable_dnssd_tests=False).OnlyIfRe('-tests')
199200
target.AppendModifier('chip-casting-simplified', chip_casting_simplified=True).OnlyIfRe('-tv-casting-app')

scripts/build/builders/host.py

+2
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,
470470
if enable_test_event_triggers is not None:
471471
if 'EVSE' in enable_test_event_triggers:
472472
self.extra_gn_options.append('chip_enable_energy_evse_trigger=true')
473+
if 'MTRID' in enable_test_event_triggers:
474+
self.extra_gn_options.append('chip_enable_meter_identification_trigger=true')
473475

474476
if enable_dnssd_tests is not None:
475477
if enable_dnssd_tests:

scripts/py_matter_idl/matter_idl/tests/outputs/large_all_clusters_app/cpp-app/cluster-init-callback.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ void emberAfClusterInitCallback(EndpointId endpoint, ClusterId clusterId)
115115
case app::Clusters::MediaPlayback::Id:
116116
emberAfMediaPlaybackClusterInitCallback(endpoint);
117117
break;
118+
case app::Clusters::MeterIdentification::Id:
119+
emberAfMeterIdentificationClusterInitCallback(endpoint);
120+
break;
118121
case app::Clusters::ModeSelect::Id:
119122
emberAfModeSelectClusterInitCallback(endpoint);
120123
break;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
*
3+
* Copyright (c) 2025 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#include <app-common/zap-generated/cluster-objects.h>
21+
#include <app/TestEventTriggerDelegate.h>
22+
23+
/**
24+
* @brief User handler for handling the test event trigger
25+
*
26+
* @note If TestEventTrigger is enabled, it needs to be implemented in the app
27+
*
28+
* @param eventTrigger Event trigger to handle
29+
*
30+
* @retval true on success
31+
* @retval false if error happened
32+
*/
33+
bool HandleMeterIdentificationTestEventTrigger(uint64_t eventTrigger);
34+
35+
namespace chip {
36+
37+
/*
38+
* These Test EventTrigger values are specified in the TC_MTRID test plan
39+
* and are defined conditions used in test events.
40+
*
41+
* They are sent along with the enableKey (manufacturer defined secret)
42+
* in the General Diagnostic cluster TestEventTrigger command
43+
*/
44+
enum class MeterIdentificationTrigger : uint64_t
45+
{
46+
// Scenarios
47+
// Attributes Value Update Test Event | Increment attribute values
48+
kAttributesValueUpdate = 0x0b06000000000000,
49+
// Attributes Value Test Event Clear | Return the device to pre-test status
50+
kAttributesValueUpdateClear = 0x0b06000000000001,
51+
};
52+
53+
class MeterIdentificationTestEventTriggerHandler : public TestEventTriggerHandler
54+
{
55+
public:
56+
explicit MeterIdentificationTestEventTriggerHandler() {}
57+
58+
/** This function must return True if the eventTrigger is recognised and handled
59+
* It must return False to allow a higher level TestEvent handler to check other
60+
* clusters that may handle it.
61+
*/
62+
CHIP_ERROR HandleEventTrigger(uint64_t eventTrigger) override
63+
{
64+
if (HandleMeterIdentificationTestEventTrigger(eventTrigger))
65+
{
66+
return CHIP_NO_ERROR;
67+
}
68+
return CHIP_ERROR_INVALID_ARGUMENT;
69+
}
70+
};
71+
72+
} // namespace chip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
#include "meter-identification-server.h"
19+
20+
#include <protocols/interaction_model/StatusCode.h>
21+
22+
#include <app/AttributeAccessInterface.h>
23+
#include <app/AttributeAccessInterfaceRegistry.h>
24+
#include <app/EventLogging.h>
25+
#include <app/reporting/reporting.h>
26+
#include <app/util/attribute-storage.h>
27+
#include <lib/support/CodeUtils.h>
28+
29+
using namespace chip;
30+
using namespace chip::app;
31+
using namespace chip::app::DataModel;
32+
using namespace chip::app::Clusters;
33+
using namespace chip::app::Clusters::MeterIdentification;
34+
using namespace chip::app::Clusters::MeterIdentification::Attributes;
35+
36+
using chip::Protocols::InteractionModel::Status;
37+
38+
namespace chip {
39+
namespace app {
40+
namespace Clusters {
41+
namespace MeterIdentification {
42+
43+
CHIP_ERROR Instance::Init()
44+
{
45+
VerifyOrReturnError(AttributeAccessInterfaceRegistry::Instance().Register(this), CHIP_ERROR_INCORRECT_STATE);
46+
return CHIP_NO_ERROR;
47+
}
48+
49+
void Instance::Shutdown()
50+
{
51+
AttributeAccessInterfaceRegistry::Instance().Unregister(this);
52+
}
53+
54+
bool Instance::HasFeature(const Feature & aFeature) const
55+
{
56+
return mFeature.Has(aFeature);
57+
}
58+
59+
// static CHIP_ERROR EncodeStringOnSuccess(CHIP_ERROR status, AttributeValueEncoder & encoder, const char * buf, size_t maxBufSize)
60+
//{
61+
// ReturnErrorOnFailure(status);
62+
// return encoder.Encode(chip::CharSpan(buf, strnlen(buf, maxBufSize)));
63+
// }
64+
65+
// AttributeAccessInterface
66+
CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
67+
{
68+
ChipLogProgress(Zcl, "Meter Indication read attr %d", aPath.mAttributeId);
69+
70+
switch (aPath.mAttributeId)
71+
{
72+
case FeatureMap::Id:
73+
ReturnErrorOnFailure(aEncoder.Encode(mFeature));
74+
break;
75+
case MeterType::Id:
76+
ReturnErrorOnFailure(aEncoder.Encode(mDelegate.GetMeterType()));
77+
break;
78+
79+
case PointOfDelivery::Id:
80+
ReturnErrorOnFailure(aEncoder.Encode(mDelegate.GetPointOfDelivery()));
81+
break;
82+
83+
case MeterSerialNumber::Id:
84+
ReturnErrorOnFailure(aEncoder.Encode(mDelegate.GetMeterSerialNumber()));
85+
break;
86+
87+
case ProtocolVersion::Id:
88+
ReturnErrorOnFailure(aEncoder.Encode(mDelegate.GetProtocolVersion()));
89+
break;
90+
91+
case PowerThreshold::Id:
92+
if (HasFeature(Feature::kPowerThreshold))
93+
ReturnErrorOnFailure(aEncoder.Encode(mDelegate.GetPowerThreshold()));
94+
else
95+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
96+
break;
97+
}
98+
return CHIP_NO_ERROR;
99+
}
100+
101+
CHIP_ERROR Instance::Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder)
102+
{
103+
/*
104+
105+
switch (aPath.mAttributeId)
106+
{
107+
108+
default:
109+
break;
110+
}
111+
*/
112+
return CHIP_NO_ERROR;
113+
}
114+
115+
} // namespace MeterIdentification
116+
} // namespace Clusters
117+
} // namespace app
118+
} // namespace chip
119+
120+
// -----------------------------------------------------------------------------
121+
// Plugin initialization
122+
123+
void MatterMeterIdentificationPluginServerInitCallback() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#include <stddef.h>
21+
22+
#include <lib/core/Optional.h>
23+
24+
#include <app-common/zap-generated/cluster-enums.h>
25+
#include <app-common/zap-generated/cluster-objects.h>
26+
#include <app/AttributeAccessInterface.h>
27+
#include <app/util/basic-types.h>
28+
#include <lib/core/CHIPError.h>
29+
30+
using chip::app::Clusters::MeterIdentification::MeterTypeEnum;
31+
using Feature = chip::app::Clusters::MeterIdentification::Feature;
32+
33+
namespace chip {
34+
namespace app {
35+
namespace Clusters {
36+
namespace MeterIdentification {
37+
38+
struct Delegate
39+
{
40+
public:
41+
virtual ~Delegate() = default;
42+
43+
void SetEndpointId(const EndpointId & aEndpoint) { mEndpointId = aEndpoint; }
44+
45+
virtual DataModel::Nullable<MeterTypeEnum> GetMeterType() = 0;
46+
virtual DataModel::Nullable<CharSpan> GetPointOfDelivery() = 0;
47+
virtual DataModel::Nullable<CharSpan> GetMeterSerialNumber() = 0;
48+
virtual DataModel::Nullable<CharSpan> GetProtocolVersion() = 0;
49+
virtual DataModel::Nullable<Structs::PowerThresholdStruct::Type> GetPowerThreshold() = 0;
50+
51+
protected:
52+
EndpointId mEndpointId = 0;
53+
};
54+
55+
class Instance : public AttributeAccessInterface
56+
{
57+
public:
58+
Instance(const EndpointId & aEndpointId, Delegate & aDelegate, const BitMask<Feature> & aFeature) :
59+
AttributeAccessInterface(MakeOptional(aEndpointId), Id), mDelegate(aDelegate), mFeature(aFeature)
60+
{
61+
/* set the base class delegates endpointId */
62+
mDelegate.SetEndpointId(aEndpointId);
63+
}
64+
~Instance() { Shutdown(); }
65+
66+
CHIP_ERROR Init();
67+
void Shutdown();
68+
69+
bool HasFeature(const Feature & aFeature) const;
70+
71+
private:
72+
Delegate & mDelegate;
73+
BitMask<Feature> mFeature;
74+
75+
// AttributeAccessInterface
76+
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;
77+
CHIP_ERROR Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) override;
78+
};
79+
80+
} // namespace MeterIdentification
81+
} // namespace Clusters
82+
} // namespace app
83+
} // namespace chip

0 commit comments

Comments
 (0)