• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_info_cmd.h"
17 
18 #include "mechbody_controller_log.h"
19 
20 namespace OHOS {
21 namespace MechBodyController {
22 namespace {
23     const std::string TAG = "SetMechCameraInfoCmd";
24 }
25 
SetMechCameraInfoCmd(const CameraInfoParams & params)26 SetMechCameraInfoCmd::SetMechCameraInfoCmd(const CameraInfoParams& params)
27     : params_(params)
28 {
29     cmdSet_ = CMD_SET;
30     cmdId_ = CMD_ID;
31     reqSize_ = REQ_SIZE;
32     rspSize_ = RSP_SIZE;
33     needResponse_ = (RSP_SIZE > 0);
34     timeoutMs_ = MECHBODY_MSG_TIMEOUT;
35     retryTimes_ = CMD_PRIORITY_HIGH;
36 }
37 
Marshal() const38 std::shared_ptr<MechDataBuffer> SetMechCameraInfoCmd::Marshal() const
39 {
40     HILOGI("start.");
41     auto buffer = std::make_shared<MechDataBuffer>(reqSize_ + BIT_OFFSET_2);
42     if (buffer == nullptr) {
43         HILOGE("Failed to allocate memory for Marshal buffer");
44         return nullptr;
45     }
46 
47     CHECK_ERR_RETURN_VALUE(buffer->AppendUint8(cmdSet_), nullptr, "append cmdSet_");
48     CHECK_ERR_RETURN_VALUE(buffer->AppendUint8(cmdId_), nullptr, "append cmdId_");
49     CHECK_ERR_RETURN_VALUE(buffer->AppendUint8(params_.fovV), nullptr, "append fovV");
50     CHECK_ERR_RETURN_VALUE(buffer->AppendUint8(params_.fovH), nullptr, "append fovH");
51     CHECK_ERR_RETURN_VALUE(buffer->AppendFloat(params_.zoomFactor), nullptr, "append zoomFactor");
52 
53     uint8_t controlByte = 0;
54     controlByte |= params_.isRecording << BIT_5;
55     controlByte |= (params_.cameraType != CameraType::BACK);
56     CHECK_ERR_RETURN_VALUE(buffer->AppendUint8(controlByte), nullptr, "append controlByte");
57 
58     HILOGI("end.");
59     return buffer;
60 }
61 
TriggerResponse(std::shared_ptr<MechDataBuffer> data)62 void SetMechCameraInfoCmd::TriggerResponse(std::shared_ptr<MechDataBuffer> data)
63 {
64     if (responseCb_) {
65         HILOGI("trigger response callback.");
66         responseCb_();
67     }
68 }
69 
GetParams() const70 const CameraInfoParams& SetMechCameraInfoCmd::GetParams() const
71 {
72     return params_;
73 }
74 } // namespace MechBodyController
75 } // namespace OHOS
76