• 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 #ifndef MECHBODY_CONTROLLER_MECHBODY_CONTROLLER_TYPES_H
17 #define MECHBODY_CONTROLLER_MECHBODY_CONTROLLER_TYPES_H
18 
19 #include <vector>
20 #include <functional>
21 #include <cstdint>
22 #include <memory>
23 #include "iremote_broker.h"
24 #include "ipc_skeleton.h"
25 #include "parcel.h"
26 #include "mechbody_controller_enums.h"
27 #include "mechbody_controller_utils.h"
28 
29 namespace OHOS {
30 namespace MechBodyController {
31 
32 struct TimeLimit {
33     float min = 0;
34     float max = 0;
35 };
36 
37 struct MechInfo : public OHOS::Parcelable {
38     int32_t mechId = 0;
39     MechType mechType = MechType::PORTABLE_GIMBAL;
40     std::string mechName;
41     std::string mac;
42     AttachmentState state = AttachmentState::DETACHED;
43     bool gattCoonectState = false;
44     bool pairState = false;
45     bool hidState = false;
46 
47 public:
48     MechInfo() = default;
49 
50     bool operator<(const MechInfo &other) const
51     {
52         return mechId < other.mechId;
53     }
54 
MarshallingMechInfo55     bool Marshalling(OHOS::Parcel &parcel) const override
56     {
57         return parcel.WriteInt32(mechId) && parcel.WriteInt32(static_cast<int32_t>(mechType)) &&
58                parcel.WriteString(mechName);
59     }
60 
UnmarshallingMechInfo61     static MechInfo *Unmarshalling(OHOS::Parcel &parcel)
62     {
63         auto info = new MechInfo();
64         int32_t type = 0;
65         if (!parcel.ReadInt32(info->mechId) || !parcel.ReadInt32(type) || !parcel.ReadString(info->mechName)) {
66             delete info;
67             return nullptr;
68         }
69         info->mechType = static_cast<MechType>(type);
70         return info;
71     }
72 
ToStringMechInfo73     std::string ToString() const
74     {
75         return "MechInfo { mechId=" + std::to_string(mechId) + ", mechType=" +
76             std::to_string(static_cast<int>(mechType)) + ", mac=" + GetAnonymStr(mac) + ", mechName=" +
77                 GetAnonymStr(mechName) + ", state=" + std::to_string(static_cast<int>(state)) + ", gattCoonectState=" +
78                 std::to_string(gattCoonectState) + ", pairState=" + std::to_string(pairState) + ", hidState=" +
79                 std::to_string(hidState) + " }";
80     }
81 
SetGattConnectStateMechInfo82     void SetGattConnectState(bool state)
83     {
84         gattCoonectState = state;
85     }
86 
SetPairStateMechInfo87     void SetPairState(bool state)
88     {
89         pairState = state;
90     }
91 
SetHidStateMechInfo92     void SetHidState(bool state)
93     {
94         hidState = state;
95     }
96 
SetAttachStateMechInfo97     void SetAttachState(AttachmentState attachState)
98     {
99         state = attachState;
100     }
101 };
102 
103 struct EulerAngles : public OHOS::Parcelable {
104     float yaw = 0;
105     float roll = 0;
106     float pitch = 0;
107     EulerAngles() = default;
EulerAnglesEulerAngles108     EulerAngles(float yaw, float roll, float pitch) : yaw(yaw), roll(roll), pitch(pitch) {}
109     bool operator!=(const EulerAngles& other) const
110     {
111         return (std::abs(yaw - other.yaw) > FLOAT_EPSILON) ||
112             (std::abs(roll - other.roll) > FLOAT_EPSILON) ||
113             (std::abs(pitch - other.pitch) > FLOAT_EPSILON);
114     }
MarshallingEulerAngles115     bool Marshalling(OHOS::Parcel &parcel) const override
116     {
117         return parcel.WriteFloat(yaw) &&
118                 parcel.WriteFloat(roll) &&
119                 parcel.WriteFloat(pitch);
120     }
UnmarshallingEulerAngles121     static EulerAngles *Unmarshalling(OHOS::Parcel &parcel)
122     {
123         auto obj = new EulerAngles();
124         if (!parcel.ReadFloat(obj->yaw) ||
125             !parcel.ReadFloat(obj->roll) ||
126             !parcel.ReadFloat(obj->pitch)) {
127             delete obj;
128             return nullptr;
129         }
130         return obj;
131     }
ToStringEulerAngles132     std::string ToString() const
133     {
134         return "EulerAngles { yaw=" + std::to_string(yaw) + ", roll=" + std::to_string(roll) +
135             ", pitch=" + std::to_string(pitch) + " }";
136     }
137 };
138 
139 struct RotateByDegreeParam : public OHOS::Parcelable {
140     EulerAngles degree;
141     int32_t duration = 0;
142 public:
MarshallingRotateByDegreeParam143     bool Marshalling(OHOS::Parcel &parcel) const override
144     {
145         return parcel.WriteParcelable(&degree) && parcel.WriteInt32(duration);
146     }
UnmarshallingRotateByDegreeParam147     static RotateByDegreeParam *Unmarshalling(OHOS::Parcel &parcel)
148     {
149         auto param = new RotateByDegreeParam();
150         auto degreePtr = parcel.ReadParcelable<EulerAngles>();
151         if (!degreePtr) {
152             delete param;
153             return nullptr;
154         }
155         param->degree = *degreePtr;
156         delete degreePtr;
157 
158         if (!parcel.ReadInt32(param->duration)) {
159             delete param;
160             return nullptr;
161         }
162         return param;
163     }
164 
ToStringRotateByDegreeParam165     std::string ToString() const
166     {
167         return "RotateByDegreeParam { degree=" + degree.ToString() + ", duration=" + std::to_string(duration) + " }";
168     }
169 };
170 
171 struct RotateToEulerAnglesParam : public OHOS::Parcelable {
172     EulerAngles angles;
173     int32_t duration = 0;
174 
175 public:
MarshallingRotateToEulerAnglesParam176     bool Marshalling(OHOS::Parcel &parcel) const override
177     {
178         return parcel.WriteParcelable(&angles) &&
179                parcel.WriteInt32(duration);
180     }
UnmarshallingRotateToEulerAnglesParam181     static RotateToEulerAnglesParam *Unmarshalling(OHOS::Parcel &parcel)
182     {
183         std::unique_ptr<RotateToEulerAnglesParam> param = std::make_unique<RotateToEulerAnglesParam>();
184         if (param == nullptr) {
185             return nullptr;
186         }
187         EulerAngles* angles = parcel.ReadParcelable<EulerAngles>();
188         if (angles == nullptr) {
189             return nullptr;
190         }
191         param->angles = *angles;
192         if (!parcel.ReadInt32(param->duration)) {
193             delete angles;
194             return nullptr;
195         }
196         delete angles;
197         return param.release();
198     }
199 
ToStringRotateToEulerAnglesParam200     std::string ToString() const
201     {
202         return "RotateToEulerAnglesParam { degree=" + angles.ToString() + ", duration=" + std::to_string(duration) +
203                " }";
204     }
205 };
206 
207 struct RotateParam {
208     EulerAngles degree;
209     int32_t duration = 0;
210     bool isRelative = false;
211     uint8_t taskId = 0;
212 
213     RotateParam() = default;
214     RotateParam(const EulerAngles &deg, int32_t dur = 0, bool isRel = false)
degreeRotateParam215         : degree(deg),
216           duration(dur),
217           isRelative(isRel)
218     {
219     }
220 
221 public:
ToStringRotateParam222     std::string ToString() const
223     {
224         return "RotateParam { degree=" + degree.ToString() + ", duration=" + std::to_string(duration) +
225                ", isRelative=" + std::to_string(isRelative) + ", taskId=" + std::to_string(taskId) + " }";
226     }
227 };
228 
229 struct RotateSpeed : public OHOS::Parcelable {
230     float yawSpeed = 0;
231     float rollSpeed = 0;
232     float pitchSpeed = 0;
MarshallingRotateSpeed233     bool Marshalling(OHOS::Parcel &parcel) const override
234     {
235         return parcel.WriteFloat(yawSpeed) &&
236                parcel.WriteFloat(rollSpeed) &&
237                parcel.WriteFloat(pitchSpeed);
238     }
UnmarshallingRotateSpeed239     static RotateSpeed *Unmarshalling(OHOS::Parcel &parcel)
240     {
241         auto param = new RotateSpeed();
242         if (!parcel.ReadFloat(param->yawSpeed) ||
243             !parcel.ReadFloat(param->rollSpeed) ||
244             !parcel.ReadFloat(param->pitchSpeed)) {
245             delete param;
246             return nullptr;
247         }
248         return param;
249     }
ToStringRotateSpeed250     std::string ToString() const
251     {
252         return "RotateSpeed { yawSpeed=" + std::to_string(yawSpeed) + ", rollSpeed=" + std::to_string(rollSpeed) +
253             ", pitchSpeed=" + std::to_string(pitchSpeed) + " }";
254     }
255 };
256 
257 struct RotateBySpeedParam : public OHOS::Parcelable {
258     RotateSpeed speed;
259     float duration = 0;
MarshallingRotateBySpeedParam260     bool Marshalling(OHOS::Parcel &parcel) const override
261     {
262         return speed.Marshalling(parcel) &&
263                parcel.WriteFloat(duration);
264     }
UnmarshallingRotateBySpeedParam265     static RotateBySpeedParam *Unmarshalling(OHOS::Parcel &parcel)
266     {
267         auto param = new RotateBySpeedParam();
268 
269         RotateSpeed *speed = RotateSpeed::Unmarshalling(parcel);
270         if (speed == nullptr) {
271             delete param;
272             return nullptr;
273         }
274         param->speed = *speed;
275         delete speed;
276 
277         if (!parcel.ReadFloat(param->duration)) {
278             delete param;
279             return nullptr;
280         }
281         return param;
282     }
ToStringRotateBySpeedParam283     std::string ToString() const
284     {
285         return "RotateBySpeedParam { " + speed.ToString() + ", duration=" + std::to_string(duration) + " }";
286     }
287 };
288 
289 struct RotateSpeedLimit : public OHOS::Parcelable {
290     RotateSpeed speedMax;
291     RotateSpeed speedMin;
MarshallingRotateSpeedLimit292     bool Marshalling(OHOS::Parcel &parcel) const override
293     {
294         return parcel.WriteParcelable(&speedMax) &&
295                parcel.WriteParcelable(&speedMin);
296     }
UnmarshallingRotateSpeedLimit297     static RotateSpeedLimit *Unmarshalling(OHOS::Parcel &parcel)
298     {
299         auto obj = new RotateSpeedLimit();
300         auto speedMax = parcel.ReadParcelable<RotateSpeed>();
301         auto speedMin = parcel.ReadParcelable<RotateSpeed>();
302         if (!speedMax || !speedMin) {
303             delete obj;
304             delete speedMax;
305             delete speedMin;
306             return nullptr;
307         }
308         obj->speedMax = *speedMax;
309         obj->speedMin = *speedMin;
310         delete speedMax;
311         delete speedMin;
312         return obj;
313     }
ToStringRotateSpeedLimit314     std::string ToString() const
315     {
316         return "RotateSpeedLimit { speedMax=" + speedMax.ToString() + ", speedMin=" + speedMin.ToString() + " }";
317     }
318 };
319 
320 struct RotateDegreeLimit : public OHOS::Parcelable {
321     EulerAngles negMax;
322     EulerAngles posMax;
MarshallingRotateDegreeLimit323     bool Marshalling(OHOS::Parcel &parcel) const override
324     {
325         return parcel.WriteParcelable(&negMax) &&
326                parcel.WriteParcelable(&posMax);
327     }
UnmarshallingRotateDegreeLimit328     static RotateDegreeLimit *Unmarshalling(OHOS::Parcel &parcel)
329     {
330         auto obj = new RotateDegreeLimit();
331         auto negMax = parcel.ReadParcelable<EulerAngles>();
332         auto posMax = parcel.ReadParcelable<EulerAngles>();
333         if (!negMax || !posMax) {
334             delete obj;
335             delete negMax;
336             delete posMax;
337             return nullptr;
338         }
339         obj->negMax = *negMax;
340         obj->posMax = *posMax;
341         delete negMax;
342         delete posMax;
343         return obj;
344     }
ToStringRotateDegreeLimit345     std::string ToString() const
346     {
347         return "RotateDegreeLimit { negMax=" + negMax.ToString() + ", posMax=" + posMax.ToString() + " }";
348     }
349 };
350 
351 struct RotationAxesStatus : public OHOS::Parcelable {
352     bool yawEnabled = true;
353     bool rollEnabled = true;
354     bool pitchEnabled = true;
355     RotationAxisLimited yawLimited = RotationAxisLimited::NOT_LIMITED;
356     RotationAxisLimited rollLimited = RotationAxisLimited::NOT_LIMITED;
357     RotationAxisLimited pitchLimited = RotationAxisLimited::NOT_LIMITED;
358 
359 public:
MarshallingRotationAxesStatus360     bool Marshalling(OHOS::Parcel &parcel) const override
361     {
362         return parcel.WriteBool(yawEnabled) &&
363                parcel.WriteUint32(static_cast<uint32_t>(yawLimited)) &&
364                parcel.WriteBool(rollEnabled) &&
365                parcel.WriteUint32(static_cast<uint32_t>(rollLimited)) &&
366                parcel.WriteBool(pitchEnabled) &&
367                parcel.WriteUint32(static_cast<uint32_t>(pitchLimited));
368     }
UnmarshallingRotationAxesStatus369     static RotationAxesStatus *Unmarshalling(OHOS::Parcel &parcel)
370     {
371         RotationAxesStatus *status = new (std::nothrow) RotationAxesStatus();
372         if (status == nullptr) {
373             return nullptr;
374         }
375 
376         uint32_t limitValue;
377         if (!parcel.ReadBool(status->yawEnabled) ||
378             !parcel.ReadUint32(limitValue)) {
379             delete status;
380             return nullptr;
381         }
382         status->yawLimited = static_cast<RotationAxisLimited>(limitValue);
383 
384         if (!parcel.ReadBool(status->rollEnabled) ||
385             !parcel.ReadUint32(limitValue)) {
386             delete status;
387             return nullptr;
388         }
389         status->rollLimited = static_cast<RotationAxisLimited>(limitValue);
390 
391         if (!parcel.ReadBool(status->pitchEnabled) ||
392             !parcel.ReadUint32(limitValue)) {
393             delete status;
394             return nullptr;
395         }
396         status->pitchLimited = static_cast<RotationAxisLimited>(limitValue);
397         return status;
398     }
399     bool operator==(const RotationAxesStatus &other) const
400     {
401         return (yawEnabled == other.yawEnabled) && (rollEnabled == other.rollEnabled) &&
402                (pitchEnabled == other.pitchEnabled) && (yawLimited == other.yawLimited) &&
403                (rollLimited == other.rollLimited) && (pitchLimited == other.pitchLimited);
404     }
405     bool operator!=(const RotationAxesStatus &other) const
406     {
407         return (yawEnabled != other.yawEnabled) || (rollEnabled != other.rollEnabled) ||
408                (pitchEnabled != other.pitchEnabled) || (yawLimited != other.yawLimited) ||
409                (rollLimited != other.rollLimited) || (pitchLimited != other.pitchLimited);
410     }
ToStringRotationAxesStatus411     std::string ToString() const
412     {
413         auto limitToString = [](RotationAxisLimited limit) {
414             switch (limit) {
415                 case RotationAxisLimited::NOT_LIMITED:
416                     return "NOT_LIMITED";
417                 case RotationAxisLimited::NEG_LIMITED:
418                     return "NEG_LIMITED";
419                 case RotationAxisLimited::POS_LIMITED:
420                     return "POS_LIMITED";
421                 default:
422                     return "UNKNOWN";
423             }
424         };
425         return "RotateAxisStatus{yawEnabled:" + std::to_string(yawEnabled) + ", yawLimited:" +
426             limitToString(yawLimited) + ", rollEnabled:" + std::to_string(rollEnabled) + ", rollLimited:" +
427             limitToString(rollLimited) + ", pitchEnabled:" + std::to_string(pitchEnabled) +
428             ", pitchLimited:" + limitToString(pitchLimited) + "}";
429     }
430 };
431 
432 struct MechStateInfo {
433     MechMode mechMode = MechMode::INVALID;
434     bool isCaptureVertical = false;
435     bool isPhoneOn = false;
436     bool operator==(const MechStateInfo &other) const
437     {
438         return (mechMode == other.mechMode) && (isCaptureVertical == other.isCaptureVertical) &&
439                (isPhoneOn == other.isPhoneOn);
440     }
441 };
442 
443 struct WheelData {
444     int16_t degree = 0;
445     int16_t speed = 0;
446     uint8_t speed_ratio = 0;
447 };
448 
449 struct LayoutParams {
450     bool isDefault = true;
451     float offsetX = 0;
452     float offsetY = 0;
ToStringLayoutParams453     std::string ToString() const
454     {
455         return "LayoutParams { isDefault=" + std::to_string(isDefault) + ", offsetX=" + std::to_string(offsetX) +
456             ", offsetY=" + std::to_string(offsetY) + " }";
457     }
458 };
459 
460 struct CameraInfoParams {
461     uint8_t fovV;
462     uint8_t fovH;
463     float zoomFactor = 0;
464     bool isRecording = false;
465     CameraType cameraType;
466 };
467 
468 struct MechBaseInfo {
469     bool obtainable = false;
470     std::string mechType;
471     std::string ctrlMode;
472     std::string mechModel;
473     std::string mechVendor;
474 };
475 
476 struct CompositionRange {
477     int32_t min = 0;
478     int32_t max = 500;
479 };
480 
481 struct MotionRange {
482     int32_t min = 0;
483     int32_t max = 500;
484 };
485 
486 struct MechCapabilityInfo {
487     bool obtainable = false;
488     bool automaticReturn = false;
489     bool hvSwitching = false;
490     bool intelligentTracking = false;
491     int32_t movingTrackQuantity = 0;
492     CompositionRange x;
493     CompositionRange y;
494     MotionRange yaw;
495     MotionRange roll;
496     MotionRange pitch;
497     int32_t yawMaxSpeed = 0;
498     int32_t rollMaxSpeed = 0;
499     int32_t pitchMaxSpeed = 0;
500     int32_t reportingFrequency = 0;
501 };
502 
503 struct ROI {
504     float x = 0.0f;
505     float y = 0.0f;
506     float width = 0.0f;
507     float height = 0.0f;
ToStringROI508     std::string ToString() const
509     {
510         return "ROI {x=" + std::to_string(x) + ", y=" + std::to_string(y) + ", width=" + std::to_string(width) +
511                ", height=" + std::to_string(height) + " }";
512     }
513 };
514 
515 struct TrackingFrameParams {
516     uint16_t targetId = 0;
517     uint64_t timeStamp;
518     ConfidenceLevel confidence;
519     uint8_t objectType;
520     ROI roi;
521     float fovV;
522     float fovH;
523     bool isRecording;
524     uint32_t timeDelay;
ToStringTrackingFrameParams525     std::string ToString() const
526     {
527         return "TrackingFrameParams {targetId=" + std::to_string(targetId) + ", timeStamp=" +
528             std::to_string(timeStamp) + ", confidence=" + std::to_string(static_cast<int>(confidence)) +
529             ", objectType=" + std::to_string(objectType) + ", roi.x=" + std::to_string(roi.x) + ", roi.y=" +
530             std::to_string(roi.y) + ", roi.width=" + std::to_string(roi.width) + ", roi.height=" +
531             std::to_string(roi.height) + ", fovV=" + std::to_string(fovV) + ", fovH=" + std::to_string(fovH) +
532             ", isRecording=" + std::to_string(isRecording) + ", timeDelay=" + std::to_string(timeDelay) + " }";
533     }
534 };
535 }  // namespace MechBodyController
536 }  // namespace OHOS
537 #endif  // MECHBODY_CONTROLLER_MECHBODY_CONTROLLER_TYPES_H
538