From b61bd5bf31e7a442a846513bc0b7cb4057ff1d3d Mon Sep 17 00:00:00 2001 From: elafargue Date: Sun, 8 May 2011 00:57:59 +0200 Subject: [PATCH] Start of Uploader plugin parsing of packaged firmware. work in progress, not fully working yet. --- .../src/plugins/uploader/devicewidget.cpp | 43 +++++++++++++++++++ .../src/plugins/uploader/devicewidget.h | 2 + .../src/plugins/uploader/devicewidget.ui | 36 +++++++++++----- 3 files changed, 70 insertions(+), 11 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp b/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp index c68ae4a0e..79619c9cf 100644 --- a/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp +++ b/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp @@ -199,6 +199,49 @@ void deviceWidget::uploadFirmware() return; } + // TODO : parse the firmware last 100 bytes and see whether it is + // packaged: + QFile file(filename); + if (!file.open(QIODevice::ReadOnly)) { + status("Can't open file", STATUSICON_FAIL); + return; + } + + QByteArray arr = file.readAll(); + QByteArray desc = arr.right(100); + if (desc.startsWith("OpFw")) { + // This looks like a binary with a description at the end + /* + # 4 bytes: header: "OpFw" + # 4 bytes: GIT commit tag (short version of SHA1) + # 4 bytes: Unix timestamp of compile time + # 2 bytes: target platform. Should follow same rule as BOARD_TYPE and BOARD_REVISION in board define files. + # 26 bytes: commit tag if it is there, otherwise "Unreleased". Zero-padded + # ---- 40 bytes limit --- + # 20 bytes: SHA1 sum of the firmware. + # 40 bytes: free for now. + */ + // I don't want to use structs, ok ? + QByteArray gitCommitTag = desc.mid(4,4); + quint32 buildDate = desc.at(8)&0xFF; + for (int i=1;i<4;i++) { + buildDate = buildDate<<8; + buildDate += desc.at(8+i) & 0xFF; + } + + myDevice->buildDate->setText(QDateTime::fromTime_t(buildDate).toString()); + QByteArray targetPlatform = desc.mid(12,2); + // TODO: check platform compatibility + QString dscText = QString(desc.mid(14,26)); + myDevice->description->setText(dscText); + + return; + + } else { + // TODO : tell the user that the firmware is not packaged. + } + + status("Starting firmware upload", STATUSICON_RUNNING); // We don't know which device was used previously, so we // are cautious and reenter DFU for this deviceID: diff --git a/ground/openpilotgcs/src/plugins/uploader/devicewidget.h b/ground/openpilotgcs/src/plugins/uploader/devicewidget.h index 16c4f7f93..c57ce7548 100644 --- a/ground/openpilotgcs/src/plugins/uploader/devicewidget.h +++ b/ground/openpilotgcs/src/plugins/uploader/devicewidget.h @@ -33,6 +33,8 @@ #include "op_dfu.h" #include #include +#include +#include #include #include diff --git a/ground/openpilotgcs/src/plugins/uploader/devicewidget.ui b/ground/openpilotgcs/src/plugins/uploader/devicewidget.ui index 5007ed0b9..49a152e96 100644 --- a/ground/openpilotgcs/src/plugins/uploader/devicewidget.ui +++ b/ground/openpilotgcs/src/plugins/uploader/devicewidget.ui @@ -19,28 +19,28 @@ - + DeviceID - + 0 - + ReadWrite - + @@ -56,7 +56,7 @@ - + false @@ -66,7 +66,7 @@ - + Update the firmware on this board. @@ -76,7 +76,7 @@ - + Download the current board firmware to your computer @@ -86,28 +86,28 @@ - + BootLoaderVersion - + fwCRC - + MaxCodeSize - + @@ -137,6 +137,20 @@ + + + + Compile Date + + + + + + + Commit tag: + + +