ApmFirmwareConfig.cc 22.6 KB
Newer Older
1 2
#include <QTimer>

3 4 5 6 7
#include "LinkManager.h"
#include "LinkInterface.h"
#include "qserialport.h"
#include "qserialportinfo.h"
#include "SerialLink.h"
8 9 10

#include "ApmFirmwareConfig.h"

11 12 13
ApmFirmwareConfig::ApmFirmwareConfig(QWidget *parent) : QWidget(parent)
{
    ui.setupUi(this);
14
    //firmwareStatus = 0;
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
    m_betaFirmwareChecked = false;
    m_tempFirmwareFile=0;
    //

    //QNetworkRequest req(QUrl("https://raw.github.com/diydrones/binary/master/Firmware/firmware2.xml"));



    m_networkManager = new QNetworkAccessManager(this);

    connect(ui.roverPushButton,SIGNAL(clicked()),this,SLOT(burnButtonClicked()));
    connect(ui.planePushButton,SIGNAL(clicked()),this,SLOT(burnButtonClicked()));
    connect(ui.copterPushButton,SIGNAL(clicked()),this,SLOT(burnButtonClicked()));
    connect(ui.hexaPushButton,SIGNAL(clicked()),this,SLOT(burnButtonClicked()));
    connect(ui.octaQuadPushButton,SIGNAL(clicked()),this,SLOT(burnButtonClicked()));
    connect(ui.octaPushButton,SIGNAL(clicked()),this,SLOT(burnButtonClicked()));
    connect(ui.quadPushButton,SIGNAL(clicked()),this,SLOT(burnButtonClicked()));
    connect(ui.triPushButton,SIGNAL(clicked()),this,SLOT(burnButtonClicked()));
    connect(ui.y6PushButton,SIGNAL(clicked()),this,SLOT(burnButtonClicked()));
34
    QTimer::singleShot(500,this,SLOT(requestFirmwares()));
35 36 37 38 39 40 41
    connect(ui.betaFirmwareButton,SIGNAL(clicked(bool)),this,SLOT(betaFirmwareButtonClicked(bool)));

    ui.progressBar->setMaximum(100);
    ui.progressBar->setValue(0);

    ui.textBrowser->setVisible(false);
    connect(ui.showOutputCheckBox,SIGNAL(clicked(bool)),ui.textBrowser,SLOT(setShown(bool)));
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

    addBetaLabel(ui.roverPushButton);
    addBetaLabel(ui.planePushButton);
    addBetaLabel(ui.copterPushButton);
    addBetaLabel(ui.quadPushButton);
    addBetaLabel(ui.hexaPushButton);
    addBetaLabel(ui.octaQuadPushButton);
    addBetaLabel(ui.octaPushButton);
    addBetaLabel(ui.triPushButton);
    addBetaLabel(ui.y6PushButton);

}
void ApmFirmwareConfig::hideBetaLabels()
{
    for (int i=0;i<m_betaButtonLabelList.size();i++)
    {
        m_betaButtonLabelList[i]->hide();
    }
    ui.warningLabel->hide();
61
}
62

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
void ApmFirmwareConfig::showBetaLabels()
{
    for (int i=0;i<m_betaButtonLabelList.size();i++)
    {
        m_betaButtonLabelList[i]->show();
    }
    ui.warningLabel->show();
}

void ApmFirmwareConfig::addBetaLabel(QWidget *parent)
{

    QLabel *label = new QLabel(parent);
    QVBoxLayout *layout = new QVBoxLayout();
    parent->setLayout(layout);
    label->setAlignment(Qt::AlignRight | Qt::AlignBottom);
    label->setText("<h1><font color=#FFAA00>BETA</font></h1>");
    layout->addWidget(label);
    m_betaButtonLabelList.append(label);
}
83 84

