2 ******************************************************************************
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
6 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
7 * @addtogroup GCSPlugins GCS Plugins
9 * @addtogroup Uploader Uploader Plugin
11 * @brief The uploader plugin
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 #define MAX_PACKET_DATA_LEN 255
38 #define MAX_PACKET_BUF_SIZE (1 + 1 + MAX_PACKET_DATA_LEN + 2)
49 #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
66 wrong_packet_received
, // 2
67 too_many_packets
, // 3
69 Last_operation_Success
, // 5
72 Last_operation_failed
, // 8
73 uploadingStarting
, // 9
74 outsideDevCapabilities
, // 10
83 actionProgramAndVerify
,
95 Req_Capabilities
, // 1
96 Rep_Capabilities
, // 2
100 Abort_Operation
, // 6
105 Status_Request
, // 11
116 eBoardSparky2
= 0x92,
129 class DFUObject
: public QThread
{
133 static quint32
CRCFromQBArray(QByteArray array
, quint32 Size
);
135 DFUObject(bool debug
, bool use_serial
, QString port
);
137 virtual ~DFUObject();
140 bool enterDFU(int const &devNumber
);
142 int JumpToApp(bool safeboot
, bool erase
);
143 int ResetDevice(void);
144 DFU::Status
StatusRequest();
146 int AbortOperation(void);
152 // Upload (send to device) commands
153 DFU::Status
UploadDescription(QVariant description
);
154 bool UploadFirmware(const QString
&sfile
, const bool &verify
, int device
);
156 // Download (get from device) commands:
157 // DownloadDescription is synchronous
158 QString
DownloadDescription(int const & numberOfChars
);
159 QByteArray
DownloadDescriptionAsBA(int const & numberOfChars
);
160 // Asynchronous firmware download: initiates fw download,
161 // and a downloadFinished signal is emitted when download
163 bool DownloadFirmware(QByteArray
*byteArray
, int device
);
165 // Comparison functions (is this needed?)
166 DFU::Status
CompareFirmware(const QString
&sfile
, const CompareType
&type
, int device
);
168 bool SaveByteArrayToFile(QString
const & file
, QByteArray
const &array
);
171 QList
<device
> devices
;
177 QString
StatusToString(DFU::Status
const & status
);
178 static quint32
CRC32WideFast(quint32 Crc
, quint32 Size
, quint32
*Buffer
);
179 DFU::eBoardType
GetBoardType(int boardNum
);
182 void progressUpdated(int);
183 void downloadFinished();
184 void uploadFinished(DFU::Status
);
185 void operationProgress(QString status
);
188 // Generic variables:
198 // opHID_hidapi *hidHandle;
200 int sendData(void *, int);
201 int receiveData(void *data
, int size
);
202 uint8_t sspTxBuf
[MAX_PACKET_BUF_SIZE
];
203 uint8_t sspRxBuf
[MAX_PACKET_BUF_SIZE
];
205 int setStartBit(int command
)
207 return command
| 0x20;
210 void CopyWords(char *source
, char *destination
, int count
);
211 void printProgBar(int const & percent
, QString
const & label
);
212 bool StartUpload(qint32
const &numberOfBytes
, TransferTypes
const & type
, quint32 crc
);
213 bool UploadData(qint32
const & numberOfPackets
, QByteArray
& data
);
215 // Thread management:
216 // Same as startDownload except that we store in an external array:
217 bool StartDownloadT(QByteArray
*fw
, qint32
const & numberOfBytes
, TransferTypes
const & type
);
218 DFU::Status
UploadFirmwareT(const QString
&sfile
, const bool &verify
, int device
);
220 DFU::Commands requestedOperation
;
222 DFU::TransferTypes requestTransferType
;
223 QByteArray
*requestStorage
;
224 QString requestFilename
;
229 void run(); // Executes the upload or download operations
233 Q_DECLARE_METATYPE(DFU::Status
)