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-08-24 18:27:32 +00:00
|
|
|
#define BUF_LEN 64
|
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,
|
|
|
|
Last_operation_failed
|
|
|
|
|
|
|
|
};
|
|
|
|
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);
|
|
|
|
void enterDFU(int devNumber);
|
2010-08-24 18:27:32 +00:00
|
|
|
void StartUpload(qint32 numberOfBytes, TransferTypes type);
|
2010-08-22 19:13:18 +00:00
|
|
|
void UploadData(qint32 numberOfPackets,QByteArray data);
|
2010-09-02 22:46:06 +00:00
|
|
|
void UploadDescription(QString description);
|
2010-08-26 20:19:40 +00:00
|
|
|
void UploadFirmware(const QString &sfile);
|
2010-08-22 19:13:18 +00:00
|
|
|
int StatusRequest();
|
|
|
|
void EndOperation();
|
|
|
|
QString DownloadDescription(int devNumber,int numberOfChars);
|
|
|
|
QByteArray StartDownload(qint32 numberOfPackets, TransferTypes type);
|
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);
|
|
|
|
OP_DFU();
|
2010-09-02 22:46:06 +00:00
|
|
|
void findDevices();
|
2010-08-22 19:13:18 +00:00
|
|
|
private:
|
2010-09-02 22:46:06 +00:00
|
|
|
int numberOfDevices;
|
|
|
|
int RWFlags;
|
|
|
|
QList<device> devices;
|
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
|