Subversion Repositories Projects

Rev

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

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