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)
43 // Command Line Options
44 #define DOWNLOAD "-dn" // done
45 #define DEVICE "-d" // done
46 #define DOWNDESCRIPTION "-dd" // done
47 #define PROGRAMFW "-p" // done
48 #define PROGRAMDESC "-w" // done
49 #define VERIFY "-v" // done
50 #define COMPARECRC "-cc"
51 #define COMPAREALL "-ca"
52 #define STATUSREQUEST "-s" // done
53 #define LISTDEVICES "-ls" // done
56 #define USE_SERIAL "-t"
57 #define NO_COUNTDOWN "-i"
63 wrong_packet_received
, // 2
64 too_many_packets
, // 3
66 Last_operation_Success
, // 5
69 Last_operation_failed
, // 8
70 uploadingStarting
, // 9
71 outsideDevCapabilities
, // 10
79 actionProgramAndVerify
,
91 Req_Capabilities
, // 1
92 Rep_Capabilities
, // 2
101 Status_Request
, // 11
125 class DFUObject
: public QThread
{
129 static quint32
CRCFromQBArray(QByteArray array
, quint32 Size
);
130 // DFUObject(bool debug);
131 DFUObject(bool debug
, bool use_serial
, QString port
);
133 virtual ~DFUObject();
136 bool enterDFU(int const &devNumber
);
138 int JumpToApp(bool safeboot
, bool erase
);
139 int ResetDevice(void);
140 void sendReset(void);
141 OP_DFU::Status
StatusRequest();
143 int AbortOperation(void);
149 // Upload (send to device) commands
150 OP_DFU::Status
UploadDescription(QVariant description
);
151 bool UploadFirmware(const QString
&sfile
, const bool &verify
, int device
);
153 // Download (get from device) commands:
154 // DownloadDescription is synchronous
155 QString
DownloadDescription(int const & numberOfChars
);
156 QByteArray
DownloadDescriptionAsBA(int const & numberOfChars
);
157 // Asynchronous firmware download: initiates fw download,
158 // and a downloadFinished signal is emitted when download
160 bool DownloadFirmware(QByteArray
*byteArray
, int device
);
162 // Comparison functions (is this needed?)
163 OP_DFU::Status
CompareFirmware(const QString
&sfile
, const CompareType
&type
, int device
);
165 bool SaveByteArrayToFile(QString
const & file
, QByteArray
const &array
);
169 QList
<device
> devices
;
175 QString
StatusToString(OP_DFU::Status
const & status
);
176 static quint32
CRC32WideFast(quint32 Crc
, quint32 Size
, quint32
*Buffer
);
177 OP_DFU::eBoardType
GetBoardType(int boardNum
);
181 void progressUpdated(int);
182 void downloadFinished();
183 void uploadFinished(OP_DFU::Status
);
184 void operationProgress(QString status
);
187 // Generic variables:
193 int sendData(void *, int);
194 int receiveData(void *data
, int size
);
195 uint8_t sspTxBuf
[MAX_PACKET_BUF_SIZE
];
196 uint8_t sspRxBuf
[MAX_PACKET_BUF_SIZE
];
201 // opHID_hidapi hidHandle;
202 int setStartBit(int command
)
204 return command
| 0x20;
207 void CopyWords(char *source
, char *destination
, int count
);
208 void printProgBar(int const & percent
, QString
const & label
);
209 bool StartUpload(qint32
const &numberOfBytes
, TransferTypes
const & type
, quint32 crc
);
210 bool UploadData(qint32
const & numberOfPackets
, QByteArray
& data
);
212 // Thread management:
213 // Same as startDownload except that we store in an external array:
214 bool StartDownloadT(QByteArray
*fw
, qint32
const & numberOfBytes
, TransferTypes
const & type
);
215 OP_DFU::Status
UploadFirmwareT(const QString
&sfile
, const bool &verify
, int device
);
217 OP_DFU::Commands requestedOperation
;
219 OP_DFU::TransferTypes requestTransferType
;
220 QByteArray
*requestStorage
;
221 QString requestFilename
;
226 void run(); // Executes the upload or download operations
230 Q_DECLARE_METATYPE(OP_DFU::Status
)