1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-30 08:24:11 +01:00

OP-21/Flight PC app - Update to work with embedded changes.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1684 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
zedamota 2010-09-18 23:39:37 +00:00 committed by zedamota
parent 128df749f0
commit 40c9c208cf
3 changed files with 53 additions and 39 deletions

View File

@ -93,13 +93,13 @@ int main(int argc, char *argv[])
} }
} }
else if(args.contains(COMPAREHASH) || args.contains(COMPAREALL)) else if(args.contains(COMPARECRC) || args.contains(COMPAREALL))
{ {
int index; int index;
if(args.contains(COMPAREHASH)) if(args.contains(COMPARECRC))
{ {
index=args.indexOf(COMPAREHASH); index=args.indexOf(COMPARECRC);
action=OP_DFU::actionCompareHash; action=OP_DFU::actionCompareCrc;
} }
else else
{ {
@ -218,6 +218,8 @@ int main(int argc, char *argv[])
cout<<"Error:Invalid Device"; cout<<"Error:Invalid Device";
return -1; return -1;
} }
// if(dfu.numberOfDevices==1)
// dfu.use_delay=false;
if(!dfu.enterDFU(device)) if(!dfu.enterDFU(device))
{ {
cout<<"Error:Could not enter DFU mode\n"; cout<<"Error:Could not enter DFU mode\n";
@ -225,6 +227,12 @@ int main(int argc, char *argv[])
} }
if (action==OP_DFU::actionProgram) if (action==OP_DFU::actionProgram)
{ {
if(((OP_DFU::device)dfu.devices[device]).Writable==false)
{
cout<<"ERROR device not Writable\n";
return false;
}
OP_DFU::Status retstatus=dfu.UploadFirmware(file.toAscii(),verify, device); OP_DFU::Status retstatus=dfu.UploadFirmware(file.toAscii(),verify, device);
if(retstatus!=OP_DFU::Last_operation_Success) if(retstatus!=OP_DFU::Last_operation_Success)
{ {
@ -244,23 +252,28 @@ int main(int argc, char *argv[])
} }
else if (action==OP_DFU::actionDownload) else if (action==OP_DFU::actionDownload)
{ {
if(((OP_DFU::device)dfu.devices[device]).Readable==false)
{
cout<<"ERROR device not readable\n";
return false;
}
qint32 size=((OP_DFU::device)dfu.devices[device]).SizeOfCode; qint32 size=((OP_DFU::device)dfu.devices[device]).SizeOfCode;
bool ret=dfu.SaveByteArrayToFile(file.toAscii(),dfu.StartDownload(size,OP_DFU::FW)); bool ret=dfu.SaveByteArrayToFile(file.toAscii(),dfu.StartDownload(size,OP_DFU::FW));
return ret; return ret;
} }
// else if(action==OP_DFU::downdesc) else if(action==OP_DFU::actionCompareCrc)
// {
// int size=((OP_DFU::device)dfu.devices[device]).SizeOfDesc;
// cout<<"Description:"<<dfu.DownloadDescription(size).toLatin1().data()<<"\n";
// }
else if(action==OP_DFU::actionCompareHash)
{ {
dfu.CompareFirmware(file.toAscii(),OP_DFU::hashcompare); dfu.CompareFirmware(file.toAscii(),OP_DFU::crccompare,device);
return 1; return 1;
} }
else if(action==OP_DFU::actionCompareAll) else if(action==OP_DFU::actionCompareAll)
{ {
dfu.CompareFirmware(file.toAscii(),OP_DFU::bytetobytecompare); if(((OP_DFU::device)dfu.devices[device]).Readable==false)
{
cout<<"ERROR device not readable\n";
return false;
}
dfu.CompareFirmware(file.toAscii(),OP_DFU::bytetobytecompare,device);
return 1; return 1;
} }

View File

@ -6,6 +6,7 @@
OP_DFU::OP_DFU(bool _debug): debug(_debug) OP_DFU::OP_DFU(bool _debug): debug(_debug)
{ {
send_delay=10; send_delay=10;
use_delay=true;
int numDevices=0; int numDevices=0;
cout<<"Please connect device now\n"; cout<<"Please connect device now\n";
int count=0; int count=0;
@ -148,7 +149,8 @@ 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]; // 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); //delay::msleep(send_delay);
if(int ret=StatusRequest()!=OP_DFU::uploading) return false;
int result = hidHandle.send(0,buf, BUF_LEN, 5000); int result = hidHandle.send(0,buf, BUF_LEN, 5000);
// qDebug()<<"sent:"<<result; // qDebug()<<"sent:"<<result;
if(result<1) if(result<1)
@ -165,8 +167,7 @@ bool OP_DFU::UploadData(qint32 const & numberOfBytes, QByteArray & data)
} }
OP_DFU::Status OP_DFU::UploadDescription(QString & description) OP_DFU::Status OP_DFU::UploadDescription(QString & description)
{ {
if(debug) cout<<"Starting uploading description\n";
qDebug()<<"Starting uploading description";
if(description.length()%4!=0) if(description.length()%4!=0)
{ {
int pad=description.length()/4; int pad=description.length()/4;
@ -188,7 +189,7 @@ OP_DFU::Status OP_DFU::UploadDescription(QString & description)
return OP_DFU::abort; return OP_DFU::abort;
} }
int ret=StatusRequest(); int ret=StatusRequest();
qDebug()<<"------"<<ret;
if(debug) if(debug)
qDebug()<<"Upload description Status="<<ret; qDebug()<<"Upload description Status="<<ret;
return (OP_DFU::Status)ret; return (OP_DFU::Status)ret;
@ -486,12 +487,13 @@ OP_DFU::Status OP_DFU::UploadFirmware(const QString &sfile, const bool &verify,i
} }
return OP_DFU::abort; return OP_DFU::abort;
} }
cout<<"Erasing memory"; cout<<"Erasing memory\n";
delay::msleep(3000); if(StatusRequest()==OP_DFU::abort) return OP_DFU::abort;
for(int x=0;x<3;++x) for(int x=0;x<3;++x)
{ {
OP_DFU::Status ret=StatusRequest(); OP_DFU::Status ret=StatusRequest();
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
@ -518,7 +520,6 @@ OP_DFU::Status OP_DFU::UploadFirmware(const QString &sfile, const bool &verify,i
return OP_DFU::abort; return OP_DFU::abort;
} }
ret=StatusRequest(); ret=StatusRequest();
// qDebug()<<"---------------------------"<<StatusToString(ret);
if(ret==OP_DFU::Last_operation_Success) if(ret==OP_DFU::Last_operation_Success)
{ {
@ -547,7 +548,7 @@ OP_DFU::Status OP_DFU::UploadFirmware(const QString &sfile, const bool &verify,i
cout<<"Firmware Uploading succeeded\n"; cout<<"Firmware Uploading succeeded\n";
return ret; return ret;
} }
OP_DFU::Status OP_DFU::CompareFirmware(const QString &sfile, const CompareType &type) OP_DFU::Status OP_DFU::CompareFirmware(const QString &sfile, const CompareType &type,int device)
{ {
cout<<"Starting Firmware Compare...\n"; cout<<"Starting Firmware Compare...\n";
QFile file(sfile); QFile file(sfile);
@ -558,9 +559,7 @@ OP_DFU::Status OP_DFU::CompareFirmware(const QString &sfile, const CompareType &
return OP_DFU::abort; return OP_DFU::abort;
} }
QByteArray arr=file.readAll(); QByteArray arr=file.readAll();
QByteArray hash=QCryptographicHash::hash(arr,QCryptographicHash::Sha1);
if(debug)
qDebug()<<"hash size="<<hash.length()<<" -"<<hash;
if(debug) if(debug)
qDebug()<<"Bytes Loaded="<<arr.length(); qDebug()<<"Bytes Loaded="<<arr.length();
if(arr.length()%4!=0) if(arr.length()%4!=0)
@ -571,18 +570,19 @@ OP_DFU::Status OP_DFU::CompareFirmware(const QString &sfile, const CompareType &
pad=pad-arr.length(); pad=pad-arr.length();
arr.append(QByteArray(pad,255)); arr.append(QByteArray(pad,255));
} }
if(type==OP_DFU::hashcompare) if(type==OP_DFU::crccompare)
{ {
// if(hash==StartDownload(hash.length(),OP_DFU::Hash)) quint32 crc=CRCFromQBArray(arr,devices[device].SizeOfCode);
// { if(crc==devices[device].FW_CRC)
// cout<<"Compare Successfull Hashes MATCH!\n"; {
// } cout<<"Compare Successfull CRC MATCH!\n";
// else }
// { else
// cout<<"Compare failed Hashes DONT MATCH!\n"; {
// } cout<<"Compare failed CRC DONT MATCH!\n";
// return StatusRequest(); }
} return StatusRequest();
}
else else
{ {
if(arr==StartDownload(arr.length(),OP_DFU::FW)) if(arr==StartDownload(arr.length(),OP_DFU::FW))

View File

@ -19,7 +19,7 @@ using namespace std;
#define PROGRAMFW "-p" //done #define PROGRAMFW "-p" //done
#define PROGRAMDESC "-w" //done #define PROGRAMDESC "-w" //done
#define VERIFY "-v" //done #define VERIFY "-v" //done
#define COMPAREHASH "-cc" #define COMPARECRC "-cc"
#define COMPAREALL "-ca" #define COMPAREALL "-ca"
#define STATUSREQUEST "-s" //done #define STATUSREQUEST "-s" //done
#define LISTDEVICES "-ls" //done #define LISTDEVICES "-ls" //done
@ -36,7 +36,7 @@ public:
}; };
enum CompareType enum CompareType
{ {
hashcompare, crccompare,
bytetobytecompare bytetobytecompare
}; };
@ -64,7 +64,7 @@ public:
actionProgramAndVerify, actionProgramAndVerify,
actionDownload, actionDownload,
actionCompareAll, actionCompareAll,
actionCompareHash, actionCompareCrc,
actionListDevs, actionListDevs,
actionStatusReq, actionStatusReq,
actionReset, actionReset,
@ -119,11 +119,12 @@ public:
QList<device> devices; QList<device> devices;
int numberOfDevices; int numberOfDevices;
QString StatusToString(OP_DFU::Status const & status); QString StatusToString(OP_DFU::Status const & status);
OP_DFU::Status CompareFirmware(const QString &sfile, const CompareType &type); OP_DFU::Status CompareFirmware(const QString &sfile, const CompareType &type,int device);
quint32 CRC32WideFast(quint32 Crc, quint32 Size, quint32 *Buffer); quint32 CRC32WideFast(quint32 Crc, quint32 Size, quint32 *Buffer);
quint32 CRCFromQBArray(QByteArray array, quint32 Size); quint32 CRCFromQBArray(QByteArray array, quint32 Size);
void test(); void test();
int send_delay; int send_delay;
bool use_delay;
private: private:
bool debug; bool debug;
int RWFlags; int RWFlags;