Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / experimental / USB_UPLOAD_TOOL / SSP / qssp.h
blob1a7f7a8f9130f19e865754b587e07dd72f20998f
1 /**
2 ******************************************************************************
4 * @file qssp.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 QSSP_H
29 #define QSSP_H
31 #include "common.h"
32 #include "port.h"
34 #include <stdint.h>
36 /** LOCAL DEFINITIONS **/
37 #ifndef TRUE
38 #define TRUE 1
39 #endif
41 #ifndef FALSE
42 #define FALSE 0
43 #endif
45 #define SPP_USES_CRC
47 #define SSP_TX_IDLE 0 // not expecting a ACK packet (no current transmissions in progress)
48 #define SSP_TX_WAITING 1 // waiting for a valid ACK to arrive
49 #define SSP_TX_TIMEOUT 2 // failed to receive a valid ACK in the timeout period, after retrying.
50 #define SSP_TX_ACKED 3 // valid ACK received before timeout period.
51 #define SSP_TX_BUFOVERRUN 4 // amount of data to send execeds the transmission buffer sizeof
52 #define SSP_TX_BUSY 5 // Attempted to start a transmission while a transmission was already in progress.
53 // #define SSP_TX_FAIL - failure...
55 #define SSP_RX_IDLE 0
56 #define SSP_RX_RECEIVING 1
57 #define SSP_RX_COMPLETE 2
59 // types of packet that can be received
60 #define SSP_RX_DATA 5
61 #define SSP_RX_ACK 6
62 #define SSP_RX_SYNCH 7
64 typedef struct {
65 uint8_t *pbuff;
66 uint16_t length;
67 uint16_t crc;
68 uint8_t seqNo;
69 } Packet_t;
71 typedef struct {
72 uint8_t *rxBuf; // Buffer used to store rcv data
73 uint16_t rxBufSize; // rcv buffer size.
74 uint8_t *txBuf; // Length of data in buffer
75 uint16_t txBufSize; // CRC for data in Packet buff
76 uint16_t max_retry; // Maximum number of retrys for a single transmit.
77 int32_t timeoutLen; // how long to wait for each retry to succeed
78 // function returns time in number of seconds that has elapsed from a given reference point
79 } PortConfig_t;
81 /** Public Data **/
83 /** EXTERNAL FUNCTIONS **/
85 class qssp {
86 private:
87 port *thisport;
88 bool debug;
90 // static void sf_SendSynchPacket( Port_t *thisport );
91 uint16_t sf_crc16(uint16_t crc, uint8_t data);
92 void sf_write_byte(uint8_t c);
93 void sf_SetSendTimeout();
94 uint16_t sf_CheckTimeout();
95 int16_t sf_DecodeState(uint8_t c);
96 int16_t sf_ReceiveState(uint8_t c);
98 void sf_SendPacket();
99 void sf_SendAckPacket(uint8_t seqNumber);
100 void sf_MakePacket(uint8_t *buf, const uint8_t *pdata, uint16_t length, uint8_t seqNo);
101 int16_t sf_ReceivePacket();
102 uint16_t ssp_SendDataBlock(uint8_t *data, uint16_t length);
104 public:
105 qssp(port *info, bool debug);
107 int16_t ssp_ReceiveProcess();
108 int16_t ssp_SendProcess();
109 uint16_t ssp_SendString(char *str);
110 int16_t ssp_SendData(const uint8_t *data, const uint16_t length);
111 void ssp_Init(const PortConfig_t *const info);
112 int16_t ssp_ReceiveByte();
113 uint16_t ssp_Synchronise();
115 virtual void pfCallBack(uint8_t *, uint16_t); // call back function that is called when a full packet has been received
118 #endif // QSSP_H