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 "AdditionalDataParseCommand.h"
20 #include <setup_payload/AdditionalDataPayload.h>
21 #include <setup_payload/AdditionalDataPayloadParser.h>
24 using namespace ::chip;
25 using namespace ::chip::SetupPayloadData;
27 CHIP_ERROR AdditionalDataParseCommand::Run(PersistentStorage & storage, NodeId localId, NodeId remoteId)
29 std::vector<uint8_t> payloadData;
30 AdditionalDataPayload resultPayload;
31 CHIP_ERROR err = CHIP_NO_ERROR;
32 std::string payloadString(mPayload);
34 // Decode input payload
35 size_t len = payloadString.length();
37 for (size_t i = 0; i < len; i += 2)
39 auto str = payloadString.substr(i, 2);
40 uint8_t x = (uint8_t) stoi(str, 0, 16);
41 payloadData.push_back(x);
43 err = AdditionalDataPayloadParser(payloadData.data(), (uint32_t) payloadData.size()).populatePayload(resultPayload);
45 ChipLogProgress(chipTool, "AdditionalDataParseCommand, RotatingDeviceId=%s", resultPayload.rotatingDeviceId.c_str());