Skip to content

Commit f43e968

Browse files
committed
Adjust the legth of kMaxManaulCodeLength and move some long functions from .h to .cpp
1 parent 848f98c commit f43e968

File tree

4 files changed

+87
-62
lines changed

4 files changed

+87
-62
lines changed

examples/fabric-admin/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ static_library("fabric-admin-utils") {
6161
"${chip_root}/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp",
6262
"commands/clusters/ModelCommand.cpp",
6363
"commands/clusters/ModelCommand.h",
64+
"commands/clusters/ReportCommand.cpp",
65+
"commands/clusters/ReportCommand.h",
6466
"commands/common/CHIPCommand.cpp",
6567
"commands/common/CHIPCommand.h",
6668
"commands/common/Command.cpp",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2024 Project CHIP Authors
3+
* All rights reserved.
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+
19+
#include "ReportCommand.h"
20+
21+
#include <app/InteractionModelEngine.h>
22+
#include <inttypes.h>
23+
24+
using namespace ::chip;
25+
26+
void ReportCommand::OnAttributeData(const app::ConcreteDataAttributePath & path, TLV::TLVReader * data,
27+
const app::StatusIB & status)
28+
{
29+
CHIP_ERROR error = status.ToChipError();
30+
if (CHIP_NO_ERROR != error)
31+
{
32+
LogErrorOnFailure(RemoteDataModelLogger::LogErrorAsJSON(path, status));
33+
34+
ChipLogError(NotSpecified, "Response Failure: %s", ErrorStr(error));
35+
mError = error;
36+
return;
37+
}
38+
39+
if (data == nullptr)
40+
{
41+
ChipLogError(NotSpecified, "Response Failure: No Data");
42+
mError = CHIP_ERROR_INTERNAL;
43+
return;
44+
}
45+
46+
LogErrorOnFailure(RemoteDataModelLogger::LogAttributeAsJSON(path, data));
47+
}
48+
49+
void ReportCommand::OnEventData(const app::EventHeader & eventHeader, TLV::TLVReader * data, const app::StatusIB * status)
50+
{
51+
if (status != nullptr)
52+
{
53+
CHIP_ERROR error = status->ToChipError();
54+
if (CHIP_NO_ERROR != error)
55+
{
56+
LogErrorOnFailure(RemoteDataModelLogger::LogErrorAsJSON(eventHeader, *status));
57+
58+
ChipLogError(NotSpecified, "Response Failure: %s", ErrorStr(error));
59+
mError = error;
60+
return;
61+
}
62+
}
63+
64+
if (data == nullptr)
65+
{
66+
ChipLogError(NotSpecified, "Response Failure: No Data");
67+
mError = CHIP_ERROR_INTERNAL;
68+
return;
69+
}
70+
71+
LogErrorOnFailure(RemoteDataModelLogger::LogEventAsJSON(eventHeader, data));
72+
73+
CHIP_ERROR error = DataModelLogger::LogEvent(eventHeader, data);
74+
if (CHIP_NO_ERROR != error)
75+
{
76+
ChipLogError(NotSpecified, "Response Failure: Can not decode Data");
77+
mError = error;
78+
return;
79+
}
80+
}

examples/fabric-admin/commands/clusters/ReportCommand.h

+2-61
Original file line numberDiff line numberDiff line change
@@ -32,69 +32,10 @@ class ReportCommand : public InteractionModelReports, public ModelCommand, publi
3232

3333
/////////// ReadClient Callback Interface /////////
3434
void OnAttributeData(const chip::app::ConcreteDataAttributePath & path, chip::TLV::TLVReader * data,
35-
const chip::app::StatusIB & status) override
36-
{
37-
CHIP_ERROR error = status.ToChipError();
38-
if (CHIP_NO_ERROR != error)
39-
{
40-
LogErrorOnFailure(RemoteDataModelLogger::LogErrorAsJSON(path, status));
41-
42-
ChipLogError(NotSpecified, "Response Failure: %s", chip::ErrorStr(error));
43-
mError = error;
44-
return;
45-
}
46-
47-
if (data == nullptr)
48-
{
49-
ChipLogError(NotSpecified, "Response Failure: No Data");
50-
mError = CHIP_ERROR_INTERNAL;
51-
return;
52-
}
53-
54-
LogErrorOnFailure(RemoteDataModelLogger::LogAttributeAsJSON(path, data));
55-
56-
error = DataModelLogger::LogAttribute(path, data);
57-
if (CHIP_NO_ERROR != error)
58-
{
59-
ChipLogError(NotSpecified, "Response Failure: Can not decode Data");
60-
mError = error;
61-
return;
62-
}
63-
}
35+
const chip::app::StatusIB & status) override;
6436

6537
void OnEventData(const chip::app::EventHeader & eventHeader, chip::TLV::TLVReader * data,
66-
const chip::app::StatusIB * status) override
67-
{
68-
if (status != nullptr)
69-
{
70-
CHIP_ERROR error = status->ToChipError();
71-
if (CHIP_NO_ERROR != error)
72-
{
73-
LogErrorOnFailure(RemoteDataModelLogger::LogErrorAsJSON(eventHeader, *status));
74-
75-
ChipLogError(NotSpecified, "Response Failure: %s", chip::ErrorStr(error));
76-
mError = error;
77-
return;
78-
}
79-
}
80-
81-
if (data == nullptr)
82-
{
83-
ChipLogError(NotSpecified, "Response Failure: No Data");
84-
mError = CHIP_ERROR_INTERNAL;
85-
return;
86-
}
87-
88-
LogErrorOnFailure(RemoteDataModelLogger::LogEventAsJSON(eventHeader, data));
89-
90-
CHIP_ERROR error = DataModelLogger::LogEvent(eventHeader, data);
91-
if (CHIP_NO_ERROR != error)
92-
{
93-
ChipLogError(NotSpecified, "Response Failure: Can not decode Data");
94-
mError = error;
95-
return;
96-
}
97-
}
38+
const chip::app::StatusIB * status) override;
9839

9940
void OnError(CHIP_ERROR error) override
10041
{

examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace {
3333

3434
// Constants
3535
constexpr uint32_t kCommissionPrepareTimeMs = 500;
36-
constexpr uint16_t kMaxManaulCodeLength = 11;
36+
constexpr uint16_t kMaxManaulCodeLength = 21;
3737
constexpr uint16_t kSubscribeMinInterval = 0;
3838
constexpr uint16_t kSubscribeMaxInterval = 60;
3939

@@ -94,6 +94,8 @@ void FabricSyncDeviceCommand::OnCommissioningComplete(chip::NodeId deviceId, CHI
9494
{
9595
if (mAssignedNodeId != deviceId)
9696
{
97+
// Ignore if the deviceId does not match the mAssignedNodeId.
98+
// This scenario should not occur because no other device should be commissioned during the fabric sync process.
9799
return;
98100
}
99101

0 commit comments

Comments
 (0)