File indexing completed on 2024-06-16 05:22:58
0001 /* 0002 * Copyright 2019 Eike Hein <hein@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) version 3, or any 0008 * later version accepted by the membership of KDE e.V. (or its 0009 * successor approved by the membership of KDE e.V.), which shall 0010 * act as a proxy defined in Section 6 of version 3 of the license. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public 0018 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #pragma once 0022 0023 #include <QObject> 0024 0025 class Parrot : public QObject 0026 { 0027 public: 0028 Parrot() 0029 : QObject() 0030 { 0031 } 0032 ~Parrot() 0033 { 0034 } 0035 0036 enum HeaderSizes { HEADER_COMMAND = 4, HEADER_FRAME = 7 }; 0037 Q_ENUM(HeaderSizes) 0038 0039 enum DataType { ACK = 1, DATA = 2, LOW_LATENCY_DATA = 3, DATA_WITH_ACK = 4 }; 0040 Q_ENUM(DataType) 0041 0042 enum BufferId { 0043 BUFFER_PING = 0, 0044 BUFFER_PONG = 1, 0045 BUFFER_C2D_NON_ACK_DATA = 10, 0046 BUFFER_C2D_ACK_DATA = 11, 0047 BUFFER_C2D_EMERGENCY_DATA = 12, 0048 BUFFER_D2C_ACK_DATA = 126, 0049 BUFFER_D2C_NON_ACK_DATA = 127, 0050 BUFFER_D2C_ACK_FOR_C2D_ACK_DATA = BUFFER_C2D_ACK_DATA + 128 0051 }; 0052 Q_ENUM(BufferId) 0053 0054 enum ArgumentType { 0055 TYPE_U8 = 0, 0056 TYPE_I8 = 1, 0057 TYPE_U16 = 2, 0058 TYPE_I16 = 3, 0059 TYPE_U32 = 4, 0060 TYPE_I32 = 5, 0061 TYPE_U64 = 6, 0062 TYPE_I64 = 7, 0063 TYPE_FLOAT = 8, 0064 TYPE_DOUBLE = 9, 0065 TYPE_STRING = 10, 0066 TYPE_ENUM = 11 0067 }; 0068 Q_ENUM(ArgumentType) 0069 0070 enum Command { 0071 UnknownCommand = 0, 0072 Ardrone3AccessoryStateBattery = 1, 0073 Ardrone3AnimationsFlip = 2, 0074 Ardrone3AntiflickeringStateelectricFrequencyChanged = 3, 0075 Ardrone3AntiflickeringStatemodeChanged = 4, 0076 Ardrone3AntiflickeringelectricFrequency = 5, 0077 Ardrone3AntiflickeringsetMode = 6, 0078 Ardrone3CameraOrientationV2 = 7, 0079 Ardrone3CameraStateOrientationV2 = 8, 0080 Ardrone3CameraStateVelocityRange = 9, 0081 Ardrone3CameraStatedefaultCameraOrientationV2 = 10, 0082 Ardrone3CameraVelocity = 11, 0083 Ardrone3GPSSettingsHomeType = 12, 0084 Ardrone3GPSSettingsReturnHomeDelay = 13, 0085 Ardrone3GPSSettingsSendControllerGPS = 14, 0086 Ardrone3GPSSettingsStateGPSFixStateChanged = 15, 0087 Ardrone3GPSSettingsStateGeofenceCenterChanged = 16, 0088 Ardrone3GPSSettingsStateHomeChanged = 17, 0089 Ardrone3GPSSettingsStateHomeTypeChanged = 18, 0090 Ardrone3GPSSettingsStateReturnHomeDelayChanged = 19, 0091 Ardrone3GPSStateHomeTypeAvailabilityChanged = 20, 0092 Ardrone3GPSStateHomeTypeChosenChanged = 21, 0093 Ardrone3GPSStateNumberOfSatelliteChanged = 22, 0094 Ardrone3MediaRecordEventPictureEventChanged = 23, 0095 Ardrone3MediaRecordEventVideoEventChanged = 24, 0096 Ardrone3MediaRecordPictureV2 = 25, 0097 Ardrone3MediaRecordStatePictureStateChangedV2 = 26, 0098 Ardrone3MediaRecordStateVideoStateChangedV2 = 27, 0099 Ardrone3MediaRecordVideoV2 = 28, 0100 Ardrone3MediaStreamingStateVideoEnableChanged = 29, 0101 Ardrone3MediaStreamingStateVideoStreamModeChanged = 30, 0102 Ardrone3MediaStreamingVideoEnable = 31, 0103 Ardrone3MediaStreamingVideoStreamMode = 32, 0104 Ardrone3NetworkSettingsStateWifiSelectionChanged = 33, 0105 Ardrone3NetworkSettingsStatewifiSecurity = 34, 0106 Ardrone3NetworkSettingsWifiSelection = 35, 0107 Ardrone3NetworkSettingswifiSecurity = 36, 0108 Ardrone3NetworkStateAllWifiAuthChannelChanged = 37, 0109 Ardrone3NetworkStateAllWifiScanChanged = 38, 0110 Ardrone3NetworkStateWifiAuthChannelListChanged = 39, 0111 Ardrone3NetworkStateWifiScanListChanged = 40, 0112 Ardrone3NetworkWifiAuthChannel = 41, 0113 Ardrone3NetworkWifiScan = 42, 0114 Ardrone3PictureSettingsAutoWhiteBalanceSelection = 43, 0115 Ardrone3PictureSettingsExpositionSelection = 44, 0116 Ardrone3PictureSettingsPictureFormatSelection = 45, 0117 Ardrone3PictureSettingsSaturationSelection = 46, 0118 Ardrone3PictureSettingsStateAutoWhiteBalanceChanged = 47, 0119 Ardrone3PictureSettingsStateExpositionChanged = 48, 0120 Ardrone3PictureSettingsStatePictureFormatChanged = 49, 0121 Ardrone3PictureSettingsStateSaturationChanged = 50, 0122 Ardrone3PictureSettingsStateTimelapseChanged = 51, 0123 Ardrone3PictureSettingsStateVideoAutorecordChanged = 52, 0124 Ardrone3PictureSettingsStateVideoFramerateChanged = 53, 0125 Ardrone3PictureSettingsStateVideoRecordingModeChanged = 54, 0126 Ardrone3PictureSettingsStateVideoResolutionsChanged = 55, 0127 Ardrone3PictureSettingsStateVideoStabilizationModeChanged = 56, 0128 Ardrone3PictureSettingsTimelapseSelection = 57, 0129 Ardrone3PictureSettingsVideoAutorecordSelection = 58, 0130 Ardrone3PictureSettingsVideoFramerate = 59, 0131 Ardrone3PictureSettingsVideoRecordingMode = 60, 0132 Ardrone3PictureSettingsVideoResolutions = 61, 0133 Ardrone3PictureSettingsVideoStabilizationMode = 62, 0134 Ardrone3PilotingCancelMoveTo = 63, 0135 Ardrone3PilotingEmergency = 64, 0136 Ardrone3PilotingEventmoveByEnd = 65, 0137 Ardrone3PilotingFlatTrim = 66, 0138 Ardrone3PilotingLanding = 67, 0139 Ardrone3PilotingNavigateHome = 68, 0140 Ardrone3PilotingPCMD = 69, 0141 Ardrone3PilotingSettingsBankedTurn = 70, 0142 Ardrone3PilotingSettingsMaxAltitude = 71, 0143 Ardrone3PilotingSettingsMaxDistance = 72, 0144 Ardrone3PilotingSettingsMaxTilt = 73, 0145 Ardrone3PilotingSettingsNoFlyOverMaxDistance = 74, 0146 Ardrone3PilotingSettingsSetMotionDetectionMode = 75, 0147 Ardrone3PilotingSettingsStateAutonomousFlightMaxHorizontalAcceleration = 76, 0148 Ardrone3PilotingSettingsStateAutonomousFlightMaxHorizontalSpeed = 77, 0149 Ardrone3PilotingSettingsStateAutonomousFlightMaxRotationSpeed = 78, 0150 Ardrone3PilotingSettingsStateAutonomousFlightMaxVerticalAcceleration = 79, 0151 Ardrone3PilotingSettingsStateAutonomousFlightMaxVerticalSpeed = 80, 0152 Ardrone3PilotingSettingsStateBankedTurnChanged = 81, 0153 Ardrone3PilotingSettingsStateMaxAltitudeChanged = 82, 0154 Ardrone3PilotingSettingsStateMaxDistanceChanged = 83, 0155 Ardrone3PilotingSettingsStateMaxTiltChanged = 84, 0156 Ardrone3PilotingSettingsStateMotionDetection = 85, 0157 Ardrone3PilotingSettingsStateNoFlyOverMaxDistanceChanged = 86, 0158 Ardrone3PilotingSettingssetAutonomousFlightMaxHorizontalAcceleration = 87, 0159 Ardrone3PilotingSettingssetAutonomousFlightMaxHorizontalSpeed = 88, 0160 Ardrone3PilotingSettingssetAutonomousFlightMaxRotationSpeed = 89, 0161 Ardrone3PilotingSettingssetAutonomousFlightMaxVerticalAcceleration = 90, 0162 Ardrone3PilotingSettingssetAutonomousFlightMaxVerticalSpeed = 91, 0163 Ardrone3PilotingStartPilotedPOI = 92, 0164 Ardrone3PilotingStateAlertStateChanged = 93, 0165 Ardrone3PilotingStateAltitudeChanged = 94, 0166 Ardrone3PilotingStateAttitudeChanged = 95, 0167 Ardrone3PilotingStateFlatTrimChanged = 96, 0168 Ardrone3PilotingStateFlyingStateChanged = 97, 0169 Ardrone3PilotingStateGpsLocationChanged = 98, 0170 Ardrone3PilotingStateMotionState = 99, 0171 Ardrone3PilotingStateNavigateHomeStateChanged = 100, 0172 Ardrone3PilotingStatePilotedPOI = 101, 0173 Ardrone3PilotingStatePositionChanged = 102, 0174 Ardrone3PilotingStateReturnHomeBatteryCapacity = 103, 0175 Ardrone3PilotingStateSpeedChanged = 104, 0176 Ardrone3PilotingStatemoveToChanged = 105, 0177 Ardrone3PilotingStopPilotedPOI = 106, 0178 Ardrone3PilotingTakeOff = 107, 0179 Ardrone3PilotingUserTakeOff = 108, 0180 Ardrone3PilotingmoveBy = 109, 0181 Ardrone3PilotingmoveTo = 110, 0182 Ardrone3SettingsStateCPUID = 111, 0183 Ardrone3SettingsStateMotorErrorLastErrorChanged = 112, 0184 Ardrone3SettingsStateMotorErrorStateChanged = 113, 0185 Ardrone3SettingsStateMotorFlightsStatusChanged = 114, 0186 Ardrone3SettingsStateProductGPSVersionChanged = 115, 0187 Ardrone3SoundStartAlertSound = 116, 0188 Ardrone3SoundStateAlertSound = 117, 0189 Ardrone3SoundStopAlertSound = 118, 0190 Ardrone3SpeedSettingsHullProtection = 119, 0191 Ardrone3SpeedSettingsMaxPitchRollRotationSpeed = 120, 0192 Ardrone3SpeedSettingsMaxRotationSpeed = 121, 0193 Ardrone3SpeedSettingsMaxVerticalSpeed = 122, 0194 Ardrone3SpeedSettingsStateHullProtectionChanged = 123, 0195 Ardrone3SpeedSettingsStateMaxPitchRollRotationSpeedChanged = 124, 0196 Ardrone3SpeedSettingsStateMaxRotationSpeedChanged = 125, 0197 Ardrone3SpeedSettingsStateMaxVerticalSpeedChanged = 126, 0198 CommonARLibsVersionsStateControllerLibARCommandsVersion = 127, 0199 CommonARLibsVersionsStateDeviceLibARCommandsVersion = 128, 0200 CommonARLibsVersionsStateSkyControllerLibARCommandsVersion = 129, 0201 CommonCalibrationMagnetoCalibration = 130, 0202 CommonCalibrationStateMagnetoCalibrationAxisToCalibrateChanged = 131, 0203 CommonCalibrationStateMagnetoCalibrationRequiredState = 132, 0204 CommonCalibrationStateMagnetoCalibrationStartedChanged = 133, 0205 CommonCalibrationStateMagnetoCalibrationStateChanged = 134, 0206 CommonCalibrationStatePitotCalibrationStateChanged = 135, 0207 CommonCameraSettingsStateCameraSettingsChanged = 136, 0208 CommonCommonAllStates = 137, 0209 CommonCommonCurrentDate = 138, 0210 CommonCommonCurrentTime = 139, 0211 CommonCommonReboot = 140, 0212 CommonCommonStateAllStatesChanged = 141, 0213 CommonCommonStateBatteryStateChanged = 142, 0214 CommonCommonStateCurrentDateChanged = 143, 0215 CommonCommonStateCurrentTimeChanged = 144, 0216 CommonCommonStateMassStorageContent = 145, 0217 CommonCommonStateMassStorageContentForCurrentRun = 146, 0218 CommonCommonStateMassStorageInfoStateListChanged = 147, 0219 CommonCommonStateMassStorageStateListChanged = 148, 0220 CommonCommonStateSensorsStatesListChanged = 149, 0221 CommonCommonStateVideoRecordingTimestamp = 150, 0222 CommonCommonStateWifiSignalChanged = 151, 0223 CommonControllerisPiloting = 152, 0224 CommonFactoryReset = 153, 0225 CommonFlightPlanEventSpeedBridleEvent = 154, 0226 CommonFlightPlanEventStartingErrorEvent = 155, 0227 CommonFlightPlanSettingsReturnHomeOnDisconnect = 156, 0228 CommonFlightPlanSettingsStateReturnHomeOnDisconnectChanged = 157, 0229 CommonFlightPlanStateAvailabilityStateChanged = 158, 0230 CommonFlightPlanStateComponentStateListChanged = 159, 0231 CommonFlightPlanStateLockStateChanged = 160, 0232 CommonMavlinkPause = 161, 0233 CommonMavlinkStart = 162, 0234 CommonMavlinkStateMavlinkFilePlayingStateChanged = 163, 0235 CommonMavlinkStateMissionItemExecuted = 164, 0236 CommonMavlinkStop = 165, 0237 CommonNetworkEventDisconnection = 166, 0238 CommonOverHeatStateOverHeatRegulationChanged = 167, 0239 CommonRunStateRunIdChanged = 168, 0240 CommonSettingsAllSettings = 169, 0241 CommonSettingsAutoCountry = 170, 0242 CommonSettingsCountry = 171, 0243 CommonSettingsProductName = 172, 0244 CommonSettingsReset = 173, 0245 CommonSettingsStateAllSettingsChanged = 174, 0246 CommonSettingsStateAutoCountryChanged = 175, 0247 CommonSettingsStateCountryChanged = 176, 0248 CommonSettingsStateProductNameChanged = 177, 0249 CommonSettingsStateProductSerialHighChanged = 178, 0250 CommonSettingsStateProductSerialLowChanged = 179, 0251 CommonSettingsStateProductVersionChanged = 180, 0252 CommonSettingsStateResetChanged = 181, 0253 CommonWifiSettingsOutdoorSetting = 182, 0254 CommonWifiSettingsStateoutdoorSettingsChanged = 183, 0255 Bla = 184 0256 }; 0257 Q_ENUM(Command) 0258 }; 0259 0260 class ParrotCommand 0261 { 0262 public: 0263 struct Tuple { 0264 quint8 productId; 0265 quint8 classId; 0266 quint16 commandId; 0267 0268 inline bool operator==(const Tuple &t) const 0269 { 0270 return (productId == t.productId && classId == t.classId && commandId == t.commandId); 0271 } 0272 }; 0273 0274 explicit ParrotCommand(Parrot::Command command, const QVariantList &arguments = QVariantList()); 0275 explicit ParrotCommand(Parrot::Command command, const QByteArray &arguments = QByteArray()); 0276 explicit ParrotCommand(const QByteArray &data); 0277 explicit ParrotCommand(); 0278 ~ParrotCommand(); 0279 0280 QByteArray pack() const; 0281 Parrot::Command id() const; 0282 0283 Tuple tuple; 0284 QByteArray data; 0285 0286 private: 0287 static Parrot::Command commandForTuple(const Tuple &tuple); 0288 static Tuple tupleForCommand(Parrot::Command command); 0289 0290 static QHash<Tuple, Parrot::Command> m_commandForTuple; 0291 static QHash<Parrot::Command, Tuple> m_tupleForCommand; 0292 static QHash<Parrot::Command, QVector<Parrot::ArgumentType>> m_signatureForCommand; 0293 }; 0294 0295 Q_DECLARE_METATYPE(ParrotCommand) 0296 0297 inline uint qHash(const ParrotCommand::Tuple &t) 0298 { 0299 return t.productId * t.classId * t.commandId; 0300 } 0301 0302 class ParrotFrame 0303 { 0304 public: 0305 explicit ParrotFrame(quint8 dataType, quint8 bufferId, quint8 seq, const QByteArray &data = QByteArray()); 0306 explicit ParrotFrame(const QByteArray &data, int start); 0307 ~ParrotFrame(); 0308 0309 QByteArray pack() const; 0310 ParrotCommand command() const; 0311 0312 quint8 dataType = 0; 0313 quint8 bufferId = 0; 0314 quint8 seq = 0; 0315 quint32 size = 0; 0316 QByteArray data; 0317 int retry = 0; // NOTE: Setting to -1 before sending means infinite retries. 0318 };