1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-21 11:54:15 +01:00

OP-35 Further cleanup of Uploader gadget, better debug messages, more reliable.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2169 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-11-27 13:44:16 +00:00 committed by edouard
parent a9cd9ac329
commit 02366bf368
2 changed files with 25 additions and 34 deletions

View File

@ -224,6 +224,7 @@ void deviceWidget::downloadFirmware()
void deviceWidget::downloadFinished() void deviceWidget::downloadFinished()
{ {
disconnect(m_dfu, SIGNAL(downloadFinished()), this, SLOT(downloadFinished())); disconnect(m_dfu, SIGNAL(downloadFinished()), this, SLOT(downloadFinished()));
disconnect(m_dfu, SIGNAL(progressUpdated(int)), this, SLOT(setProgress(int)));
status("Download successful"); status("Download successful");
// Now save the result (use the utility function from OP_DFU) // Now save the result (use the utility function from OP_DFU)
m_dfu->SaveByteArrayToFile(filename, downloadedFirmware); m_dfu->SaveByteArrayToFile(filename, downloadedFirmware);
@ -236,6 +237,8 @@ void deviceWidget::downloadFinished()
void deviceWidget::uploadFinished(OP_DFU::Status retstatus) void deviceWidget::uploadFinished(OP_DFU::Status retstatus)
{ {
disconnect(m_dfu, SIGNAL(uploadFinished(OP_DFU::Status)), this, SLOT(uploadFinished(OP_DFU::Status))); disconnect(m_dfu, SIGNAL(uploadFinished(OP_DFU::Status)), this, SLOT(uploadFinished(OP_DFU::Status)));
disconnect(m_dfu, SIGNAL(progressUpdated(int)), this, SLOT(setProgress(int)));
disconnect(m_dfu, SIGNAL(operationProgress(QString)), this, SLOT(status(QString)));
if(retstatus != OP_DFU::Last_operation_Success) { if(retstatus != OP_DFU::Last_operation_Success) {
status(QString("Upload failed with code: ") + m_dfu->StatusToString(retstatus).toLatin1().data()); status(QString("Upload failed with code: ") + m_dfu->StatusToString(retstatus).toLatin1().data());
return; return;
@ -253,7 +256,6 @@ void deviceWidget::uploadFinished(OP_DFU::Status retstatus)
} }
/** /**
Slot to update the progress bar Slot to update the progress bar
*/ */
@ -274,7 +276,7 @@ QString deviceWidget::setOpenFileName()
QString fileName = QFileDialog::getOpenFileName(this, QString fileName = QFileDialog::getOpenFileName(this,
tr("Select firmware file"), tr("Select firmware file"),
"", "",
tr("All Files (*);;Firmware Files (*.bin)"), tr("Firmware Files (*.bin)"),
&selectedFilter, &selectedFilter,
options); options);
return fileName; return fileName;

View File

@ -210,11 +210,11 @@ OP_DFU::Status DFUObject::UploadDescription(QString description)
{ {
return OP_DFU::abort; return OP_DFU::abort;
} }
int ret=StatusRequest(); OP_DFU::Status ret = StatusRequest();
if(debug) if(debug)
qDebug()<<"Upload description Status="<<ret; qDebug() << "Upload description Status=" << StatusToString(ret);
return (OP_DFU::Status)ret; return ret;
} }
@ -315,6 +315,7 @@ bool DFUObject::StartDownloadT(QByteArray *fw, qint32 const & numberOfBytes, Tra
// Now get those packets: // Now get those packets:
for(qint32 x=0;x<numberOfPackets;++x) for(qint32 x=0;x<numberOfPackets;++x)
{ {
int size;
percentage=(float)(x+1)/numberOfPackets*100; percentage=(float)(x+1)/numberOfPackets*100;
if(laspercentage!=(int)percentage) if(laspercentage!=(int)percentage)
printProgBar((int)percentage,"DOWNLOADING"); printProgBar((int)percentage,"DOWNLOADING");
@ -323,7 +324,6 @@ bool DFUObject::StartDownloadT(QByteArray *fw, qint32 const & numberOfBytes, Tra
result = hidHandle.receive(0,buf,BUF_LEN,5000); result = hidHandle.receive(0,buf,BUF_LEN,5000);
if(debug) if(debug)
qDebug() << result << " bytes received"<<" Count="<<x<<"-"<<(int)buf[2]<<";"<<(int)buf[3]<<";"<<(int)buf[4]<<";"<<(int)buf[5]<<" Data="<<(int)buf[6]<<";"<<(int)buf[7]<<";"<<(int)buf[8]<<";"<<(int)buf[9]; qDebug() << result << " bytes received"<<" Count="<<x<<"-"<<(int)buf[2]<<";"<<(int)buf[3]<<";"<<(int)buf[4]<<";"<<(int)buf[5]<<" Data="<<(int)buf[6]<<";"<<(int)buf[7]<<";"<<(int)buf[8]<<";"<<(int)buf[9];
int size;
if(x==numberOfPackets-1) if(x==numberOfPackets-1)
size=lastPacketCount*4; size=lastPacketCount*4;
else else
@ -589,13 +589,13 @@ OP_DFU::Status DFUObject::UploadFirmwareT(const QString &sfile, const bool &veri
if( !StartUpload(arr.length(), OP_DFU::FW, crc)) if( !StartUpload(arr.length(), OP_DFU::FW, crc))
{ {
ret = StatusRequest();
if(debug) if(debug)
{ {
qDebug() << "StartUpload failed"; qDebug() << "StartUpload failed";
OP_DFU::Status ret = StatusRequest();
qDebug() << "StartUpload returned:" << StatusToString(ret); qDebug() << "StartUpload returned:" << StatusToString(ret);
} }
return OP_DFU::abort; return ret;
} }
emit operationProgress(QString("Erasing memory, please wait...")); emit operationProgress(QString("Erasing memory, please wait..."));
@ -606,62 +606,50 @@ OP_DFU::Status DFUObject::UploadFirmwareT(const QString &sfile, const bool &veri
// TODO: why is there a loop there? The "if" statement // TODO: why is there a loop there? The "if" statement
// will cause a break or return anyway!! // will cause a break or return anyway!!
for (int x = 0; x < 3; ++x) { for (int x = 0; x < 3; ++x) {
OP_DFU::Status ret = StatusRequest(); ret = StatusRequest();
if (debug) qDebug() << "Erase returned: " << StatusToString(ret); if (debug) qDebug() << "Erase returned: " << StatusToString(ret);
if (ret == OP_DFU::uploading) if (ret == OP_DFU::uploading)
break; break;
else else
return OP_DFU::abort; return ret;
} }
emit operationProgress(QString("Uploading firmware")); emit operationProgress(QString("Uploading firmware"));
if( !UploadData(arr.length(),arr)) if( !UploadData(arr.length(),arr))
{ {
ret = StatusRequest();
if(debug) if(debug)
{ {
qDebug()<<"Upload failed (upload data)"; qDebug()<<"Upload failed (upload data)";
OP_DFU::Status ret=StatusRequest(); qDebug()<<"UploadData returned:"<<StatusToString(ret);
qDebug()<<"StartUpload returned:"<<StatusToString(ret);
} }
return OP_DFU::abort; return ret;
} }
if(!EndOperation()) if(!EndOperation())
{ {
ret = StatusRequest();
if(debug) if(debug)
{ {
qDebug()<<"Upload failed (end operation)"; qDebug()<<"Upload failed (end operation)";
OP_DFU::Status ret=StatusRequest(); qDebug()<<"EndOperation returned:"<<StatusToString(ret);
qDebug()<<"StartUpload returned:"<<StatusToString(ret);
} }
return OP_DFU::abort;
}
ret=StatusRequest();
if(ret==OP_DFU::Last_operation_Success)
{
}
else
{
return ret; return ret;
} }
if(verify) ret = StatusRequest();
{ if(ret != OP_DFU::Last_operation_Success)
return ret;
if(verify) {
emit operationProgress(QString("Verifying firmware")); emit operationProgress(QString("Verifying firmware"));
cout<<"Starting code verification\n"; cout<<"Starting code verification\n";
QByteArray arr2; QByteArray arr2;
StartDownloadT(&arr2, arr.length(),OP_DFU::FW); StartDownloadT(&arr2, arr.length(),OP_DFU::FW);
if (arr == arr2 ) if (arr != arr2 ) {
cout<<"Verify:PASSED\n";
else
{
cout<<"Verify:FAILED\n"; cout<<"Verify:FAILED\n";
return OP_DFU::abort; return OP_DFU::abort;
} }
} }
else
{
return ret;
}
if(debug) if(debug)
qDebug()<<"Status="<<ret; qDebug()<<"Status="<<ret;
cout<<"Firmware Uploading succeeded\n"; cout<<"Firmware Uploading succeeded\n";
@ -793,6 +781,7 @@ void DFUObject::printProgBar( int const & percent,QString const& label){
std::cout<< percent << "% " << std::flush; std::cout<< percent << "% " << std::flush;
} }
} }
quint32 DFUObject::CRC32WideFast(quint32 Crc, quint32 Size, quint32 *Buffer) quint32 DFUObject::CRC32WideFast(quint32 Crc, quint32 Size, quint32 *Buffer)
{ {
//Size = Size >> 2; // /4 Size passed in as a byte count, assumed to be a multiple of 4 //Size = Size >> 2; // /4 Size passed in as a byte count, assumed to be a multiple of 4