mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +01:00
OP-21/Flight Bootloader PC APP- More command line parameters handled.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1531 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
492227c916
commit
70715ba0e2
@ -9,215 +9,238 @@ int main(int argc, char *argv[])
|
||||
QCoreApplication a(argc, argv);
|
||||
if(argc>1)
|
||||
{
|
||||
bool debug=false;
|
||||
OP_DFU::Actions action;
|
||||
QString file;
|
||||
QString description;
|
||||
int device=-1;
|
||||
QStringList args;
|
||||
for(int i=0;i<argc;++i)
|
||||
{
|
||||
args<<argv[i];
|
||||
}
|
||||
bool verify;
|
||||
bool debug=false;
|
||||
OP_DFU::Actions action;
|
||||
QString file;
|
||||
QString description;
|
||||
int device=-1;
|
||||
QStringList args;
|
||||
for(int i=0;i<argc;++i)
|
||||
{
|
||||
args<<argv[i];
|
||||
}
|
||||
|
||||
if(args.contains("-?"))
|
||||
{
|
||||
cout<<"| Commands\n";
|
||||
cout<<"| \n";
|
||||
cout<<"| -ls : lists available devices\n";
|
||||
cout<<"| -p <file> : program hw (requires:-d - optionals:-v,-w)\n";
|
||||
cout<<"| -dn <file> : download firmware to file (requires:-d)\n";
|
||||
cout<<"| -dd <file> : download discription (requires:-d)\n";
|
||||
cout<<"| -d <number Of Device : (requires: -p or -dn)\n";
|
||||
cout<<"| -w <description> : (requires: -p)\n";
|
||||
cout<<"| -ca <file> : compares byte by byte current firmware with file\n";
|
||||
cout<<"| -ch <file> : compares hash of current firmware with file\n";
|
||||
cout<<"| -s : requests status of device\n";
|
||||
return 0;
|
||||
if(args.contains("-?"))
|
||||
{
|
||||
cout<<"| Commands\n";
|
||||
cout<<"| \n";
|
||||
cout<<"| -ls : lists available devices\n";
|
||||
cout<<"| -p <file> : program hw (requires:-d - optionals:-v,-w)\n";
|
||||
cout<<"| -v : verify (requires:-d)\n";
|
||||
cout<<"| -dn <file> : download firmware to file (requires:-d)\n";
|
||||
cout<<"| -dd <file> : download discription (requires:-d)\n";
|
||||
cout<<"| -d <number Of Device : (requires: -p or -dn)\n";
|
||||
cout<<"| -w <description> : (requires: -p)\n";
|
||||
cout<<"| -ca <file> : compares byte by byte current firmware with file\n";
|
||||
cout<<"| -ch <file> : compares hash of current firmware with file\n";
|
||||
cout<<"| -s : requests status of device\n";
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
else if(args.contains("-dd"))
|
||||
{
|
||||
action=OP_DFU::downdesc;
|
||||
if(args.contains(DEVICE))
|
||||
}
|
||||
else if(args.contains(DOWNDESCRIPTION))
|
||||
{
|
||||
if(args.indexOf(DEVICE)+1<args.length())
|
||||
action=OP_DFU::downdesc;
|
||||
if(args.contains(DEVICE))
|
||||
{
|
||||
device=(args[args.indexOf(DEVICE)+1]).toInt();
|
||||
if(args.indexOf(DEVICE)+1<args.length())
|
||||
{
|
||||
device=(args[args.indexOf(DEVICE)+1]).toInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(args.contains("-p"))
|
||||
{
|
||||
if(args.contains("-w"))
|
||||
else if(args.contains(PROGRAMFW))
|
||||
{
|
||||
if(args.indexOf("-w")+1<args.length())
|
||||
if(args.contains(VERIFY))
|
||||
{
|
||||
description=(args[args.indexOf("-w")+1]);
|
||||
verify=true;
|
||||
}
|
||||
else
|
||||
verify=false;
|
||||
if(args.contains(PROGRAMDESC))
|
||||
{
|
||||
if(args.indexOf(PROGRAMDESC)+1<args.length())
|
||||
{
|
||||
description=(args[args.indexOf(PROGRAMDESC)+1]);
|
||||
}
|
||||
|
||||
}
|
||||
action=OP_DFU::program;
|
||||
if(args.contains(DEVICE))
|
||||
{
|
||||
if(args.indexOf(DEVICE)+1<args.length())
|
||||
{
|
||||
device=(args[args.indexOf(DEVICE)+1]).toInt();
|
||||
}
|
||||
if(args.indexOf("-p")+1<args.length())
|
||||
action=OP_DFU::program;
|
||||
if(args.contains(DEVICE))
|
||||
{
|
||||
file=args[args.indexOf("-p")+1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<("Device not specified\n");
|
||||
return -1;
|
||||
}
|
||||
if(args.contains("-v"))
|
||||
action=OP_DFU::programandverify;
|
||||
}
|
||||
else if(args.contains("-ch") || args.contains("-ca"))
|
||||
{
|
||||
int index;
|
||||
if(args.contains("-ch"))
|
||||
{
|
||||
index=args.indexOf("-ch");
|
||||
action=OP_DFU::comparehash;
|
||||
}
|
||||
else
|
||||
{
|
||||
index=args.indexOf("-ca");
|
||||
action=OP_DFU::compareall;
|
||||
}
|
||||
if(args.contains(DEVICE))
|
||||
{
|
||||
if(args.indexOf(DEVICE)+1<args.length())
|
||||
{
|
||||
device=(args[args.indexOf(DEVICE)+1]).toInt();
|
||||
if(args.indexOf(DEVICE)+1<args.length())
|
||||
{
|
||||
device=(args[args.indexOf(DEVICE)+1]).toInt();
|
||||
}
|
||||
if(args.indexOf(PROGRAMFW)+1<args.length())
|
||||
{
|
||||
file=args[args.indexOf(PROGRAMFW)+1];
|
||||
}
|
||||
}
|
||||
if(index+1<args.length())
|
||||
else
|
||||
{
|
||||
file=args[index+1];
|
||||
cout<<("Device not specified\n");
|
||||
return -1;
|
||||
}
|
||||
if(args.contains(VERIFY))
|
||||
action=OP_DFU::programandverify;
|
||||
}
|
||||
else if(args.contains(COMPAREHASH) || args.contains(COMPAREALL))
|
||||
{
|
||||
int index;
|
||||
if(args.contains(COMPAREHASH))
|
||||
{
|
||||
index=args.indexOf(COMPAREHASH);
|
||||
action=OP_DFU::comparehash;
|
||||
}
|
||||
else
|
||||
{
|
||||
index=args.indexOf(COMPAREALL);
|
||||
action=OP_DFU::compareall;
|
||||
}
|
||||
if(args.contains(DEVICE))
|
||||
{
|
||||
if(args.indexOf(DEVICE)+1<args.length())
|
||||
{
|
||||
device=(args[args.indexOf(DEVICE)+1]).toInt();
|
||||
}
|
||||
if(index+1<args.length())
|
||||
{
|
||||
file=args[index+1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"Device not specified";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(args.contains(DOWNLOAD))
|
||||
{
|
||||
cout<<"Device not specified";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if(args.contains(DOWNLOAD))
|
||||
{
|
||||
int index;
|
||||
int index;
|
||||
index=args.indexOf(DOWNLOAD);
|
||||
action=OP_DFU::download;
|
||||
|
||||
if(args.contains(DEVICE))
|
||||
{
|
||||
if(args.indexOf(DEVICE)+1<args.length())
|
||||
if(args.contains(DEVICE))
|
||||
{
|
||||
device=(args[args.indexOf(DEVICE)+1]).toInt();
|
||||
}
|
||||
if(index+1<args.length())
|
||||
{
|
||||
file=args[index+1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"Device not specified";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if(args.contains("-s"))
|
||||
{
|
||||
action=OP_DFU::statusreq;
|
||||
}
|
||||
else if(args.contains("-ls"))
|
||||
{
|
||||
action=OP_DFU::listdevs;
|
||||
}
|
||||
if((file.isEmpty()|| device==-1) && action!=OP_DFU::downdesc && action!=OP_DFU::statusreq && action!=OP_DFU::listdevs)
|
||||
{
|
||||
cout<<"wrong parameters";
|
||||
return -1;
|
||||
}
|
||||
|
||||
// qDebug()<<"Action="<<(int)action;
|
||||
// qDebug()<<"File="<<file;
|
||||
// qDebug()<<"Device="<<device;
|
||||
// qDebug()<<"Action="<<action;
|
||||
OP_DFU dfu(debug);
|
||||
if(!dfu.enterDFU(0))
|
||||
{
|
||||
cout<<"Could not enter DFU mode\n";
|
||||
return -1;
|
||||
}
|
||||
if(action!=OP_DFU::statusreq)
|
||||
{
|
||||
dfu.findDevices();
|
||||
if(action==OP_DFU::listdevs)
|
||||
{
|
||||
cout<<"Found "<<dfu.numberOfDevices<<"\n";
|
||||
for(int x=0;x<dfu.numberOfDevices;++x)
|
||||
{
|
||||
cout<<"Device #"<<x+1<<"\n";
|
||||
cout<<"Device ID="<<dfu.devices[x].ID<<"\n";
|
||||
cout<<"Device Readable="<<dfu.devices[x].Readable<<"\n";
|
||||
cout<<"Device Writable="<<dfu.devices[x].Writable<<"\n";
|
||||
cout<<"Device SizeOfCode="<<dfu.devices[x].SizeOfCode<<"\n";
|
||||
cout<<"Device SizeOfHash="<<dfu.devices[x].SizeOfHash<<"\n";
|
||||
cout<<"Device SizeOfDesc="<<dfu.devices[x].SizeOfDesc<<"\n";
|
||||
cout<<"\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else if (action==OP_DFU::program)
|
||||
{
|
||||
if(device>dfu.numberOfDevices)
|
||||
{
|
||||
cout<<"Error:Invalid Device";
|
||||
return -1;
|
||||
}
|
||||
if(!dfu.enterDFU(device))
|
||||
{
|
||||
cout<<"Error:Could not enter DFU mode\n";
|
||||
return -1;
|
||||
}
|
||||
OP_DFU::Status retstatus=dfu.UploadFirmware(file.toAscii());
|
||||
if(retstatus!=OP_DFU::Last_operation_Success)
|
||||
{
|
||||
cout<<"Upload failed with code:"<<dfu.StatusToString(retstatus).data();
|
||||
return -1;
|
||||
}
|
||||
if(!description.isEmpty())
|
||||
{
|
||||
retstatus=dfu.UploadDescription(description);
|
||||
if(retstatus!=OP_DFU::Last_operation_Success)
|
||||
if(args.indexOf(DEVICE)+1<args.length())
|
||||
{
|
||||
cout<<"Upload failed with code:"<<dfu.StatusToString(retstatus).toLatin1().data();
|
||||
return -1;
|
||||
device=(args[args.indexOf(DEVICE)+1]).toInt();
|
||||
}
|
||||
if(index+1<args.length())
|
||||
{
|
||||
file=args[index+1];
|
||||
}
|
||||
}
|
||||
cout<<"Uploading Succeded!\n";
|
||||
else
|
||||
{
|
||||
cout<<"Device not specified";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (action==OP_DFU::download)
|
||||
else if(args.contains(STATUSREQUEST))
|
||||
{
|
||||
qint32 size=((OP_DFU::device)dfu.devices[device]).SizeOfCode;
|
||||
action=OP_DFU::statusreq;
|
||||
}
|
||||
else if(args.contains(LISTDEVICES))
|
||||
{
|
||||
action=OP_DFU::listdevs;
|
||||
}
|
||||
if((file.isEmpty()|| device==-1) && action!=OP_DFU::downdesc && action!=OP_DFU::statusreq && action!=OP_DFU::listdevs)
|
||||
{
|
||||
cout<<"wrong parameters";
|
||||
return -1;
|
||||
}
|
||||
|
||||
// qDebug()<<"Action="<<(int)action;
|
||||
// qDebug()<<"File="<<file;
|
||||
// qDebug()<<"Device="<<device;
|
||||
// qDebug()<<"Action="<<action;
|
||||
OP_DFU dfu(debug);
|
||||
if(!dfu.enterDFU(0))
|
||||
{
|
||||
cout<<"Could not enter DFU mode\n";
|
||||
return -1;
|
||||
}
|
||||
if(action!=OP_DFU::statusreq)
|
||||
{
|
||||
dfu.findDevices();
|
||||
if(action==OP_DFU::listdevs)
|
||||
{
|
||||
cout<<"Found "<<dfu.numberOfDevices<<"\n";
|
||||
for(int x=0;x<dfu.numberOfDevices;++x)
|
||||
{
|
||||
cout<<"Device #"<<x<<"\n";
|
||||
cout<<"Device ID="<<dfu.devices[x].ID<<"\n";
|
||||
cout<<"Device Readable="<<dfu.devices[x].Readable<<"\n";
|
||||
cout<<"Device Writable="<<dfu.devices[x].Writable<<"\n";
|
||||
cout<<"Device SizeOfCode="<<dfu.devices[x].SizeOfCode<<"\n";
|
||||
cout<<"Device SizeOfHash="<<dfu.devices[x].SizeOfHash<<"\n";
|
||||
cout<<"Device SizeOfDesc="<<dfu.devices[x].SizeOfDesc<<"\n";
|
||||
int size=((OP_DFU::device)dfu.devices[x]).SizeOfDesc;
|
||||
cout<<"Description:"<<dfu.DownloadDescription(size).toLatin1().data()<<"\n";
|
||||
cout<<"\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else if (action==OP_DFU::program)
|
||||
{
|
||||
if(device>dfu.numberOfDevices)
|
||||
{
|
||||
cout<<"Error:Invalid Device";
|
||||
return -1;
|
||||
}
|
||||
if(!dfu.enterDFU(device))
|
||||
{
|
||||
cout<<"Error:Could not enter DFU mode\n";
|
||||
return -1;
|
||||
}
|
||||
OP_DFU::Status retstatus=dfu.UploadFirmware(file.toAscii(),verify);
|
||||
if(retstatus!=OP_DFU::Last_operation_Success)
|
||||
{
|
||||
cout<<"Upload failed with code:"<<dfu.StatusToString(retstatus).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";
|
||||
}
|
||||
else if (action==OP_DFU::download)
|
||||
{
|
||||
if(device>dfu.numberOfDevices)
|
||||
{
|
||||
cout<<"Error:Invalid Device";
|
||||
return -1;
|
||||
}
|
||||
if(!dfu.enterDFU(device))
|
||||
{
|
||||
cout<<"Error:Could not enter DFU mode\n";
|
||||
return -1;
|
||||
}
|
||||
qint32 size=((OP_DFU::device)dfu.devices[device]).SizeOfCode;
|
||||
bool ret=dfu.SaveByteArrayToFile(file.toAscii(),dfu.StartDownload(size,OP_DFU::FW));
|
||||
return ret;
|
||||
|
||||
}
|
||||
else if(action==OP_DFU::downdesc)
|
||||
{
|
||||
int size=((OP_DFU::device)dfu.devices[device]).SizeOfDesc;
|
||||
cout<<"Description:"<<dfu.DownloadDescription(size).toLatin1().data();
|
||||
}
|
||||
|
||||
}
|
||||
else if(action==OP_DFU::downdesc)
|
||||
{
|
||||
int size=((OP_DFU::device)dfu.devices[device]).SizeOfDesc;
|
||||
cout<<"Description:"<<dfu.DownloadDescription(size).toLatin1().data();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
OP_DFU dfu(true);
|
||||
OP_DFU dfu(true);
|
||||
dfu.enterDFU(0);
|
||||
// dfu.enterDFU(1);
|
||||
// dfu.StartUpload(4,OP_DFU::Descript);
|
||||
@ -234,12 +257,12 @@ OP_DFU dfu(true);
|
||||
// dfu.UploadDescription(1,"jose manuel");
|
||||
// QString str=dfu.DownloadDescription(1,12);
|
||||
// dfu.JumpToApp();
|
||||
// dfu.findDevices();
|
||||
// dfu.findDevices();
|
||||
|
||||
// dfu.UploadFirmware(filename.toAscii());
|
||||
dfu.UploadFirmware("c:/openpilot.bin",true);
|
||||
// dfu.UploadDescription("josemanuel");
|
||||
QString str=dfu.DownloadDescription(12);
|
||||
// QString str=dfu.DownloadDescription(12);
|
||||
// dfu.JumpToApp();
|
||||
qDebug()<<"Description="<<str;
|
||||
// qDebug()<<"Description="<<str;
|
||||
return a.exec();
|
||||
}
|
||||
|
@ -5,8 +5,8 @@
|
||||
|
||||
OP_DFU::OP_DFU(bool _debug): debug(_debug)
|
||||
{
|
||||
QWaitCondition sleep;
|
||||
QMutex mutex;
|
||||
QWaitCondition sleep;
|
||||
QMutex mutex;
|
||||
int numDevices=0;
|
||||
cout<<"Please connect device now\n";
|
||||
int count=0;
|
||||
@ -28,6 +28,21 @@ QMutex mutex;
|
||||
if(debug)
|
||||
qDebug() << numDevices << " device(s) opened";
|
||||
}
|
||||
bool OP_DFU::SaveByteArrayToFile(QString sfile, const QByteArray &array)
|
||||
{
|
||||
QFile file(sfile);
|
||||
//QFile file("in.txt");
|
||||
if (!file.open(QIODevice::WriteOnly))
|
||||
{
|
||||
if(debug)
|
||||
qDebug()<<"Cant open file";
|
||||
return false;
|
||||
}
|
||||
file.write(array);
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OP_DFU::enterDFU(int devNumber)
|
||||
{
|
||||
char buf[BUF_LEN];
|
||||
@ -104,8 +119,14 @@ bool OP_DFU::UploadData(qint32 numberOfBytes, QByteArray data)
|
||||
buf[0] =0x02;//reportID
|
||||
buf[1] = OP_DFU::Upload;//DFU Command
|
||||
int packetsize;
|
||||
float percentage;
|
||||
int laspercentage;
|
||||
for(qint32 packetcount=0;packetcount<numberOfPackets;++packetcount)
|
||||
{
|
||||
percentage=(float)(packetcount+1)/numberOfPackets*100;
|
||||
if(laspercentage!=(int)percentage)
|
||||
printProgBar((int)percentage,"UPLOADING");
|
||||
laspercentage=(int)percentage;
|
||||
if(packetcount==numberOfPackets)
|
||||
packetsize=lastPacketCount;
|
||||
else
|
||||
@ -133,6 +154,7 @@ bool OP_DFU::UploadData(qint32 numberOfBytes, QByteArray data)
|
||||
}
|
||||
|
||||
// qDebug() << "UPLOAD:"<<"Data="<<(int)buf[6]<<(int)buf[7]<<(int)buf[8]<<(int)buf[9]<<";"<<result << " bytes sent";
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -189,10 +211,10 @@ QByteArray OP_DFU::StartDownload(qint32 numberOfBytes, TransferTypes type)
|
||||
char buf[BUF_LEN];
|
||||
buf[0] =0x02;//reportID
|
||||
buf[1] = OP_DFU::Download_Req;//DFU Command
|
||||
buf[2] = (char)numberOfPackets>>24;//DFU Count
|
||||
buf[3] = (char)numberOfPackets>>16;//DFU Count
|
||||
buf[4] = (char)numberOfPackets>>8;//DFU Count
|
||||
buf[5] = (char)numberOfPackets;//DFU Count
|
||||
buf[2] = numberOfPackets>>24;//DFU Count
|
||||
buf[3] = numberOfPackets>>16;//DFU Count
|
||||
buf[4] = numberOfPackets>>8;//DFU Count
|
||||
buf[5] = numberOfPackets;//DFU Count
|
||||
buf[6] = (int)type;//DFU Data0
|
||||
buf[7] = lastPacketCount;//DFU Data1
|
||||
buf[8] = 1;//DFU Data2
|
||||
@ -200,13 +222,21 @@ QByteArray OP_DFU::StartDownload(qint32 numberOfBytes, TransferTypes type)
|
||||
|
||||
int result = hidHandle.send(0,buf, BUF_LEN, 500);
|
||||
if(debug)
|
||||
qDebug() << "StartDownload:"<<result << " bytes sent";
|
||||
qDebug() << "StartDownload:"<<numberOfPackets<<"packets"<<" Last Packet Size="<<lastPacketCount<<" "<<result << " bytes sent";
|
||||
float percentage;
|
||||
int laspercentage;
|
||||
for(qint32 x=0;x<numberOfPackets;++x)
|
||||
{
|
||||
// qDebug()<<"Status="<<StatusToString(StatusRequest());
|
||||
percentage=(float)(x+1)/numberOfPackets*100;
|
||||
if(laspercentage!=(int)percentage)
|
||||
printProgBar((int)percentage,"DOWNLOADING");
|
||||
laspercentage=(int)percentage;
|
||||
|
||||
|
||||
// qDebug()<<"Status="<<StatusToString(StatusRequest());
|
||||
result = hidHandle.receive(0,buf,BUF_LEN,5000);
|
||||
if(debug)
|
||||
qDebug() << result << " bytes received"<<" Count="<<(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)
|
||||
size=lastPacketCount*4;
|
||||
@ -375,7 +405,7 @@ bool OP_DFU::EndOperation()
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
OP_DFU::Status OP_DFU::UploadFirmware(const QString &sfile)
|
||||
OP_DFU::Status OP_DFU::UploadFirmware(const QString &sfile, const bool &verify)
|
||||
{
|
||||
cout<<"Starting Firmware Uploading...\n";
|
||||
QFile file(sfile);
|
||||
@ -423,6 +453,17 @@ OP_DFU::Status OP_DFU::UploadFirmware(const QString &sfile)
|
||||
{
|
||||
cout<<"Firmware Uploading succeeded...going to upload hash\n";
|
||||
}
|
||||
if(verify)
|
||||
{
|
||||
if(arr==StartDownload(arr.length(),OP_DFU::FW))
|
||||
cout<<"Verify:PASSED\n";
|
||||
else
|
||||
{
|
||||
cout<<"Verify:FAILED\n";
|
||||
return OP_DFU::abort;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return ret;
|
||||
@ -497,3 +538,20 @@ QString OP_DFU::StatusToString(OP_DFU::Status status)
|
||||
|
||||
}
|
||||
}
|
||||
void OP_DFU::printProgBar( int percent,QString const& label){
|
||||
std::string bar;
|
||||
|
||||
for(int i = 0; i < 50; i++){
|
||||
if( i < (percent/2)){
|
||||
bar.replace(i,1,"=");
|
||||
}else if( i == (percent/2)){
|
||||
bar.replace(i,1,">");
|
||||
}else{
|
||||
bar.replace(i,1," ");
|
||||
}
|
||||
}
|
||||
|
||||
std::cout<< "\r"<<label.toLatin1().data()<< "[" << bar << "] ";
|
||||
std::cout.width( 3 );
|
||||
std::cout<< percent << "% " << std::flush;
|
||||
}
|
||||
|
@ -10,8 +10,20 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#define BUF_LEN 64
|
||||
#define DOWNLOAD "-dn"
|
||||
#define DEVICE "-d"
|
||||
|
||||
//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"
|
||||
#define COMPAREHASH "-ch"
|
||||
#define COMPAREALL "-ca"
|
||||
#define STATUSREQUEST "-s" //done
|
||||
#define LISTDEVICES "-ls" //done
|
||||
|
||||
|
||||
class OP_DFU
|
||||
{
|
||||
public:
|
||||
@ -81,11 +93,13 @@ public:
|
||||
bool StartUpload(qint32 numberOfBytes, TransferTypes type);
|
||||
bool UploadData(qint32 numberOfPackets,QByteArray data);
|
||||
Status UploadDescription(QString description);
|
||||
Status UploadFirmware(const QString &sfile);
|
||||
Status UploadFirmware(const QString &sfile, const bool &verify);
|
||||
Status StatusRequest();
|
||||
bool EndOperation();
|
||||
void printProgBar( int percent,QString const& label);
|
||||
QString DownloadDescription(int numberOfChars);
|
||||
QByteArray StartDownload(qint32 numberOfBytes, TransferTypes type);
|
||||
bool SaveByteArrayToFile(QString file,QByteArray const &array);
|
||||
void CopyWords(char * source, char* destination, int count);
|
||||
// QByteArray DownloadData(int devNumber,int numberOfPackets);
|
||||
OP_DFU(bool debug);
|
||||
|
@ -8,7 +8,7 @@ QT += core
|
||||
|
||||
QT -= gui
|
||||
|
||||
TARGET = HIDTest
|
||||
TARGET = OPUploadTool
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user