1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

OP-35 Firmware upload works (tested on mainboard). Use at your own risk! Not threaded yet, so UI kind of freezes during the process, but it works. Don't blame me if it fries your board, though...

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2063 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-11-03 21:41:32 +00:00 committed by edouard
parent ae22e9103b
commit 48a3b6c569
6 changed files with 137 additions and 108 deletions

View File

@ -58,6 +58,7 @@ void deviceWidget::populate()
myDevice->deviceACL->setText(QString("Access: ") + QString(r ? "R" : "-") + QString(w ? "W" : "-"));
myDevice->maxCodeSize->setText(QString("Max code size: ") +QString::number(m_dfu->devices[deviceID].SizeOfCode));
myDevice->fwCRC->setText(QString("FW CRC: ") + QString::number(m_dfu->devices[deviceID].FW_CRC));
myDevice->BLVersion->setText(QString("BL Version: ") + QString::number(m_dfu->devices[deviceID].BL_Version));
int size=((OP_DFU::device)m_dfu->devices[deviceID]).SizeOfDesc;
m_dfu->enterDFU(deviceID);
@ -69,6 +70,26 @@ void deviceWidget::populate()
}
/**
Freezes the contents of the widget so that a user cannot
try to modify the contents
*/
void deviceWidget::freeze()
{
myDevice->description->setEnabled(false);
myDevice->updateButton->setEnabled(false);
myDevice->verifyButton->setEnabled(false);
myDevice->retrieveButton->setEnabled(false);
}
/**
Updates status message
*/
void deviceWidget::status(QString str)
{
myDevice->statusLabel->setText(str);
}
/**
Verifies the firmware CRC
*/
@ -88,27 +109,29 @@ void deviceWidget::uploadFirmware()
}
bool verify = true;
QString filename = setOpenFileName();
if (filename.isEmpty()) {
status("Empty filename");
return;
}
/*
OP_DFU::Status retstatus=dfu.UploadFirmware(file.toAscii(),verify, device);
if(retstatus!=OP_DFU::Last_operation_Success)
{
cout<<"Upload failed with code:"<<dfu.StatusToString(retstatus).toLatin1().data();
return -1;
}
if(!description.isEmpty())
{
retstatus=dfu.UploadDescription(description);
if(retstatus!=OP_DFU::Last_operation_Success)
{
cout<<"Upload failed with code:"<<dfu.StatusToString(retstatus).toLatin1().data();
return -1;
}
}
cout<<"Uploading Succeded!\n";
*/
status("Uploading firmware to device");
repaint(); // FW Upload is not threaded and will mostly freeze the UI...
connect(m_dfu, SIGNAL(progressUpdated(int)), this, SLOT(setProgress(int)));
OP_DFU::Status retstatus = m_dfu->UploadFirmware(filename.toAscii(),verify, deviceID);
if(retstatus != OP_DFU::Last_operation_Success) {
status(QString("Upload failed with code: ") + m_dfu->StatusToString(retstatus).toLatin1().data());
return;
} else
if(!myDevice->description->text().isEmpty()) {
retstatus = m_dfu->UploadDescription(myDevice->description->text());
if( retstatus != OP_DFU::Last_operation_Success) {
status(QString("Upload failed with code: ") + m_dfu->StatusToString(retstatus).toLatin1().data());
return;
}
}
status("Uploading Succeded!");
}
/**
@ -127,3 +150,29 @@ void deviceWidget::downloadFirmware()
return ret;
*/
}
/**
Slot to update the progress bar
*/
void deviceWidget::setProgress(int percent)
{
myDevice->progressBar->setValue(percent);
}
/**
Opens an open file dialog.
*/
QString deviceWidget::setOpenFileName()
{
QFileDialog::Options options;
QString selectedFilter;
QString fileName = QFileDialog::getOpenFileName(this,
tr("Select firmware file"),
"",
tr("All Files (*);;Firmware Files (*.bin)"),
&selectedFilter,
options);
return fileName;
}

View File

