5 #include <ophid/inc/ophid_hidapi.h>
6 #include <ophid/inc/ophid_usbmon.h>
7 #include <ophid/inc/ophid_usbsignal.h>
12 #include <QMutexLocker>
14 #include <QCryptographicHash>
19 #include <QtSerialPort/QSerialPort>
20 #include <QtSerialPort/QSerialPortInfo>
25 #include "SSP/qsspt.h"
30 #define MAX_PACKET_DATA_LEN 255
31 #define MAX_PACKET_BUF_SIZE (1 + 1 + MAX_PACKET_DATA_LEN + 2)
48 wrong_packet_received
, // 2
49 too_many_packets
, // 3
51 Last_operation_Success
, // 5
54 Last_operation_failed
, // 8
55 uploadingStarting
, // 9
56 outsideDevCapabilities
, // 10
64 actionProgramAndVerify
,
76 Req_Capabilities
, // 1
77 Rep_Capabilities
, // 2
109 class DFUObject
: public QThread
{
113 static quint32
CRCFromQBArray(QByteArray array
, quint32 Size
);
114 // DFUObject(bool debug);
115 DFUObject(bool debug
, bool use_serial
, QString port
);
117 virtual ~DFUObject();
120 bool enterDFU(int const &devNumber
);
122 int JumpToApp(bool safeboot
, bool erase
);
123 int ResetDevice(void);
124 OP_DFU::Status
StatusRequest();
126 int AbortOperation(void);
132 // Upload (send to device) commands
133 OP_DFU::Status
UploadDescription(QVariant description
);
134 bool UploadFirmware(const QString
&sfile
, const bool &verify
, int device
);
136 // Download (get from device) commands:
137 // DownloadDescription is synchronous
138 QString
DownloadDescription(int const & numberOfChars
);
139 QByteArray
DownloadDescriptionAsBA(int const & numberOfChars
);
140 // Asynchronous firmware download: initiates fw download,
141 // and a downloadFinished signal is emitted when download
143 bool DownloadFirmware(QByteArray
*byteArray
, int device
);
145 // Comparison functions (is this needed?)
146 OP_DFU::Status
CompareFirmware(const QString
&sfile
, const CompareType
&type
, int device
);
148 bool SaveByteArrayToFile(QString
const & file
, QByteArray
const &array
);
152 QList
<device
> devices
;
158 QString
StatusToString(OP_DFU::Status
const & status
);
159 static quint32
CRC32WideFast(quint32 Crc
, quint32 Size
, quint32
*Buffer
);
160 OP_DFU::eBoardType
GetBoardType(int boardNum
);
164 void progressUpdated(int);
165 void downloadFinished();
166 void uploadFinished(OP_DFU::Status
);
167 void operationProgress(QString status
);
170 // Generic variables:
176 int sendData(void *, int);
177 int receiveData(void *data
, int size
);
178 uint8_t sspTxBuf
[MAX_PACKET_BUF_SIZE
];
179 uint8_t sspRxBuf
[MAX_PACKET_BUF_SIZE
];
184 opHID_hidapi hidHandle
;
185 int setStartBit(int command
)
187 return command
| 0x20;
190 void CopyWords(char *source
, char *destination
, int count
);
191 void printProgBar(int const & percent
, QString
const & label
);
192 bool StartUpload(qint32
const &numberOfBytes
, TransferTypes
const & type
, quint32 crc
);
193 bool UploadData(qint32
const & numberOfPackets
, QByteArray
& data
);
195 // Thread management:
196 // Same as startDownload except that we store in an external array:
197 bool StartDownloadT(QByteArray
*fw
, qint32
const & numberOfBytes
, TransferTypes
const & type
);
198 OP_DFU::Status
UploadFirmwareT(const QString
&sfile
, const bool &verify
, int device
);
200 OP_DFU::Commands requestedOperation
;
202 OP_DFU::TransferTypes requestTransferType
;
203 QByteArray
*requestStorage
;
204 QString requestFilename
;
209 void run(); // Executes the upload or download operations
213 Q_DECLARE_METATYPE(OP_DFU::Status
)