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>
|
|
|
|
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
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
2010-08-22 19:13:18 +00:00
|
|
|
class OP_DFU
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum TransferTypes
|
|
|
|
{
|
|
|
|
FW,
|
|
|
|
Hash,
|
|
|
|
Descript
|
|
|
|
};
|
|
|
|
enum Status
|
|
|
|
{
|
|
|
|
DFUidle,
|
|
|
|
uploading,
|
|
|
|
wrong_packet_received,
|
|
|
|
too_many_packets,
|
|
|
|
too_few_packets,
|
|
|
|
Last_operation_Success,
|
|
|
|
downloading,
|
|
|
|
idle,
|
2010-09-04 01:07:44 +00:00
|
|
|
Last_operation_failed,
|
|
|
|
outsideDevCapabilities,
|
|
|
|
abort
|
2010-08-22 19:13:18 +00:00
|
|
|
|
|
|
|
};
|
2010-09-04 01:07:44 +00:00
|
|
|
enum Actions
|
|
|
|
{
|
|
|
|
program,
|
|
|
|
programandverify,
|
|
|
|
download,
|
|
|
|
compareall,
|
|
|
|
comparehash,
|
|
|
|
listdevs,
|
|
|
|
statusreq,
|
|
|
|
downdesc
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
int SizeOfHash;
|
|
|
|
int SizeOfDesc;
|
|
|
|
quint32 SizeOfCode;
|
|
|
|
bool Readable;
|
|
|
|
bool Writable;
|
|
|
|
};
|
|
|
|
|
2010-08-22 19:13:18 +00:00
|
|
|
void JumpToApp();
|
|
|
|
void ResetDevice(void);
|
2010-09-04 01:07:44 +00:00
|
|
|
bool enterDFU(int devNumber);
|
|
|
|
bool StartUpload(qint32 numberOfBytes, TransferTypes type);
|
|
|
|
bool UploadData(qint32 numberOfPackets,QByteArray data);
|
|
|
|
Status UploadDescription(QString description);
|
2010-09-05 00:18:49 +00:00
|
|
|
Status UploadFirmware(const QString &sfile, const bool &verify);
|
2010-09-04 01:07:44 +00:00
|
|
|
Status StatusRequest();
|
|
|
|
bool EndOperation();
|
2010-09-05 00:18:49 +00:00
|
|
|
void printProgBar( int percent,QString const& label);
|
2010-09-04 01:07:44 +00:00
|
|
|
QString DownloadDescription(int numberOfChars);
|
|
|
|
QByteArray StartDownload(qint32 numberOfBytes, TransferTypes type);
|
2010-09-05 00:18:49 +00:00
|
|
|
bool SaveByteArrayToFile(QString 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-04 01:07:44 +00:00
|
|
|
QString StatusToString(OP_DFU::Status);
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
#endif // OP_DFU_H
|