@ -31,6 +31,8 @@
#include "ui_devicewidget.h"
#include "op_dfu.h"
#include <QWidget>
#include <QFileDialog>
class deviceWidget : public QWidget
{
@ -40,11 +42,14 @@ public:
void setDeviceID(int devID);
void setDfu(OP_DFU* dfu);
void populate();
void freeze();
QString setOpenFileName();
private:
Ui_deviceWidget *myDevice;
int deviceID;
OP_DFU *m_dfu;
void status(QString str);
signals:
@ -52,6 +57,7 @@ public slots:
void verifyFirmware();
void uploadFirmware();
void downloadFirmware();
void setProgress(int);
};

View File

@ -24,6 +24,11 @@ OP_DFU::OP_DFU(bool _debug): debug(_debug)
qDebug() << numDevices << " device(s) opened";
}
OP_DFU::~OP_DFU()
{
}
bool OP_DFU::SaveByteArrayToFile(QString const & sfile, const QByteArray &array)
{
QFile file(sfile);
@ -147,7 +152,7 @@ bool OP_DFU::UploadData(qint32 const & numberOfBytes, QByteArray & data)
// }
// qDebug()<<" Data0="<<(int)data[0]<<" Data0="<<(int)data[1]<<" Data0="<<(int)data[2]<<" Data0="<<(int)data[3]<<" buf6="<<(int)buf[6]<<" buf7="<<(int)buf[7]<<" buf8="<<(int)buf[8]<<" buf9="<<(int)buf[9];
//delay::msleep(send_delay);
if(int ret=StatusRequest()!=OP_DFU::uploading) return false;
if(StatusRequest()!=OP_DFU::uploading) return false;
int result = hidHandle.send(0,buf, BUF_LEN, 5000);
// qDebug()<<"sent:"<<result;
if(result<1)
@ -162,7 +167,7 @@ bool OP_DFU::UploadData(qint32 const & numberOfBytes, QByteArray & data)
// while(true){}
return true;
}
OP_DFU::Status OP_DFU::UploadDescription(QString & description)
OP_DFU::Status OP_DFU::UploadDescription(QString description)
{
cout<<"Starting uploading description\n";
if(description.length()%4!=0)
@ -191,6 +196,9 @@ OP_DFU::Status OP_DFU::UploadDescription(QString & description)
qDebug()<<"Upload description Status="<<ret;
return (OP_DFU::Status)ret;
}
QString OP_DFU::DownloadDescription(int const & numberOfChars)
{
// enterDFU(devNumber);
@ -199,26 +207,7 @@ QString OP_DFU::DownloadDescription(int const & numberOfChars)
return str;
}
void OP_DFU::test()
{
char buf[BUF_LEN];
int result;
buf[0]=0x02;
buf[1]=11;
buf[2]=11;
buf[63]=333;
while(true)
{
buf[0]=0x02;
++buf[1];
++buf[2];
++buf[63];
hidHandle.send(0,buf,BUF_LEN,5000);
result = hidHandle.receive(0,buf,BUF_LEN,5000);
qDebug()<<"Result="<<result;
qDebug()<<(int)buf[0]<<":"<<(int)buf[1]<<":"<<(int)buf[2]<<":"<<(int)buf[63];
}}
QByteArray OP_DFU::StartDownload(qint32 const & numberOfBytes, TransferTypes const & type)
{
@ -275,7 +264,8 @@ QByteArray OP_DFU::StartDownload(qint32 const & numberOfBytes, TransferTypes con
StatusRequest();
return ret;
}
void OP_DFU::ResetDevice(void)
int OP_DFU::ResetDevice(void)
{
char buf[BUF_LEN];
buf[0] =0x02;//reportID
@ -288,9 +278,10 @@ void OP_DFU::ResetDevice(void)
buf[7] = 0;
buf[8] = 0;
buf[9] = 0;
int result = hidHandle.send(0,buf, BUF_LEN, 500);
return hidHandle.send(0,buf, BUF_LEN, 500);
}
void OP_DFU::AbortOperation(void)
int OP_DFU::AbortOperation(void)
{
char buf[BUF_LEN];
buf[0] =0x02;//reportID
@ -303,9 +294,10 @@ void OP_DFU::AbortOperation(void)
buf[7] = 0;
buf[8] = 0;
buf[9] = 0;
int result = hidHandle.send(0,buf, BUF_LEN, 500);
return hidHandle.send(0,buf, BUF_LEN, 500);
}
void OP_DFU::JumpToApp()
int OP_DFU::JumpToApp()
{
char buf[BUF_LEN];
buf[0] =0x02;//reportID
@ -319,7 +311,7 @@ void OP_DFU::JumpToApp()
buf[8] = 0;
buf[9] = 0;
int result = hidHandle.send(0,buf, BUF_LEN, 500);
return hidHandle.send(0,buf, BUF_LEN, 500);
}
OP_DFU::Status OP_DFU::StatusRequest()
@ -659,6 +651,8 @@ QString OP_DFU::StatusToString(OP_DFU::Status const & status)
void OP_DFU::printProgBar( int const & percent,QString const& label){
std::string bar;
emit(progressUpdated(percent));
for(int i = 0; i < 50; i++){
if( i < (percent/2)){
bar.replace(i,1,"=");

View File

@ -12,23 +12,13 @@
using namespace std;
#define BUF_LEN 64
//Command Line Options
#define DOWNLOAD "-dn" //done
#define DEVICE "-d" //done
//#define DOWNDESCRIPTION "-dd" //done
#define PROGRAMFW "-p" //done
#define PROGRAMDESC "-w" //done
#define VERIFY "-v" //done
#define COMPARECRC "-cc"
#define COMPAREALL "-ca"
#define STATUSREQUEST "-s" //done
#define LISTDEVICES "-ls" //done
#define RESET "-r"
#define JUMP "-j"
class OP_DFU
class OP_DFU : public QObject
{
public:
Q_OBJECT;
public:
enum TransferTypes
{
FW,
@ -99,12 +89,15 @@ public:
bool Writable;
};
void JumpToApp();
void ResetDevice(void);
OP_DFU(bool debug);
~OP_DFU();
int JumpToApp();
int ResetDevice(void);
bool enterDFU(int const &devNumber);
bool StartUpload(qint32 const &numberOfBytes, TransferTypes const & type,quint32 crc);
bool UploadData(qint32 const & numberOfPackets,QByteArray & data);
Status UploadDescription(QString & description);
Status UploadDescription(QString description);
Status UploadFirmware(const QString &sfile, const bool &verify,int device);
Status StatusRequest();
bool EndOperation();
@ -114,7 +107,6 @@ public:
bool SaveByteArrayToFile(QString const & file,QByteArray const &array);
void CopyWords(char * source, char* destination, int count);
// QByteArray DownloadData(int devNumber,int numberOfPackets);
OP_DFU(bool debug);
bool findDevices();
QList<device> devices;
int numberOfDevices;
@ -122,14 +114,17 @@ public:
OP_DFU::Status CompareFirmware(const QString &sfile, const CompareType &type,int device);
quint32 CRC32WideFast(quint32 Crc, quint32 Size, quint32 *Buffer);
quint32 CRCFromQBArray(QByteArray array, quint32 Size);
void test();
int send_delay;
bool use_delay;
void AbortOperation(void);
int AbortOperation(void);
signals:
void progressUpdated(int);
private:
bool debug;
int RWFlags;
pjrc_rawhid hidHandle;
int setStartBit(int command){return command|0x20;}
};

View File

@ -32,6 +32,7 @@ UploaderGadgetWidget::UploaderGadgetWidget(QWidget *parent) : QWidget(parent)
m_config->setupUi(this);
currentStep = IAP_STATE_READY;
resetOnly=false;
dfu = NULL;
//m_config->systemElements->addTab((QWidget*)new deviceWidget(),QString("Device"));
@ -118,28 +119,28 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
// Tell the mainboard to get into bootloader state:
log("Going into Bootloader mode...");
OP_DFU dfu(true);
dfu.AbortOperation();
if(!dfu.enterDFU(0))
dfu = new OP_DFU(false);
dfu->AbortOperation();
if(!dfu->enterDFU(0))
{
log("Could not enter DFU mode.");
return;
}
m_config->boardStatus->setText("Bootloader");
currentStep = IAP_STATE_BOOTLOADER;
//OP_DFU::Status ret=dfu.StatusRequest();
dfu.findDevices();
log(QString("Found ") + QString::number(dfu.numberOfDevices) + QString(" device(s)."));
//dfu.StatusRequest();
dfu->findDevices();
log(QString("Found ") + QString::number(dfu->numberOfDevices) + QString(" device(s)."));
// Delete all previous tabs:
for (int i=0; i< m_config->systemElements->count(); i++) {
QWidget *qw = m_config->systemElements->widget(i);
m_config->systemElements->removeTab(i);
delete qw;
}
for(int i=0;i<dfu.numberOfDevices;i++) {
for(int i=0;i<dfu->numberOfDevices;i++) {
deviceWidget* dw = new deviceWidget(this);
dw->setDeviceID(i);
dw->setDfu(&dfu);
dw->setDfu(dfu);
dw->populate();
m_config->systemElements->addTab(dw, QString("Device") + QString::number(i));
}
@ -175,15 +176,16 @@ void UploaderGadgetWidget::systemBoot()
{
if (currentStep == IAP_STATE_BOOTLOADER) {
clearLog();
OP_DFU dfu(true);
dfu.AbortOperation();
if(!dfu.enterDFU(0))
if (!dfu)
dfu = new OP_DFU(true);
dfu->AbortOperation();
if(!dfu->enterDFU(0))
{
log("Could not enter DFU mode.");
return;
}
log("Booting system...");
dfu.JumpToApp();
dfu->JumpToApp();
currentStep = IAP_STATE_READY;
// stop the polling thread: otherwise it will mess up DFU
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
@ -193,6 +195,14 @@ void UploaderGadgetWidget::systemBoot()
m_config->haltButton->setEnabled(true);
m_config->resetButton->setEnabled(true);
m_config->boardStatus->setText("Running");
// Freeze the tabs, they are not useful anymore and their buttons
// will cause segfaults or weird stuff if we use them.
for (int i=0; i< m_config->systemElements->count(); i++) {
deviceWidget *qw = (deviceWidget*)m_config->systemElements->widget(i);
qw->freeze();
}
delete dfu;
} else {
log("Not in bootloader mode!");
@ -214,35 +224,12 @@ void UploaderGadgetWidget::clearLog()
m_config->textBrowser->clear();
}
//user pressed send, send file using a new thread with qymodem library
void UploaderGadgetWidget::send()
{
}
//destructor !!?! do I need to delete something else?
UploaderGadgetWidget::~UploaderGadgetWidget()
{
}
/**
Opens an open file dialog.
*/
void UploaderGadgetWidget::setOpenFileName()
{
QFileDialog::Options options;
QString selectedFilter;
QString fileName = QFileDialog::getOpenFileName(this,
tr("QFileDialog::getOpenFileName()"),
openFileNameLE->text(),
tr("All Files (*);;Text Files (*.bin)"),
&selectedFilter,
options);
if (!fileName.isEmpty()) openFileNameLE->setText(fileName);
}
/**
Shows a message box with an error string.

View File

@ -42,7 +42,6 @@
#include <QLabel>
#include <QLineEdit>
#include <QThread>
#include <QFileDialog>
#include <QMessageBox>
@ -58,6 +57,7 @@ public:
private:
Ui_UploaderWidget *m_config;
OP_DFU *dfu;
IAPStep currentStep;
bool resetOnly;
void log(QString str);
@ -66,8 +66,6 @@ private:
QLineEdit* openFileNameLE;
private slots:
void setOpenFileName();
void send();
void error(QString errorString,int errorNumber);
void info(QString infoString,int infoNumber);
void goToBootloader(UAVObject* = NULL, bool = false);