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 Serial and USB Uploader Plugin
11 * @brief The USB and Serial protocol 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
30 #include <QSerialPort>
33 port::port(QString name
, bool debug
) : mstatus(port::closed
), debug(debug
)
36 sport
= new QSerialPort(name
, this);
37 if (sport
->open(QIODevice::ReadWrite
)) {
38 if (sport
->setBaudRate(QSerialPort::Baud57600
)
39 && sport
->setDataBits(QSerialPort::Data8
)
40 && sport
->setParity(QSerialPort::NoParity
)
41 && sport
->setStopBits(QSerialPort::OneStop
)
42 && sport
->setFlowControl(QSerialPort::NoFlowControl
)) {
46 qDebug() << sport
->error();
47 mstatus
= port::error
;
56 port::portstatus
port::status()
61 int16_t port::pfSerialRead(void)
65 // TODO why the wait ? (gcs uploader dfu does not have it)
66 sport
->waitForBytesWritten(1);
67 if (sport
->bytesAvailable() || sport
->waitForReadyRead(0)) {
70 if (((uint8_t)c
[0]) == 0xe1 || rxDebugBuff
.count() > 50) {
71 qDebug() << "PORT R " << rxDebugBuff
.toHex();
74 rxDebugBuff
.append(c
[0]);
82 void port::pfSerialWrite(uint8_t c
)
89 if (((uint8_t)cc
[0]) == 0xe1 || rxDebugBuff
.count() > 50) {
90 qDebug() << "PORT T " << txDebugBuff
.toHex();
93 txDebugBuff
.append(cc
[0]);
95 // TODO why the wait ? (gcs uploader dfu does not have it)
96 sport
->waitForBytesWritten(1);
99 uint32_t port::pfGetTime(void)
101 return timer
.elapsed();