Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

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