Subversion Repositories Projects

Rev

Rev 305 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
158 KeyOz 1
/***************************************************************************
2
 *   Copyright (C) 2008 by Manuel Schrape                                  *
3
 *   manuel.schrape@gmx.de                                                 *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation; either version 2 of the License.        *
8
 *                                                                         *
9
 *   This program is distributed in the hope that it will be useful,       *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU General Public License for more details.                          *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
19
 
250 KeyOz 20
// TODO: Wiederholungssenden wieder einbauen
21
 
158 KeyOz 22
#include <QtGui>
23
 
24
#include <QLineEdit>
25
#include <QString>
26
#include <QTimer>
27
#include <QIcon>
28
#include <QToolButton>
29
#include <QSpinBox>
199 KeyOz 30
#include <QAction>
227 KeyOz 31
#include <QPalette>
158 KeyOz 32
 
33
#include "mktool.h"
34
#include "dlg_Config.h"
35
#include "dlg_Motortest.h"
159 KeyOz 36
#include "dlg_Preferences.h"
158 KeyOz 37
#include "../global.h"
227 KeyOz 38
#include "../Classes/ToolBox.h"
158 KeyOz 39
 
40
#include <stdlib.h>
41
 
42
MKTool::MKTool()
43
{
44
    setupUi(this);
45
 
46
    Settings = new cSettings;
47
 
48
    init_Arrays();
49
    init_GUI();
306 KeyOz 50
    init_Cockpit();
158 KeyOz 51
 
52
    init_Objects();
53
    init_Connections();
54
 
55
    init_Plot();
56
}
57
 
58
void MKTool::init_GUI()
59
{
60
    setWindowTitle(QA_NAME + " v" + QA_VERSION);
61
 
167 KeyOz 62
    // Tab mit Debug-Elementen verbergen
272 KeyOz 63
    tab_Main->removeTab(6);
64
    // Develop - Nicht gebrauchte sachen abschalten.
65
    pb_SettingsReset->hide();
66
    pb_Flash->hide();
67
    rb_NC->hide();
167 KeyOz 68
 
279 KeyOz 69
    // Beta-Sachen einschalten.
70
#ifdef _BETA_
71
    ac_QMKServer->setEnabled(true);
72
#endif
167 KeyOz 73
    // Settings-Tab hinzufügen.
74
    f_Settings = new wdg_Settings( this );
227 KeyOz 75
    f_Settings->set_Config(Settings);
76
    tab_Main->insertTab ( 2, f_Settings, ac_View2->icon(), "FC-Settings");
167 KeyOz 77
    tab_Main->widget(2)->setObjectName("Tab_2");
78
 
79
    // Zusätzliche Widgets in die Toolbar.
227 KeyOz 80
    tb_TTY->addWidget(lb_Port);
81
    tb_TTY->addWidget(le_Port);
166 KeyOz 82
 
227 KeyOz 83
    tb_Hardware->addWidget(rb_SelFC);
84
    tb_Hardware->addWidget(rb_SelNC);
85
    tb_Hardware->addWidget(rb_SelMag);
166 KeyOz 86
 
227 KeyOz 87
    tb_Allgemein->setVisible(Settings->GUI.ToolViews[0]);
88
    tb_Werkzeuge->setVisible(Settings->GUI.ToolViews[1]);
89
    tb_Debug->setVisible(Settings->GUI.ToolViews[2]);
90
    tb_TTY->setVisible(Settings->GUI.ToolViews[3]);
91
    tb_Hardware->setVisible(Settings->GUI.ToolViews[4]);
92
 
272 KeyOz 93
#ifdef _EEEPC_
94
    lb_Status->hide();
95
#endif
96
 
199 KeyOz 97
    lb_Status->setText(tr("Hallo bei QMK-Groundstation...!!!"));
98
 
158 KeyOz 99
    resize(Settings->GUI.Size);
100
    move(Settings->GUI.Point);
101
 
102
    if (Settings->GUI.isMax)
103
    {
104
        showMaximized();
105
    }
106
 
199 KeyOz 107
    // Analoglabels anzeigen
158 KeyOz 108
    for (int a = 0; a < MaxAnalog; a++)
109
    {
162 KeyOz 110
        lb_Analog[a]->setText(Settings->Analog1.Label[a]);
158 KeyOz 111
    }
112
 
199 KeyOz 113
    // Kopie der Tabs anlegen
272 KeyOz 114
    for (int b = 0; b < 7; b++)
158 KeyOz 115
    {
116
        TabWidgets[b] = tab_Main->widget(b);
117
    }
118
 
199 KeyOz 119
    // Ausgeblendete Tabs ausblenden
272 KeyOz 120
    for (int c = 0; c < 7; c++)
158 KeyOz 121
    {
122
        if (Settings->GUI.TabViews[c] == false)
123
        {
124
            QString TabName = QString("Tab_%1").arg(c);
125
 
126
            for (int d = 0; d < tab_Main->count(); d++)
127
            {
128
                if (tab_Main->widget(d)->objectName() == TabName)
129
                {
130
                    tab_Main->removeTab(d);
131
                }
132
            }
133
        }
134
    }
135
 
136
    ac_View0->setChecked(Settings->GUI.TabViews[0]);
137
    ac_View1->setChecked(Settings->GUI.TabViews[1]);
138
    ac_View2->setChecked(Settings->GUI.TabViews[2]);
139
    ac_View3->setChecked(Settings->GUI.TabViews[3]);
140
    ac_View4->setChecked(Settings->GUI.TabViews[4]);
141
    ac_View5->setChecked(Settings->GUI.TabViews[5]);
272 KeyOz 142
    ac_View6->setChecked(Settings->GUI.TabViews[6]);
158 KeyOz 143
 
144
    le_Port->setText(Settings->TTY.Port);
162 KeyOz 145
 
146
    cb_ShowMSG->setChecked(Settings->GUI.Term_Info);
147
    cb_ShowData->setChecked(Settings->GUI.Term_Data);
148
    cb_ShowAlways->setChecked(Settings->GUI.Term_Always);
158 KeyOz 149
}
150
 
306 KeyOz 151
void MKTool::init_Cockpit()
152
{
153
    // Cockpit-Elemente
154
    QPalette newPalette;
155
 
156
    newPalette.setColor(QPalette::Base, Qt::darkBlue);
157
    newPalette.setColor(QPalette::Foreground, QColor(Qt::darkBlue).dark(120));
158
    newPalette.setColor(QPalette::Text, Qt::white);
159
 
160
    Compass->setScaleOptions(QwtDial::ScaleTicks | QwtDial::ScaleLabel);
161
    Compass->setScaleTicks(0, 0, 3);
162
    Compass->setScale(36, 5, 0);
163
 
164
    Compass->setNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow, true, Qt::red, QColor(Qt::gray).light(130)));
165
    Compass->setPalette(newPalette);
166
    Compass->setMaximumSize(QSize(MeterSize, MeterSize));
167
    Compass->setMinimumSize(QSize(MeterSize, MeterSize));
168
 
169
    QPalette newPalette1;
170
 
171
    newPalette1.setColor(QPalette::Base, Qt::darkBlue);
172
    newPalette1.setColor(QPalette::Foreground, QColor(255,128,0).dark(120));
173
    newPalette1.setColor(QPalette::Text, Qt::white);
174
 
175
    Attitude = new AttitudeIndicator(this);
176
    Attitude->setMaximumSize(QSize(MeterSize, MeterSize));
177
    Attitude->setMinimumSize(QSize(MeterSize, MeterSize));
178
    Attitude->setPalette(newPalette1);
179
 
180
    verticalLayout->addWidget(Attitude);
181
 
182
    qwt_Rate->setRange(-10.0, 10.0, 0.1, 0);
183
 
184
    newPalette1.setColor(QPalette::Foreground, QColor(Qt::darkBlue).dark(120));
185
 
186
    SpeedMeter = new cSpeedMeter(this);
187
    SpeedMeter->setMaximumSize(QSize(MeterSize, MeterSize));
188
    SpeedMeter->setMinimumSize(QSize(MeterSize, MeterSize));
189
    SpeedMeter->setPalette(newPalette1);
190
    SpeedMeter->setRange(0.0, 5.0);
191
    SpeedMeter->setScale(1, 2, 0.5);
192
    SpeedMeter->setProperty("END", 5);
193
 
194
    LayOut_Speed->addWidget(SpeedMeter);
195
}
196
 
158 KeyOz 197
void MKTool::init_Objects()
198
{
199
    // QTimer-Instanzen
199 KeyOz 200
    Ticker = new QTimer(this);
158 KeyOz 201
 
306 KeyOz 202
    // Verbindungsobject
203
    o_Connection = new cConnection();
250 KeyOz 204
 
239 Brean 205
    // neuer Logger
240 Brean 206
    logger = new Logger(Settings, &Mode);
159 KeyOz 207
 
227 KeyOz 208
    // LCD-Dialog
209
    f_LCD = new dlg_LCD(this);
210
 
305 KeyOz 211
    // LCD-Dialog
212
    f_Map = new dlg_Map(this);
306 KeyOz 213
    f_Map->create_Map(Settings);
305 KeyOz 214
 
306 KeyOz 215
    KML_Server = new cKML_Server();
199 KeyOz 216
 
272 KeyOz 217
    QMK_Server = new cQMK_Server();
218
    QMK_Server->setProperty("Connect", false);
199 KeyOz 219
 
220
    if (Settings->Server.StartServer)
221
    {
222
        ac_StartServer->setChecked(true);
306 KeyOz 223
        KML_Server->start_Server(Settings->Server.Port.toInt(), Settings);
199 KeyOz 224
    }
158 KeyOz 225
}
226
 
227
void MKTool::init_Connections()
228
{
250 KeyOz 229
    connect(Dec, SIGNAL(clicked()), this, SLOT(slot_Test()));
199 KeyOz 230
 
306 KeyOz 231
    // Waypoints übergeben
232
    connect(f_Map, SIGNAL(set_Target(sWayPoint)), this , SLOT(slot_MAP_SetTarget(sWayPoint)));
233
 
250 KeyOz 234
    // Daten Senden / Empfangen
306 KeyOz 235
    connect(o_Connection, SIGNAL(newData(sRxData)), this, SLOT(slot_newData(sRxData)));
236
    connect(o_Connection, SIGNAL(showTerminal(int, QString)), this, SLOT(slot_showTerminal(int, QString)));
158 KeyOz 237
 
199 KeyOz 238
    // Serielle Verbundung öffnen / schließen
239
    connect(ac_ConnectTTY, SIGNAL(triggered()), this, SLOT(slot_OpenPort()));
240
 
227 KeyOz 241
    // TCP-Connection verbinden / trennen
242
    connect(ac_QMKServer, SIGNAL(triggered()), this, SLOT(slot_QMKS_Connect()));
243
 
167 KeyOz 244
    // Buttons Settings lesen / schreiben
199 KeyOz 245
    connect(f_Settings->pb_Read,   SIGNAL(clicked()), this, SLOT(slot_GetFCSettings()));
246
    connect(f_Settings->pb_Write,  SIGNAL(clicked()), this, SLOT(slot_SetFCSettings()));
158 KeyOz 247
 
248
    // Actions
249
    connect(ac_Config,       SIGNAL(triggered()), this, SLOT(slot_ac_Config()));
159 KeyOz 250
    connect(ac_Preferences,  SIGNAL(triggered()), this, SLOT(slot_ac_Preferences()));
158 KeyOz 251
    connect(ac_Motortest,    SIGNAL(triggered()), this, SLOT(slot_ac_Motortest()));
227 KeyOz 252
    connect(ac_LCD,          SIGNAL(triggered()), this, SLOT(slot_ac_LCD()));
305 KeyOz 253
    connect(ac_Map,          SIGNAL(triggered()), this, SLOT(slot_ac_Map()));
199 KeyOz 254
    connect(ac_FastDebug,    SIGNAL(triggered()), this, SLOT(slot_ac_FastDebug()));
255
    connect(ac_NoDebug,      SIGNAL(triggered()), this, SLOT(slot_ac_NoDebug()));
256
    connect(ac_FastNavi,     SIGNAL(triggered()), this, SLOT(slot_ac_FastNavi()));
257
    connect(ac_NoNavi,       SIGNAL(triggered()), this, SLOT(slot_ac_NoNavi()));
158 KeyOz 258
    connect(ac_GetLabels,    SIGNAL(triggered()), this, SLOT(slot_ac_GetLabels()));
259
 
167 KeyOz 260
    // Plotter starten / scrollen
261
    connect(scroll_plot,     SIGNAL(valueChanged(int)), this, SLOT(slot_ScrollPlot(int)));
262
    connect(ac_StartPlotter, SIGNAL(triggered()), this, SLOT(slot_ac_StartPlotter()));
199 KeyOz 263
    connect(ac_StartServer,  SIGNAL(triggered()), this, SLOT(slot_ac_StartServer()));
167 KeyOz 264
 
158 KeyOz 265
    // Tabs ein & ausblenden
266
    connect(ac_View0,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
267
    connect(ac_View1,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
268
    connect(ac_View2,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
269
    connect(ac_View3,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
270
    connect(ac_View4,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
271
    connect(ac_View5,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
227 KeyOz 272
    connect(ac_View6,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
158 KeyOz 273
 
199 KeyOz 274
    connect(ac_SelNC,        SIGNAL(triggered()), this, SLOT(slot_ac_Hardware()));
275
    connect(ac_SelFC,        SIGNAL(triggered()), this, SLOT(slot_ac_Hardware()));
276
    connect(ac_SelMag,       SIGNAL(triggered()), this, SLOT(slot_ac_Hardware()));
277
 
278
    connect(rb_SelNC,        SIGNAL(clicked()), this, SLOT(slot_rb_Hardware()));
279
    connect(rb_SelFC,        SIGNAL(clicked()), this, SLOT(slot_rb_Hardware()));
280
    connect(rb_SelMag,       SIGNAL(clicked()), this, SLOT(slot_rb_Hardware()));
281
 
167 KeyOz 282
    // firmeware Updateen / flashen
199 KeyOz 283
    connect(pb_Update,   SIGNAL(clicked()), this, SLOT(slot_pb_Update()));
166 KeyOz 284
    connect(pb_HexFile,  SIGNAL(clicked()), this, SLOT(slot_pb_HexFile()));
158 KeyOz 285
 
250 KeyOz 286
    // Wegpunkt-Befehl
287
    connect(pb_FlyTo,        SIGNAL(clicked()), this, SLOT(slot_pb_SendWaypoint()));
288
 
167 KeyOz 289
    // CVS-Record starten / stoppen
239 Brean 290
    connect(ac_RecordCSV,  SIGNAL(triggered()), this, SLOT(slot_RecordLog()));
158 KeyOz 291
 
292
    // Timer-Events
293
    connect(Ticker,   SIGNAL(timeout()),       SLOT(slot_Ticker()));
294
 
167 KeyOz 295
    // Seitenwechsel
199 KeyOz 296
    connect(tab_Main,             SIGNAL(currentChanged(int)), this, SLOT(slot_TabChanged(int)));
306 KeyOz 297
//    connect(f_Settings->tab_Par,  SIGNAL(currentChanged(int)), this, SLOT(slot_TabChanged(int)));
298
    connect(f_Settings->listWidget,  SIGNAL(currentRowChanged(int)), this, SLOT(slot_TabChanged(int)));
158 KeyOz 299
 
167 KeyOz 300
    // About QMK & About-QT Dialog einfügen
301
    connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About()));
158 KeyOz 302
    menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt()));
303
}
304
 
305
void MKTool::init_Arrays()
306
{
307
    lb_Analog[0]  = lb_A_0;
308
    lb_Analog[1]  = lb_A_1;
309
    lb_Analog[2]  = lb_A_2;
310
    lb_Analog[3]  = lb_A_3;
311
    lb_Analog[4]  = lb_A_4;
312
    lb_Analog[5]  = lb_A_5;
313
    lb_Analog[6]  = lb_A_6;
314
    lb_Analog[7]  = lb_A_7;
315
    lb_Analog[8]  = lb_A_8;
316
    lb_Analog[9]  = lb_A_9;
317
    lb_Analog[10] = lb_A_10;
318
    lb_Analog[11] = lb_A_11;
319
    lb_Analog[12] = lb_A_12;
320
    lb_Analog[13] = lb_A_13;
321
    lb_Analog[14] = lb_A_14;
322
    lb_Analog[15] = lb_A_15;
323
    lb_Analog[16] = lb_A_16;
324
    lb_Analog[17] = lb_A_17;
325
    lb_Analog[18] = lb_A_18;
326
    lb_Analog[19] = lb_A_19;
327
    lb_Analog[20] = lb_A_20;
328
    lb_Analog[21] = lb_A_21;
329
    lb_Analog[22] = lb_A_22;
330
    lb_Analog[23] = lb_A_23;
331
    lb_Analog[24] = lb_A_24;
332
    lb_Analog[25] = lb_A_25;
333
    lb_Analog[26] = lb_A_26;
334
    lb_Analog[27] = lb_A_27;
335
    lb_Analog[28] = lb_A_28;
336
    lb_Analog[29] = lb_A_29;
337
    lb_Analog[30] = lb_A_30;
338
    lb_Analog[31] = lb_A_31;
339
}
340
 
341
void MKTool::init_Plot()
342
{
343
    NextPlot = 0;
344
 
345
    qwtPlot->setCanvasBackground(QColor(QRgb(0x00000000)));
346
 
347
    qwtPlot->insertLegend(new QwtLegend(), QwtPlot::RightLegend);
348
 
349
    QwtPlotGrid *Grid = new QwtPlotGrid();
350
    Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
351
 
352
    Grid->attach(qwtPlot);
353
 
166 KeyOz 354
    qwtPlot->setAxisScale(QwtPlot::xBottom,0,Settings->Data.Plotter_Count,0);
158 KeyOz 355
 
356
    for (int a = 0; a < MaxAnalog; a++)
357
    {
162 KeyOz 358
        Plot[a] = new QwtPlotCurve(Settings->Analog1.Label[a]);
359
        Plot[a]->setPen(QPen(QColor(Def_Colors[a])));
250 KeyOz 360
//        Plot[a]->setRenderHint(QwtPlotItem::RenderAntialiased);
158 KeyOz 361
 
162 KeyOz 362
        if (Settings->Analog1.PlotView[a])
158 KeyOz 363
            Plot[a]->attach(qwtPlot);
364
    }
365
    qwtPlot->replot();
366
}
367
 
306 KeyOz 368
void MKTool::slot_set_Settings(cSettings *t_Settings)
369
{
370
    Settings = t_Settings;
371
}
372
 
199 KeyOz 373
void MKTool::slot_Test()
158 KeyOz 374
{
272 KeyOz 375
//    qDebug("Decode Data");
376
    sRxData RX;
377
 
378
    RX.String = IN->text();
379
 
380
//    qDebug(RX.String.toLatin1().data());
381
 
382
//    if (ToolBox::check_CRC(RX.String))
383
    {
384
        qDebug("Decode Data CRC OK");
385
        RX.Input = RX.String.toLatin1().data();
386
 
387
//        qDebug(RX.Input);
388
 
389
        slot_newData(RX);
390
    }
250 KeyOz 391
}
158 KeyOz 392
 
272 KeyOz 393
// KML-Datei nach Wegpunkt parsen
394
// TODO: Richtigen KML-Parser bauen
250 KeyOz 395
void MKTool::parse_TargetKML()
396
{
397
    QString Tmp = te_KML->toPlainText().simplified();
398
    QStringList List;
158 KeyOz 399
 
250 KeyOz 400
    if ((Tmp.contains("<kml xmlns=\"http://earth.google.com/kml/2.2\">"))  && (Tmp.contains("<coordinates>")))
401
    {
402
        List = Tmp.split("<coordinates>");
403
        List = List[1].split(",");
404
 
405
        le_TarLong->setText(ToolBox::get_Float((List[0].toDouble() * 10000000), 10000000));
406
        le_TarLat->setText(ToolBox::get_Float((List[1].toDouble() * 10000000), 10000000));
407
    }
158 KeyOz 408
}
409
 
272 KeyOz 410
// Waypoint zur NC Senden.
250 KeyOz 411
void MKTool::slot_pb_SendWaypoint()
412
{
413
    if ((Navi.Current.Longitude == 0) && (Navi.Current.Latitude == 0))
414
    {
415
        QMessageBox msgB;
416
        QString msg;
417
        msgB.setText("Fehler: Es konnten keine GPS-Daten vom Mikrokopter empfangen werden");
418
        msgB.exec();
419
        return;
420
    }
272 KeyOz 421
 
250 KeyOz 422
    //erstelle einen Wegpunkt, den die NaviCtrl auswerten kann
423
    Waypoint_t desired_pos;
424
    bool ok_lat, ok_lon;
425
 
426
    //eingegebene Daten holen
427
    double desired_long, desired_lat;
428
 
429
    desired_long = le_TarLong->text().toDouble(&ok_lon);
430
    desired_lat  = le_TarLat->text().toDouble(&ok_lat);
431
 
432
    if (ok_lon && desired_long < 100)
433
        desired_long *= 10000000+0.5;
434
 
435
    if (ok_lat && desired_lat < 100)
436
        desired_lat *= 10000000+0.5;
437
 
438
    //fülle Wegpunkt-Daten
439
    desired_pos.Position.Altitude = 0;
440
    desired_pos.Position.Longitude = int32_t(desired_long);
441
    desired_pos.Position.Latitude =  int32_t(desired_lat);
442
    desired_pos.Position.Status = NEWDATA;
443
    desired_pos.Heading = -1;
444
    desired_pos.ToleranceRadius = 1;
445
    desired_pos.HoldTime = 60;
446
    desired_pos.Event_Flag = 0;
447
    desired_pos.reserve[0] = 0; // reserve
448
    desired_pos.reserve[1] = 0; // reserve
449
    desired_pos.reserve[2] = 0; // reserve
450
    desired_pos.reserve[3] = 0; // reserve
451
 
452
    //...und sende ihn an die NaviCtrl
453
    int max_radius = 10000;
454
    if (ok_lat && ok_lon &&
455
        abs(Navi.Current.Longitude - desired_pos.Position.Longitude) < max_radius &&
456
        abs(Navi.Current.Latitude  - desired_pos.Position.Latitude) < max_radius)
457
    {
306 KeyOz 458
            o_Connection->send_Cmd('s', ADDRESS_NC, (char *)&desired_pos, sizeof(desired_pos), false);
250 KeyOz 459
    }
460
    else
461
    {
462
        QMessageBox msgB;
463
        QString msg;
464
        msg += "Bitte die Eingabe ueberpruefen!\n";
465
        msg += "Die Werte muessen sich in der Naehe der aktuellen Koordinaten befinden\n";
466
        msg += "(Lon: ";
467
        msg += ToolBox::get_Float(Navi.Current.Longitude,10000000);
468
        msg += ", ";
469
        msg += "Lat: ";
470
        msg += ToolBox::get_Float(Navi.Current.Latitude,10000000);
471
        msg += ")";
472
        msgB.setText(msg);
473
        msgB.exec();
474
    }
475
}
476
 
199 KeyOz 477
void MKTool::slot_ac_Hardware()
478
{
479
    QAction *Action = (QAction*)sender();
158 KeyOz 480
 
199 KeyOz 481
    if (Action->isChecked() == false)
482
    {
483
        Action->setChecked(true);
484
    }
485
 
486
    slot_rb_Hardware();
487
}
488
 
489
void MKTool::slot_rb_Hardware()
490
{
491
    if ((rb_SelNC->isChecked() == false) && (Mode.ID != ADDRESS_NC))
492
    {
493
        lb_Status->setText(tr("Schalte um auf NaviCtrl."));
494
        TX_Data[0] = 0x1B;
495
        TX_Data[1] = 0x1B;
496
        TX_Data[2] = 0x55;
497
        TX_Data[3] = 0xAA;
498
        TX_Data[4] = 0x00;
499
        TX_Data[5] = '\r';
306 KeyOz 500
        o_Connection->send_Cmd('#', ADDRESS_NC, TX_Data, 6, false);
227 KeyOz 501
        ToolBox::Wait(SLEEP);
199 KeyOz 502
    }
503
 
504
    if (rb_SelFC->isChecked())
505
    {
506
        lb_Status->setText(tr("Schalte um auf FlightCtrl."));
507
        TX_Data[0] = 0;
306 KeyOz 508
        o_Connection->send_Cmd('u', ADDRESS_NC, TX_Data, 1, false);
199 KeyOz 509
    }
510
    else
511
    if (rb_SelMag->isChecked())
512
    {
513
        lb_Status->setText(tr("Schalte um auf MK3MAG."));
514
        TX_Data[0] = 1;
306 KeyOz 515
        o_Connection->send_Cmd('u', ADDRESS_NC, TX_Data, 1, false);
199 KeyOz 516
    }
517
    else
518
    if (rb_SelNC->isChecked())
519
    {
520
        lb_Status->setText(tr("Schalte um auf NaviCtrl."));
521
        TX_Data[0] = 0x1B;
522
        TX_Data[1] = 0x1B;
523
        TX_Data[2] = 0x55;
524
        TX_Data[3] = 0xAA;
525
        TX_Data[4] = 0x00;
526
        TX_Data[5] = '\r';
306 KeyOz 527
        o_Connection->send_Cmd('#', ADDRESS_NC, TX_Data, 6, false);
199 KeyOz 528
    }
227 KeyOz 529
    ToolBox::Wait(SLEEP);
199 KeyOz 530
 
531
//    qDebug("Select RB Hardware");
306 KeyOz 532
    o_Connection->send_Cmd('v', ADDRESS_ALL, TX_Data, 0, true);
199 KeyOz 533
}
534
 
158 KeyOz 535
// Ticker-Event
536
///////////////
537
void MKTool::slot_Ticker()
538
{
539
    if (TickerDiv)
540
        TickerDiv = false;
541
    else
542
        TickerDiv = true;
543
 
250 KeyOz 544
    if (cb_ClipBoard->isChecked())
545
    {
546
        QString s_OLD = te_KML->toPlainText();
547
        te_KML->clear();
548
        te_KML->paste();
549
        if (s_OLD != te_KML->toPlainText())
550
        {
551
            parse_TargetKML();
552
        }
553
    }
554
 
158 KeyOz 555
    for (int a = 0; a < MaxTickerEvents; a++)
556
    {
557
        if (TickerEvent[a] == true)
558
        {
559
            switch(a)
560
            {
561
                case 0 :
562
                    if (TickerDiv)
563
                    {
564
                        QByteArray Temp(LastSend.toUtf8());
250 KeyOz 565
//                        serialPort->sendData(Temp);
158 KeyOz 566
                    }
567
                break;
568
                case 1 :
159 KeyOz 569
                    TX_Data[0] = 0;
306 KeyOz 570
                    o_Connection->send_Cmd('p', ADDRESS_FC, TX_Data, 0, false);
158 KeyOz 571
                break;
159 KeyOz 572
                case 2 :
227 KeyOz 573
                    if (f_LCD->cb_LCD->isChecked())
167 KeyOz 574
                    {
227 KeyOz 575
                        if (!f_LCD->isVisible())
576
                        {
577
                            Ticker->setInterval(2000);
578
                            TickerEvent[2] = false;
579
                        }
167 KeyOz 580
                        TX_Data[0] = LCD_Page;
581
                        TX_Data[1] = 0;
306 KeyOz 582
                        o_Connection->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true);
167 KeyOz 583
                    }
159 KeyOz 584
                break;
167 KeyOz 585
                case 3 :
199 KeyOz 586
                    if (ac_FastDebug->isChecked())
167 KeyOz 587
                    {
588
                        TX_Data[0] = Settings->Data.Debug_Fast / 10;
306 KeyOz 589
                        o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
167 KeyOz 590
                    }
591
                    else
592
                    {
593
                        TX_Data[0] = Settings->Data.Debug_Slow / 10;
306 KeyOz 594
                        o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
167 KeyOz 595
                    }
596
                break;
158 KeyOz 597
            }
598
        }
599
    }
600
}
601
 
227 KeyOz 602
void MKTool::slot_QMKS_Connect()
603
{
604
    if (ac_QMKServer->isChecked())
605
    {
606
        lb_Status->setText(tr("Verbinde zum QMK-Datenserver."));
158 KeyOz 607
 
272 KeyOz 608
        QMK_Server->Connect(Settings->Server.QMKS_Host, Settings->Server.QMKS_Port.toInt(), Settings->Server.QMKS_Login, Settings->Server.QMKS_Password);
227 KeyOz 609
 
272 KeyOz 610
        connect(QMK_Server, SIGNAL(sig_Connected()), this, SLOT(slot_QMKS_Connected()));
611
        connect(QMK_Server, SIGNAL(sig_Disconnected(int)), this, SLOT(slot_QMKS_Disconnected(int)));
227 KeyOz 612
    }
613
    else
614
    {
272 KeyOz 615
        if ((QMK_Server->property("Connect")) == true)
227 KeyOz 616
        {
272 KeyOz 617
            disconnect(QMK_Server, SIGNAL(sig_Disconnected(int)), 0, 0);
227 KeyOz 618
            lb_Status->setText(tr("Trenne vom QMK-Datenserver."));
619
 
272 KeyOz 620
            QMK_Server->Disconnect();
621
            QMK_Server->setProperty("Connect", false);
227 KeyOz 622
            ac_QMKServer->setText("QMK-Server Verbinden");
623
        }
624
    }
625
}
626
 
627
void MKTool::slot_QMKS_Connected()
628
{
272 KeyOz 629
    QMK_Server->setProperty("Connect", true);
227 KeyOz 630
    ac_QMKServer->setText("QMK-Server Trennnen");
631
    lb_Status->setText(tr("Verbunden mit QMK-Datenserver."));
632
}
633
 
634
void MKTool::slot_QMKS_Disconnected(int Error)
635
{
272 KeyOz 636
    QMK_Server->setProperty("Connect", false);
227 KeyOz 637
    ac_QMKServer->setText("QMK-Server Verbinden");
638
    ac_QMKServer->setChecked(false);
639
 
272 KeyOz 640
    disconnect(QMK_Server, SIGNAL(sig_Disconnected(int)), 0, 0);
227 KeyOz 641
 
642
    switch (Error)
643
    {
644
        case 1 :
645
        {
646
            lb_Status->setText(tr("Verbindung vom Server beendet."));
647
            QMessageBox::warning(this, QA_NAME,"QMK-Datenserver: Verbindung wurde vom Server beendet.", QMessageBox::Ok);
648
        }
649
        break;
650
        case 2 :
651
        {
652
            lb_Status->setText(tr("Server nicht gefunden."));
653
            QMessageBox::warning(this, QA_NAME,"QMK-Datenserver: Kann nicht zum Server verbinden.", QMessageBox::Ok);
654
        }
655
        break;
656
        case 3 :
657
        {
658
            lb_Status->setText(tr("Serververbindung getrennt. Logindaten falsch."));
659
            QMessageBox::warning(this, QA_NAME,"QMK-Datenserver: Loginname oder Password falsch.", QMessageBox::Ok);
660
        }
661
        break;
662
        default :
663
        {
664
            lb_Status->setText(tr("Getrennt vom QMK-Datenserver."));
665
        }
666
        break;
667
    }
668
}
669
 
158 KeyOz 670
// Slots der Actions (Menüpunkte, Buttons)
671
//////////////////////////////////////////
672
void MKTool::slot_ac_Motortest()
673
{
674
    dlg_Motortest *f_Motortest = new dlg_Motortest(this);
675
 
676
    connect(f_Motortest, SIGNAL(updateMotor(int, int, int, int)), this, SLOT(slot_Motortest(int, int, int, int)));
677
 
678
    if (f_Motortest->exec()==QDialog::Accepted)
679
    {
680
    }
681
 
682
    disconnect(f_Motortest, 0,0,0);
683
    slot_Motortest(0,0,0,0);
684
}
685
 
227 KeyOz 686
void MKTool::slot_ac_LCD()
687
{
688
    if (!f_LCD->isVisible())
689
    {
306 KeyOz 690
        delete f_LCD;
227 KeyOz 691
        f_LCD = new dlg_LCD(this);
692
 
693
        // LCD auf / ab
694
        connect(f_LCD->pb_LCDup,   SIGNAL(clicked()), this, SLOT(slot_LCD_UP()));
695
        connect(f_LCD->pb_LCDdown, SIGNAL(clicked()), this, SLOT(slot_LCD_DOWN()));
696
 
697
        f_LCD->show();
698
        TX_Data[0] = 0;
699
        TX_Data[1] = 0;
306 KeyOz 700
        o_Connection->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true);
227 KeyOz 701
 
702
        Ticker->setInterval(500);
703
        TickerEvent[2] = true;
704
    }
705
}
706
 
305 KeyOz 707
void MKTool::slot_ac_Map()
708
{
709
    if (!f_Map->isVisible())
710
    {
306 KeyOz 711
//        delete f_Map;
712
//        f_Map = new dlg_Map(this);
713
//        f_Map->create_Map(Settings);
305 KeyOz 714
 
715
        f_Map->show();
716
    }
717
}
718
 
306 KeyOz 719
void MKTool::slot_MAP_SetTarget(sWayPoint Target)
720
{
721
    le_TarLong->setText(QString("%1").arg(Target.Longitude));
722
    le_TarLat->setText(QString("%1").arg(Target.Latitude));
723
    sb_TarTime->setValue(Target.Time);
305 KeyOz 724
 
306 KeyOz 725
    slot_pb_SendWaypoint();
726
}
727
 
158 KeyOz 728
void MKTool::slot_Motortest(int Motor1, int Motor2, int Motor3, int Motor4)
729
{
730
    TX_Data[0] = Motor1;
731
    TX_Data[1] = Motor2;
732
    TX_Data[2] = Motor3;
733
    TX_Data[3] = Motor4;
306 KeyOz 734
    o_Connection->send_Cmd('t', ADDRESS_FC, TX_Data, 4, false);
158 KeyOz 735
}
736
 
737
void MKTool::slot_ac_Config()
738
{
162 KeyOz 739
    set_Analog Old_Analog1;
158 KeyOz 740
 
162 KeyOz 741
    Old_Analog1 = Settings->Analog1;
742
 
158 KeyOz 743
    dlg_Config *f_Config = new dlg_Config(this);
162 KeyOz 744
    f_Config->set_Settings(Settings, Mode.ID);
158 KeyOz 745
 
746
    if (f_Config->exec()==QDialog::Accepted)
747
    {
748
        Settings = f_Config->get_Settings();
162 KeyOz 749
        Settings->write_Settings_Analog(Mode.ID);
158 KeyOz 750
 
163 KeyOz 751
        // Plotter neu einrichten
752
        if (Old_Analog1.PlotView != Settings->Analog1.PlotView)
158 KeyOz 753
        {
163 KeyOz 754
            config_Plot();
158 KeyOz 755
        }
756
 
163 KeyOz 757
        // CVS-Datei neu anlegen.
241 KeyOz 758
        if ((logger->is_active()) && (Old_Analog1.LogView != Settings->Analog1.LogView))
158 KeyOz 759
        {
239 Brean 760
            logger->close();
240 Brean 761
            logger->start_Log();
158 KeyOz 762
        }
763
 
764
    }
765
}
766
 
239 Brean 767
//aktualisiere Logging-Status
241 KeyOz 768
void MKTool::update_Log()
769
{
239 Brean 770
    if (logger->is_active())
771
    {
272 KeyOz 772
 
239 Brean 773
        ac_RecordCSV->setText("Log Stop");
774
        lb_Status->setText(tr("Log-Record gestartet."));
775
    }
776
    else
777
    {
241 KeyOz 778
        ac_RecordCSV->setText("Log Aufzeichnen");
239 Brean 779
        lb_Status->setText(tr("Log-Record gestopt."));
780
    }
781
}
782
 
783
//starte/stoppe Logging, wenn auf den entsprechenden Button gedrückt wurde
784
void MKTool::slot_RecordLog()
785
{
786
    if (!logger->is_active())
787
        logger->start_Log();
788
    else
789
        logger->close();
241 KeyOz 790
 
239 Brean 791
    update_Log();
792
}
793
 
159 KeyOz 794
void MKTool::slot_ac_Preferences()
795
{
796
    dlg_Preferences *f_Preferences = new dlg_Preferences(this);
797
 
166 KeyOz 798
    Settings->TTY.Port = le_Port->text();
163 KeyOz 799
    f_Preferences->set_Settings(Settings);
800
 
159 KeyOz 801
    if (f_Preferences->exec()==QDialog::Accepted)
802
    {
163 KeyOz 803
        Settings = f_Preferences->get_Settings();
804
        Settings->write_Settings();
166 KeyOz 805
        le_Port->setText(Settings->TTY.Port);
806
        config_Plot();
159 KeyOz 807
    }
808
}
809
 
158 KeyOz 810
void MKTool::slot_ac_StartPlotter()
811
{
812
    if (ac_StartPlotter->isChecked())
813
    {
199 KeyOz 814
        lb_Status->setText(tr("Datenplotter gestartet."));
158 KeyOz 815
        ac_StartPlotter->setText("Stop Plotter");
816
        pb_StartPlotter->setText("Stop Plotter");
817
    }
818
    else
819
    {
199 KeyOz 820
        lb_Status->setText(tr("Datenplotter gestopt."));
158 KeyOz 821
        ac_StartPlotter->setText("Start Plotter");
822
        pb_StartPlotter->setText("Start Plotter");
823
    }
824
}
825
 
826
void MKTool::slot_ac_View()
827
{
227 KeyOz 828
    int Aktive = -1;
158 KeyOz 829
 
830
    QAction *Action = (QAction*)sender();
831
 
832
    if (Action->objectName() == QString("ac_View0"))
833
        Aktive = 0;
834
    if (Action->objectName() == QString("ac_View1"))
835
        Aktive = 1;
836
    if (Action->objectName() == QString("ac_View2"))
837
        Aktive = 2;
838
    if (Action->objectName() == QString("ac_View3"))
839
        Aktive = 3;
840
    if (Action->objectName() == QString("ac_View4"))
841
        Aktive = 4;
842
    if (Action->objectName() == QString("ac_View5"))
843
        Aktive = 5;
272 KeyOz 844
    if (Action->objectName() == QString("ac_View6"))
845
        Aktive = 6;
158 KeyOz 846
 
847
    QString TabName = QString("Tab_%1").arg(Aktive);
848
 
849
    if (!Action->isChecked())
850
    {
851
        for (int a = 0; a < tab_Main->count(); a++)
852
        {
853
            if (tab_Main->widget(a)->objectName() == TabName)
854
            {
855
                tab_Main->removeTab(a);
856
            }
857
        }
858
    }
859
    else
860
    {
227 KeyOz 861
        tab_Main->insertTab(Aktive, TabWidgets[Aktive], Action->icon(), Action->text());
158 KeyOz 862
    }
863
}
864
 
199 KeyOz 865
void MKTool::slot_ac_FastNavi() // DONE NC 0.12i
158 KeyOz 866
{
199 KeyOz 867
    if (!ac_NoNavi->isChecked())
158 KeyOz 868
    {
199 KeyOz 869
        if (ac_FastNavi->isChecked())
166 KeyOz 870
        {
199 KeyOz 871
            lb_Status->setText(tr("Fordere schnelle NaviDaten an."));
872
            TX_Data[0] = Settings->Data.Navi_Fast / 10;
873
        }
874
        else
875
        {
876
            lb_Status->setText(tr("Fordere langsame NaviDaten an."));
877
            TX_Data[0] = Settings->Data.Navi_Slow / 10;
878
        }
306 KeyOz 879
        o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false);
199 KeyOz 880
    }
881
}
882
 
883
void MKTool::slot_ac_NoNavi() // DONE NC 0.12i
884
{
885
    if (ac_NoNavi->isChecked())
886
    {
887
        lb_Status->setText(tr("NaviDaten abstellen."));
888
        TX_Data[0] = 0;
889
    }
890
    else
891
    {
892
        if (ac_FastNavi->isChecked())
893
        {
894
            lb_Status->setText(tr("Fordere schnelle NaviDaten an."));
895
            TX_Data[0] = Settings->Data.Navi_Fast / 10;
896
        }
897
        else
898
        {
899
            lb_Status->setText(tr("Fordere langsame NaviDaten an."));
900
            TX_Data[0] = Settings->Data.Navi_Slow / 10;
901
        }
902
    }
306 KeyOz 903
    o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false);
199 KeyOz 904
}
905
 
906
void MKTool::slot_ac_FastDebug() // DONE 0.71g
907
{
908
    if (!ac_NoDebug->isChecked())
909
    {
910
        if (ac_FastDebug->isChecked())
911
        {
912
            lb_Status->setText(tr("Fordere schnelle DebugDaten an."));
166 KeyOz 913
            TX_Data[0] = Settings->Data.Debug_Fast / 10;
914
        }
915
        else
916
        {
199 KeyOz 917
            lb_Status->setText(tr("Fordere langsame DebugDaten an."));
166 KeyOz 918
            TX_Data[0] = Settings->Data.Debug_Slow / 10;
919
        }
306 KeyOz 920
        o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
166 KeyOz 921
    }
922
}
923
 
199 KeyOz 924
void MKTool::slot_ac_NoDebug() // DONE 0.71g
166 KeyOz 925
{
199 KeyOz 926
    if (ac_NoDebug->isChecked())
166 KeyOz 927
    {
199 KeyOz 928
        lb_Status->setText(tr("DebugDaten abstellen."));
167 KeyOz 929
        TickerEvent[3] = false;
166 KeyOz 930
        TX_Data[0] = 0;
931
    }
158 KeyOz 932
    else
933
    {
167 KeyOz 934
        // Wenn MK3MAG dann andauernd Daten neu anfragen.
935
        if (Mode.ID == ADDRESS_MK3MAG)
936
            TickerEvent[3] = true;
937
 
199 KeyOz 938
        if (ac_FastDebug->isChecked())
166 KeyOz 939
        {
199 KeyOz 940
            lb_Status->setText(tr("Fordere schnelle DebugDaten an."));
166 KeyOz 941
            TX_Data[0] = Settings->Data.Debug_Fast / 10;
942
        }
943
        else
944
        {
199 KeyOz 945
            lb_Status->setText(tr("Fordere langsame DebugDaten an."));
166 KeyOz 946
            TX_Data[0] = Settings->Data.Debug_Slow / 10;
947
        }
948
    }
306 KeyOz 949
    o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
158 KeyOz 950
}
951
 
952
void MKTool::slot_ac_About()
953
{
954
    QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT);
955
}
956
 
159 KeyOz 957
void MKTool::slot_ac_GetLabels() // DONE 0.71g
158 KeyOz 958
{
199 KeyOz 959
    lb_Status->setText(tr("Analoglabels auslesen."));
158 KeyOz 960
    TX_Data[0] = 0;
306 KeyOz 961
    o_Connection->send_Cmd('a', ADDRESS_ALL, TX_Data, 1, true);
158 KeyOz 962
}
963
 
199 KeyOz 964
void MKTool::slot_ac_StartServer()
965
{
966
    if (ac_StartServer->isChecked())
967
    {
306 KeyOz 968
        lb_Status->setText(tr("KML-Server gestartet."));
969
        KML_Server->start_Server(Settings->Server.Port.toInt(), Settings);
199 KeyOz 970
    }
971
    else
972
    {
306 KeyOz 973
        lb_Status->setText(tr("KML-Server gestopt."));
974
        KML_Server->stop_Server();
199 KeyOz 975
    }
976
}
159 KeyOz 977
 
227 KeyOz 978
 
158 KeyOz 979
//  Daten-Plotter
980
/////////////////
981
void MKTool::update_Plot()
982
{
983
    for (int a = 0; a < MaxAnalog; a++)
984
    {
985
        Plot[a]->setData(aID,aData[a],NextPlot - 1);
986
    }
987
 
166 KeyOz 988
    if ((NextPlot > Settings->Data.Plotter_Count))
158 KeyOz 989
    {
166 KeyOz 990
        scroll_plot->setMaximum(NextPlot - Settings->Data.Plotter_Count);
158 KeyOz 991
    }
992
 
166 KeyOz 993
    if ((scroll_plot->value() == NextPlot - (Settings->Data.Plotter_Count + 1)))
158 KeyOz 994
    {
166 KeyOz 995
        qwtPlot->setAxisScale(QwtPlot::xBottom,NextPlot - Settings->Data.Plotter_Count,NextPlot,0);
996
        scroll_plot->setValue(NextPlot - Settings->Data.Plotter_Count);
158 KeyOz 997
    }
998
 
999
    qwtPlot->replot();
1000
}
1001
 
1002
void MKTool::config_Plot()
1003
{
166 KeyOz 1004
//    qDebug("Plotter rekonfiguriert..!!");
1005
    qwtPlot->setAxisScale(QwtPlot::xBottom,0,Settings->Data.Plotter_Count,0);
1006
 
158 KeyOz 1007
    for (int a = 0; a < MaxAnalog; a++)
1008
    {
1009
        Plot[a]->detach();
162 KeyOz 1010
        Plot[a]->setPen(QPen(QColor(Def_Colors[a])));
158 KeyOz 1011
 
162 KeyOz 1012
        if (Settings->Analog1.PlotView[a])
1013
        {
1014
            Plot[a]->setTitle(Settings->Analog1.Label[a]);
158 KeyOz 1015
            Plot[a]->attach(qwtPlot);
162 KeyOz 1016
        }
158 KeyOz 1017
    }
166 KeyOz 1018
    qwtPlot->replot();
158 KeyOz 1019
}
1020
 
1021
void MKTool::slot_ScrollPlot(int Pos)
1022
{
166 KeyOz 1023
    qwtPlot->setAxisScale(QwtPlot::xBottom,Pos,Pos + Settings->Data.Plotter_Count,0);
158 KeyOz 1024
    qwtPlot->replot();
1025
}
1026
 
1027
 
1028
// Firmeware-Update
1029
///////////////////
1030
void MKTool::slot_pb_Update()
1031
{
167 KeyOz 1032
    QString Device;
1033
    QString Hardware;
158 KeyOz 1034
 
167 KeyOz 1035
    if (rb_FC->isChecked())
1036
    {
1037
        Device   = "m644";
1038
        Hardware = "FlightCtrl";
1039
    }
1040
    else if (rb_MK3MAG->isChecked())
1041
    {
1042
        Device   = "m168";
1043
        Hardware = "MK3MAG";
1044
    }
1045
    else if (rb_BL->isChecked())
1046
    {
1047
        Device   = "m8";
1048
        Hardware = "BL-Ctrl";
1049
    }
166 KeyOz 1050
 
1051
    QString Message = "Firmeware-Datei \n\n";
1052
    Message = Message + le_HexFile->text() + "\n\n";
167 KeyOz 1053
    Message = Message + "an " + Hardware + trUtf8(" mit AVRDUDE - Seriel & Bootloader über ") + le_Port->text() + trUtf8(" übertragen?\n");
166 KeyOz 1054
 
1055
    if (le_HexFile->text() == "")
162 KeyOz 1056
    {
166 KeyOz 1057
        QMessageBox::warning(this, QA_NAME, trUtf8("Bitte Firmeware-Datei wählen."), QMessageBox::Ok);
162 KeyOz 1058
    }
166 KeyOz 1059
    else if (QMessageBox::warning(this, QA_NAME, Message, QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
1060
    {
306 KeyOz 1061
        QString Programm = Settings->DIR.AVRDUDE;
162 KeyOz 1062
 
166 KeyOz 1063
        QStringList Argumente;
162 KeyOz 1064
 
166 KeyOz 1065
        Update = new QProcess();
162 KeyOz 1066
 
306 KeyOz 1067
        if (o_Connection->isOpen())
166 KeyOz 1068
        {
1069
            slot_OpenPort();
1070
        }
1071
 
1072
        Argumente << "-P";
1073
        Argumente << le_Port->text();
1074
        Argumente << "-p";
1075
        Argumente << Device;
1076
        Argumente << "-c";
1077
        Argumente << "butterfly";
1078
        Argumente << "-b";
1079
        Argumente << "57600";
1080
        Argumente << "-U";
1081
        Argumente << "flash:w:" + le_HexFile->text();
1082
 
1083
//    QString Programm = "/home/Manuel/bin/avrdude -p m644 -P /dev/ttyS0 -c butterfly -b 57600 -U flash:w:/home/Manuel/Documents/Mikrokopter/Firmeware/FlightCtrl/Flight-Ctrl_MEGA644_V0_71h.hex";
1084
 
1085
        te_Shell->setText(""); // Ausgabefenster säubern
1086
 
1087
        connect(Update, SIGNAL(readyReadStandardOutput()), this, SLOT(slot_UpdateShell()) );
1088
        connect(Update, SIGNAL(readyReadStandardError()), this, SLOT(slot_UpdateShell()) );
1089
 
1090
        Update->start(Programm, Argumente); // Programmaufruf
1091
    }
158 KeyOz 1092
}
1093
 
1094
void MKTool::slot_UpdateShell()
1095
{
162 KeyOz 1096
    QByteArray Output;
158 KeyOz 1097
 
166 KeyOz 1098
    Output = Update->readAllStandardError(); // Shellausgabe an Variable
162 KeyOz 1099
    te_Shell->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1100
    te_Shell->insertPlainText(QString::fromUtf8(Output));
158 KeyOz 1101
 
166 KeyOz 1102
    Output = Update->readAll();
1103
    te_Shell->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1104
    te_Shell->insertPlainText(QString::fromUtf8(Output));
158 KeyOz 1105
}
1106
 
166 KeyOz 1107
void MKTool::slot_pb_HexFile()
1108
{
1109
    QString FileName = QFileDialog::getOpenFileName(this,trUtf8(("Firmeware-Datei wählen")),"",
1110
                                tr("Intel Hex(*.hex);;Alle Dateien (*)"));
1111
    if (!FileName.isEmpty())
1112
    {
1113
        le_HexFile->setText(FileName);
1114
    }
1115
}
158 KeyOz 1116
 
1117
 
167 KeyOz 1118
// Wechsel der Tabs erkennen
159 KeyOz 1119
void MKTool::slot_TabChanged(int Tab) // DONE 0.71g
158 KeyOz 1120
{
1121
    Tab = Tab;
162 KeyOz 1122
    if (tab_Main->count() != 0)
158 KeyOz 1123
    {
306 KeyOz 1124
        if ((tab_Main->currentWidget()->objectName() == QString("Tab_2")) && (f_Settings->listWidget->currentRow() == 1))
162 KeyOz 1125
        {
1126
            TX_Data[0] = 0;
306 KeyOz 1127
            o_Connection->send_Cmd('p', ADDRESS_FC, TX_Data, 0, true);
159 KeyOz 1128
 
162 KeyOz 1129
            Ticker->setInterval(500);
1130
            TickerEvent[1] = true;
1131
        }
1132
        else
1133
        {
1134
            Ticker->setInterval(2000);
1135
            TickerEvent[1] = false;
1136
        }
159 KeyOz 1137
    }
158 KeyOz 1138
}
1139
 
167 KeyOz 1140
// LCD-Seiten weiterschalten
159 KeyOz 1141
void MKTool::slot_LCD_UP() // DONE 0.71g
158 KeyOz 1142
{
159 KeyOz 1143
    if (LCD_Page == LCD_MAX_Page)
1144
        TX_Data[0] = 0;
1145
    else
1146
        TX_Data[0] = LCD_Page + 1;
1147
 
1148
    TX_Data[1] = 0;
306 KeyOz 1149
    o_Connection->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true);
159 KeyOz 1150
}
1151
 
1152
void MKTool::slot_LCD_DOWN() // DONE 0.71g
1153
{
1154
    if (LCD_Page == 0)
1155
        TX_Data[0] = LCD_MAX_Page;
1156
    else
1157
        TX_Data[0] = LCD_Page - 1;
1158
 
1159
    TX_Data[1] = 0;
306 KeyOz 1160
    o_Connection->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true);
159 KeyOz 1161
}
1162
 
167 KeyOz 1163
// Settings aus MK lesen / in MK schreiben
199 KeyOz 1164
void MKTool::slot_GetFCSettings() // DONE 0.71g
159 KeyOz 1165
{
199 KeyOz 1166
    lb_Status->setText(tr("Lese FlightCtrl-Settings aus."));
167 KeyOz 1167
    TX_Data[0] = f_Settings->sb_Set->value();
158 KeyOz 1168
    TX_Data[1] = 0;
306 KeyOz 1169
    o_Connection->send_Cmd('q', ADDRESS_FC, TX_Data, 1);
158 KeyOz 1170
}
1171
 
199 KeyOz 1172
void MKTool::slot_SetFCSettings() // DONE 0.71g
158 KeyOz 1173
{
199 KeyOz 1174
    char *TX_Data2 = f_Settings->GetFCSettings();
158 KeyOz 1175
 
199 KeyOz 1176
    lb_Status->setText(tr("Schreibe FlightCtrl-Settings."));
167 KeyOz 1177
 
306 KeyOz 1178
    o_Connection->send_Cmd('s', ADDRESS_FC, TX_Data2, MaxParameter + 2, false);
158 KeyOz 1179
}
1180
 
159 KeyOz 1181
 
167 KeyOz 1182
// Save GUI-Preferences
1183
///////////////////////
1184
void MKTool::set_Preferences()
158 KeyOz 1185
{
163 KeyOz 1186
    Settings->GUI.TabViews.setBit(0, ac_View0->isChecked());
1187
    Settings->GUI.TabViews.setBit(1, ac_View1->isChecked());
1188
    Settings->GUI.TabViews.setBit(2, ac_View2->isChecked());
1189
    Settings->GUI.TabViews.setBit(3, ac_View3->isChecked());
1190
    Settings->GUI.TabViews.setBit(4, ac_View4->isChecked());
1191
    Settings->GUI.TabViews.setBit(5, ac_View5->isChecked());
227 KeyOz 1192
    Settings->GUI.TabViews.setBit(6, ac_View6->isChecked());
158 KeyOz 1193
 
227 KeyOz 1194
    Settings->GUI.ToolViews.setBit(0, tb_Allgemein->isVisibleTo(this));
1195
    Settings->GUI.ToolViews.setBit(1, tb_Werkzeuge->isVisibleTo(this));
1196
    Settings->GUI.ToolViews.setBit(2, tb_Debug->isVisibleTo(this));
1197
    Settings->GUI.ToolViews.setBit(3, tb_TTY->isVisibleTo(this));
1198
    Settings->GUI.ToolViews.setBit(4, tb_Hardware->isVisibleTo(this));
1199
 
162 KeyOz 1200
    Settings->GUI.Term_Info   = cb_ShowMSG->isChecked();
1201
    Settings->GUI.Term_Data   = cb_ShowData->isChecked();
1202
    Settings->GUI.Term_Always = cb_ShowAlways->isChecked();
166 KeyOz 1203
    Settings->GUI.Term_Send   = cb_ShowSend->isChecked();
167 KeyOz 1204
    Settings->GUI.isMax       = isMaximized();
1205
    Settings->GUI.Size        = size();
1206
    Settings->GUI.Point       = pos();
162 KeyOz 1207
 
163 KeyOz 1208
    Settings->TTY.Port = le_Port->text();
158 KeyOz 1209
}
1210
 
1211
void MKTool::show_DebugData()
1212
{
241 KeyOz 1213
    if (logger->is_active())
1214
        logger->write(AnalogData);
158 KeyOz 1215
 
1216
    if (ac_StartPlotter->isChecked())
1217
    {
1218
        aID[NextPlot] = NextPlot;
1219
 
1220
        for (int a = 0; a < MaxAnalog; a++)
1221
        {
1222
            aData[a][NextPlot] = AnalogData[a];
1223
        }
1224
        NextPlot++;
1225
 
1226
        if ((tab_Main->currentWidget()->objectName() == QString("Tab_1")))
1227
            update_Plot();
1228
    }
1229
 
1230
    le_A_0->setText(QString("%1").arg(AnalogData[0]));
1231
    le_A_1->setText(QString("%1").arg(AnalogData[1]));
1232
    le_A_2->setText(QString("%1").arg(AnalogData[2]));
1233
    le_A_3->setText(QString("%1").arg(AnalogData[3]));
1234
    le_A_4->setText(QString("%1").arg(AnalogData[4]));
1235
    le_A_5->setText(QString("%1").arg(AnalogData[5]));
1236
    le_A_6->setText(QString("%1").arg(AnalogData[6]));
1237
    le_A_7->setText(QString("%1").arg(AnalogData[7]));
1238
    le_A_8->setText(QString("%1").arg(AnalogData[8]));
1239
    le_A_9->setText(QString("%1").arg(AnalogData[9]));
1240
    le_A_10->setText(QString("%1").arg(AnalogData[10]));
1241
    le_A_11->setText(QString("%1").arg(AnalogData[11]));
1242
    le_A_12->setText(QString("%1").arg(AnalogData[12]));
1243
    le_A_13->setText(QString("%1").arg(AnalogData[13]));
1244
    le_A_14->setText(QString("%1").arg(AnalogData[14]));
1245
    le_A_15->setText(QString("%1").arg(AnalogData[15]));
1246
    le_A_16->setText(QString("%1").arg(AnalogData[16]));
1247
    le_A_17->setText(QString("%1").arg(AnalogData[17]));
1248
    le_A_18->setText(QString("%1").arg(AnalogData[18]));
1249
    le_A_19->setText(QString("%1").arg(AnalogData[19]));
1250
    le_A_20->setText(QString("%1").arg(AnalogData[20]));
1251
    le_A_21->setText(QString("%1").arg(AnalogData[21]));
1252
    le_A_22->setText(QString("%1").arg(AnalogData[22]));
1253
    le_A_23->setText(QString("%1").arg(AnalogData[23]));
1254
    le_A_24->setText(QString("%1").arg(AnalogData[24]));
1255
    le_A_25->setText(QString("%1").arg(AnalogData[25]));
1256
    le_A_26->setText(QString("%1").arg(AnalogData[26]));
1257
    le_A_27->setText(QString("%1").arg(AnalogData[27]));
1258
    le_A_28->setText(QString("%1").arg(AnalogData[28]));
1259
    le_A_29->setText(QString("%1").arg(AnalogData[29]));
1260
    le_A_30->setText(QString("%1").arg(AnalogData[30]));
1261
    le_A_31->setText(QString("%1").arg(AnalogData[31]));
227 KeyOz 1262
 
1263
    if ((Mode.ID == ADDRESS_FC) && (FCSettings[P_GYRO_ACC_FAKTOR] > 0))
1264
    {
1265
        bar_UBAT->setValue(AnalogData[9]);
1266
        bar_RX->setValue(AnalogData[10]);
1267
 
1268
        Compass->setValue(AnalogData[8]);
1269
 
1270
        int Roll = (AnalogData[1] * FCSettings[P_GYRO_ACC_FAKTOR]) / 1024;
1271
        int Nick = (AnalogData[0] * FCSettings[P_GYRO_ACC_FAKTOR]) / 1024;
1272
 
1273
        if (Roll > 128)
1274
            Roll = Roll - 255;
1275
 
1276
        if (Nick > 128)
1277
            Nick = Nick - 255;
1278
 
1279
        Attitude->setAngle(Roll);
1280
        Attitude->setGradient(double(double(Nick) / 100.0));
1281
    }
158 KeyOz 1282
}
1283
 
199 KeyOz 1284
void MKTool::new_NaviData(sRxData RX)
1285
{
306 KeyOz 1286
//    qDebug("Navi-Data");
1287
 
1288
    switch(RX.Decode[N_NC_FLAGS])
1289
    {
1290
        case 1 : lb_Mode->setText("Free"); break;
1291
        case 2 : lb_Mode->setText("Position Hold"); break;
1292
        case 4 : lb_Mode->setText("Coming Home"); break;
1293
        case 8 : lb_Mode->setText("Range Limit"); break;
1294
    }
1295
 
246 KeyOz 1296
    Navi.Current.Longitude = ToolBox::Data2Long(RX.Decode, N_CUR_LONGITUDE, true);
1297
    Navi.Current.Latitude  = ToolBox::Data2Long(RX.Decode, N_CUR_LATITUDE,  true);
1298
    Navi.Current.Altitude  = ToolBox::Data2Long(RX.Decode, N_CUR_ALTITUDE,  true);
1299
    Navi.Target.Longitude  = ToolBox::Data2Long(RX.Decode, N_TAR_LONGITUDE, true);
1300
    Navi.Target.Latitude   = ToolBox::Data2Long(RX.Decode, N_TAR_LATITUDE,  true);
1301
    Navi.Target.Altitude   = ToolBox::Data2Long(RX.Decode, N_TAR_ALTITUDE,  true);
199 KeyOz 1302
 
246 KeyOz 1303
    le_CDistance->setText(QString("%1 cm").arg(ToolBox::Data2Int(RX.Decode, N_HOME_DISTANCE)));
1304
    le_CWPA->setText(QString("%1").arg(RX.Decode[N_WP_INDEX]));
1305
    le_CWPT->setText(QString("%1").arg(RX.Decode[N_WP_NUMBER]));
1306
    le_CSats->setText(QString("%1").arg(RX.Decode[N_SATS_IN_USER]));
227 KeyOz 1307
 
246 KeyOz 1308
    qwt_Rate->setValue(double(ToolBox::Data2Int(RX.Decode, N_VARIOMETER, true)));
227 KeyOz 1309
 
246 KeyOz 1310
    le_CTime->setText(QString("%1 sec.").arg(ToolBox::Data2Int(RX.Decode, N_FLYING_TIME)));
227 KeyOz 1311
 
246 KeyOz 1312
    bar_UBAT->setValue(RX.Decode[N_UBAT]);
227 KeyOz 1313
 
246 KeyOz 1314
    double Speed = double((ToolBox::Data2Int(RX.Decode, N_GROUND_SPEED)) / 10.0);
227 KeyOz 1315
 
1316
    if ((Speed > 4.5) && SpeedMeter->property("END") == 5)
1317
    {
1318
        SpeedMeter->setRange(0.0, 10.0);
1319
        SpeedMeter->setScale(1, 2, 1);
1320
        SpeedMeter->setProperty("END", 10);
1321
    }
1322
 
1323
    if ((Speed > 9) && SpeedMeter->property("END") == 10)
1324
    {
1325
        SpeedMeter->setRange(0.0, 20.0);
1326
        SpeedMeter->setScale(1, 2, 2);
1327
        SpeedMeter->setProperty("END", 20);
1328
    }
1329
 
1330
    SpeedMeter->setValue(Speed);
1331
 
246 KeyOz 1332
    Compass->setValue(ToolBox::Data2Int(RX.Decode, N_COMAPSS_HEADING)); //(68)
227 KeyOz 1333
 
246 KeyOz 1334
    bar_RX->setValue(RX.Decode[N_RC_QUALITY]);
227 KeyOz 1335
 
246 KeyOz 1336
    int Nick = RX.Decode[N_ANGLE_NICK];
1337
    int Roll = RX.Decode[N_ANGLE_ROLL];
227 KeyOz 1338
 
1339
    if (Roll > 128)
1340
        Roll = Roll - 255;
1341
 
1342
    if (Nick > 128)
1343
        Nick = Nick - 255;
1344
 
1345
    Attitude->setAngle(Roll);
234 KeyOz 1346
    Attitude->setGradient(double(0.0 - (double(Nick) / 100.0)));
227 KeyOz 1347
 
199 KeyOz 1348
    sNaviString NaviString;
1349
 
1350
    NaviString.Longitude = ToolBox::get_Float(Navi.Current.Longitude,10000000);
1351
    NaviString.Latitude  = ToolBox::get_Float(Navi.Current.Latitude,10000000);
1352
    NaviString.Altitude  = ToolBox::get_Float(Navi.Current.Altitude,1000);
1353
 
306 KeyOz 1354
    le_CurLong->setText(NaviString.Longitude);
1355
    le_CurLat->setText(NaviString.Latitude);
199 KeyOz 1356
 
306 KeyOz 1357
    KML_Server->store_NaviString(NaviString);
1358
 
305 KeyOz 1359
    f_Map->add_Position(NaviString.Longitude.toDouble(), NaviString.Latitude.toDouble());
1360
 
272 KeyOz 1361
    if ((QMK_Server->property("Connect")) == true)
227 KeyOz 1362
    {
272 KeyOz 1363
//        qDebug("Send Data to Server..!!");
1364
        QMK_Server->NewPosition(NaviString);
227 KeyOz 1365
    }
199 KeyOz 1366
}
1367
 
272 KeyOz 1368
// Kopter-Kommunikations-Bereich, Befehle senden und Daten empfangen
1369
////////////////////////////////////////////////////////////////////
158 KeyOz 1370
 
1371
// Neues Datenpacket empfangen -> Verarbeiten
250 KeyOz 1372
void MKTool::slot_newData(sRxData RX) // DONE 0.71g
158 KeyOz 1373
{
1374
    if (LastSend.length() > 2)
1375
    {
1376
    }
162 KeyOz 1377
    int HardwareID = RX.Input[1] - 'a';
1378
 
167 KeyOz 1379
    switch(HardwareID)
158 KeyOz 1380
    {
167 KeyOz 1381
        case ADDRESS_FC :
1382
            switch(RX.Input[2])
1383
            {
1384
                // Stick-Belegung der Fernsteuerung
1385
                case 'P' : // DONE 0.71g
1386
                    if (ToolBox::Decode64(RX))
158 KeyOz 1387
                    {
167 KeyOz 1388
                        f_Settings->pb_K1->setValue(ToolBox::Data2Int(RX.Decode,  2,true));
1389
                        f_Settings->pb_K2->setValue(ToolBox::Data2Int(RX.Decode,  4,true));
1390
                        f_Settings->pb_K3->setValue(ToolBox::Data2Int(RX.Decode,  6,true));
1391
                        f_Settings->pb_K4->setValue(ToolBox::Data2Int(RX.Decode,  8,true));
1392
                        f_Settings->pb_K5->setValue(ToolBox::Data2Int(RX.Decode, 10 ,true));
1393
                        f_Settings->pb_K6->setValue(ToolBox::Data2Int(RX.Decode, 12,true));
1394
                        f_Settings->pb_K7->setValue(ToolBox::Data2Int(RX.Decode, 14,true));
1395
                        f_Settings->pb_K8->setValue(ToolBox::Data2Int(RX.Decode, 16,true));
1396
                    }
1397
                break;
1398
                // Settings lesen
1399
                case 'Q' : // DONE 0.71g
1400
                    if (ToolBox::Decode64(RX))
1401
                    {
1402
                        TickerEvent[0] = false;
1403
 
1404
                        if (RX.Decode[1] == VERSION_SETTINGS)
1405
                        {
1406
                            int Settings_ID = RX.Decode[0];
1407
                            for (int a = 0; a < MaxParameter; a++)
1408
                            {
199 KeyOz 1409
                                FCSettings[a] = RX.Decode[a + 2];
167 KeyOz 1410
                            }
1411
                            //show_ParameterSet(Settings_ID);
199 KeyOz 1412
                            f_Settings->show_FCSettings(Settings_ID, FCSettings);
1413
                            f_Settings->pb_Read->setEnabled(true);
1414
                            f_Settings->pb_Write->setEnabled(true);
167 KeyOz 1415
                        }
1416
                        else
1417
                        {
1418
                            f_Settings->pb_Read->setDisabled(true);
1419
                            f_Settings->pb_Write->setDisabled(true);
1420
 
1421
                            QMessageBox::warning(this, QA_NAME,
1422
                                   "Versionen inkompatibel. \nParameterbearbeitung nicht moeglich.", QMessageBox::Ok);
1423
                        }
1424
                    }
1425
                break;
1426
                // Settings geschrieben
1427
                case 'S' : // DONE 0.71g
1428
                    TickerEvent[0] = false;
1429
                break;
1430
            }
1431
 
1432
        case ADDRESS_NC :
1433
            switch(RX.Input[2])
1434
            {
1435
                // Navigationsdaten
1436
                case 'O' : // NOT DONE 0.12h
1437
                    if (ToolBox::Decode64(RX))
1438
                    {
199 KeyOz 1439
                        new_NaviData(RX);
167 KeyOz 1440
                    }
1441
                break;
1442
            }
1443
//        case ADDRESS_MK3MAG :
1444
 
1445
        default :
1446
            switch(RX.Input[2])
1447
            {
1448
                // LCD-Anzeige
1449
                case 'L' : // DONE 0.71g
1450
                    if (ToolBox::Decode64(RX))
1451
                    {
159 KeyOz 1452
                        int LCD[150];
1453
                        memcpy(LCD,RX.Decode, sizeof(RX.Decode));
1454
 
227 KeyOz 1455
                        f_LCD->show_Data(LCD);
1456
 
159 KeyOz 1457
                        LCD_Page     = RX.Decode[0];
1458
                        LCD_MAX_Page = RX.Decode[1];
1459
 
1460
                        TickerEvent[0] = false;
158 KeyOz 1461
                    }
1462
                break;
167 KeyOz 1463
                // Analoglabels
1464
                case 'A' : // DONE 0.71g
1465
                    if (ToolBox::Decode64(RX))
158 KeyOz 1466
                    {
159 KeyOz 1467
                        int Position = RX.Decode[0];
163 KeyOz 1468
                        if (Position != 31)
158 KeyOz 1469
                        {
162 KeyOz 1470
                            Settings->Analog1.Label[Position] = ToolBox::Data2QString(RX.Decode,1,17).trimmed();
167 KeyOz 1471
                            if (Settings->Analog1.Label[Position] == "")
1472
                            {
1473
                                Settings->Analog1.Label[Position] = "A-" + QString("%1").arg(Position);
1474
                            }
158 KeyOz 1475
                            Position ++;
1476
                            TX_Data[0] = Position;
306 KeyOz 1477
                            o_Connection->send_Cmd('a', ADDRESS_ALL, TX_Data, 1, true);
158 KeyOz 1478
                        }
166 KeyOz 1479
                        if (Position == 31)
158 KeyOz 1480
                        {
1481
                            for (int a = 0; a < MaxAnalog; a++)
1482
                            {
162 KeyOz 1483
                                lb_Analog[a]->setText(Settings->Analog1.Label[a]);
158 KeyOz 1484
                            }
163 KeyOz 1485
                            Settings->Analog1.Version = Mode.Version;
162 KeyOz 1486
                            Settings->write_Settings_AnalogLabels(HardwareID);
158 KeyOz 1487
                            config_Plot();
1488
                        }
1489
                    }
1490
                break;
167 KeyOz 1491
                // Debug-Daten
1492
                case 'D' : // DONE 0.71g
1493
                    if (ToolBox::Decode64(RX))
158 KeyOz 1494
                    {
1495
                        for (int i = 0; i < MaxAnalog; i++)
1496
                        {
1497
                            AnalogData[i] = ToolBox::Data2Int(RX.Decode, (i * 2) + 2);
1498
                        }
1499
                        show_DebugData();
1500
                    }
1501
                break;
167 KeyOz 1502
                // Version
1503
                case 'V' : // DONE 0.71h
1504
                    if (ToolBox::Decode64(RX))
159 KeyOz 1505
                    {
167 KeyOz 1506
                        TickerEvent[0] = false;
159 KeyOz 1507
 
167 KeyOz 1508
                        Mode.ID            = HardwareID;
1509
                        Mode.VERSION_MAJOR = RX.Decode[0];
1510
                        Mode.VERSION_MINOR = RX.Decode[1];
1511
                        Mode.VERSION_PATCH = RX.Decode[4];
1512
                        Mode.VERSION_SERIAL_MAJOR = RX.Decode[2];
1513
                        Mode.VERSION_SERIAL_MINOR = RX.Decode[3];
159 KeyOz 1514
 
167 KeyOz 1515
                        Mode.Hardware   = HardwareType[Mode.ID];
1516
                        Mode.Version    = QString("%1").arg(RX.Decode[0]) + "." + QString("%1").arg(RX.Decode[1]) + QString(RX.Decode[4] + 'a');
158 KeyOz 1517
 
167 KeyOz 1518
                        setWindowTitle(QA_NAME + " v" + QA_VERSION + " - " + Mode.Hardware + " " + Mode.Version);
158 KeyOz 1519
 
167 KeyOz 1520
                        if (Mode.VERSION_SERIAL_MAJOR != VERSION_SERIAL_MAJOR)
1521
                        {
272 KeyOz 1522
//                                AllowSend = false;
167 KeyOz 1523
                                QMessageBox::warning(this, QA_NAME,
1524
                                   "Serielles Protokoll Inkompatibel. \nBitte neue Programmversion installieren,", QMessageBox::Ok);
1525
                        }
159 KeyOz 1526
 
199 KeyOz 1527
                        if (ac_NoDebug->isChecked())
1528
                        {
1529
                            TX_Data[0] = 0;
1530
                        }
1531
                        else
1532
                        if (ac_FastDebug->isChecked())
1533
                        {
1534
                            TX_Data[0] = Settings->Data.Debug_Fast / 10;
1535
                        }
1536
                        else
1537
                        {
1538
                            TX_Data[0] = Settings->Data.Debug_Slow / 10;
1539
                        }
1540
 
306 KeyOz 1541
                        o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
199 KeyOz 1542
 
167 KeyOz 1543
                        // Wenn MK3MAG dann andauernd Daten neu anfragen.
1544
                        if (Mode.ID == ADDRESS_MK3MAG)
1545
                        {
1546
                            TickerEvent[3] = true;
199 KeyOz 1547
                            rb_SelMag->setChecked(true);
167 KeyOz 1548
                        }
158 KeyOz 1549
 
199 KeyOz 1550
                        // Wenn NaviCtrl dann hier.
1551
                        if (Mode.ID == ADDRESS_NC)
1552
                        {
1553
                            rb_SelNC->setChecked(true);
158 KeyOz 1554
 
199 KeyOz 1555
                            if (ac_NoNavi->isChecked())
1556
                            {
1557
                                TX_Data[0] = 0;
1558
                            }
1559
                            else
1560
                            if (ac_FastNavi->isChecked())
1561
                            {
1562
                                TX_Data[0] = Settings->Data.Navi_Fast / 10;
1563
                            }
1564
                            else
1565
                            {
1566
                                TX_Data[0] = Settings->Data.Navi_Slow / 10;
1567
                            }
1568
 
306 KeyOz 1569
                            o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false);
199 KeyOz 1570
                        }
1571
 
1572
 
167 KeyOz 1573
                        // Wenn FlightCtrl dann Settings abfragen.
1574
                        if (Mode.ID == ADDRESS_FC)
1575
                        {
199 KeyOz 1576
                            rb_SelFC->setChecked(true);
167 KeyOz 1577
                            {
1578
                                TX_Data[0] = 0xff;
1579
                                TX_Data[1] = 0;
250 KeyOz 1580
 
1581
                                // DEP: Raus wenn Resend implementiert.
1582
                                ToolBox::Wait(SLEEP);
306 KeyOz 1583
                                o_Connection->send_Cmd('q', ADDRESS_FC, TX_Data, 1, true);
250 KeyOz 1584
                                qDebug("FC - Get Settings");
167 KeyOz 1585
                            }
1586
                        }
1587
                        // Wenn nicht Lesen und Schreiben der Settings deaktivieren.
1588
                        else
1589
                        {
1590
                                f_Settings->pb_Read->setDisabled(true);
1591
                                f_Settings->pb_Write->setDisabled(true);
1592
                        }
158 KeyOz 1593
 
167 KeyOz 1594
                        Settings->read_Settings_Analog(HardwareID);
1595
                        Settings->read_Settings_AnalogLabels(HardwareID);
159 KeyOz 1596
 
167 KeyOz 1597
                        if (Settings->Analog1.Version != Mode.Version)
158 KeyOz 1598
                        {
167 KeyOz 1599
                            lb_Status->setText("Analoglabel-Version unterschiedlich. Lese Analoglabels neu aus.");
1600
                            slot_ac_GetLabels();
158 KeyOz 1601
                        }
167 KeyOz 1602
                        else
1603
                        for (int a = 0; a < MaxAnalog; a++)
1604
                        {
1605
                            lb_Analog[a]->setText(Settings->Analog1.Label[a]);
1606
                        }
1607
                        config_Plot();
158 KeyOz 1608
                    }
1609
                break;
167 KeyOz 1610
            }
158 KeyOz 1611
    }
272 KeyOz 1612
 
1613
    // TODO: Roh-Daten senden zum QMK-Server dazu Sendebuffer bauen.
1614
    if ((QMK_Server->property("Connect")) == true)
1615
    {
1616
//        QMK_Server->send_RawData(RX.String);
1617
    }
1618
 
1619
    slot_showTerminal(1, RX.String);
158 KeyOz 1620
}
1621
 
250 KeyOz 1622
void MKTool::slot_showTerminal(int Typ, QString Text)
158 KeyOz 1623
{
250 KeyOz 1624
    switch(Typ)
158 KeyOz 1625
    {
250 KeyOz 1626
        case 1 :
158 KeyOz 1627
        {
250 KeyOz 1628
            if ((cb_ShowData->isChecked()) && ((tab_Main->currentWidget()->objectName() == QString("Tab_3")) || (cb_ShowAlways->isChecked())))
158 KeyOz 1629
            {
250 KeyOz 1630
                te_RX->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1631
                te_RX->insertHtml("<span style=\"color:#00008b;\">" + Text + "<br /></span>");
158 KeyOz 1632
            }
250 KeyOz 1633
        }
1634
        break;
1635
        case 2 :
1636
        {
1637
            if ((cb_ShowMSG->isChecked()) && ((tab_Main->currentWidget()->objectName() == QString("Tab_3")) || (cb_ShowAlways->isChecked())))
158 KeyOz 1638
            {
250 KeyOz 1639
                te_RX->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1640
                te_RX->insertHtml("<span style=\"color:#008b00;\">" + Text + "</span>");
158 KeyOz 1641
            }
1642
        }
250 KeyOz 1643
        break;
1644
        case 3 :
158 KeyOz 1645
        {
250 KeyOz 1646
            if (cb_ShowSend->isChecked())
158 KeyOz 1647
            {
250 KeyOz 1648
                te_RX->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1649
                te_RX->insertHtml("<span style='color:#8b0000;'>" + Text + "<br /></span>");
158 KeyOz 1650
            }
1651
        }
250 KeyOz 1652
        break;
158 KeyOz 1653
    }
1654
}
1655
 
272 KeyOz 1656
// Verbindung zum Kopter herstellen / Trennen
158 KeyOz 1657
void MKTool::slot_OpenPort()
1658
{
306 KeyOz 1659
    if (o_Connection->isOpen())
250 KeyOz 1660
    {
199 KeyOz 1661
        TX_Data[0] = Settings->Data.Debug_Off / 10;
306 KeyOz 1662
        o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
227 KeyOz 1663
        ToolBox::Wait(SLEEP);
158 KeyOz 1664
 
199 KeyOz 1665
        if (Mode.ID == ADDRESS_NC)
1666
        {
1667
            TX_Data[0] = Settings->Data.Navi_Off / 10;
306 KeyOz 1668
            o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false);
227 KeyOz 1669
            ToolBox::Wait(SLEEP);
199 KeyOz 1670
        }
1671
 
272 KeyOz 1672
        if (Mode.ID == ADDRESS_FC)
199 KeyOz 1673
        {
1674
            TX_Data[0] = 0;
1675
            TX_Data[1] = 0;
1676
            TX_Data[2] = 0;
1677
            TX_Data[3] = 0;
306 KeyOz 1678
            o_Connection->send_Cmd('t', ADDRESS_FC, TX_Data, 4, false);
227 KeyOz 1679
            ToolBox::Wait(SLEEP);
199 KeyOz 1680
        }
250 KeyOz 1681
 
306 KeyOz 1682
        o_Connection->Close();
250 KeyOz 1683
 
263 KeyOz 1684
        ac_ConnectTTY->setText("Kopter Verbinden");
199 KeyOz 1685
        le_Port->setEnabled(true);
1686
 
167 KeyOz 1687
        Ticker->stop();
158 KeyOz 1688
    }
1689
    else
1690
    {
263 KeyOz 1691
        int i_Type;
1692
        if (le_Port->text().contains(QString("IP:")))
158 KeyOz 1693
        {
263 KeyOz 1694
            i_Type = C_IP;
1695
        }
1696
        else
1697
        {
1698
            i_Type = C_TTY;
1699
        }
1700
 
306 KeyOz 1701
        if (o_Connection->Open(i_Type, le_Port->text()))
263 KeyOz 1702
        {
1703
            ac_ConnectTTY->setText("Kopter Trennen");
199 KeyOz 1704
            le_Port->setEnabled(false);
158 KeyOz 1705
 
306 KeyOz 1706
            o_Connection->send_Cmd('v', ADDRESS_ALL, TX_Data, 0, true);
159 KeyOz 1707
 
167 KeyOz 1708
            Ticker->start(2000);
158 KeyOz 1709
        }
1710
    }
1711
}
1712
 
1713
// Programm beenden
1714
///////////////////
162 KeyOz 1715
 
1716
MKTool::~MKTool()
158 KeyOz 1717
{
306 KeyOz 1718
    if (o_Connection->isOpen())
158 KeyOz 1719
    {
306 KeyOz 1720
        o_Connection->Close();
158 KeyOz 1721
    }
1722
 
167 KeyOz 1723
    set_Preferences();
162 KeyOz 1724
    Settings->write_Settings();
158 KeyOz 1725
 
239 Brean 1726
    logger->close();
158 KeyOz 1727
}