From 877177ab51320e49cb1ac8632ed7a32c31f27c36 Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Tue, 10 Apr 2018 12:00:35 +0200 Subject: [PATCH] LP-593 Basic check for firmware, tagged and matched firmware with GCS --- .../gcs/src/plugins/uploader/devicewidget.cpp | 16 ++++++-- .../plugins/uploader/runningdevicewidget.cpp | 37 ++++++++++++++++--- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/ground/gcs/src/plugins/uploader/devicewidget.cpp b/ground/gcs/src/plugins/uploader/devicewidget.cpp index e207f4940..0b9587dca 100644 --- a/ground/gcs/src/plugins/uploader/devicewidget.cpp +++ b/ground/gcs/src/plugins/uploader/devicewidget.cpp @@ -26,6 +26,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "devicewidget.h" +#include "version_info/version_info.h" #include #include @@ -216,10 +217,14 @@ bool DeviceWidget::populateBoardStructuredDescription(QByteArray desc) if (UAVObjectUtilManager::descriptionToStructure(desc, onBoardDescription)) { myDevice->lblGitTag->setText(onBoardDescription.gitHash); myDevice->lblBuildDate->setText(onBoardDescription.gitDate.insert(4, "-").insert(7, "-")); - if (onBoardDescription.gitTag.startsWith("RELEASE", Qt::CaseSensitive)) { + if ((onBoardDescription.gitTag == VersionInfo::tag()) && (onBoardDescription.gitHash == VersionInfo::hash8())) { myDevice->lblDescription->setText(onBoardDescription.gitTag); myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/application-certificate.svg")); myDevice->lblCertified->setToolTip(tr("Tagged officially released firmware build")); + } else if ((onBoardDescription.gitTag == VersionInfo::fwTag()) && (onBoardDescription.gitHash == VersionInfo::hash8())) { + myDevice->lblDescription->setText(onBoardDescription.gitTag); + myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/dialog-apply.svg")); + myDevice->lblCertified->setToolTip(tr("Matched firmware build")); } else { myDevice->lblDescription->setText(onBoardDescription.gitTag); myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/warning.svg")); @@ -239,11 +244,16 @@ bool DeviceWidget::populateLoadedStructuredDescription(QByteArray desc) if (UAVObjectUtilManager::descriptionToStructure(desc, LoadedDescription)) { myDevice->lblGitTagL->setText(LoadedDescription.gitHash); myDevice->lblBuildDateL->setText(LoadedDescription.gitDate.insert(4, "-").insert(7, "-")); - if (LoadedDescription.gitTag.startsWith("RELEASE", Qt::CaseSensitive)) { + if ((LoadedDescription.gitTag == VersionInfo::tag()) && (LoadedDescription.gitHash == VersionInfo::hash8())) { myDevice->lblDescritpionL->setText(LoadedDescription.gitTag); myDevice->description->setText(LoadedDescription.gitTag); myDevice->lblCertifiedL->setPixmap(QPixmap(":uploader/images/application-certificate.svg")); myDevice->lblCertifiedL->setToolTip(tr("Tagged officially released firmware build")); + } else if ((LoadedDescription.gitTag == VersionInfo::fwTag()) && (LoadedDescription.gitHash == VersionInfo::hash8())) { + myDevice->lblDescritpionL->setText(LoadedDescription.gitTag); + myDevice->description->setText(LoadedDescription.gitTag); + myDevice->lblCertifiedL->setPixmap(QPixmap(":uploader/images/dialog-apply.svg")); + myDevice->lblCertifiedL->setToolTip(tr("Matched firmware build")); } else { myDevice->lblDescritpionL->setText(LoadedDescription.gitTag); myDevice->description->setText(LoadedDescription.gitTag); @@ -347,7 +357,7 @@ void DeviceWidget::loadFirmware(QString fwfilename) } else if (QDateTime::fromString(onBoardDescription.gitDate) > QDateTime::fromString(LoadedDescription.gitDate)) { myDevice->statusLabel->setText(tr("The board has newer firmware than loaded. Are you sure you want to update?")); px.load(QString(":/uploader/images/warning.svg")); - } else if (!LoadedDescription.gitTag.startsWith("RELEASE", Qt::CaseSensitive)) { + } else if (!(LoadedDescription.gitTag == VersionInfo::tag()) && (onBoardDescription.gitHash == VersionInfo::hash8())) { myDevice->statusLabel->setText(tr("The loaded firmware is untagged or custom build. Update only if it was received from a trusted source (official website or your own build).")); px.load(QString(":/uploader/images/warning.svg")); } else { diff --git a/ground/gcs/src/plugins/uploader/runningdevicewidget.cpp b/ground/gcs/src/plugins/uploader/runningdevicewidget.cpp index 58372ed18..9d6512e72 100644 --- a/ground/gcs/src/plugins/uploader/runningdevicewidget.cpp +++ b/ground/gcs/src/plugins/uploader/runningdevicewidget.cpp @@ -28,6 +28,7 @@ #include "runningdevicewidget.h" #include "devicedescriptorstruct.h" #include "uploadergadgetwidget.h" +#include "version_info/version_info.h" RunningDeviceWidget::RunningDeviceWidget(QWidget *parent) : QWidget(parent) @@ -135,15 +136,41 @@ void RunningDeviceWidget::populate() deviceDescriptorStruct devDesc; if (UAVObjectUtilManager::descriptionToStructure(description, devDesc)) { - if (devDesc.gitTag.startsWith("RELEASE", Qt::CaseSensitive)) { - myDevice->lblFWTag->setText(tr("Firmware tag: ") + devDesc.gitTag); + // Convert current QString uavoHashArray stored in GCS to QByteArray + QString uavoHash = VersionInfo::uavoHashArray(); + + uavoHash.chop(2); + uavoHash.remove(0, 2); + uavoHash = uavoHash.trimmed(); + + QByteArray uavoHashArray; + bool ok; + foreach(QString str, uavoHash.split(",")) { + uavoHashArray.append(str.toInt(&ok, 16)); + } + + bool isCompatibleUavo = (uavoHashArray == devDesc.uavoHash); + bool isTaggedGcs = (VersionInfo::tag() != ""); + bool isSameCommit = (devDesc.gitHash == VersionInfo::hash8()); + bool isSameTag = (devDesc.gitTag == VersionInfo::fwTag()); + + if (isTaggedGcs && isSameCommit && isSameTag && isCompatibleUavo) { + // GCS tagged and firmware from same commit myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/application-certificate.svg")); - myDevice->lblCertified->setToolTip(tr("Tagged officially released firmware build")); - } else { - myDevice->lblFWTag->setText(tr("Firmware tag: ") + devDesc.gitTag); + myDevice->lblCertified->setToolTip(tr("Matched firmware build with official tagged release")); + } else if (!isTaggedGcs && isSameCommit && isSameTag && isCompatibleUavo) { + // GCS untagged and firmware from same commit + myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/dialog-apply.svg")); + myDevice->lblCertified->setToolTip(tr("Matched firmware build")); + } else if ((!isSameCommit || !isSameTag) && isCompatibleUavo) { + // firmware not matching current GCS but compatible UAVO myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/warning.svg")); myDevice->lblCertified->setToolTip(tr("Untagged or custom firmware build")); + } else { + myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/error.svg")); + myDevice->lblCertified->setToolTip(tr("Uncompatible firmware build")); } + myDevice->lblFWTag->setText(tr("Firmware tag: ") + devDesc.gitTag); myDevice->lblGitCommitTag->setText(tr("Git commit hash: ") + devDesc.gitHash); myDevice->lblFWDate->setText(tr("Firmware date: ") + devDesc.gitDate.insert(4, "-").insert(7, "-")); } else {