mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-30 08:24:11 +01:00
OP-21/Flight PC app - Added send delay.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1679 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
97b44ffb04
commit
569e7a94e7
2
ground/src/experimental/USB_UPLOAD_TOOL/delay.cpp
Normal file
2
ground/src/experimental/USB_UPLOAD_TOOL/delay.cpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#include "delay.h"
|
||||||
|
|
13
ground/src/experimental/USB_UPLOAD_TOOL/delay.h
Normal file
13
ground/src/experimental/USB_UPLOAD_TOOL/delay.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef DELAY_H
|
||||||
|
#define DELAY_H
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
|
class delay : public QThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void msleep(unsigned long msecs)
|
||||||
|
{
|
||||||
|
QThread::msleep(msecs);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif // DELAY_H
|
@ -184,6 +184,11 @@ int main(int argc, char *argv[])
|
|||||||
cout<<"Could not enter DFU mode\n";
|
cout<<"Could not enter DFU mode\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
|
OP_DFU::Status ret=dfu.StatusRequest();
|
||||||
|
qDebug()<<dfu.StatusToString(ret);
|
||||||
|
}
|
||||||
if(!(action==OP_DFU::actionStatusReq || action==OP_DFU::actionReset || action== OP_DFU::actionJump))
|
if(!(action==OP_DFU::actionStatusReq || action==OP_DFU::actionReset || action== OP_DFU::actionJump))
|
||||||
{
|
{
|
||||||
dfu.findDevices();
|
dfu.findDevices();
|
||||||
@ -202,6 +207,7 @@ int main(int argc, char *argv[])
|
|||||||
cout<<"FW CRC="<<dfu.devices[x].FW_CRC<<"\n";
|
cout<<"FW CRC="<<dfu.devices[x].FW_CRC<<"\n";
|
||||||
|
|
||||||
int size=((OP_DFU::device)dfu.devices[x]).SizeOfDesc;
|
int size=((OP_DFU::device)dfu.devices[x]).SizeOfDesc;
|
||||||
|
dfu.enterDFU(x);
|
||||||
cout<<"Description:"<<dfu.DownloadDescription(size).toLatin1().data()<<"\n";
|
cout<<"Description:"<<dfu.DownloadDescription(size).toLatin1().data()<<"\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
}
|
}
|
||||||
@ -274,10 +280,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//OP_DFU dfu(false);
|
OP_DFU dfu(true);
|
||||||
//dfu.findDevices();
|
//dfu.findDevices();
|
||||||
|
dfu.enterDFU(1);
|
||||||
//dfu.UploadFirmware("c:/openpilot.bin",true,0);
|
dfu.UploadFirmware("c:/ahrs.bin",true,1);
|
||||||
// dfu.UploadDescription("josemanuel");
|
// dfu.UploadDescription("josemanuel");
|
||||||
// QString str=dfu.DownloadDescription(12);
|
// QString str=dfu.DownloadDescription(12);
|
||||||
// dfu.JumpToApp();
|
// dfu.JumpToApp();
|
||||||
|
@ -5,17 +5,14 @@
|
|||||||
|
|
||||||
OP_DFU::OP_DFU(bool _debug): debug(_debug)
|
OP_DFU::OP_DFU(bool _debug): debug(_debug)
|
||||||
{
|
{
|
||||||
QWaitCondition sleep;
|
send_delay=10;
|
||||||
QMutex mutex;
|
|
||||||
int numDevices=0;
|
int numDevices=0;
|
||||||
cout<<"Please connect device now\n";
|
cout<<"Please connect device now\n";
|
||||||
int count=0;
|
int count=0;
|
||||||
while(numDevices==0)
|
while(numDevices==0)
|
||||||
{
|
{
|
||||||
cout<<".";
|
cout<<".";
|
||||||
mutex.lock();
|
delay::msleep(500);
|
||||||
sleep.wait(&mutex,500);
|
|
||||||
mutex.unlock();
|
|
||||||
numDevices = hidHandle.open(1,0x20a0,0x4117,0,0); //0xff9c,0x0001);
|
numDevices = hidHandle.open(1,0x20a0,0x4117,0,0); //0xff9c,0x0001);
|
||||||
if(++count==10)
|
if(++count==10)
|
||||||
{
|
{
|
||||||
@ -91,7 +88,7 @@ bool OP_DFU::StartUpload(qint32 const & numberOfBytes, TransferTypes const & typ
|
|||||||
buf[9] = crc>>16;
|
buf[9] = crc>>16;
|
||||||
buf[10] = crc>>8;
|
buf[10] = crc>>8;
|
||||||
buf[11] = crc;
|
buf[11] = crc;
|
||||||
|
if(debug)
|
||||||
qDebug()<<"Number of packets:"<<numberOfPackets<<" Size of last packet:"<<lastPacketCount;
|
qDebug()<<"Number of packets:"<<numberOfPackets<<" Size of last packet:"<<lastPacketCount;
|
||||||
int result = hidHandle.send(0,buf, BUF_LEN, 5000);
|
int result = hidHandle.send(0,buf, BUF_LEN, 5000);
|
||||||
if(debug)
|
if(debug)
|
||||||
@ -104,7 +101,6 @@ bool OP_DFU::StartUpload(qint32 const & numberOfBytes, TransferTypes const & typ
|
|||||||
}
|
}
|
||||||
bool OP_DFU::UploadData(qint32 const & numberOfBytes, QByteArray & data)
|
bool OP_DFU::UploadData(qint32 const & numberOfBytes, QByteArray & data)
|
||||||
{
|
{
|
||||||
qDebug()<<(int)data[0];
|
|
||||||
int lastPacketCount;
|
int lastPacketCount;
|
||||||
qint32 numberOfPackets=numberOfBytes/4/14;
|
qint32 numberOfPackets=numberOfBytes/4/14;
|
||||||
int pad=(numberOfBytes-numberOfPackets*4*14)/4;
|
int pad=(numberOfBytes-numberOfPackets*4*14)/4;
|
||||||
@ -135,6 +131,7 @@ bool OP_DFU::UploadData(qint32 const & numberOfBytes, QByteArray & data)
|
|||||||
packetsize=lastPacketCount;
|
packetsize=lastPacketCount;
|
||||||
else
|
else
|
||||||
packetsize=14;
|
packetsize=14;
|
||||||
|
// qDebug()<<packetcount;
|
||||||
buf[2] = packetcount>>24;//DFU Count
|
buf[2] = packetcount>>24;//DFU Count
|
||||||
buf[3] = packetcount>>16;//DFU Count
|
buf[3] = packetcount>>16;//DFU Count
|
||||||
buf[4] = packetcount>>8;//DFU Count
|
buf[4] = packetcount>>8;//DFU Count
|
||||||
@ -151,8 +148,9 @@ 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);
|
||||||
int result = hidHandle.send(0,buf, BUF_LEN, 5000);
|
int result = hidHandle.send(0,buf, BUF_LEN, 5000);
|
||||||
|
// qDebug()<<"sent:"<<result;
|
||||||
if(result<1)
|
if(result<1)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -162,10 +160,13 @@ bool OP_DFU::UploadData(qint32 const & numberOfBytes, QByteArray & data)
|
|||||||
|
|
||||||
}
|
}
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
|
// while(true){}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
OP_DFU::Status OP_DFU::UploadDescription(QString & description)
|
OP_DFU::Status OP_DFU::UploadDescription(QString & description)
|
||||||
{
|
{
|
||||||
|
if(debug)
|
||||||
|
qDebug()<<"Starting uploading description";
|
||||||
if(description.length()%4!=0)
|
if(description.length()%4!=0)
|
||||||
{
|
{
|
||||||
int pad=description.length()/4;
|
int pad=description.length()/4;
|
||||||
@ -446,6 +447,7 @@ bool OP_DFU::EndOperation()
|
|||||||
}
|
}
|
||||||
OP_DFU::Status OP_DFU::UploadFirmware(const QString &sfile, const bool &verify,int device)
|
OP_DFU::Status OP_DFU::UploadFirmware(const QString &sfile, const bool &verify,int device)
|
||||||
{
|
{
|
||||||
|
OP_DFU::Status ret;
|
||||||
cout<<"Starting Firmware Uploading...\n";
|
cout<<"Starting Firmware Uploading...\n";
|
||||||
QFile file(sfile);
|
QFile file(sfile);
|
||||||
//QFile file("in.txt");
|
//QFile file("in.txt");
|
||||||
@ -467,17 +469,29 @@ OP_DFU::Status OP_DFU::UploadFirmware(const QString &sfile, const bool &verify,i
|
|||||||
pad=pad-arr.length();
|
pad=pad-arr.length();
|
||||||
arr.append(QByteArray(pad,255));
|
arr.append(QByteArray(pad,255));
|
||||||
}
|
}
|
||||||
|
if(devices[device].SizeOfCode<arr.length())
|
||||||
|
{
|
||||||
|
cout<<"ERROR file to big for device\n";
|
||||||
|
return OP_DFU::abort;;
|
||||||
|
}
|
||||||
quint32 crc=CRCFromQBArray(arr,devices[device].SizeOfCode);
|
quint32 crc=CRCFromQBArray(arr,devices[device].SizeOfCode);
|
||||||
|
cout<<"NEW FIRMWARE CRC="<<crc<<"\n";
|
||||||
if(!StartUpload(arr.length(),FW,crc))
|
if(!StartUpload(arr.length(),FW,crc))
|
||||||
{
|
{
|
||||||
if(debug)
|
if(debug)
|
||||||
|
{
|
||||||
qDebug()<<"StartUpload failed";
|
qDebug()<<"StartUpload failed";
|
||||||
|
OP_DFU::Status ret=StatusRequest();
|
||||||
|
qDebug()<<"StartUpload returned:"<< StatusToString(ret);
|
||||||
|
}
|
||||||
return OP_DFU::abort;
|
return OP_DFU::abort;
|
||||||
}
|
}
|
||||||
cout<<"Erasing memory";
|
cout<<"Erasing memory";
|
||||||
|
delay::msleep(3000);
|
||||||
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 (ret==OP_DFU::uploading)
|
if (ret==OP_DFU::uploading)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
@ -486,23 +500,32 @@ OP_DFU::Status OP_DFU::UploadFirmware(const QString &sfile, const bool &verify,i
|
|||||||
if(!UploadData(arr.length(),arr))
|
if(!UploadData(arr.length(),arr))
|
||||||
{
|
{
|
||||||
if(debug)
|
if(debug)
|
||||||
qDebug()<<"Upload failed";
|
{
|
||||||
|
qDebug()<<"Upload failed (upload data)";
|
||||||
|
OP_DFU::Status ret=StatusRequest();
|
||||||
|
qDebug()<<"StartUpload returned:"<<StatusToString(ret);
|
||||||
|
}
|
||||||
return OP_DFU::abort;
|
return OP_DFU::abort;
|
||||||
}
|
}
|
||||||
if(!EndOperation())
|
if(!EndOperation())
|
||||||
{
|
{
|
||||||
if(debug)
|
if(debug)
|
||||||
qDebug()<<"Upload failed";
|
{
|
||||||
|
qDebug()<<"Upload failed (end operation)";
|
||||||
|
OP_DFU::Status ret=StatusRequest();
|
||||||
|
qDebug()<<"StartUpload returned:"<<StatusToString(ret);
|
||||||
|
}
|
||||||
return OP_DFU::abort;
|
return OP_DFU::abort;
|
||||||
}
|
}
|
||||||
OP_DFU::Status ret=StatusRequest();
|
ret=StatusRequest();
|
||||||
|
// qDebug()<<"---------------------------"<<StatusToString(ret);
|
||||||
if(ret==OP_DFU::Last_operation_Success)
|
if(ret==OP_DFU::Last_operation_Success)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return OP_DFU::abort;
|
return ret;
|
||||||
}
|
}
|
||||||
if(verify)
|
if(verify)
|
||||||
{
|
{
|
||||||
@ -614,6 +637,8 @@ QString OP_DFU::StatusToString(OP_DFU::Status const & status)
|
|||||||
return "Jmp to user FW failed";
|
return "Jmp to user FW failed";
|
||||||
case abort:
|
case abort:
|
||||||
return "abort";
|
return "abort";
|
||||||
|
case uploadingStarting:
|
||||||
|
return "Uploading Starting";
|
||||||
default:
|
default:
|
||||||
return "unknown";
|
return "unknown";
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "delay.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
#define BUF_LEN 64
|
#define BUF_LEN 64
|
||||||
|
|
||||||
@ -41,19 +42,20 @@ public:
|
|||||||
|
|
||||||
enum Status
|
enum Status
|
||||||
{
|
{
|
||||||
DFUidle,
|
DFUidle,//0
|
||||||
uploading,
|
uploading,//1
|
||||||
wrong_packet_received,
|
wrong_packet_received,//2
|
||||||
too_many_packets,
|
too_many_packets,//3
|
||||||
too_few_packets,
|
too_few_packets,//4
|
||||||
Last_operation_Success,
|
Last_operation_Success,//5
|
||||||
downloading,
|
downloading,//6
|
||||||
idle,
|
idle,//7
|
||||||
Last_operation_failed,
|
Last_operation_failed,//8
|
||||||
outsideDevCapabilities,
|
uploadingStarting,//9
|
||||||
CRC_Fail,
|
outsideDevCapabilities,//10
|
||||||
failed_jump,
|
CRC_Fail,//11
|
||||||
abort
|
failed_jump,//12
|
||||||
|
abort//13
|
||||||
|
|
||||||
};
|
};
|
||||||
enum Actions
|
enum Actions
|
||||||
@ -121,6 +123,7 @@ public:
|
|||||||
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;
|
||||||
private:
|
private:
|
||||||
bool debug;
|
bool debug;
|
||||||
int RWFlags;
|
int RWFlags;
|
||||||
|
@ -15,9 +15,11 @@ CONFIG -= app_bundle
|
|||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
op_dfu.cpp
|
op_dfu.cpp \
|
||||||
|
delay.cpp
|
||||||
HEADERS += ../../plugins/rawhid/pjrc_rawhid.h \
|
HEADERS += ../../plugins/rawhid/pjrc_rawhid.h \
|
||||||
op_dfu.h
|
op_dfu.h \
|
||||||
|
delay.h
|
||||||
|
|
||||||
win32 {
|
win32 {
|
||||||
SOURCES += ../../plugins/rawhid/pjrc_rawhid_win.cpp
|
SOURCES += ../../plugins/rawhid/pjrc_rawhid_win.cpp
|
||||||
|
Loading…
Reference in New Issue
Block a user