Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / experimental / USB_UPLOAD_TOOL / SSP / main.cpp
blob1b142d7e362ea77d51c222970fe7bb5d6776c14e
1 /**
2 ******************************************************************************
4 * @file main.cpp
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 #include "qssp.h"
29 #include "port.h"
30 #include "qsspt.h"
32 #include "../../../libs/qextserialport/src/qextserialport.h"
34 #include <QtCore/QCoreApplication>
35 #include <QTime>
36 #include <QDebug>
38 #define MAX_PACKET_DATA_LEN 255
39 #define MAX_PACKET_BUF_SIZE (1 + 1 + 255 + 2)
41 int main(int argc, char *argv[])
43 uint8_t sspTxBuf[MAX_PACKET_BUF_SIZE];
44 uint8_t sspRxBuf[MAX_PACKET_BUF_SIZE];
46 port *info;
47 PortSettings settings;
49 settings.BaudRate = BAUD57600;
50 settings.DataBits = DATA_8;
51 settings.FlowControl = FLOW_OFF;
52 settings.Parity = PAR_NONE;
53 settings.StopBits = STOP_1;
54 settings.Timeout_Millisec = 5000;
56 info = new port(settings, "COM3");
57 info->rxBuf = sspRxBuf;
58 info->rxBufSize = MAX_PACKET_DATA_LEN;
59 info->txBuf = sspTxBuf;
60 info->txBufSize = 255;
61 info->max_retry = 3;
62 info->timeoutLen = 5000;
63 // qssp b(info);
64 qsspt bb(info);
65 uint8_t buf[1000];
66 QCoreApplication a(argc, argv);
67 while (!bb.ssp_Synchronise()) {
68 qDebug() << "trying sync";
70 bb.start();
71 qDebug() << "sync complete";
72 buf[0] = 0;
73 buf[1] = 1;
74 buf[2] = 2;
75 while (true) {
76 if (bb.sendData(buf, 63)) {
77 qDebug() << "send OK";
79 // else
80 // qDebug()<<"send NOK";
81 ////bb.ssp_SendData(buf,63);
83 while (true) {
84 if (bb.packets_Available() > 0) {
85 bb.read_Packet(buf);
86 qDebug() << "receive=" << (int)buf[0] << (int)buf[1] << (int)buf[2];
87 ++buf[0];
88 ++buf[1];
89 ++buf[2];
90 // bb.ssp_SendData(buf,63);
91 bb.sendData(buf, 63);
93 // bb.ssp_ReceiveProcess();
94 // bb.ssp_SendProcess();
96 return a.exec();