1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "mc_set_mech_camera_tracking_frame_cmd.h"
17
18 #include "mechbody_controller_log.h"
19
20 namespace OHOS {
21 namespace MechBodyController {
22 namespace {
23 const std::string TAG = "SetMechCameraTrackingFrameCmd";
24 constexpr uint8_t CMD_CAMERA_TYPE_DEFAULT = 0x02;
25 }
26
SetMechCameraTrackingFrameCmd(const TrackingFrameParams & params)27 SetMechCameraTrackingFrameCmd::SetMechCameraTrackingFrameCmd(const TrackingFrameParams& params)
28 : params_(params)
29 {
30 cmdSet_ = CMD_SET;
31 cmdId_ = CMD_ID;
32 reqSize_ = REQ_SIZE;
33 rspSize_ = RSP_SIZE;
34 needResponse_ = (RSP_SIZE > 0);
35 timeoutMs_ = MECHBODY_MSG_TIMEOUT;
36 retryTimes_ = CMD_PRIORITY_LOW;
37 }
38
Marshal() const39 std::shared_ptr<MechDataBuffer> SetMechCameraTrackingFrameCmd::Marshal() const
40 {
41 HILOGD("start.");
42 auto buffer = std::make_shared<MechDataBuffer>(reqSize_ + BIT_OFFSET_2);
43 if (buffer == nullptr) {
44 HILOGE("Failed to allocate memory for Marshal buffer");
45 return nullptr;
46 }
47
48 CHECK_ERR_RETURN_VALUE(buffer->AppendUint8(cmdSet_), nullptr, "append cmdSet_");
49 CHECK_ERR_RETURN_VALUE(buffer->AppendUint8(cmdId_), nullptr, "append cmdId_");
50 CHECK_ERR_RETURN_VALUE(buffer->AppendUint64(params_.timeStamp), nullptr, "append timeStamp");
51 CHECK_ERR_RETURN_VALUE(buffer->AppendUint8(CMD_CAMERA_TYPE_DEFAULT), nullptr, "append cameraType");
52 CHECK_ERR_RETURN_VALUE(buffer->AppendUint8(static_cast<uint8_t>(params_.confidence)), nullptr, "append confidence");
53 CHECK_ERR_RETURN_VALUE(buffer->AppendUint8(params_.objectType), nullptr, "append objectType");
54 CHECK_ERR_RETURN_VALUE(buffer->AppendUint16(params_.targetId), nullptr, "append targetId");
55 CHECK_ERR_RETURN_VALUE(buffer->AppendFloat(params_.roi.x), nullptr, "append x");
56 CHECK_ERR_RETURN_VALUE(buffer->AppendFloat(params_.roi.y), nullptr, "append y");
57 CHECK_ERR_RETURN_VALUE(buffer->AppendFloat(params_.roi.width), nullptr, "append width");
58 CHECK_ERR_RETURN_VALUE(buffer->AppendFloat(params_.roi.height), nullptr, "append height");
59 CHECK_ERR_RETURN_VALUE(buffer->AppendUint16(params_.fovV), nullptr, "append fovV");
60 CHECK_ERR_RETURN_VALUE(buffer->AppendUint16(params_.fovH), nullptr, "append fovH");
61 CHECK_ERR_RETURN_VALUE(buffer->AppendUint8(params_.isRecording), nullptr, "append isRecording");
62 CHECK_ERR_RETURN_VALUE(buffer->AppendUint32(params_.timeDelay), nullptr, "append timeDelay");
63
64 HILOGD("end.");
65 return buffer;
66 }
67
TriggerResponse(std::shared_ptr<MechDataBuffer> data)68 void SetMechCameraTrackingFrameCmd::TriggerResponse(std::shared_ptr<MechDataBuffer> data)
69 {
70 if (responseCb_) {
71 HILOGI("trigger response callback.");
72 responseCb_();
73 }
74 }
75
GetParams() const76 const TrackingFrameParams& SetMechCameraTrackingFrameCmd::GetParams() const
77 {
78 return params_;
79 }
80 } // namespace MechBodyController
81 } // namespace OHOS
82