void ApmFirmwareConfig::requestBetaFirmwares()
85
{
86
    m_betaFirmwareChecked = true;
87
    showBetaLabels();
88 89 90 91 92 93 94 95 96
    QNetworkReply *reply1 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Copter/beta/apm2-heli/git-version.txt")));
    QNetworkReply *reply2 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Copter/beta/apm2-quad/git-version.txt")));
    QNetworkReply *reply3 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Copter/beta/apm2-hexa/git-version.txt")));
    QNetworkReply *reply4 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Copter/beta/apm2-octa/git-version.txt")));
    QNetworkReply *reply5 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Copter/beta/apm2-octa-quad/git-version.txt")));
    QNetworkReply *reply6 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Copter/beta/apm2-tri/git-version.txt")));
    QNetworkReply *reply7 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Copter/beta/apm2-y6/git-version.txt")));
    QNetworkReply *reply8 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Plane/beta/apm2/git-version.txt")));
    QNetworkReply *reply9 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Rover/beta/apm2/git-version.txt")));
97

98 99 100 101 102 103 104 105 106
    m_buttonToUrlMap[ui.roverPushButton] = "http://firmware.diydrones.com/Rover/beta/apm2/APMrover2.hex";
    m_buttonToUrlMap[ui.planePushButton] = "http://firmware.diydrones.com/Plane/beta/apm2/ArduPlane.hex";
    m_buttonToUrlMap[ui.copterPushButton] = "http://firmware.diydrones.com/Copter/beta/apm2-heli/ArduCopter.hex";
    m_buttonToUrlMap[ui.hexaPushButton] = "http://firmware.diydrones.com/Copter/beta/apm2-hexa/ArduCopter.hex";
    m_buttonToUrlMap[ui.octaQuadPushButton] = "http://firmware.diydrones.com/Copter/beta/apm2-octa-quad/ArduCopter.hex";
    m_buttonToUrlMap[ui.octaPushButton] = "http://firmware.diydrones.com/Copter/beta/apm2-octa/ArduCopter.hex";
    m_buttonToUrlMap[ui.quadPushButton] = "http://firmware.diydrones.com/Copter/beta/apm2-quad/ArduCopter.hex";
    m_buttonToUrlMap[ui.triPushButton] = "http://firmware.diydrones.com/Copter/beta/apm2-tri/ArduCopter.hex";
    m_buttonToUrlMap[ui.y6PushButton] = "http://firmware.diydrones.com/Copter/beta/apm2-y6/ArduCopter.hex";
107

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    //http://firmware.diydrones.com/Plane/stable/apm2/ArduPlane.hex
    connect(reply1,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply1,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply2,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply2,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply3,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply3,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply4,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply4,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply5,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply5,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply6,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply6,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply7,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply7,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply8,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply8,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply9,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply9,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    qDebug() << "Getting Beta firmware...";
}
129

130 131 132
void ApmFirmwareConfig::requestFirmwares()
{
    m_betaFirmwareChecked = false;
133
    hideBetaLabels();
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
    QNetworkReply *reply1 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Copter/stable/apm2-heli/git-version.txt")));
    QNetworkReply *reply2 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Copter/stable/apm2-quad/git-version.txt")));
    QNetworkReply *reply3 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Copter/stable/apm2-hexa/git-version.txt")));
    QNetworkReply *reply4 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Copter/stable/apm2-octa/git-version.txt")));
    QNetworkReply *reply5 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Copter/stable/apm2-octa-quad/git-version.txt")));
    QNetworkReply *reply6 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Copter/stable/apm2-tri/git-version.txt")));
    QNetworkReply *reply7 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Copter/stable/apm2-y6/git-version.txt")));
    QNetworkReply *reply8 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Plane/stable/apm2/git-version.txt")));
    QNetworkReply *reply9 = m_networkManager->get(QNetworkRequest(QUrl("http://firmware.diydrones.com/Rover/stable/apm2/git-version.txt")));

    m_buttonToUrlMap[ui.roverPushButton] = "http://firmware.diydrones.com/Rover/stable/apm2/APMrover2.hex";
    m_buttonToUrlMap[ui.planePushButton] = "http://firmware.diydrones.com/Plane/stable/apm2/ArduPlane.hex";
    m_buttonToUrlMap[ui.copterPushButton] = "http://firmware.diydrones.com/Copter/stable/apm2-heli/ArduCopter.hex";
    m_buttonToUrlMap[ui.hexaPushButton] = "http://firmware.diydrones.com/Copter/stable/apm2-hexa/ArduCopter.hex";
    m_buttonToUrlMap[ui.octaQuadPushButton] = "http://firmware.diydrones.com/Copter/stable/apm2-octa-quad/ArduCopter.hex";
    m_buttonToUrlMap[ui.octaPushButton] = "http://firmware.diydrones.com/Copter/stable/apm2-octa/ArduCopter.hex";
    m_buttonToUrlMap[ui.quadPushButton] = "http://firmware.diydrones.com/Copter/stable/apm2-quad/ArduCopter.hex";
    m_buttonToUrlMap[ui.triPushButton] = "http://firmware.diydrones.com/Copter/stable/apm2-tri/ArduCopter.hex";
    m_buttonToUrlMap[ui.y6PushButton] = "http://firmware.diydrones.com/Copter/stable/apm2-y6/ArduCopter.hex";

    //http://firmware.diydrones.com/Plane/stable/apm2/ArduPlane.hex
    connect(reply1,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply1,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply2,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply2,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply3,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply3,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply4,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply4,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply5,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply5,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply6,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply6,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply7,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply7,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply8,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply8,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    connect(reply9,SIGNAL(finished()),this,SLOT(firmwareListFinished()));
    connect(reply9,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
    qDebug() << "Getting Stable firmware...";
174 175
}

176
void ApmFirmwareConfig::betaFirmwareButtonClicked(bool betafirmwareenabled)
177
{
178
    if (betafirmwareenabled)
179
    {
180 181
        ui.label->setText(tr("<h2>Beta Firmware</h2>"));
        ui.betaFirmwareButton->setText(tr("Stable Firmware"));
182
        requestBetaFirmwares();
183 184 185
    }
    else
    {
186 187
        ui.label->setText(tr("<h2>Firmware</h2>"));
        ui.betaFirmwareButton->setText(tr("Beta Firmware"));
188
        requestFirmwares();
189 190 191 192 193 194 195 196 197
    }
}
void ApmFirmwareConfig::firmwareProcessFinished(int status)
{
    QProcess *proc = qobject_cast<QProcess*>(sender());
    if (!proc)
    {
        return;
    }
198 199 200
    if (status != 0)
    {
        //Error of some kind
201
        QMessageBox::information(0,tr("Error"),tr("An error has occured during the upload process. See window for details"));
202 203 204 205 206 207 208 209
        ui.textBrowser->setVisible(true);
        ui.showOutputCheckBox->setChecked(true);
        ui.textBrowser->setPlainText(ui.textBrowser->toPlainText().append("\n\nERROR!!\n" + proc->errorString()));
        QScrollBar *sb = ui.textBrowser->verticalScrollBar();
        if (sb)
        {
            sb->setValue(sb->maximum());
        }
210
        ui.statusLabel->setText(tr("Error during upload"));
211 212 213 214 215
    }
    else
    {
        //Ensure we're reading 100%
        ui.progressBar->setValue(100);
216
        ui.statusLabel->setText(tr("Upload complete"));
217
    }
218 219 220 221 222 223 224 225 226 227 228 229
    //qDebug() << "Upload finished!" << QString::number(status);
    m_tempFirmwareFile->deleteLater(); //This will remove the temporary file.
    m_tempFirmwareFile = 0;

}
void ApmFirmwareConfig::firmwareProcessReadyRead()
{
    QProcess *proc = qobject_cast<QProcess*>(sender());
    if (!proc)
    {
        return;
    }
230 231
    QString output = proc->readAllStandardError() + proc->readAllStandardOutput();
    if (output.contains("Writing"))
232
    {
233 234
        //firmwareStatus->resetProgress();
        ui.progressBar->setValue(0);
235
    }
236
    else if (output.contains("Reading"))
237
    {
238
        ui.progressBar->setValue(50);
239
    }
240
    if (output.startsWith("#"))
241
    {
242 243 244 245 246 247 248 249
        ui.progressBar->setValue(ui.progressBar->value()+1);

        ui.textBrowser->setPlainText(ui.textBrowser->toPlainText().append(output));
        QScrollBar *sb = ui.textBrowser->verticalScrollBar();
        if (sb)
        {
            sb->setValue(sb->maximum());
        }
250 251 252
    }
    else
    {
253 254 255 256 257 258
        ui.textBrowser->setPlainText(ui.textBrowser->toPlainText().append(output + "\n"));
        QScrollBar *sb = ui.textBrowser->verticalScrollBar();
        if (sb)
        {
            sb->setValue(sb->maximum());
        }
259
    }
260 261

    qDebug() << "E:" << output;
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
    //qDebug() << "AVR Output:" << proc->readAllStandardOutput();
    //qDebug() << "AVR Output:" << proc->readAllStandardError();
}

void ApmFirmwareConfig::downloadFinished()
{
    qDebug() << "Download finished, burning firmware";
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    if (!reply)
    {
        return;
    }
    QByteArray hex = reply->readAll();
    m_tempFirmwareFile = new QTemporaryFile();
    m_tempFirmwareFile->open();
    m_tempFirmwareFile->write(hex);
    m_tempFirmwareFile->flush();
    m_tempFirmwareFile->close();
    //tempfirmware.fileName()
    QProcess *process = new QProcess(this);
    connect(process,SIGNAL(finished(int)),this,SLOT(firmwareProcessFinished(int)));
    connect(process,SIGNAL(readyReadStandardOutput()),this,SLOT(firmwareProcessReadyRead()));
    connect(process,SIGNAL(readyReadStandardError()),this,SLOT(firmwareProcessReadyRead()));
    connect(process,SIGNAL(error(QProcess::ProcessError)),this,SLOT(firmwareProcessError(QProcess::ProcessError)));
    QList<QSerialPortInfo> portList =  QSerialPortInfo::availablePorts();


    foreach (const QSerialPortInfo &info, portList)
    {
        qDebug() << "PortName    : " << info.portName()
               << "Description : " << info.description();
        qDebug() << "Manufacturer: " << info.manufacturer();


    }

    //info.manufacturer() == "Arduino LLC (www.arduino.cc)"
    //info.description() == "%mega2560.name%"
300

301 302 303 304
    qDebug() << "Attempting to reset port";

    QSerialPort port;

305
    port.setPortName(m_detectedComPort);
306 307 308 309 310 311
    port.open(QIODevice::ReadWrite);
    port.setDataTerminalReady(true);
    port.waitForBytesWritten(250);
    port.setDataTerminalReady(false);
    port.close();

312 313 314
    QString avrdudeExecutable;
    QStringList stringList;

315
    ui.statusLabel->setText(tr("Flashing"));
316
#ifdef Q_OS_WIN
317 318 319 320 321
    stringList = QStringList() << "-Cavrdude/avrdude.conf" << "-pm2560"
                               << "-cstk500" << QString("-P").append(m_detectedComPort)
                               << QString("-Uflash:w:").append(m_tempFirmwareFile->fileName()).append(":i");

    avrdudeExecutable = "avrdude/avrdude.exe";
322
#endif
323 324 325 326 327 328 329 330 331 332
#ifdef Q_OS_MAC
    stringList = QStringList() << "-v" << "-pm2560"
                                           << "-cstk500" << QString("-P/dev/cu.").append(m_detectedComPort)
                                           << QString("-Uflash:w:").append(m_tempFirmwareFile->fileName()).append(":i");
    avrdudeExecutable = "/usr/local/CrossPack-AVR/bin/avrdude";
#endif

    // Start the Flashing
    qDebug() << avrdudeExecutable << stringList;
    process->start(avrdudeExecutable,stringList);
333 334 335 336 337
}
void ApmFirmwareConfig::firmwareProcessError(QProcess::ProcessError error)
{
    qDebug() << "Error:" << error;
}
338 339 340 341
void ApmFirmwareConfig::firmwareDownloadProgress(qint64 received,qint64 total)
{
    ui.progressBar->setValue( 100.0 * ((double)received/(double)total));
}
342 343 344 345 346 347

void ApmFirmwareConfig::burnButtonClicked()
{
    QPushButton *senderbtn = qobject_cast<QPushButton*>(sender());
    if (m_buttonToUrlMap.contains(senderbtn))
    {
348 349 350 351 352 353 354 355 356 357 358 359
        bool foundconnected = false;
        for (int i=0;i<LinkManager::instance()->getLinks().size();i++)
        {
            if (LinkManager::instance()->getLinks()[i]->isConnected())
            {
                //This is likely the serial link we want.
                SerialLink *link = qobject_cast<SerialLink*>(LinkManager::instance()->getLinks()[i]);
                if (!link)
                {
                    qDebug() << "Eror, trying to program over a non serial link. This should not happen";
                    return;
                }
360
                if (!(QMessageBox::question(this,tr("WARNING"),tr("You are about to upload new firmware to your board. This will disconnect you if you are currently connected. Be sure the MAV is on the ground, and connected over USB/Serial link.\n\nDo you wish to proceed?"),QMessageBox::Yes,QMessageBox::No) == QMessageBox::Yes))
361 362 363 364 365 366 367 368 369 370 371 372 373
                {
                    return;
                }

                m_detectedComPort = link->getPortName();
                link->requestReset();
                foundconnected = true;
                link->disconnect();
                link->wait(1000); // Wait 1 second for it to disconnect.
            }
        }
        if (!foundconnected)
        {
374
            QMessageBox::information(0,tr("Error"),tr("You must be connected to a MAV over serial link to flash firmware. Please connect to a MAV then try again"));
375 376 377
            return;
        }

378 379 380 381 382 383
        qDebug() << "Go download:" << m_buttonToUrlMap[senderbtn];
        QNetworkReply *reply = m_networkManager->get(QNetworkRequest(QUrl(m_buttonToUrlMap[senderbtn])));
        //http://firmware.diydrones.com/Plane/stable/apm2/ArduPlane.hex
        connect(reply,SIGNAL(finished()),this,SLOT(downloadFinished()));

        connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(firmwareListError(QNetworkReply::NetworkError)));
384 385
        connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(firmwareDownloadProgress(qint64,qint64)));
        ui.statusLabel->setText("Downloading");
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
    }
}

void ApmFirmwareConfig::firmwareListError(QNetworkReply::NetworkError error)
{
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    qDebug() << "Error!" << reply->errorString();
}
bool ApmFirmwareConfig::stripVersionFromGitReply(QString url, QString reply,QString type,QString stable,QString *out)
{
    if (url.contains(type) && url.contains("git-version.txt") && url.contains(stable))
    {
        QString version = reply.mid(reply.indexOf("APMVERSION:")+12).replace("\n","").replace("\r","").trimmed();
        *out = version;
        return true;
    }
    return false;

}

void ApmFirmwareConfig::firmwareListFinished()
{
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    QString replystr = reply->readAll();
    QString outstr = "";
    if (stripVersionFromGitReply(reply->url().toString(),replystr,"apm2-heli",(m_betaFirmwareChecked ? "beta" : "stable"),&outstr))
    {
413 414 415 416 417 418 419 420
        if (m_betaFirmwareChecked)
        {
            ui.copterLabel->setText("BETA " + outstr);
        }
        else
        {
            ui.copterLabel->setText(outstr);
        }
421 422 423 424
        return;
    }
    if (stripVersionFromGitReply(reply->url().toString(),replystr,"apm2-quad",(m_betaFirmwareChecked ? "beta" : "stable"),&outstr))
    {
425 426 427 428 429 430 431 432
        if (m_betaFirmwareChecked)
        {
            ui.quadLabel->setText("BETA " + outstr);
        }
        else
        {
            ui.quadLabel->setText(outstr);
        }
433 434 435 436
        return;
    }
    if (stripVersionFromGitReply(reply->url().toString(),replystr,"apm2-hexa",(m_betaFirmwareChecked ? "beta" : "stable"),&outstr))
    {
437 438 439 440 441 442 443 444
        if (m_betaFirmwareChecked)
        {
            ui.hexaLabel->setText("BETA " + outstr);
        }
        else
        {
            ui.hexaLabel->setText(outstr);
        }
445 446
        return;
    }
447
    if (stripVersionFromGitReply(reply->url().toString(),replystr,"apm2-octa-quad",(m_betaFirmwareChecked ? "beta" : "stable"),&outstr))
448
    {
449 450 451 452 453 454 455 456
        if (m_betaFirmwareChecked)
        {
            ui.octaQuadLabel->setText("BETA " + outstr);
        }
        else
        {
            ui.octaQuadLabel->setText(outstr);
        }
457 458
        return;
    }
459
    if (stripVersionFromGitReply(reply->url().toString(),replystr,"apm2-octa",(m_betaFirmwareChecked ? "beta" : "stable"),&outstr))
460
    {
461 462 463 464 465 466 467 468
        if (m_betaFirmwareChecked)
        {
            ui.octaLabel->setText("BETA " + outstr);
        }
        else
        {
            ui.octaLabel->setText(outstr);
        }
469 470 471 472
        return;
    }
    if (stripVersionFromGitReply(reply->url().toString(),replystr,"apm2-tri",(m_betaFirmwareChecked ? "beta" : "stable"),&outstr))
    {
473 474 475 476 477 478 479 480
        if (m_betaFirmwareChecked)
        {
            ui.triLabel->setText("BETA " + outstr);
        }
        else
        {
            ui.triLabel->setText(outstr);
        }
481 482 483 484
        return;
    }
    if (stripVersionFromGitReply(reply->url().toString(),replystr,"apm2-y6",(m_betaFirmwareChecked ? "beta" : "stable"),&outstr))
    {
485 486 487 488 489 490 491 492
        if (m_betaFirmwareChecked)
        {
            ui.y6Label->setText("BETA " + outstr);
        }
        else
        {
            ui.y6Label->setText(outstr);
        }
493 494 495 496
        return;
    }
    if (stripVersionFromGitReply(reply->url().toString(),replystr,"Plane",(m_betaFirmwareChecked ? "beta" : "stable"),&outstr))
    {
497 498 499 500 501 502 503 504
        if (m_betaFirmwareChecked)
        {
            ui.planeLabel->setText("BETA " + outstr);
        }
        else
        {
            ui.planeLabel->setText(outstr);
        }
505 506 507 508
        return;
    }
    if (stripVersionFromGitReply(reply->url().toString(),replystr,"Rover",(m_betaFirmwareChecked ? "beta" : "stable"),&outstr))
    {
509
        if (m_betaFirmwareChecked)
510
        {
511 512 513 514 515
            ui.roverLabel->setText("BETA " + outstr);
        }
        else
        {
            ui.roverLabel->setText(outstr);
516
        }
517 518 519 520
        return;
    }
    qDebug() << "Match not found for:" << reply->url();
    qDebug() << "Git version line:" <<  replystr;
521 522 523 524 525
}

ApmFirmwareConfig::~ApmFirmwareConfig()
{
}