From 9c4f4c6e4c11aa7fb3f3659a46c797821c6eaa5c Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Tue, 10 Mar 2020 12:11:27 -0700 Subject: [PATCH] More changes to ArduPilot manifest lookup --- src/VehicleSetup/FirmwareUpgrade.qml | 3 +- src/VehicleSetup/FirmwareUpgradeController.cc | 43 ++++++++----------- src/VehicleSetup/FirmwareUpgradeController.h | 2 + 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/VehicleSetup/FirmwareUpgrade.qml b/src/VehicleSetup/FirmwareUpgrade.qml index 178380924..094b30b2f 100644 --- a/src/VehicleSetup/FirmwareUpgrade.qml +++ b/src/VehicleSetup/FirmwareUpgrade.qml @@ -383,8 +383,7 @@ SetupPage { anchors.right: parent.right visible: !px4Flow && apmFlightStack.checked && !controller.downloadingFirmwareList && controller.apmFirmwareNames.length !== 0 model: controller.apmFirmwareNames - - onModelChanged: console.log("model", model) + onModelChanged: currentIndex = controller.apmFirmwareNamesBestIndex } QGCLabel { diff --git a/src/VehicleSetup/FirmwareUpgradeController.cc b/src/VehicleSetup/FirmwareUpgradeController.cc index ae5ec5d01..e04fad68c 100644 --- a/src/VehicleSetup/FirmwareUpgradeController.cc +++ b/src/VehicleSetup/FirmwareUpgradeController.cc @@ -730,52 +730,47 @@ void FirmwareUpgradeController::_buildAPMFirmwareNames(void) QString boardDescription = _foundBoardInfo.description(); quint16 boardVID = _foundBoardInfo.vendorIdentifier(); quint16 boardPID = _foundBoardInfo.productIdentifier(); - -#if 0 - // This is left in for debugging manifest problems - boardDescription = "KakuteF7"; - boardVID = 1155; - boardPID = 22336; -#endif + uint32_t rawBoardId = _bootloaderBoardID == Bootloader::boardIDPX4FMUV3 ? Bootloader::boardIDPX4FMUV2 : _bootloaderBoardID; qCDebug(FirmwareUpgradeLog) << QStringLiteral("_buildAPMFirmwareNames description(%1) vid(%2/0x%3) pid(%4/0x%5)").arg(boardDescription).arg(boardVID).arg(boardVID, 1, 16).arg(boardPID).arg(boardPID, 1, 16); _apmFirmwareNames.clear(); + _apmFirmwareNamesBestIndex = -1; _apmFirmwareUrls.clear(); QString apmDescriptionSuffix("-BL"); + QString boardDescriptionPrefix; bool bootloaderMatch = boardDescription.endsWith(apmDescriptionSuffix); + int currentIndex = 0; for (const ManifestFirmwareInfo_t& firmwareInfo: _rgManifestFirmwareInfo) { bool match = false; - if (firmwareInfo.firmwareBuildType == _selectedFirmwareBuildType && firmwareInfo.chibios == chibios && firmwareInfo.vehicleType == vehicleType) { - if (bootloaderMatch) { - if (firmwareInfo.rgBootloaderPortString.contains(boardDescription)) { - qCDebug(FirmwareUpgradeLog) << "Bootloader match:" << firmwareInfo.friendlyName << boardDescription << firmwareInfo.rgBootloaderPortString << firmwareInfo.url << firmwareInfo.vehicleType; - match = true; - } + if (firmwareInfo.firmwareBuildType == _selectedFirmwareBuildType && firmwareInfo.chibios == chibios && firmwareInfo.vehicleType == vehicleType && firmwareInfo.boardId == rawBoardId) { + if (firmwareInfo.fmuv2 && _bootloaderBoardID == Bootloader::boardIDPX4FMUV3) { + qCDebug(FirmwareUpgradeLog) << "Skipping fmuv2 manifest entry for fmuv3 board:" << firmwareInfo.friendlyName << boardDescription << firmwareInfo.rgBootloaderPortString << firmwareInfo.url << firmwareInfo.vehicleType; } else { - if (firmwareInfo.rgVID.contains(boardVID) && firmwareInfo.rgPID.contains(boardPID)) { - qCDebug(FirmwareUpgradeLog) << "VID/PID match:" << firmwareInfo.friendlyName << boardVID << boardPID << _bootloaderBoardID << firmwareInfo.url << firmwareInfo.vehicleType; - match = true; + qCDebug(FirmwareUpgradeLog) << "Board id match:" << firmwareInfo.friendlyName << boardDescription << firmwareInfo.rgBootloaderPortString << firmwareInfo.url << firmwareInfo.vehicleType; + match = true; + if (bootloaderMatch && _apmFirmwareNamesBestIndex == -1 && firmwareInfo.rgBootloaderPortString.contains(boardDescription)) { + _apmFirmwareNamesBestIndex = currentIndex; + qCDebug(FirmwareUpgradeLog) << "Bootloader best match:" << firmwareInfo.friendlyName << boardDescription << firmwareInfo.rgBootloaderPortString << firmwareInfo.url << firmwareInfo.vehicleType; } } } - // Do a final filter on fmuv2/fmuv3 - if (match && _bootloaderBoardID == Bootloader::boardIDPX4FMUV3) { - match = !firmwareInfo.fmuv2; - } - if (match) { _apmFirmwareNames.append(firmwareInfo.friendlyName); _apmFirmwareUrls.append(firmwareInfo.url); + currentIndex++; } } - if (_apmFirmwareNames.count() > 1) { - _apmFirmwareNames.prepend(tr("Choose board type")); - _apmFirmwareUrls.prepend(QString()); + if (_apmFirmwareNamesBestIndex == -1) { + _apmFirmwareNamesBestIndex++; + if (_apmFirmwareNames.count() > 1) { + _apmFirmwareNames.prepend(tr("Choose board type")); + _apmFirmwareUrls.prepend(QString()); + } } emit apmFirmwareNamesChanged(); diff --git a/src/VehicleSetup/FirmwareUpgradeController.h b/src/VehicleSetup/FirmwareUpgradeController.h index 5a375a9ae..88f20f00a 100644 --- a/src/VehicleSetup/FirmwareUpgradeController.h +++ b/src/VehicleSetup/FirmwareUpgradeController.h @@ -94,6 +94,7 @@ public: Q_PROPERTY(bool px4FlowBoard READ px4FlowBoard NOTIFY boardFound) Q_PROPERTY(FirmwareBuildType_t selectedFirmwareBuildType READ selectedFirmwareBuildType WRITE setSelectedFirmwareBuildType NOTIFY selectedFirmwareBuildTypeChanged) Q_PROPERTY(QStringList apmFirmwareNames MEMBER _apmFirmwareNames NOTIFY apmFirmwareNamesChanged) + Q_PROPERTY(int apmFirmwareNamesBestIndex MEMBER _apmFirmwareNamesBestIndex NOTIFY apmFirmwareNamesChanged) Q_PROPERTY(QStringList apmFirmwareUrls MEMBER _apmFirmwareUrls NOTIFY apmFirmwareNamesChanged) Q_PROPERTY(QString px4StableVersion READ px4StableVersion NOTIFY px4StableVersionChanged) Q_PROPERTY(QString px4BetaVersion READ px4BetaVersion NOTIFY px4BetaVersionChanged) @@ -308,6 +309,7 @@ private: QMap _manifestMavFirmwareVersionTypeToFirmwareBuildTypeMap; QMap _manifestMavTypeToFirmwareVehicleTypeMap; QStringList _apmFirmwareNames; + int _apmFirmwareNamesBestIndex = 0; QStringList _apmFirmwareUrls; Fact* _apmChibiOSSetting; Fact* _apmVehicleTypeSetting; -- 2.22.0