diff --git a/ground/src/experimental/USB_UPLOAD_TOOL/main.cpp b/ground/src/experimental/USB_UPLOAD_TOOL/main.cpp index 6bad5d6c7..4f0fc373a 100644 --- a/ground/src/experimental/USB_UPLOAD_TOOL/main.cpp +++ b/ground/src/experimental/USB_UPLOAD_TOOL/main.cpp @@ -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 : program hw (requires:-d - optionals:-v,-w)\n"; - cout<<"| -dn : download firmware to file (requires:-d)\n"; - cout<<"| -dd : download discription (requires:-d)\n"; - cout<<"| -d : (requires: -p)\n"; - cout<<"| -ca : compares byte by byte current firmware with file\n"; - cout<<"| -ch : 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 : program hw (requires:-d - optionals:-v,-w)\n"; + cout<<"| -v : verify (requires:-d)\n"; + cout<<"| -dn : download firmware to file (requires:-d)\n"; + cout<<"| -dd : download discription (requires:-d)\n"; + cout<<"| -d : (requires: -p)\n"; + cout<<"| -ca : compares byte by byte current firmware with file\n"; + cout<<"| -ch : 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)+1dfu.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.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.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:"<>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:"<"); + }else{ + bar.replace(i,1," "); + } + } + + std::cout<< "\r"< 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); diff --git a/ground/src/experimental/USB_UPLOAD_TOOL/upload.pro b/ground/src/experimental/USB_UPLOAD_TOOL/upload.pro index 3e872c878..b89b2dbd1 100644 --- a/ground/src/experimental/USB_UPLOAD_TOOL/upload.pro +++ b/ground/src/experimental/USB_UPLOAD_TOOL/upload.pro @@ -8,7 +8,7 @@ QT += core QT -= gui -TARGET = HIDTest +TARGET = OPUploadTool CONFIG += console CONFIG -= app_bundle