QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
FirmwarePlugin.cc
Go to the documentation of this file.
1#include "FirmwarePlugin.h"
2
3#include <QtCore/QDir>
4#include <QtCore/QFile>
5#include <QtCore/QRegularExpression>
6#include <QtCore/QSettings>
7#include <QtCore/QStandardPaths>
8#include <QtCore/QThread>
9
10#include "AppMessages.h"
11#include "AutoPilotPlugin.h"
12#include "Autotune.h"
14#include "MAVLinkLib.h"
15#include "MAVLinkProtocol.h"
16#include "ParameterMetaData.h"
17#include "QGCApplication.h"
18#include "QGCCameraManager.h"
19#include "QGCCompression.h"
20#include "QGCFileDownload.h"
21#include "QGCFileHelper.h"
22#include "QGCLoggingCategory.h"
23#include "QGCMAVLink.h"
24#include "QGCVersionCheck.h"
25#include "Vehicle.h"
27#include "VehicleComponent.h"
28#include "VehicleLinkManager.h"
29#include "VehicleReadiness.h"
30
31QGC_LOGGING_CATEGORY(FirmwarePluginLog, "FirmwarePlugin.FirmwarePlugin")
32
33static const QString guided_mode_not_supported_by_vehicle = QObject::tr("Guided mode not supported by Vehicle.");
34
36 : QObject(parent)
37{
38 qCDebug(FirmwarePluginLog) << this;
39}
40
42{
43 qCDebug(FirmwarePluginLog) << this;
44}
45
47{
48 return new GenericAutoPilotPlugin(vehicle, vehicle);
49}
50
51QString FirmwarePlugin::flightMode(uint8_t base_mode, uint32_t custom_mode) const
52{
53 Q_UNUSED(custom_mode);
54
55 struct Bit2Name {
56 const uint8_t baseModeBit;
57 const char *name;
58 };
59
60 static constexpr Bit2Name rgBit2Name[] = {
61 { MAV_MODE_FLAG_MANUAL_INPUT_ENABLED, "Manual" },
62 { MAV_MODE_FLAG_STABILIZE_ENABLED, "Stabilize" },
63 { MAV_MODE_FLAG_GUIDED_ENABLED, "Guided" },
64 { MAV_MODE_FLAG_AUTO_ENABLED, "Auto" },
65 { MAV_MODE_FLAG_TEST_ENABLED, "Test" },
66 };
67
68 QString flightMode;
69 if (base_mode == 0) {
70 flightMode = "PreFlight";
71 } else if (base_mode & MAV_MODE_FLAG_CUSTOM_MODE_ENABLED) {
72 flightMode = _modeEnumToString.value(custom_mode, QStringLiteral("Custom:0x%1").arg(custom_mode, 0, 16));
73 } else {
74 for (size_t i = 0; i < std::size(rgBit2Name); i++) {
75 if (base_mode & rgBit2Name[i].baseModeBit) {
76 if (i != 0) {
77 flightMode += " ";
78 }
79 flightMode += rgBit2Name[i].name;
80 }
81 }
82 }
83
84 return flightMode;
85}
86
87bool FirmwarePlugin::setFlightMode(const QString &flightMode, uint8_t *base_mode, uint32_t *custom_mode) const
88{
89 Q_UNUSED(flightMode);
90 Q_UNUSED(base_mode);
91 Q_UNUSED(custom_mode);
92
93 qCWarning(FirmwarePluginLog) << "FirmwarePlugin::setFlightMode called on base class, not supported";
94
95 return false;
96}
97
99{
100 switch (vehicleClass) {
102 return QStringLiteral(":/json/MavCmdInfoCommon.json");
104 return QStringLiteral(":/json/MavCmdInfoFixedWing.json");
106 return QStringLiteral(":/json/MavCmdInfoMultiRotor.json");
108 return QStringLiteral(":/json/MavCmdInfoVTOL.json");
110 return QStringLiteral(":/json/MavCmdInfoSub.json");
112 return QStringLiteral(":/json/MavCmdInfoRover.json");
113 default:
114 qCWarning(FirmwarePluginLog) << "FirmwarePlugin::missionCommandOverrides called with bad VehicleClass_t:" << vehicleClass;
115 return QString();
116 }
117}
118
119void FirmwarePlugin::setGuidedMode(Vehicle *vehicle, bool guidedMode) const
120{
121 Q_UNUSED(vehicle);
122 Q_UNUSED(guidedMode);
124}
125
127{
128 Q_UNUSED(vehicle);
130}
131
132void FirmwarePlugin::guidedModeRTL(Vehicle *vehicle, bool smartRTL) const
133{
134 Q_UNUSED(vehicle);
135 Q_UNUSED(smartRTL);
137}
138
140{
141 Q_UNUSED(vehicle);
143}
144
145void FirmwarePlugin::guidedModeTakeoff(Vehicle *vehicle, double takeoffAltRel) const
146{
147 Q_UNUSED(vehicle);
148 Q_UNUSED(takeoffAltRel);
150}
151
152bool FirmwarePlugin::guidedModeGotoLocation(Vehicle *vehicle, const QGeoCoordinate &gotoCoord, double forwardFlightLoiterRadius) const
153{
154 Q_UNUSED(vehicle);
155 Q_UNUSED(gotoCoord);
156 Q_UNUSED(forwardFlightLoiterRadius);
158 return false;
159}
160
166
171
176
177void FirmwarePlugin::guidedModeChangeHeading(Vehicle *vehicle, const QGeoCoordinate &/*headingCoord*/) const
178{
179 Q_UNUSED(vehicle);
181}
182
183bool FirmwarePlugin::guidedModeROI(Vehicle *vehicle, const QGeoCoordinate &roiCenterCoord, double relativeAltitudeMeters) const
184{
185 // MAVLink spec path: firmware honors the frame in the command
186 _sendROICommand(vehicle, roiCenterCoord, MAV_FRAME_GLOBAL_RELATIVE_ALT, static_cast<float>(relativeAltitudeMeters));
187 return true;
188}
189
190void FirmwarePlugin::_sendROICommand(Vehicle *vehicle, const QGeoCoordinate &coord, MAV_FRAME frame, float altitude) const
191{
192 qCDebug(FirmwarePluginLog) << "_sendROICommand: lat" << coord.latitude() << "lon" << coord.longitude()
193 << "frame" << frame << "altitude" << altitude;
194
195 if (vehicle->capabilityBits() & MAV_PROTOCOL_CAPABILITY_COMMAND_INT) {
196 vehicle->sendMavCommandInt(
197 vehicle->defaultComponentId(),
198 MAV_CMD_DO_SET_ROI_LOCATION,
199 frame,
200 true, // show error if fails
201 static_cast<float>(qQNaN()),
202 static_cast<float>(qQNaN()),
203 static_cast<float>(qQNaN()),
204 static_cast<float>(qQNaN()),
205 coord.latitude(),
206 coord.longitude(),
207 altitude);
208 } else {
209 vehicle->sendMavCommand(
210 vehicle->defaultComponentId(),
211 MAV_CMD_DO_SET_ROI_LOCATION,
212 true, // show error if fails
213 static_cast<float>(qQNaN()),
214 static_cast<float>(qQNaN()),
215 static_cast<float>(qQNaN()),
216 static_cast<float>(qQNaN()),
217 static_cast<float>(coord.latitude()),
218 static_cast<float>(coord.longitude()),
219 altitude);
220 }
221}
222
224{
225 // Not supported by generic vehicle
227}
228
233
240
241const QVariantList &FirmwarePlugin::toolIndicators(const Vehicle*)
242{
243 //-- Default list of indicators for all vehicles.
244 if (_toolIndicatorList.isEmpty()) {
245 _toolIndicatorList = QVariantList({
246 QVariant::fromValue(QUrl::fromUserInput("qrc:/qml/QGroundControl/Toolbar/TelemetryRSSIIndicator.qml")),
247 QVariant::fromValue(QUrl::fromUserInput("qrc:/qml/QGroundControl/Toolbar/RCRSSIIndicator.qml")),
248 QVariant::fromValue(QUrl::fromUserInput("qrc:/qml/QGroundControl/Toolbar/BatteryIndicator.qml")),
249 QVariant::fromValue(QUrl::fromUserInput("qrc:/qml/QGroundControl/Toolbar/RemoteIDIndicator.qml")),
250 QVariant::fromValue(QUrl::fromUserInput("qrc:/qml/QGroundControl/Toolbar/GimbalIndicator.qml")),
251 QVariant::fromValue(QUrl::fromUserInput("qrc:/qml/QGroundControl/Toolbar/EscIndicator.qml")),
252 QVariant::fromValue(QUrl::fromUserInput("qrc:/qml/QGroundControl/Toolbar/JoystickIndicator.qml")),
253 QVariant::fromValue(QUrl::fromUserInput("qrc:/qml/QGroundControl/Toolbar/MultiVehicleSelector.qml")),
254#ifdef QT_DEBUG
255 // ControlIndicator is only available in debug builds for the moment
256 QVariant::fromValue(QUrl::fromUserInput("qrc:/qml/QGroundControl/Toolbar/GCSControlIndicator.qml")),
257#endif
258 });
259 }
260
261 return _toolIndicatorList;
262}
263
265{
266 if (vehicle->armed()) {
267 return true;
268 }
269
270 bool vehicleArmed = false;
271
272 // Only try arming the vehicle a single time. Doing retries on arming with a delay can lead to safety issues.
273 vehicle->setArmed(true, false /* showError */);
274
275 // Wait 1500 msecs for vehicle to arm (waiting for the next heartbeat)
276 for (int i = 0; i < 15; i++) {
277 if (vehicle->armed()) {
278 vehicleArmed = true;
279 break;
280 }
281 QThread::msleep(100);
282 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
283 }
284
285 return vehicleArmed;
286}
287
289{
290 if (vehicle->flightMode() == flightMode) {
291 return true;
292 }
293
294 bool flightModeChanged = false;
295
296 // We try 3 times
297 for (int retries = 0; retries < 3; retries++) {
298 vehicle->setFlightMode(flightMode);
299
300 // Wait for vehicle to return flight mode
301 for (int i = 0; i < 13; i++) {
302 if (vehicle->flightMode() == flightMode) {
303 flightModeChanged = true;
304 break;
305 }
306 QThread::msleep(100);
307 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
308 }
309
310 if (flightModeChanged) {
311 break;
312 }
313 }
314
315 return flightModeChanged;
316}
317
318
319void FirmwarePlugin::batteryConsumptionData(Vehicle *vehicle, int &mAhBattery, double &hoverAmps, double &cruiseAmps) const
320{
321 Q_UNUSED(vehicle);
322 mAhBattery = 0;
323 hoverAmps = 0;
324 cruiseAmps = 0;
325}
326
327bool FirmwarePlugin::hasGimbal(Vehicle *vehicle, bool &rollSupported, bool &pitchSupported, bool &yawSupported) const
328{
329 Q_UNUSED(vehicle);
330 rollSupported = false;
331 pitchSupported = false;
332 yawSupported = false;
333 return false;
334}
335
337{
338 return new QGCCameraManager(vehicle);
339}
340
342{
343 return new VehicleCameraControl(info, vehicle, compID, parent);
344}
345
347{
348 // This is required as mocklink uses a hardcoded firmware version
349 if (QGC::runningUnitTests()) {
350 qCDebug(FirmwarePluginLog) << "Skipping version check";
351 return;
352 }
353
354 const QString versionFile = _getLatestVersionFileUrl(vehicle);
355 qCDebug(FirmwarePluginLog) << "Downloading" << versionFile;
356 QGCFileDownload *const downloader = new QGCFileDownload(vehicle);
357 (void) connect(downloader, &QGCFileDownload::finished, this, [vehicle, this, versionFile](bool success, const QString &localFile, const QString &errorMsg) {
358 if (success) {
359 _versionFileDownloadFinished(versionFile, localFile, vehicle);
360 } else if (!errorMsg.isEmpty()) {
361 qCDebug(FirmwarePluginLog) << "Failed to download the latest fw version file. Error:" << errorMsg;
362 }
363 sender()->deleteLater();
364 });
365
366 if (!downloader->start(versionFile)) {
367 downloader->deleteLater();
368 }
369}
370
371void FirmwarePlugin::_versionFileDownloadFinished(const QString& remoteFile, const QString& localFile,
372 Vehicle* vehicle) const
373{
374 qCDebug(FirmwarePluginLog) << "Download complete" << remoteFile << localFile;
375 // Now read the version file and pull out the version string
376 QFile versionFile(localFile);
377 if (!versionFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
378 qCWarning(FirmwarePluginLog) << "Error opening downloaded version file.";
379 return;
380 }
381
382 QTextStream stream(&versionFile);
383 const QString versionFileContents = stream.readAll();
384 QString version;
385 const QRegularExpressionMatch match = QRegularExpression(_versionRegex()).match(versionFileContents);
386
387 qCDebug(FirmwarePluginLog) << "Looking for version number...";
388
389 if (match.hasMatch()) {
390 version = match.captured(1);
391 } else {
392 qCWarning(FirmwarePluginLog) << "Unable to parse version info from file" << remoteFile;
393 return;
394 }
395
396 qCDebug(FirmwarePluginLog) << "Latest stable version = " << version;
397
398 const int currType = vehicle->firmwareVersionType();
399
400 // Check if lower version than stable or same version but different type
401 if ((currType == FIRMWARE_VERSION_TYPE_OFFICIAL) && (vehicle->versionCompare(version) < 0)) {
402 const QString currentVersionNumber = QStringLiteral("%1.%2.%3").arg(vehicle->firmwareMajorVersion())
403 .arg(vehicle->firmwareMinorVersion())
404 .arg(vehicle->firmwarePatchVersion());
405 vehicle->setNewStableFirmwareVersion(version);
406
407 QSettings settings;
408 settings.beginGroup(QStringLiteral("LastNotifiedStableFirmware"));
409 const QString settingsKey = stableFirmwareSettingsKey(vehicle);
410 if (!isStableFirmwareVersionUnseen(version, settings.value(settingsKey).toString())) {
411 return;
412 }
413 settings.setValue(settingsKey, version);
414
415 QGC::showAppMessage(tr("Vehicle is not running latest stable firmware! Running %1, latest stable is %2.").arg(currentVersionNumber, version));
416 }
417}
418
420{
421 return QStringLiteral("%1_%2").arg(QString::fromLatin1(QGCMAVLink::firmwareClassToCanonicalString(
425}
426
427bool FirmwarePlugin::isStableFirmwareVersionUnseen(const QString& latestVersion, const QString& seenVersion)
428{
429 // Firmware version strings lack the "v" prefix QGCVersionCheck parses
430 return QGCVersionCheck::shouldNotify(QStringLiteral("v") + latestVersion, QStringLiteral("v") + seenVersion);
431}
432
433int FirmwarePlugin::versionCompare(const Vehicle *vehicle, int major, int minor, int patch) const
434{
435 const int currMajor = vehicle->firmwareMajorVersion();
436 const int currMinor = vehicle->firmwareMinorVersion();
437 const int currPatch = vehicle->firmwarePatchVersion();
438
439 if ((currMajor == major) && (currMinor == minor) && (currPatch == patch)) {
440 return 0;
441 }
442
443 if ((currMajor > major)
444 || ((currMajor == major) && (currMinor > minor))
445 || ((currMajor == major) && (currMinor == minor) && (currPatch > patch)))
446 {
447 return 1;
448 }
449
450 return -1;
451}
452
453int FirmwarePlugin::versionCompare(const Vehicle *vehicle, const QString &compare) const
454{
455 const QStringList versionNumbers = compare.split(".");
456 if (versionNumbers.size() != 3) {
457 qCWarning(FirmwarePluginLog) << "Error parsing version number: wrong format";
458 return -1;
459 }
460
461 const int major = versionNumbers[0].toInt();
462 const int minor = versionNumbers[1].toInt();
463 const int patch = versionNumbers[2].toInt();
464
465 return versionCompare(vehicle, major, minor, patch);
466}
467
468void FirmwarePlugin::sendGCSMotionReport(Vehicle *vehicle, const FollowMe::GCSMotionReport &motionReport, uint8_t estimationCapabilities) const
469{
470 const float altitude = static_cast<float>(motionReport.altMetersAMSL);
471 if (!vehicle || !qIsFinite(altitude)) {
472 qCDebug(FirmwarePluginLog) << "Follow target requires a vehicle and finite altitude";
473 return;
474 }
475 SharedLinkInterfacePtr sharedLink = vehicle->vehicleLinkManager()->primaryLink().lock();
476 if (!sharedLink) {
477 return;
478 }
479
480 mavlink_follow_target_t follow_target{};
481
482 follow_target.timestamp = qgcApp()->msecsSinceBoot();
483 follow_target.est_capabilities = estimationCapabilities;
484 follow_target.position_cov[0] = static_cast<float>(motionReport.pos_std_dev[0]);
485 follow_target.position_cov[2] = static_cast<float>(motionReport.pos_std_dev[2]);
486 follow_target.alt = altitude;
487 follow_target.lat = motionReport.lat_int;
488 follow_target.lon = motionReport.lon_int;
489 follow_target.vel[0] = static_cast<float>(motionReport.vxMetersPerSec);
490 follow_target.vel[1] = static_cast<float>(motionReport.vyMetersPerSec);
491
492 mavlink_message_t message{};
493 mavlink_msg_follow_target_encode_chan(MAVLinkProtocol::instance()->getSystemId(),
494 static_cast<uint8_t>(MAVLinkProtocol::getComponentId()),
495 sharedLink->mavlinkChannel(), &message, &follow_target);
496
497 (void) vehicle->sendMessageOnLinkThreadSafe(sharedLink.get(), message);
498}
499
501{
502 return new Autotune(vehicle);
503}
504
506{
507 return new VehicleReadiness(vehicle);
508}
509
511{
512 _flightModeList.clear();
513 _modeEnumToString.clear();
514
515 for (FirmwareFlightMode &flightMode : flightModeList) {
516 _modeEnumToString[flightMode.custom_mode] = flightMode.mode_name;
518 }
519
521 qCDebug(FirmwarePluginLog) << "Flight Mode:" << flightMode.mode_name << " Custom Mode:" << flightMode.custom_mode;
522 }
523}
524
526{
527 for (const FirmwareFlightMode &existingFlightMode : _flightModeList) {
528 if (existingFlightMode.custom_mode == newFlightMode.custom_mode) {
529 qCDebug(FirmwarePluginLog) << "Flight Mode:" << newFlightMode.mode_name << " Custom Mode:" << newFlightMode.custom_mode
530 << " already exists, not adding again.";
531 return;
532 }
533 }
534 _flightModeList += newFlightMode;
535}
536
537/*===========================================================================*/
538
539static constexpr const char *kCachedMetaDataFilePrefix = "ParameterFactMetaData";
540
541static QDir _parameterMetaDataCacheDir(bool ensureExists = false)
542{
543 const QString path = QStandardPaths::writableLocation(QStandardPaths::CacheLocation)
544 + QStringLiteral("/ParameterMetaData");
545 if (ensureExists) {
547 }
548 return QDir(path);
549}
550
552{
554 if (!metaData) {
555 if (_autopilotType() == MAV_AUTOPILOT_GENERIC) {
556 qCDebug(FirmwarePluginLog) << "No parameter metadata parser for firmware plugin" << this << "(expected for generic firmware)";
557 } else {
558 qCWarning(FirmwarePluginLog) << "No parameter metadata parser for firmware plugin" << this;
559 }
560 return nullptr;
561 }
562
563 const QString metaDataFile = _cachedParameterMetaDataFile(vehicle);
564 if (!metaDataFile.isEmpty()) {
565 metaData->loadParameterFactMetaDataFile(metaDataFile);
566 }
567 return metaData;
568}
569
571{
572 const MAV_AUTOPILOT autopilot = _autopilotType();
573 if (autopilot == MAV_AUTOPILOT_GENERIC) {
574 return _internalParameterMetaDataFile(vehicle);
575 }
576
577 const QString internalFile = _internalParameterMetaDataFile(vehicle);
578 // Tests always use the bundled file; resolving its version parses the whole file.
579 if (QGC::runningUnitTests()) {
580 qCDebug(FirmwarePluginLog) << "Using internal parameter metadata:" << internalFile;
581 return internalFile;
582 }
583
584 QVersionNumber internalVersion = ParameterMetaData::versionFromFileName(internalFile);
585 if (internalVersion.isNull()) {
586 internalVersion = ParameterMetaData::versionFromMetaDataFile(internalFile);
587 }
588
589 // Without a known internal version we can't safely compare against
590 // cache — use the bundled file to avoid stale overrides.
591 if (internalVersion.isNull()) {
592 qCDebug(FirmwarePluginLog) << "Using internal parameter metadata:" << internalFile;
593 return internalFile;
594 }
595
596 const int wantedMajorVersion = internalVersion.majorVersion();
597
598 const QDir cacheDir = _parameterMetaDataCacheDir();
599 const QString wildcard = QStringLiteral("%1_%2.*.json").arg(kCachedMetaDataFilePrefix).arg(autopilot);
600 const QStringList entries = cacheDir.entryList(QStringList(wildcard), QDir::Files);
601
602 QString bestFile;
603 QVersionNumber bestVersion;
604 for (const QString &entry : entries) {
605 const QVersionNumber ver = ParameterMetaData::versionFromFileName(entry);
606 if (ver.isNull() || ver.majorVersion() != wantedMajorVersion) {
607 continue;
608 }
609 if (bestVersion.isNull() || ver > bestVersion) {
610 bestVersion = ver;
611 bestFile = cacheDir.filePath(entry);
612 }
613 }
614
615 if (bestFile.isEmpty()) {
616 qCDebug(FirmwarePluginLog) << "No cached parameter metadata found, using internal:" << internalFile;
617 return internalFile;
618 }
619
620 if (internalVersion.majorVersion() == wantedMajorVersion && bestVersion <= internalVersion) {
621 qCDebug(FirmwarePluginLog) << "Internal metadata" << internalVersion.toString() << ">= cache" << bestVersion.toString()
622 << "— using internal:" << internalFile;
623 return internalFile;
624 }
625 qCDebug(FirmwarePluginLog) << "Using cached parameter metadata" << bestVersion.toString() << ":" << bestFile;
626 return bestFile;
627}
628
629void FirmwarePlugin::cacheParameterMetaDataFile(const QString &metaDataFile)
630{
631 const MAV_AUTOPILOT autopilot = _autopilotType();
632 if (autopilot == MAV_AUTOPILOT_GENERIC) {
633 return;
634 }
635
636 QString readError;
637 const QByteArray data = QGCCompression::readFile(metaDataFile, &readError);
638 if (data.isEmpty()) {
639 qCWarning(FirmwarePluginLog) << "Cannot cache parameter metadata: failed to read" << metaDataFile << readError;
640 return;
641 }
642
643 // Reject non-JSON content (e.g. XML from older PX4 firmware images)
644 // and extract the catalog version in a single parse pass.
645 bool validJson = false;
646 QVersionNumber newVersion = ParameterMetaData::versionFromJsonData(data, &validJson);
647 if (!validJson) {
648 qCDebug(FirmwarePluginLog) << "Skipping cache of non-JSON parameter metadata:" << metaDataFile;
649 return;
650 }
651 if (newVersion.isNull()) {
652 // Valid JSON but no version stamps — use fallback so unversioned
653 // files still get cached with a major version that matches the
654 // default wantedMajorVersion in _cachedParameterMetaDataFile.
655 newVersion = QVersionNumber(1, 0);
656 }
657
658 const int majorVersion = newVersion.majorVersion();
659 const QDir cacheDir = _parameterMetaDataCacheDir(true);
660
661 const QString wildcard = QStringLiteral("%1_%2.%3.*.json").arg(kCachedMetaDataFilePrefix).arg(autopilot).arg(majorVersion);
662 const QStringList existing = cacheDir.entryList(QStringList(wildcard), QDir::Files);
663
664 for (const QString &file : existing) {
665 const QVersionNumber existingVersion = ParameterMetaData::versionFromFileName(file);
666 // Strict less-than: equal versions are replaced so that
667 // re-flashing with corrected metadata (same version stamp)
668 // updates the cache.
669 if (!existingVersion.isNull() && newVersion < existingVersion) {
670 return;
671 }
672 }
673
674 const QString cachePath = cacheDir.filePath(
675 QStringLiteral("%1_%2.%3.%4.json").arg(kCachedMetaDataFilePrefix).arg(autopilot).arg(majorVersion).arg(newVersion.minorVersion()));
676 if (!QGCFileHelper::atomicWrite(cachePath, data)) {
677 qCWarning(FirmwarePluginLog) << "Failed to cache parameter metadata to" << cachePath;
678 return;
679 }
680
681 for (const QString &file : existing) {
682 const QString fullPath = cacheDir.filePath(file);
683 if (fullPath != cachePath && !QFile::remove(fullPath)) {
684 qCWarning(FirmwarePluginLog) << "Failed to remove old cache file:" << file;
685 }
686 }
687}
688
689/*===========================================================================*/
690
static constexpr const char * kCachedMetaDataFilePrefix
static const QString guided_mode_not_supported_by_vehicle
static QDir _parameterMetaDataCacheDir(bool ensureExists=false)
QList< FirmwareFlightMode > FlightModeList
std::shared_ptr< LinkInterface > SharedLinkInterfacePtr
#define qgcApp()
struct __mavlink_message mavlink_message_t
Unified file download utility with decompression, verification, and QML support.
#define QGC_LOGGING_CATEGORY(name, categoryStr)
struct __mavlink_camera_information_t mavlink_camera_information_t
The AutoPilotPlugin class is an abstract base class which represents the methods and objects which ar...
virtual CommandSupportedResult anyVersionSupportsCommand(MAV_CMD) const
CommandSupportedResult getCommandSupported(MAV_CMD cmd) const
virtual void guidedModeChangeEquivalentAirspeedMetersSecond(Vehicle *vehicle, double airspeed_equiv) const
virtual void guidedModeChangeAltitude(Vehicle *vehicle, double altitudeChange, bool pauseVehicle)
virtual void startMission(Vehicle *vehicle) const
Command the vehicle to start the mission.
virtual void checkIfIsLatestStable(Vehicle *vehicle) const
Used to check if running firmware is latest stable version.
FlightModeList _flightModeList
virtual const QVariantList & toolIndicators(const Vehicle *vehicle)
virtual void guidedModeChangeGroundSpeedMetersSecond(Vehicle *vehicle, double groundspeed) const
virtual VehicleReadiness * createVehicleReadiness(Vehicle *vehicle) const
virtual bool setFlightMode(const QString &flightMode, uint8_t *base_mode, uint32_t *custom_mode) const
virtual ~FirmwarePlugin()
virtual void _versionFileDownloadFinished(const QString &remoteFile, const QString &localFile, Vehicle *vehicle) const
Callback to process file with latest release information.
virtual void guidedModeTakeoff(Vehicle *vehicle, double takeoffAltRel) const
Command vehicle to takeoff from current location to the specified height.
void _sendROICommand(Vehicle *vehicle, const QGeoCoordinate &coord, MAV_FRAME frame, float altitude) const
Build + send MAV_CMD_DO_SET_ROI_LOCATION (COMMAND_INT when the vehicle supports it).
void cacheParameterMetaDataFile(const QString &metaDataFile)
virtual QString missionCommandOverrides(QGCMAVLinkTypes::VehicleClass_t vehicleClass) const
bool _setFlightModeAndValidate(Vehicle *vehicle, const QString &flightMode) const
virtual QString _internalParameterMetaDataFile(const Vehicle *) const
virtual QString _getLatestVersionFileUrl(Vehicle *) const
returns url with latest firmware release information.
void _updateFlightModeList(FlightModeList &flightModeList)
virtual void guidedModeChangeHeading(Vehicle *vehicle, const QGeoCoordinate &headingCoord) const
Command vehicle to rotate towards specified location.
virtual bool guidedModeGotoLocation(Vehicle *vehicle, const QGeoCoordinate &gotoCoord, double forwardFlightLoiterRadius=0.0) const
static QString stableFirmwareSettingsKey(const Vehicle *vehicle)
Settings key identifying the stable firmware stream (firmware + vehicle class) for this vehicle.
virtual QString flightMode(uint8_t base_mode, uint32_t custom_mode) const
virtual void startTakeoff(Vehicle *vehicle) const
Command the vehicle to start a takeoff.
void _addNewFlightMode(FirmwareFlightMode &flightMode)
virtual void pauseVehicle(Vehicle *vehicle) const
virtual MAV_AUTOPILOT _autopilotType() const
int versionCompare(const Vehicle *vehicle, const QString &compare) const
virtual Autotune * createAutotune(Vehicle *vehicle) const
Creates Autotune object.
static bool isStableFirmwareVersionUnseen(const QString &latestVersion, const QString &seenVersion)
ParameterMetaData * loadParameterMetaData(const Vehicle *vehicle)
virtual AutoPilotPlugin * autopilotPlugin(Vehicle *vehicle) const
virtual void guidedModeRTL(Vehicle *vehicle, bool smartRTL) const
Command vehicle to return to launch.
virtual ParameterMetaData * _createParameterMetaData()
virtual QString _versionRegex() const
Returns regex QString to extract version information from text.
bool _armVehicleAndValidate(Vehicle *vehicle) const
QVariantList _toolIndicatorList
QString _cachedParameterMetaDataFile(const Vehicle *vehicle) const
virtual void setGuidedMode(Vehicle *vehicle, bool guidedMode) const
Set guided flight mode.
FlightModeCustomModeMap _modeEnumToString
virtual bool guidedModeROI(Vehicle *vehicle, const QGeoCoordinate &roiCenterCoord, double relativeAltitudeMeters) const
virtual void batteryConsumptionData(Vehicle *vehicle, int &mAhBattery, double &hoverAmps, double &cruiseAmps) const
virtual QGCCameraManager * createCameraManager(Vehicle *vehicle) const
Creates vehicle camera manager.
virtual void sendGCSMotionReport(Vehicle *vehicle, const FollowMe::GCSMotionReport &motionReport, uint8_t estimationCapabilities) const
Sends the appropriate mavlink message for follow me support.
QMap< int, remapParamNameMinorVersionRemapMap_t > remapParamNameMajorVersionMap_t
virtual const remapParamNameMajorVersionMap_t & paramNameRemapMajorVersionMap() const
virtual void guidedModeLand(Vehicle *vehicle) const
Command vehicle to land at current location.
FirmwarePlugin(QObject *parent=nullptr)
virtual MavlinkCameraControlInterface * createCameraControl(const mavlink_camera_information_t *info, Vehicle *vehicle, int compID, QObject *parent=nullptr) const
Camera control.
virtual bool hasGimbal(Vehicle *vehicle, bool &rollSupported, bool &pitchSupported, bool &yawSupported) const
This is the generic implementation of the AutoPilotPlugin class for mavs we do not have a specific Au...
static int getComponentId()
static MAVLinkProtocol * instance()
Abstract base class for all camera controls: real and simulated.
static QVersionNumber versionFromMetaDataFile(const QString &metaDataFile)
static QVersionNumber versionFromJsonData(const QByteArray &jsonData)
void loadParameterFactMetaDataFile(const QString &metaDataFile)
static QVersionNumber versionFromFileName(const QString &fileName)
Camera Manager.
File download with progress, decompression, and hash verification.
void finished(bool success, const QString &localPath, const QString &errorMessage)
bool start(const QString &remoteUrl)
static bool shouldNotify(const QString &latestVersion, const QString &lastNotifiedVersion)
MAVLink Camera API controller - connected to a real mavlink v2 camera.
WeakLinkInterfacePtr primaryLink() const
Whether the vehicle would accept the Arm, Takeoff and Start Mission guided actions.
void sendMavCommand(int compId, MAV_CMD command, bool showError, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, float param5=0.0f, float param6=0.0f, float param7=0.0f)
Definition Vehicle.cc:2196
QString flightMode() const
Definition Vehicle.cc:1515
void setNewStableFirmwareVersion(const QString &version)
Definition Vehicle.cc:2388
uint64_t capabilityBits() const
Definition Vehicle.h:732
MAV_TYPE vehicleType() const
Definition Vehicle.h:449
VehicleLinkManager * vehicleLinkManager()
Definition Vehicle.h:602
void sendMavCommandInt(int compId, MAV_CMD command, MAV_FRAME frame, bool showError, float param1, float param2, float param3, float param4, double param5, double param6, float param7)
Definition Vehicle.cc:2225
int firmwareMinorVersion() const
Definition Vehicle.h:685
MAV_AUTOPILOT firmwareType() const
Definition Vehicle.h:448
bool sendMessageOnLinkThreadSafe(LinkInterface *link, mavlink_message_t message)
Definition Vehicle.cc:1431
void setFlightMode(const QString &flightMode)
Definition Vehicle.cc:1525
int firmwareVersionType() const
Definition Vehicle.h:687
int defaultComponentId() const
Definition Vehicle.h:705
int firmwarePatchVersion() const
Definition Vehicle.h:686
bool armed() const
Definition Vehicle.h:470
Q_INVOKABLE int versionCompare(const QString &compare) const
Used to check if running current version is equal or higher than the one being compared.
Definition Vehicle.cc:2833
int firmwareMajorVersion() const
Definition Vehicle.h:684
void setArmed(bool armed, bool showError)
Definition Vehicle.cc:1486
QByteArray readFile(const QString &filePath, QString *errorString, qint64 maxBytes)
Read file contents, transparently decompressing .gz/.xz/.zst/.bz2/.lz4 files.
bool atomicWrite(const QString &filePath, const QByteArray &data)
bool ensureDirectoryExists(const QString &path)
bool runningUnitTests()
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.
Definition AppMessages.cc:9
static constexpr VehicleClass_t VehicleClassGeneric