From fb073059ad0dd8756e5839cd5972ee75070a1362 Mon Sep 17 00:00:00 2001 From: PT_Dreamer Date: Mon, 17 Sep 2012 17:08:15 +0100 Subject: [PATCH] GCS-Use uavo definition hash to check for compatability Unfortunately had to change the iap object. --- .../src/plugins/coreplugin/gcsversioninfo.pri | 2 ++ ground/openpilotgcs/src/plugins/plugins.pro | 1 + .../uavobjectutil/devicedescriptorstruct.h | 3 +- .../uavobjectutil/uavobjectutilmanager.cpp | 27 ++++++++++------ .../uavobjectutil/uavobjectutilmanager.h | 2 +- .../src/plugins/uploader/devicewidget.cpp | 4 +-- .../plugins/uploader/runningdevicewidget.cpp | 2 +- .../plugins/uploader/uploadergadgetwidget.cpp | 31 +++++++++++++++---- make/templates/firmwareinfotemplate.c | 3 +- make/templates/gcsversioninfotemplate.h | 2 +- shared/uavobjectdefinition/firmwareiapobj.xml | 2 +- 11 files changed, 55 insertions(+), 24 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/coreplugin/gcsversioninfo.pri b/ground/openpilotgcs/src/plugins/coreplugin/gcsversioninfo.pri index 559dc3528..70bb8e475 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/gcsversioninfo.pri +++ b/ground/openpilotgcs/src/plugins/coreplugin/gcsversioninfo.pri @@ -12,12 +12,14 @@ VERSION_INFO_SCRIPT = $$ROOT_DIR/make/scripts/version-info.py VERSION_INFO_TEMPLATE = $$ROOT_DIR/make/templates/gcsversioninfotemplate.h VERSION_INFO_COMMAND = python \"$$VERSION_INFO_SCRIPT\" + UAVO_DEF_PATH = $$ROOT_DIR/shared/uavobjectdefinition # Create custom version_info target which generates a header version_info.target = $$VERSION_INFO_HEADER version_info.commands = $$VERSION_INFO_COMMAND \ --path=\"$$GCS_SOURCE_TREE\" \ --template=\"$$VERSION_INFO_TEMPLATE\" \ + --uavodir=\"$$UAVO_DEF_PATH\" \ --outfile=\"$$VERSION_INFO_HEADER\" version_info.depends = FORCE QMAKE_EXTRA_TARGETS += version_info diff --git a/ground/openpilotgcs/src/plugins/plugins.pro b/ground/openpilotgcs/src/plugins/plugins.pro index fcd84239d..f107e24b5 100644 --- a/ground/openpilotgcs/src/plugins/plugins.pro +++ b/ground/openpilotgcs/src/plugins/plugins.pro @@ -92,6 +92,7 @@ plugin_uploader.subdir = uploader plugin_uploader.depends = plugin_coreplugin plugin_uploader.depends += plugin_uavobjects plugin_uploader.depends += plugin_rawhid +plugin_uploader.depends += plugin_uavobjectutil SUBDIRS += plugin_uploader #Dial gadget diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/devicedescriptorstruct.h b/ground/openpilotgcs/src/plugins/uavobjectutil/devicedescriptorstruct.h index a2a8bbab7..886ebe649 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectutil/devicedescriptorstruct.h +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/devicedescriptorstruct.h @@ -8,7 +8,8 @@ public: QString gitHash; QString gitDate; QString gitTag; - QString uavoHash; + QByteArray fwHash; + QByteArray uavoHash; int boardType; int boardRevision; static QString idToBoardName(int id) diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp index 6538b0bfc..a5b60e384 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp @@ -257,7 +257,12 @@ FirmwareIAPObj::DataFields UAVObjectUtilManager::getFirmwareIap() int UAVObjectUtilManager::getBoardModel() { FirmwareIAPObj::DataFields firmwareIapData = getFirmwareIap(); - return (firmwareIapData.BoardType << 8) + firmwareIapData.BoardRevision; + qDebug()<<"Board type="<gitHash = QString::number(gitCommitHash, 16); + struc.gitHash = QString::number(gitCommitHash, 16); quint32 gitDate = desc.at(11) & 0xFF; for (int i = 1; i < 4; i++) { gitDate = gitDate << 8; gitDate += desc.at(11-i) & 0xFF; } - struc->gitDate = QDateTime::fromTime_t(gitDate).toUTC().toString("yyyyMMdd HH:mm"); + struc.gitDate = QDateTime::fromTime_t(gitDate).toUTC().toString("yyyyMMdd HH:mm"); QString gitTag = QString(desc.mid(14,26)); - struc->gitTag = gitTag; + struc.gitTag = gitTag; // TODO: check platform compatibility QByteArray targetPlatform = desc.mid(12,2); - struc->boardType = (int)targetPlatform.at(0); - struc->boardRevision = (int)targetPlatform.at(1); - - struc->uavoHash=desc.mid(46,20); + struc.boardType = (int)targetPlatform.at(0); + struc.boardRevision = (int)targetPlatform.at(1); + struc.fwHash.clear(); + struc.fwHash=desc.mid(40,20); + struc.uavoHash.clear(); + struc.uavoHash=desc.mid(60,20); return true; } return false; diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h index 6f71123b8..11f5f0979 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h @@ -68,7 +68,7 @@ public: quint32 getFirmwareCRC(); QByteArray getBoardDescription(); deviceDescriptorStruct getBoardDescriptionStruct(); - static bool descriptionToStructure(QByteArray desc,deviceDescriptorStruct * struc); + static bool descriptionToStructure(QByteArray desc,deviceDescriptorStruct & struc); UAVObjectManager* getObjectManager(); void saveObjectToSD(UAVObject *obj); protected: diff --git a/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp b/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp index dec1fefb7..c944f9a37 100644 --- a/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp +++ b/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp @@ -154,7 +154,7 @@ void deviceWidget::freeze() */ bool deviceWidget::populateBoardStructuredDescription(QByteArray desc) { - if(UAVObjectUtilManager::descriptionToStructure(desc,&onBoardDescription)) + if(UAVObjectUtilManager::descriptionToStructure(desc,onBoardDescription)) { myDevice->lblGitTag->setText(onBoardDescription.gitHash); myDevice->lblBuildDate->setText(onBoardDescription.gitDate.insert(4,"-").insert(7,"-")); @@ -184,7 +184,7 @@ bool deviceWidget::populateBoardStructuredDescription(QByteArray desc) } bool deviceWidget::populateLoadedStructuredDescription(QByteArray desc) { - if(UAVObjectUtilManager::descriptionToStructure(desc,&LoadedDescription)) + if(UAVObjectUtilManager::descriptionToStructure(desc,LoadedDescription)) { myDevice->lblGitTagL->setText(LoadedDescription.gitHash); myDevice->lblBuildDateL->setText( LoadedDescription.gitDate.insert(4,"-").insert(7,"-")); diff --git a/ground/openpilotgcs/src/plugins/uploader/runningdevicewidget.cpp b/ground/openpilotgcs/src/plugins/uploader/runningdevicewidget.cpp index 40be848e7..284345b62 100644 --- a/ground/openpilotgcs/src/plugins/uploader/runningdevicewidget.cpp +++ b/ground/openpilotgcs/src/plugins/uploader/runningdevicewidget.cpp @@ -101,7 +101,7 @@ void runningDeviceWidget::populate() QByteArray description = utilMngr->getBoardDescription(); deviceDescriptorStruct devDesc; - if(UAVObjectUtilManager::descriptionToStructure(description,&devDesc)) + if(UAVObjectUtilManager::descriptionToStructure(description,devDesc)) { if(devDesc.gitTag.startsWith("release",Qt::CaseInsensitive)) { diff --git a/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp b/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp index 1d296946e..afcb32669 100755 --- a/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp @@ -650,16 +650,35 @@ void UploaderGadgetWidget::versionMatchCheck() ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); UAVObjectUtilManager *utilMngr = pm->getObject(); deviceDescriptorStruct boardDescription = utilMngr->getBoardDescriptionStruct(); - + QByteArray uavoHashArray; QString uavoHash = QString::fromLatin1(Core::Constants::UAVOSHA1_STR); - uavoHash.remove( QRegExp("^[0]*") ); - QString gcsVersion = uavoHash; - QString fwVersion = boardDescription.gitHash; + uavoHash.chop(2); + uavoHash.remove(0,2); + uavoHash=uavoHash.trimmed(); + bool ok; + foreach(QString str,uavoHash.split(",")) + { + uavoHashArray.append(str.toInt(&ok,16)); + } - if (boardDescription.uavoHash != uavoHash) { + QByteArray fwVersion; + fwVersion=boardDescription.uavoHash; + if (fwVersion != uavoHashArray) { + QString uavoHashStr; + QString fwVersionStr; + foreach(char i, fwVersion) + { + qDebug()<showMessage(warning); } } diff --git a/make/templates/firmwareinfotemplate.c b/make/templates/firmwareinfotemplate.c index b876b64dd..0f0e22978 100644 --- a/make/templates/firmwareinfotemplate.c +++ b/make/templates/firmwareinfotemplate.c @@ -41,7 +41,8 @@ * 26 bytes: commit tag if it is there, otherwise branch name. '-dirty' may be added if needed. Zero-padded. * ---- 40 bytes limit --- * 20 bytes: SHA1 sum of the firmware. - * 40 bytes: free for now. + * 20 bytes: SHA1 sum of the uavo definitions. + * 20 bytes: free for now. * */ diff --git a/make/templates/gcsversioninfotemplate.h b/make/templates/gcsversioninfotemplate.h index da8a64968..7b7dc8100 100644 --- a/make/templates/gcsversioninfotemplate.h +++ b/make/templates/gcsversioninfotemplate.h @@ -26,7 +26,7 @@ */ #define GCS_REVISION ${TAG_OR_BRANCH}:${HASH8}${DIRTY} ${DATETIME} -#define UAVO_HASH ${UAVOSHA1} +#define UAVO_HASH "{ ${UAVOSHA1} }" /** * @} */ diff --git a/shared/uavobjectdefinition/firmwareiapobj.xml b/shared/uavobjectdefinition/firmwareiapobj.xml index be8431ef5..9ce85bfcf 100644 --- a/shared/uavobjectdefinition/firmwareiapobj.xml +++ b/shared/uavobjectdefinition/firmwareiapobj.xml @@ -2,7 +2,7 @@ Queries board for SN, model, revision, and sends reset command - +