Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / experimental / USB_UPLOAD_TOOL / SSP / port.h
blob01203f748d97fb2ca610eaa81337c46c05c79b32
1 /**
2 ******************************************************************************
4 * @file port.h
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
8 * @{
9 * @addtogroup Uploader Serial and USB Uploader Plugin
10 * @{
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
22 * for more details.
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
28 #ifndef PORT_H
29 #define PORT_H
31 #include "common.h"
33 #include <QObject>
34 #include <QTime>
36 #include <stdint.h>
38 class QSerialPort;
40 class port : public QObject {
41 Q_OBJECT;
43 public:
44 enum portstatus { open, closed, error };
46 port(QString name, bool debug);
47 virtual ~port();
48 portstatus status();
50 virtual int16_t pfSerialRead(void); // function to read a character from the serial input stream
51 virtual void pfSerialWrite(uint8_t); // function to write a byte to be sent out the serial port
52 virtual uint32_t pfGetTime(void);
54 uint8_t retryCount; // how many times have we tried to transmit the 'send' packet
55 uint8_t maxRetryCount; // max. times to try to transmit the 'send' packet
56 uint16_t max_retry; // Maximum number of retrys for a single transmit.
57 int32_t timeoutLen; // how long to wait for each retry to succeed
58 uint32_t timeout; // current timeout. when 'time' reaches this point we have timed out
59 uint8_t txSeqNo; // current 'send' packet sequence number
60 uint16_t rxBufPos; // current buffer position in the receive packet
61 uint16_t rxBufLen; // number of 'data' bytes in the buffer
62 uint8_t rxSeqNo; // current 'receive' packet number
63 uint16_t rxBufSize; // size of the receive buffer.
64 uint16_t txBufSize; // size of the transmit buffer.
65 uint8_t *txBuf; // transmit buffer. REquired to store a copy of packet data in case a retry is needed.
66 uint8_t *rxBuf; // receive buffer. Used to store data as a packet is received.
67 uint16_t sendSynch; // flag to indicate that we should send a synchronize packet to the host
68 // this is required when switching from the application to the bootloader
69 // and vice-versa. This fixes the firmware download timeout.
70 // when this flag is set to true, the next time we send a packet we will first
71 // send a synchronize packet.
72 ReceiveState inputState;
73 DecodeState decodeState;
74 uint16_t SendState;
75 uint16_t crc;
76 uint32_t RxError;
77 uint32_t TxError;
78 uint16_t flags;
80 private:
81 portstatus mstatus;
82 QTime timer;
83 QSerialPort *sport;
85 bool debug;
86 QByteArray rxDebugBuff;
87 QByteArray txDebugBuff;
90 #endif // PORT_H