2 * Copyright (c) 2020 Project CHIP Authors
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "ModelCommand.h"
23 using namespace ::chip;
26 constexpr uint16_t kWaitDurationInSeconds = 10;
29 CHIP_ERROR ModelCommand::Run(PersistentStorage & storage, NodeId localId, NodeId remoteId)
31 CHIP_ERROR err = CHIP_NO_ERROR;
33 err = mCommissioner.SetUdpListenPort(storage.GetListenPort());
34 VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure! Commissioner: %s", ErrorStr(err)));
36 err = mCommissioner.Init(localId, &storage);
37 VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure! Commissioner: %s", ErrorStr(err)));
39 err = mCommissioner.ServiceEvents();
40 VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure! Run Loop: %s", ErrorStr(err)));
42 err = mCommissioner.GetDevice(remoteId, &mDevice);
43 VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(chipTool, "Init failure! No pairing for device: %" PRIu64, localId));
45 err = SendCommand(mDevice, mEndPointId);
46 VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(chipTool, "Failed to send message: %s", ErrorStr(err)));
48 UpdateWaitForResponse(true);
49 WaitForResponse(kWaitDurationInSeconds);
51 VerifyOrExit(GetCommandExitStatus(), err = CHIP_ERROR_INTERNAL);
54 mCommissioner.ServiceEventSignal();
55 mCommissioner.Shutdown();