Commit 1250e4ad authored by Thomas Gubler's avatar Thomas Gubler

Merge branch 'master' of https://github.com/mavlink/qgroundcontrol into archlinux

parents 9e43860b 1923fb95
......@@ -41,6 +41,7 @@ HEADERS += \
src/QGC.h \
src/apps/qupgrade/QUpgradeApp.h \
src/apps/qupgrade/QUpgradeMainWindow.h \
src/apps/qupgrade/uploader.h \
libs/qextserialport/qextserialenumerator.h \
src/ui/PX4FirmwareUpgrader.h \
src/PX4FirmwareUpgradeWorker.h
......@@ -52,6 +53,7 @@ SOURCES += \
src/apps/qupgrade/main.cc \
src/apps/qupgrade/QUpgradeApp.cc \
src/apps/qupgrade/QUpgradeMainWindow.cc \
src/apps/qupgrade/uploader.cpp \
src/ui/PX4FirmwareUpgrader.cc \
src/PX4FirmwareUpgradeWorker.cc
......
#include <QJsonDocument>
//#include <QJsonDocument>
#include <QFile>
#include "PX4FirmwareUpgradeWorker.h"
#include <SerialLink.h>
#include <QGC.h>
#include "uploader.h"
#include <QDebug>
// protocol bytes
#define INSYNC 0x12
#define EOC 0x20
// reply bytes
#define OK 0x10
#define FAILED 0x11
#define INVALID 0x13 // rev3+
// command bytes
#define NOP 0x00 // guaranteed to be discarded by the bootloader
#define GET_SYNC 0x21
#define GET_DEVICE 0x22
#define CHIP_ERASE 0x23
#define CHIP_VERIFY 0x24 // rev2 only
#define PROG_MULTI 0x27
#define READ_MULTI 0x28 // rev2 only
#define GET_CRC 0x29 // rev3+
#define REBOOT 0x30
#define INFO_BL_REV 1 // bootloader protocol revision
#define BL_REV_MIN 2 // minimum supported bootloader protocol
#define BL_REV_MAX 3 // maximum supported bootloader protocol
#define INFO_BOARD_ID 2 // board type
#define INFO_BOARD_REV 3 // board revision
#define INFO_FLASH_SIZE 4 // max firmware size in bytes
#define PROTO_GET_SYNC 0x21
#define PROTO_EOC 0x20
#define PROTO_NOP 0x00
#define PROTO_OK 0x10
#define PROTO_FAILED 0x11
#define PROTO_INSYNC 0x12
PX4FirmwareUpgradeWorker::PX4FirmwareUpgradeWorker(QObject *parent) :
QObject(parent),
......@@ -96,7 +77,7 @@ void PX4FirmwareUpgradeWorker::detect()
link->setPortName(ports->at(i));
// Open port and talk to it
link->connect();
char buf[2] = { GET_SYNC, EOC };
char buf[2] = { PROTO_GET_SYNC, PROTO_EOC };
if (!link->isConnected()) {
continue;
}
......@@ -124,13 +105,13 @@ void PX4FirmwareUpgradeWorker::receiveBytes(LinkInterface* link, QByteArray b)
for (int position = 0; position < b.size(); position++) {
qDebug() << "BYTES";
qDebug() << (char)(b[position]);
if (((const char)b[position]) == INSYNC)
if (((const char)b[position]) == PROTO_INSYNC)
{
qDebug() << "SYNC";
insync = true;
}
if (insync && ((const char)b[position]) == OK)
if (insync && ((const char)b[position]) == PROTO_OK)
{
emit detectionStatusChanged("Found PX4 board");
}
......@@ -141,21 +122,28 @@ void PX4FirmwareUpgradeWorker::receiveBytes(LinkInterface* link, QByteArray b)
void PX4FirmwareUpgradeWorker::loadFirmware(const QString &filename)
{
qDebug() << __FILE__ << __LINE__ << "LOADING FW";
QFile f(filename);
if (f.open(QIODevice::ReadOnly))
{
QByteArray buf = f.readAll();
f.close();
firmware = QJsonDocument::fromBinaryData(buf);
if (firmware.isNull()) {
emit upgradeStatusChanged(tr("Failed decoding file %1").arg(filename));
} else {
emit upgradeStatusChanged(tr("Ready to flash %1").arg(filename));
}
} else {
emit upgradeStatusChanged(tr("Failed opening file %1").arg(filename));
}
qDebug() << __FILE__ << __LINE__ << "LOADING FW" << filename;
PX4_Uploader uploader;
const char* filenames[2];
filenames[0] = filename.toStdString().c_str();
filenames[1] = NULL;
uploader.upload(filenames, "/dev/tty.usbmodem1");
// QFile f(filename);
// if (f.open(QIODevice::ReadOnly))
// {
// QByteArray buf = f.readAll();
// f.close();
// firmware = QJsonDocument::fromBinaryData(buf);
// if (firmware.isNull()) {
// emit upgradeStatusChanged(tr("Failed decoding file %1").arg(filename));
// } else {
// emit upgradeStatusChanged(tr("Ready to flash %1").arg(filename));
// }
// } else {
// emit upgradeStatusChanged(tr("Failed opening file %1").arg(filename));
// }
}
void PX4FirmwareUpgradeWorker::upgrade()
......
......@@ -2,7 +2,7 @@
#define PX4FIRMWAREUPGRADEWORKER_H
#include <QObject>
#include <QJsonDocument>
//#include <QJsonDocument>
#include <SerialLink.h>
......@@ -67,7 +67,7 @@ protected:
private:
SerialLink *link;
bool insync;
QJsonDocument firmware;
//QJsonDocument firmware;
};
#endif // PX4FIRMWAREUPGRADEWORKER_H
......@@ -78,15 +78,15 @@ QUpgradeApp::QUpgradeApp(int &argc, char* argv[]) : QApplication(argc, argv)
// Get PX4 upgrade widget and instantiate worker thread
PX4FirmwareUpgradeWorker* worker = PX4FirmwareUpgradeWorker::putWorkerInThread(this);
connect(worker, SIGNAL(detectionStatusChanged(QString)), upgrader, SLOT(setDetectionStatusText(QString)), Qt::QueuedConnection);
connect(worker, SIGNAL(upgradeStatusChanged(QString)), upgrader, SLOT(setFlashStatusText(QString)), Qt::QueuedConnection);
connect(worker, SIGNAL(upgradeProgressChanged(int)), upgrader, SLOT(setFlashProgress(int)), Qt::QueuedConnection);
connect(worker, SIGNAL(validPortFound(QString)), upgrader, SLOT(setPortName(QString)));
connect(upgrader, SIGNAL(firmwareFileNameSet(QString)), worker, SLOT(loadFirmware(QString)), Qt::QueuedConnection);
connect(upgrader, SIGNAL(upgrade()), worker, SLOT(upgrade()), Qt::QueuedConnection);
connect(this, SIGNAL(lastWindowClosed()), worker, SLOT(abort()), Qt::QueuedConnection);
worker->loadFirmware("abc");
// connect(worker, SIGNAL(detectionStatusChanged(QString)), upgrader, SLOT(setDetectionStatusText(QString)), Qt::QueuedConnection);
// connect(worker, SIGNAL(upgradeStatusChanged(QString)), upgrader, SLOT(setFlashStatusText(QString)), Qt::QueuedConnection);
// connect(worker, SIGNAL(upgradeProgressChanged(int)), upgrader, SLOT(setFlashProgress(int)), Qt::QueuedConnection);
// connect(worker, SIGNAL(validPortFound(QString)), upgrader, SLOT(setPortName(QString)));
// connect(upgrader, SIGNAL(firmwareFileNameSet(QString)), worker, SLOT(loadFirmware(QString)), Qt::QueuedConnection);
// connect(upgrader, SIGNAL(upgrade()), worker, SLOT(upgrade()), Qt::QueuedConnection);
// connect(this, SIGNAL(lastWindowClosed()), worker, SLOT(abort()), Qt::QueuedConnection);
worker->loadFirmware("/Users/lomeier/src/Firmware/Images/px4fmu.bin");
window->setWindowTitle(applicationName() + " " + applicationVersion());
window->show();
......
This diff is collapsed.
/****************************************************************************
*
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file Firmware uploader for PX4IO
*/
#ifndef _PX4_Uploader_H
#define _PX4_Uploader_H value
#include <stdint.h>
#include <stdbool.h>
class PX4_Uploader
{
public:
PX4_Uploader();
virtual ~PX4_Uploader();
int upload(const char *filenames[], const char* port);
private:
enum {
PROTO_NOP = 0x00,
PROTO_OK = 0x10,
PROTO_FAILED = 0x11,
PROTO_INSYNC = 0x12,
PROTO_EOC = 0x20,
PROTO_GET_SYNC = 0x21,
PROTO_GET_DEVICE = 0x22,
PROTO_CHIP_ERASE = 0x23,
PROTO_CHIP_VERIFY = 0x24,
PROTO_PROG_MULTI = 0x27,
PROTO_READ_MULTI = 0x28,
PROTO_GET_CRC = 0x29,
PROTO_REBOOT = 0x30,
INFO_BL_REV = 1, /**< bootloader protocol revision */
BL_REV = 3, /**< supported bootloader protocol */
INFO_BOARD_ID = 2, /**< board type */
INFO_BOARD_REV = 3, /**< board revision */
INFO_FLASH_SIZE = 4, /**< max firmware size in bytes */
PROG_MULTI_MAX = 60, /**< protocol max is 255, must be multiple of 4 */
READ_MULTI_MAX = 60, /**< protocol max is 255, something overflows with >= 64 */
};
int _io_fd;
int _fw_fd;
uint32_t bl_rev; /**< bootloader revision */
void log(const char *fmt, ...);
int recv(uint8_t &c, unsigned timeout);
int recv(uint8_t *p, unsigned count);
void drain();
int send(uint8_t c);
int send(uint8_t *p, unsigned count);
int get_sync(unsigned timeout = 1000);
int sync();
int get_info(int param, uint32_t &val);
int erase();
int program(size_t fw_size);
int verify_rev2(size_t fw_size);
int verify_rev3(size_t fw_size);
int reboot();
};
#endif
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