Skip to content

Commit c74bf85

Browse files
Add Json For Meter Indentification
1 parent 47b358c commit c74bf85

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

examples/all-clusters-app/all-clusters-common/src/meter-identification-stub.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@ void emberAfMeterIdentificationClusterInitCallback(chip::EndpointId endpointId)
4040
gMIInstance->Init();
4141
}
4242
}
43+
44+
MeterIdentificationDelegate *chip::app::Clusters::MeterIdentification::GetDelegate()
45+
{
46+
return &(*gMIDelegate);
47+
}

examples/all-clusters-app/linux/AllClustersCommandDelegate.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <oven-operational-state-delegate.h>
3737
#include <rvc-modes.h>
3838
#include "energy-calendar-instance.h"
39+
#include <MeterIdentificationDelegate.h>
3940

4041
#include <string>
4142

@@ -195,6 +196,10 @@ void AllClustersAppCommandHandler::HandleCommand(intptr_t context)
195196
{
196197
self->OnEnergyCalendarHandler(self->mJsonValue);
197198
}
199+
else if (name == "MeterIdentification")
200+
{
201+
self->OnMeterIdentificationHandler(self->mJsonValue);
202+
}
198203
else
199204
{
200205
ChipLogError(NotSpecified, "Unhandled command: Should never happens");
@@ -506,6 +511,12 @@ void AllClustersAppCommandHandler::OnEnergyCalendarHandler(Json::Value param)
506511
provider->LoadJson(param);
507512
}
508513

514+
void AllClustersAppCommandHandler::OnMeterIdentificationHandler(Json::Value param)
515+
{
516+
MeterIdentification::MeterIdentificationDelegate *delegate = MeterIdentification::GetDelegate();
517+
delegate->LoadJson(param);
518+
}
519+
509520
void AllClustersAppCommandHandler::OnAirQualityChange(uint32_t aNewValue)
510521
{
511522
AirQuality::Instance * airQualityInstance = AirQuality::GetInstance();

examples/all-clusters-app/linux/AllClustersCommandDelegate.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,14 @@ class AllClustersAppCommandHandler
107107
void OnOperationalStateChange(std::string device, std::string operation, Json::Value param);
108108

109109
/**
110-
* Should be called when it is necessary to change the mode to manual operation.
110+
* Should be called when it is necessary to change one or some attributes.
111111
*/
112112
void OnEnergyCalendarHandler(Json::Value param);
113+
114+
/**
115+
* Should be called when it is necessary to change one or some attributes.
116+
*/
117+
void OnMeterIdentificationHandler(Json::Value param);
113118
};
114119

115120
class AllClustersCommandDelegate : public NamedPipeCommandDelegate

examples/energy-management-app/energy-management-common/include/MeterIdentificationDelegate.h

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <app/clusters/meter-identification-server/meter-identification-server.h>
2121
#include <app/util/af-types.h>
2222
#include <lib/core/CHIPError.h>
23+
#include <json/value.h>
2324

2425
namespace chip {
2526
namespace app {
@@ -31,6 +32,8 @@ class MeterIdentificationDelegate : public MeterIdentification::Delegate
3132
public:
3233
~MeterIdentificationDelegate() = default;
3334

35+
CHIP_ERROR LoadJson(Json::Value & root);
36+
3437
// Attribute Accessors
3538

3639
DataModel::Nullable<MeterTypeEnum> GetMeterType() override { return mMeterType; };
@@ -78,6 +81,9 @@ class MeterIdentificationInstance : public Instance
7881
MeterIdentificationDelegate * mDelegate;
7982
};
8083

84+
MeterIdentificationDelegate *GetDelegate();
85+
86+
8187
} // namespace MeterIdentification
8288
} // namespace Clusters
8389
} // namespace app

examples/energy-management-app/energy-management-common/src/MeterIdentificationDelegate.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,40 @@ void MeterIdentificationInstance::Shutdown()
4343

4444
// --------------- Internal Attribute Set APIs
4545

46+
CHIP_ERROR MeterIdentificationDelegate::LoadJson(Json::Value & root)
47+
{
48+
Json::Value value = root.get("MeterType", Json::Value());
49+
#if 0
50+
if (!value.empty() && value.isInt())
51+
{
52+
mMeterType.SetNonNull(value.asInt());
53+
}
54+
55+
value = root.get("Name", Json::Value());
56+
if (!mName.IsNull())
57+
{
58+
chip::Platform::MemoryFree((void*)mName.Value().data());
59+
mName.SetNull();
60+
}
61+
if (!value.empty() && value.isString())
62+
{
63+
size_t len = value.asString().size()+1;
64+
char *str = (char*)chip::Platform::MemoryAlloc(len);
65+
memcpy(str, value.asCString(), len);
66+
CharSpan nameString(str, len);
67+
mName = MakeNullable(static_cast<CharSpan>(nameString));
68+
}
69+
70+
value = root.get("ProviderID", Json::Value());
71+
if (!value.empty() && value.isInt())
72+
{
73+
providerID.SetNonNull(value.asInt());
74+
}
75+
#endif
76+
77+
return CHIP_NO_ERROR;
78+
}
79+
4680
CHIP_ERROR MeterIdentificationDelegate::SetMeterType(DataModel::Nullable<MeterTypeEnum> newValue)
4781
{
4882
//DataModel::Nullable<MeterTypeEnum> oldValue = mMeterType;

0 commit comments

Comments
 (0)