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