Subversion Repositories Projects

Rev

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

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