diff --git a/ground/src/experimental/USB_UPLOAD_TOOL/main.cpp b/ground/src/experimental/USB_UPLOAD_TOOL/main.cpp new file mode 100644 index 000000000..e67d90742 --- /dev/null +++ b/ground/src/experimental/USB_UPLOAD_TOOL/main.cpp @@ -0,0 +1,28 @@ +#include +#include +#include <../../plugins/rawhid/pjrc_rawhid.h> +#include "op_dfu.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + OP_DFU dfu; +// dfu.enterDFU(1); +// dfu.StartUpload(4,OP_DFU::Descript); +// QByteArray array; +// array[0]=11; +// array[1]=2; +// array[2]=3; +// array[3]=4; +// array[4]=5; +// array[5]=6; +// array[6]=7; +// array[7]=8; +// dfu.UploadData(8,array); + //dfu.UploadDescription(1,"jose manuel"); + //QString str=dfu.DownloadDescription(1,12); + // dfu.JumpToApp(); + dfu.UploadFirmware("C:/OpenPilot.bin"); + //qDebug()<<"Description="< +OP_DFU::OP_DFU() +{ + qDebug() << "Hello"; + + int numDevices = hidHandle.open(1,0x20a0,0x4117,0,0); //0xff9c,0x0001); + if( numDevices == 0 ) + numDevices = hidHandle.open(1,0x0483,0,0,0); + + qDebug() << numDevices << " device(s) opened"; +} +void OP_DFU::enterDFU(int devNumber) +{ + char buf[BUF_LEN]; + buf[0] =0x02;//reportID + buf[1] = OP_DFU::EnterDFU;//DFU Command + buf[2] = 0;//DFU Count + buf[3] = 0;//DFU Count + buf[4] = 0;//DFU Count + buf[5] = 0;//DFU Count + buf[6] = devNumber;//DFU Data0 + buf[7] = 1;//DFU Data1 + buf[8] = 1;//DFU Data2 + buf[9] = 1;//DFU Data3 + + int result = hidHandle.send(0,buf, BUF_LEN, 500); + + qDebug() << result << " bytes sent"; +} +void OP_DFU::StartUpload(qint32 numberOfPackets, TransferTypes type) +{ + char buf[BUF_LEN]; + buf[0] =0x02;//reportID + buf[1] = setStartBit(OP_DFU::Upload);//DFU Command + 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] = 1;//DFU Data1 + buf[8] = 1;//DFU Data2 + buf[9] = 1;//DFU Data3 + + int result = hidHandle.send(0,buf, BUF_LEN, 5000); + + qDebug() << result << " bytes sent"; +} +void OP_DFU::UploadData(qint32 numberOfPackets, QByteArray data) +{ + qDebug()<<"Start Uploading:"<>24;//DFU Count + buf[3] = packetcount>>16;//DFU Count + buf[4] = packetcount>>8;//DFU Count + buf[5] = packetcount;//DFU Count + buf[6] = data[packetcount*4+3];//DFU Data0 + buf[7] = data[packetcount*4+2];//DFU Data1 + buf[8] = data[packetcount*4+1];//DFU Data2 + buf[9] = data[packetcount*4];//DFU Data3 + + int result = hidHandle.send(0,buf, BUF_LEN, 5000); + qDebug()<