2010-08-22 19:13:18 +00:00
|
|
|
#ifndef OP_DFU_H
|
|
|
|
#define OP_DFU_H
|
|
|
|
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <../../plugins/rawhid/pjrc_rawhid.h>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QFile>
|
2010-09-02 22:46:06 +00:00
|
|
|
#include <QCryptographicHash>
|
|
|
|
#include <QList>
|
2010-09-04 01:07:44 +00:00
|
|
|
#include <iostream>
|
2010-09-18 00:47:45 +00:00
|
|
|
#include "delay.h"
|
2010-09-04 01:07:44 +00:00
|
|
|
using namespace std;
|
2010-08-24 18:27:32 +00:00
|
|
|
#define BUF_LEN 64
|
2010-09-05 00:18:49 +00:00
|
|
|
|
|
|
|
//Command Line Options
|
|
|
|
#define DOWNLOAD "-dn" //done
|
|
|
|
#define DEVICE "-d" //done
|
2010-09-05 23:15:45 +00:00
|
|
|
//#define DOWNDESCRIPTION "-dd" //done
|
2010-09-05 00:18:49 +00:00
|
|
|
#define PROGRAMFW "-p" //done
|
|
|
|
#define PROGRAMDESC "-w" //done
|
2010-09-05 23:15:45 +00:00
|
|
|
#define VERIFY "-v" //done
|
2010-09-15 18:07:25 +00:00
|
|
|
#define COMPAREHASH "-cc"
|
2010-09-05 00:18:49 +00:00
|
|
|
#define COMPAREALL "-ca"
|
|
|
|
#define STATUSREQUEST "-s" //done
|
|
|
|
#define LISTDEVICES "-ls" //done
|
2010-09-05 23:15:45 +00:00
|
|
|
#define RESET "-r"
|
|
|
|
#define JUMP "-j"
|
2010-09-05 00:18:49 +00:00
|
|
|
|
2010-08-22 19:13:18 +00:00
|
|
|
class OP_DFU
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum TransferTypes
|
|
|
|
{
|
|
|
|
FW,
|
|
|
|
Descript
|
|
|
|
};
|
2010-09-05 23:15:45 +00:00
|
|
|
enum CompareType
|
|
|
|
{
|
|
|
|
hashcompare,
|
|
|
|
bytetobytecompare
|
|
|
|
};
|
|
|
|
|
2010-08-22 19:13:18 +00:00
|
|
|
enum Status
|
|
|
|
{
|
2010-09-18 00:47:45 +00:00
|
|
|
DFUidle,//0
|
|
|
|
uploading,//1
|
|
|
|
wrong_packet_received,//2
|
|
|
|
too_many_packets,//3
|
|
|
|
too_few_packets,//4
|
|
|
|
Last_operation_Success,//5
|
|
|
|
downloading,//6
|
|
|
|
idle,//7
|
|
|
|
Last_operation_failed,//8
|
|
|
|
uploadingStarting,//9
|
|
|
|
outsideDevCapabilities,//10
|
|
|
|
CRC_Fail,//11
|
|
|
|
failed_jump,//12
|
|
|
|
abort//13
|
2010-08-22 19:13:18 +00:00
|
|
|
|
|
|
|
};
|
2010-09-04 01:07:44 +00:00
|
|
|
enum Actions
|
|
|
|
{
|
2010-09-05 23:15:45 +00:00
|
|
|
actionProgram,
|
|
|
|
actionProgramAndVerify,
|
|
|
|
actionDownload,
|
|
|
|
actionCompareAll,
|
|
|
|
actionCompareHash,
|
|
|
|
actionListDevs,
|
|
|
|
actionStatusReq,
|
|
|
|
actionReset,
|
|
|
|
actionJump
|
2010-09-04 01:07:44 +00:00
|
|
|
};
|
|
|
|
|
2010-08-22 19:13:18 +00:00
|
|
|
enum Commands
|
|
|
|
{
|
|
|
|
Reserved,
|
|
|
|
Req_Capabilities,
|
|
|
|
Rep_Capabilities,
|
|
|
|
EnterDFU,
|
|
|
|
JumpFW,
|
|
|
|
Reset,
|
|
|
|
Abort_Operation,
|
|
|
|
Upload,
|
|
|
|
Op_END,
|
|
|
|
Download_Req,
|
|
|
|
Download,
|
|
|
|
Status_Request,
|
|
|
|
Status_Rep,
|
|
|
|
|
|
|
|
};
|
2010-09-02 22:46:06 +00:00
|
|
|
struct device
|
|
|
|
{
|
|
|
|
int ID;
|
2010-09-15 18:07:25 +00:00
|
|
|
quint32 FW_CRC;
|
|
|
|
int BL_Version;
|
2010-09-02 22:46:06 +00:00
|
|
|
int SizeOfDesc;
|
|
|
|
quint32 SizeOfCode;
|
|
|
|
bool Readable;
|
|
|
|
bool Writable;
|
|
|
|
};
|
|
|
|
|
2010-08-22 19:13:18 +00:00
|
|
|
void JumpToApp();
|
|
|
|
void ResetDevice(void);
|
2010-09-06 19:05:41 +00:00
|
|
|
bool enterDFU(int const &devNumber);
|
2010-09-15 18:07:25 +00:00
|
|
|
bool StartUpload(qint32 const &numberOfBytes, TransferTypes const & type,quint32 crc);
|
2010-09-06 19:05:41 +00:00
|
|
|
bool UploadData(qint32 const & numberOfPackets,QByteArray & data);
|
|
|
|
Status UploadDescription(QString & description);
|
2010-09-15 18:07:25 +00:00
|
|
|
Status UploadFirmware(const QString &sfile, const bool &verify,int device);
|
2010-09-04 01:07:44 +00:00
|
|
|
Status StatusRequest();
|
|
|
|
bool EndOperation();
|
2010-09-06 19:05:41 +00:00
|
|
|
void printProgBar( int const & percent,QString const& label);
|
|
|
|
QString DownloadDescription(int const & numberOfChars);
|
|
|
|
QByteArray StartDownload(qint32 const & numberOfBytes, TransferTypes const & type);
|
|
|
|
bool SaveByteArrayToFile(QString const & file,QByteArray const &array);
|
2010-08-24 18:27:32 +00:00
|
|
|
void CopyWords(char * source, char* destination, int count);
|
2010-08-22 19:13:18 +00:00
|
|
|
// QByteArray DownloadData(int devNumber,int numberOfPackets);
|
2010-09-04 01:07:44 +00:00
|
|
|
OP_DFU(bool debug);
|
|
|
|
bool findDevices();
|
|
|
|
QList<device> devices;
|
2010-09-02 22:46:06 +00:00
|
|
|
int numberOfDevices;
|
2010-09-06 19:05:41 +00:00
|
|
|
QString StatusToString(OP_DFU::Status const & status);
|
2010-09-05 23:15:45 +00:00
|
|
|
OP_DFU::Status CompareFirmware(const QString &sfile, const CompareType &type);
|
2010-09-15 18:07:25 +00:00
|
|
|
quint32 CRC32WideFast(quint32 Crc, quint32 Size, quint32 *Buffer);
|
|
|
|
quint32 CRCFromQBArray(QByteArray array, quint32 Size);
|
|
|
|
void test();
|
2010-09-18 00:47:45 +00:00
|
|
|
int send_delay;
|
2010-09-04 01:07:44 +00:00
|
|
|
private:
|
|
|
|
bool debug;
|
2010-09-02 22:46:06 +00:00
|
|
|
int RWFlags;
|
2010-09-04 01:07:44 +00:00
|
|
|
|
2010-08-22 19:13:18 +00:00
|
|
|
pjrc_rawhid hidHandle;
|
2010-08-26 06:25:09 +00:00
|
|
|
int setStartBit(int command){return command|0x20;}
|
2010-08-22 19:13:18 +00:00
|
|
|
};
|
|
|
|
|
2010-09-15 18:07:25 +00:00
|
|
|
|
|
|
|
|
2010-08-22 19:13:18 +00:00
|
|
|
#endif // OP_DFU_H
|