@@ -40,6 +40,16 @@ using namespace chip::app::Clusters::GeneralCommissioning;
40
40
using namespace chip ::app::Clusters::GeneralCommissioning::Attributes;
41
41
using namespace chip ::DeviceLayer;
42
42
43
+ #define CheckSuccess (expr, code ) \
44
+ do \
45
+ { \
46
+ if (!::chip::ChipError::IsSuccess (expr)) \
47
+ { \
48
+ LogErrorOnFailure (commandObj->AddStatus (commandPath, Protocols::InteractionModel::Status::code)); \
49
+ return true ; \
50
+ } \
51
+ } while (false )
52
+
43
53
namespace {
44
54
45
55
class GeneralCommissioningAttrAccess : public AttributeAccessInterface
@@ -102,29 +112,37 @@ bool emberAfGeneralCommissioningClusterArmFailSafeCallback(app::CommandHandler *
102
112
const app::ConcreteCommandPath & commandPath,
103
113
const Commands::ArmFailSafe::DecodableType & commandData)
104
114
{
105
- auto expiryLengthSeconds = System::Clock::Seconds16 (commandData.expiryLengthSeconds );
115
+ DeviceControlServer * server = &DeviceLayer::DeviceControlServer::DeviceControlSvr ();
116
+ CheckSuccess (server->ArmFailSafe (System::Clock::Seconds16 (commandData.expiryLengthSeconds )), Failure);
106
117
107
- CHIP_ERROR err = DeviceLayer::DeviceControlServer::DeviceControlSvr ().ArmFailSafe (expiryLengthSeconds);
108
- emberAfSendImmediateDefaultResponse (err == CHIP_NO_ERROR ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
118
+ Commands::ArmFailSafeResponse::Type response;
119
+ response.errorCode = GeneralCommissioningError::kOk ;
120
+ response.debugText = CharSpan (" " , 0 );
121
+ CheckSuccess (commandObj->AddResponseData (commandPath, response), Failure);
109
122
110
123
return true ;
111
124
}
112
125
113
- /* *
114
- * Pass fabric and nodeId of commissioner to DeviceControlSvr.
115
- * This allows device to send messages back to commissioner.
116
- * Once bindings are implemented, this may no longer be needed.
117
- */
118
126
bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback (
119
127
app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
120
128
const Commands::CommissioningComplete::DecodableType & commandData)
121
129
{
122
- SessionHandle handle = commandObj->GetExchangeContext ()->GetSessionHandle ();
123
- DeviceLayer::DeviceControlServer::DeviceControlSvr ().SetFabricIndex (handle.GetFabricIndex ());
124
- DeviceLayer::DeviceControlServer::DeviceControlSvr ().SetPeerNodeId (handle.GetPeerNodeId ());
130
+ DeviceControlServer * server = &DeviceLayer::DeviceControlServer::DeviceControlSvr ();
125
131
126
- CHIP_ERROR err = DeviceLayer::DeviceControlServer::DeviceControlSvr ().CommissioningComplete ();
127
- emberAfSendImmediateDefaultResponse (err == CHIP_NO_ERROR ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
132
+ /*
133
+ * Pass fabric and nodeId of commissioner to DeviceControlSvr.
134
+ * This allows device to send messages back to commissioner.
135
+ * Once bindings are implemented, this may no longer be needed.
136
+ */
137
+ server->SetFabricIndex (commandObj->GetExchangeContext ()->GetSessionHandle ().GetFabricIndex ());
138
+ server->SetPeerNodeId (commandObj->GetExchangeContext ()->GetSessionHandle ().GetPeerNodeId ());
139
+
140
+ CheckSuccess (server->CommissioningComplete (), Failure);
141
+
142
+ Commands::CommissioningCompleteResponse::Type response;
143
+ response.errorCode = GeneralCommissioningError::kOk ;
144
+ response.debugText = CharSpan (" " , 0 );
145
+ CheckSuccess (commandObj->AddResponseData (commandPath, response), Failure);
128
146
129
147
return true ;
130
148
}
@@ -133,13 +151,13 @@ bool emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(app::CommandH
133
151
const app::ConcreteCommandPath & commandPath,
134
152
const Commands::SetRegulatoryConfig::DecodableType & commandData)
135
153
{
136
- auto & location = commandData.location ;
137
- auto & countryCode = commandData.countryCode ;
138
- auto & breadcrumb = commandData.breadcrumb ;
139
-
140
- CHIP_ERROR err = DeviceLayer::DeviceControlServer::DeviceControlSvr ().SetRegulatoryConfig (location, countryCode, breadcrumb);
154
+ DeviceControlServer * server = &DeviceLayer::DeviceControlServer::DeviceControlSvr ();
155
+ CheckSuccess (server->SetRegulatoryConfig (commandData.location , commandData.countryCode , commandData.breadcrumb ), Failure);
141
156
142
- emberAfSendImmediateDefaultResponse (err == CHIP_NO_ERROR ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
157
+ Commands::SetRegulatoryConfigResponse::Type response;
158
+ response.errorCode = GeneralCommissioningError::kOk ;
159
+ response.debugText = CharSpan (" " , 0 );
160
+ CheckSuccess (commandObj->AddResponseData (commandPath, response), Failure);
143
161
144
162
return true ;
145
163
}
0 commit comments