Subversion Repositories Projects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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