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_command_base.h" 17 18 namespace OHOS { 19 namespace MechBodyController { 20 namespace { 21 constexpr uint16_t OFFSET_8 = 8; 22 } 23 SetResponseCallback(ResponseCallback cb)24void CommandBase::SetResponseCallback(ResponseCallback cb) 25 { 26 responseCb_ = cb; 27 } 28 SetTimeoutCallback(TimeoutCallback cb)29void CommandBase::SetTimeoutCallback(TimeoutCallback cb) 30 { 31 timeoutCb_ = cb; 32 } 33 TriggerTimeout() const34void CommandBase::TriggerTimeout() const 35 { 36 if (timeoutCb_) { 37 timeoutCb_(); 38 } 39 } 40 GetCmdSet() const41uint8_t CommandBase::GetCmdSet() const 42 { 43 return cmdSet_; 44 } 45 GetCmdId() const46uint8_t CommandBase::GetCmdId() const 47 { 48 return cmdId_; 49 } 50 GetCmdType() const51uint16_t CommandBase::GetCmdType() const 52 { 53 return (static_cast<uint16_t>(cmdSet_) << OFFSET_8) | static_cast<uint16_t>(cmdId_); 54 } 55 GetReqSize() const56uint16_t CommandBase::GetReqSize() const 57 { 58 return reqSize_; 59 } 60 GetRspSize() const61uint16_t CommandBase::GetRspSize() const 62 { 63 return rspSize_; 64 } 65 GetTimeoutMs() const66uint32_t CommandBase::GetTimeoutMs() const 67 { 68 return timeoutMs_; 69 } 70 NeedResponse() const71bool CommandBase::NeedResponse() const 72 { 73 return needResponse_; 74 } 75 GetRetryTimes() const76int32_t CommandBase::GetRetryTimes() const 77 { 78 return retryTimes_; 79 } 80 81 } // namespace MechBodyController 82 } // namespace OHOS 83