Unverified Commit ef99212f authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #8869 from DonLakeFlyer/GzipManifest

Gzip ArduPilot manifest support
parents f8dd44d3 7e42330d
...@@ -108,6 +108,14 @@ SOURCES += \ ...@@ -108,6 +108,14 @@ SOURCES += \
libs/shapelib/shpopen.c \ libs/shapelib/shpopen.c \
libs/shapelib/safileio.c libs/shapelib/safileio.c
#
# [REQUIRED] zlib library
Windows {
INCLUDEPATH += $$SOURCE_DIR/libszlib/windows/include
LIBS += -L$$SOURCE_DIR/libszlib/windows/lib
}
LIBS += -lz
# #
# [REQUIRED] SDL dependency. Provides joystick/gamepad support. # [REQUIRED] SDL dependency. Provides joystick/gamepad support.
# The SDL is packaged with QGC for the Mac and Windows. Linux support requires installing the SDL # The SDL is packaged with QGC for the Mac and Windows. Linux support requires installing the SDL
...@@ -143,7 +151,7 @@ contains(DEFINES, QGC_ENABLE_PAIRING) { ...@@ -143,7 +151,7 @@ contains(DEFINES, QGC_ENABLE_PAIRING) {
exists(/usr/local/Cellar/openssl/1.0.2t/include) { exists(/usr/local/Cellar/openssl/1.0.2t/include) {
INCLUDEPATH += /usr/local/Cellar/openssl/1.0.2t/include INCLUDEPATH += /usr/local/Cellar/openssl/1.0.2t/include
LIBS += -L/usr/local/Cellar/openssl/1.0.2t/lib LIBS += -L/usr/local/Cellar/openssl/1.0.2t/lib
LIBS += -lcrypto -lz LIBS += -lcrypto
} else { } else {
# There is some circular reference settings going on between QGCExternalLibs.pri and gqgroundcontrol.pro. # There is some circular reference settings going on between QGCExternalLibs.pri and gqgroundcontrol.pro.
# So this duplicates some of the enable/disable logic which would normally be in qgroundcontrol.pro. # So this duplicates some of the enable/disable logic which would normally be in qgroundcontrol.pro.
...@@ -153,7 +161,7 @@ contains(DEFINES, QGC_ENABLE_PAIRING) { ...@@ -153,7 +161,7 @@ contains(DEFINES, QGC_ENABLE_PAIRING) {
#- Pairing is not supported on Windows #- Pairing is not supported on Windows
DEFINES -= QGC_ENABLE_PAIRING DEFINES -= QGC_ENABLE_PAIRING
} else { } else {
LIBS += -lcrypto -lz LIBS += -lcrypto
AndroidBuild { AndroidBuild {
contains(QT_ARCH, arm) { contains(QT_ARCH, arm) {
LIBS += $$ANDROID_EXTRA_LIBS LIBS += $$ANDROID_EXTRA_LIBS
......
...@@ -9,13 +9,13 @@ ...@@ -9,13 +9,13 @@
#include "FirmwareUpgradeController.h" #include "FirmwareUpgradeController.h"
#include "Bootloader.h" #include "Bootloader.h"
//-- TODO: #include "QGCQFileDialog.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#include "QGCFileDownload.h" #include "QGCFileDownload.h"
#include "QGCOptions.h" #include "QGCOptions.h"
#include "QGCCorePlugin.h" #include "QGCCorePlugin.h"
#include "FirmwareUpgradeSettings.h" #include "FirmwareUpgradeSettings.h"
#include "SettingsManager.h" #include "SettingsManager.h"
#include "QGCTemporaryFile.h"
#include <QStandardPaths> #include <QStandardPaths>
#include <QRegularExpression> #include <QRegularExpression>
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include <QJsonArray> #include <QJsonArray>
#include <QNetworkProxy> #include <QNetworkProxy>
#include "zlib.h"
const char* FirmwareUpgradeController::_manifestFirmwareJsonKey = "firmware"; const char* FirmwareUpgradeController::_manifestFirmwareJsonKey = "firmware";
const char* FirmwareUpgradeController::_manifestBoardIdJsonKey = "board_id"; const char* FirmwareUpgradeController::_manifestBoardIdJsonKey = "board_id";
const char* FirmwareUpgradeController::_manifestMavTypeJsonKey = "mav-type"; const char* FirmwareUpgradeController::_manifestMavTypeJsonKey = "mav-type";
...@@ -878,11 +880,7 @@ void FirmwareUpgradeController::_downloadArduPilotManifest(void) ...@@ -878,11 +880,7 @@ void FirmwareUpgradeController::_downloadArduPilotManifest(void)
QGCFileDownload* downloader = new QGCFileDownload(this); QGCFileDownload* downloader = new QGCFileDownload(this);
connect(downloader, &QGCFileDownload::downloadFinished, this, &FirmwareUpgradeController::_ardupilotManifestDownloadFinished); connect(downloader, &QGCFileDownload::downloadFinished, this, &FirmwareUpgradeController::_ardupilotManifestDownloadFinished);
connect(downloader, &QGCFileDownload::error, this, &FirmwareUpgradeController::_ardupilotManifestDownloadError); connect(downloader, &QGCFileDownload::error, this, &FirmwareUpgradeController::_ardupilotManifestDownloadError);
#if 0
downloader->download(QStringLiteral("http://firmware.ardupilot.org/manifest.json.gz")); downloader->download(QStringLiteral("http://firmware.ardupilot.org/manifest.json.gz"));
#else
downloader->download(QStringLiteral("http://firmware.ardupilot.org/manifest.json"));
#endif
} }
void FirmwareUpgradeController::_ardupilotManifestDownloadFinished(QString remoteFile, QString localFile) void FirmwareUpgradeController::_ardupilotManifestDownloadFinished(QString remoteFile, QString localFile)
...@@ -892,49 +890,70 @@ void FirmwareUpgradeController::_ardupilotManifestDownloadFinished(QString remot ...@@ -892,49 +890,70 @@ void FirmwareUpgradeController::_ardupilotManifestDownloadFinished(QString remot
// Delete the QGCFileDownload object // Delete the QGCFileDownload object
sender()->deleteLater(); sender()->deleteLater();
qDebug() << "_ardupilotManifestDownloadFinished" << remoteFile << localFile; qCDebug(FirmwareUpgradeLog) << "_ardupilotManifestDownloadFinished" << remoteFile << localFile;
#if 0 QFile inputFile(localFile);
QFile gzipFile(localFile); if (!inputFile.open(QIODevice::ReadOnly)) {
if (!gzipFile.open(QIODevice::ReadOnly | QIODevice::Text)) { qCWarning(FirmwareUpgradeLog) << "Unable to open ArduPilot firmware manifest file for reading" << localFile << inputFile.errorString();
qCWarning(FirmwareUpgradeLog) << "Unable to open ArduPilot firmware manifest file" << localFile << gzipFile.errorString();
QFile::remove(localFile); QFile::remove(localFile);
return; return;
} }
// Store decompressed size as first four bytes. This is required by qUncompress routine. int ret;
QByteArray raw; const int cBuffer = 1024 * 5;
int decompressedSize = 3073444; unsigned char inputBuffer[cBuffer];
raw.append((unsigned char)((decompressedSize >> 24) & 0xFF)); unsigned char outputBuffer[cBuffer];
raw.append((unsigned char)((decompressedSize >> 16) & 0xFF)); z_stream strm;
raw.append((unsigned char)((decompressedSize >> 8) & 0xFF)); QByteArray jsonBytes;
raw.append((unsigned char)((decompressedSize >> 0) & 0xFF));
strm.zalloc = nullptr;
raw.append(gzipFile.readAll()); strm.zfree = nullptr;
QByteArray bytes = qUncompress(raw); strm.opaque = nullptr;
#else strm.avail_in = 0;
strm.next_in = nullptr;
QFile jsonFile(localFile); ret = inflateInit2(&strm, 16+MAX_WBITS);
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) { if (ret != Z_OK) {
qCWarning(FirmwareUpgradeLog) << "Unable to open ArduPilot firmware manifest file" << localFile << jsonFile.errorString(); qCWarning(FirmwareUpgradeLog) << "inflateInit2 failed:" << ret;
QFile::remove(localFile); QFile::remove(localFile);
return; return;
} }
QByteArray bytes = jsonFile.readAll();
jsonFile.close(); do {
#endif strm.avail_in = static_cast<unsigned>(inputFile.read((char*)inputBuffer, cBuffer));
if (strm.avail_in == 0) {
break;
}
strm.next_in = inputBuffer;
do {
strm.avail_out = cBuffer;
strm.next_out = outputBuffer;
ret = inflate(&strm, Z_NO_FLUSH);
if (ret != Z_OK && ret != Z_STREAM_END) {
qCWarning(FirmwareUpgradeLog) << "Inflate failed" << ret;
inflateEnd(&strm);
QFile::remove(localFile);
return;
}
unsigned cBytesInflated = cBuffer - strm.avail_out;
jsonBytes.append((char*)outputBuffer, static_cast<int>(cBytesInflated));
} while (strm.avail_out == 0);
} while (ret != Z_STREAM_END);
inflateEnd(&strm);
inputFile.close();
QFile::remove(localFile); QFile::remove(localFile);
QJsonParseError jsonParseError; QJsonParseError jsonParseError;
QJsonDocument doc = QJsonDocument::fromJson(bytes, &jsonParseError); QJsonDocument doc = QJsonDocument::fromJson(jsonBytes, &jsonParseError);
if (jsonParseError.error != QJsonParseError::NoError) { if (jsonParseError.error != QJsonParseError::NoError) {
qCWarning(FirmwareUpgradeLog) << "Unable to open ArduPilot manifest json document" << localFile << jsonParseError.errorString(); qCWarning(FirmwareUpgradeLog) << "Unable to open ArduPilot manifest json document" << localFile << jsonParseError.errorString();
} }
QJsonObject json = doc.object(); QJsonObject json = doc.object();
QJsonArray rgFirmware = json[_manifestFirmwareJsonKey].toArray(); QJsonArray rgFirmware = json[_manifestFirmwareJsonKey].toArray();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment