Subversion Repositories Projects

Rev

Rev 392 | Rev 396 | 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"
391 Brean 39
#include "../com/Parser.h"
158 KeyOz 40
 
41
#include <stdlib.h>
42
 
43
MKTool::MKTool()
44
{
45
    setupUi(this);
46
 
47
    Settings = new cSettings;
48
 
49
    init_Arrays();
50
    init_GUI();
306 KeyOz 51
    init_Cockpit();
158 KeyOz 52
 
53
    init_Objects();
54
    init_Connections();
55
 
56
    init_Plot();
57
}
58
 
59
void MKTool::init_GUI()
60
{
61
    setWindowTitle(QA_NAME + " v" + QA_VERSION);
62
 
167 KeyOz 63
    // Tab mit Debug-Elementen verbergen
314 KeyOz 64
    tab_Main->removeTab(6);
272 KeyOz 65
    // Develop - Nicht gebrauchte sachen abschalten.
66
    pb_SettingsReset->hide();
67
    pb_Flash->hide();
68
    rb_NC->hide();
167 KeyOz 69
 
279 KeyOz 70
    // Beta-Sachen einschalten.
71
#ifdef _BETA_
72
    ac_QMKServer->setEnabled(true);
73
#endif
337 KeyOz 74
 
167 KeyOz 75
    // Settings-Tab hinzufügen.
76
    f_Settings = new wdg_Settings( this );
227 KeyOz 77
    f_Settings->set_Config(Settings);
358 KeyOz 78
    tab_Main->insertTab ( 2, f_Settings, ac_View2->icon(), tr("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)));
358 KeyOz 238
    connect(f_Map, SIGNAL(set_WayPoints(QList<sWayPoint>)), this , SLOT(slot_MAP_SetWayPoints(QList<sWayPoint>)));
306 KeyOz 239
 
250 KeyOz 240
    // Daten Senden / Empfangen
306 KeyOz 241
    connect(o_Connection, SIGNAL(newData(sRxData)), this, SLOT(slot_newData(sRxData)));
242
    connect(o_Connection, SIGNAL(showTerminal(int, QString)), this, SLOT(slot_showTerminal(int, QString)));
158 KeyOz 243
 
199 KeyOz 244
    // Serielle Verbundung öffnen / schließen
245
    connect(ac_ConnectTTY, SIGNAL(triggered()), this, SLOT(slot_OpenPort()));
246
 
227 KeyOz 247
    // TCP-Connection verbinden / trennen
248
    connect(ac_QMKServer, SIGNAL(triggered()), this, SLOT(slot_QMKS_Connect()));
249
 
167 KeyOz 250
    // Buttons Settings lesen / schreiben
199 KeyOz 251
    connect(f_Settings->pb_Read,   SIGNAL(clicked()), this, SLOT(slot_GetFCSettings()));
252
    connect(f_Settings->pb_Write,  SIGNAL(clicked()), this, SLOT(slot_SetFCSettings()));
158 KeyOz 253
 
254
    // Actions
255
    connect(ac_Config,       SIGNAL(triggered()), this, SLOT(slot_ac_Config()));
159 KeyOz 256
    connect(ac_Preferences,  SIGNAL(triggered()), this, SLOT(slot_ac_Preferences()));
158 KeyOz 257
    connect(ac_Motortest,    SIGNAL(triggered()), this, SLOT(slot_ac_Motortest()));
307 KeyOz 258
    connect(ac_MotorMixer,   SIGNAL(triggered()), this, SLOT(slot_ac_MotorMixer()));
227 KeyOz 259
    connect(ac_LCD,          SIGNAL(triggered()), this, SLOT(slot_ac_LCD()));
305 KeyOz 260
    connect(ac_Map,          SIGNAL(triggered()), this, SLOT(slot_ac_Map()));
199 KeyOz 261
    connect(ac_FastDebug,    SIGNAL(triggered()), this, SLOT(slot_ac_FastDebug()));
262
    connect(ac_NoDebug,      SIGNAL(triggered()), this, SLOT(slot_ac_NoDebug()));
263
    connect(ac_FastNavi,     SIGNAL(triggered()), this, SLOT(slot_ac_FastNavi()));
264
    connect(ac_NoNavi,       SIGNAL(triggered()), this, SLOT(slot_ac_NoNavi()));
158 KeyOz 265
    connect(ac_GetLabels,    SIGNAL(triggered()), this, SLOT(slot_ac_GetLabels()));
266
 
167 KeyOz 267
    // Plotter starten / scrollen
268
    connect(scroll_plot,     SIGNAL(valueChanged(int)), this, SLOT(slot_ScrollPlot(int)));
269
    connect(ac_StartPlotter, SIGNAL(triggered()), this, SLOT(slot_ac_StartPlotter()));
199 KeyOz 270
    connect(ac_StartServer,  SIGNAL(triggered()), this, SLOT(slot_ac_StartServer()));
167 KeyOz 271
 
158 KeyOz 272
    // Tabs ein & ausblenden
273
    connect(ac_View0,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
274
    connect(ac_View1,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
275
    connect(ac_View2,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
276
    connect(ac_View3,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
277
    connect(ac_View4,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
278
    connect(ac_View5,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
227 KeyOz 279
    connect(ac_View6,        SIGNAL(triggered()), this, SLOT(slot_ac_View()));
158 KeyOz 280
 
199 KeyOz 281
    connect(ac_SelNC,        SIGNAL(triggered()), this, SLOT(slot_ac_Hardware()));
282
    connect(ac_SelFC,        SIGNAL(triggered()), this, SLOT(slot_ac_Hardware()));
283
    connect(ac_SelMag,       SIGNAL(triggered()), this, SLOT(slot_ac_Hardware()));
284
 
285
    connect(rb_SelNC,        SIGNAL(clicked()), this, SLOT(slot_rb_Hardware()));
286
    connect(rb_SelFC,        SIGNAL(clicked()), this, SLOT(slot_rb_Hardware()));
287
    connect(rb_SelMag,       SIGNAL(clicked()), this, SLOT(slot_rb_Hardware()));
288
 
167 KeyOz 289
    // firmeware Updateen / flashen
199 KeyOz 290
    connect(pb_Update,   SIGNAL(clicked()), this, SLOT(slot_pb_Update()));
166 KeyOz 291
    connect(pb_HexFile,  SIGNAL(clicked()), this, SLOT(slot_pb_HexFile()));
158 KeyOz 292
 
250 KeyOz 293
    // Wegpunkt-Befehl
358 KeyOz 294
    connect(pb_FlyTo,        SIGNAL(clicked()), this, SLOT(slot_pb_SendTarget()));
250 KeyOz 295
 
167 KeyOz 296
    // CVS-Record starten / stoppen
239 Brean 297
    connect(ac_RecordCSV,  SIGNAL(triggered()), this, SLOT(slot_RecordLog()));
158 KeyOz 298
 
299
    // Timer-Events
300
    connect(Ticker,   SIGNAL(timeout()),       SLOT(slot_Ticker()));
301
 
167 KeyOz 302
    // Seitenwechsel
199 KeyOz 303
    connect(tab_Main,             SIGNAL(currentChanged(int)), this, SLOT(slot_TabChanged(int)));
306 KeyOz 304
//    connect(f_Settings->tab_Par,  SIGNAL(currentChanged(int)), this, SLOT(slot_TabChanged(int)));
305
    connect(f_Settings->listWidget,  SIGNAL(currentRowChanged(int)), this, SLOT(slot_TabChanged(int)));
158 KeyOz 306
 
167 KeyOz 307
    // About QMK & About-QT Dialog einfügen
308
    connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About()));
158 KeyOz 309
    menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt()));
310
}
311
 
312
void MKTool::init_Arrays()
313
{
314
    lb_Analog[0]  = lb_A_0;
315
    lb_Analog[1]  = lb_A_1;
316
    lb_Analog[2]  = lb_A_2;
317
    lb_Analog[3]  = lb_A_3;
318
    lb_Analog[4]  = lb_A_4;
319
    lb_Analog[5]  = lb_A_5;
320
    lb_Analog[6]  = lb_A_6;
321
    lb_Analog[7]  = lb_A_7;
322
    lb_Analog[8]  = lb_A_8;
323
    lb_Analog[9]  = lb_A_9;
324
    lb_Analog[10] = lb_A_10;
325
    lb_Analog[11] = lb_A_11;
326
    lb_Analog[12] = lb_A_12;
327
    lb_Analog[13] = lb_A_13;
328
    lb_Analog[14] = lb_A_14;
329
    lb_Analog[15] = lb_A_15;
330
    lb_Analog[16] = lb_A_16;
331
    lb_Analog[17] = lb_A_17;
332
    lb_Analog[18] = lb_A_18;
333
    lb_Analog[19] = lb_A_19;
334
    lb_Analog[20] = lb_A_20;
335
    lb_Analog[21] = lb_A_21;
336
    lb_Analog[22] = lb_A_22;
337
    lb_Analog[23] = lb_A_23;
338
    lb_Analog[24] = lb_A_24;
339
    lb_Analog[25] = lb_A_25;
340
    lb_Analog[26] = lb_A_26;
341
    lb_Analog[27] = lb_A_27;
342
    lb_Analog[28] = lb_A_28;
343
    lb_Analog[29] = lb_A_29;
344
    lb_Analog[30] = lb_A_30;
345
    lb_Analog[31] = lb_A_31;
346
}
347
 
348
void MKTool::init_Plot()
349
{
350
    NextPlot = 0;
351
 
352
    qwtPlot->setCanvasBackground(QColor(QRgb(0x00000000)));
353
 
354
    qwtPlot->insertLegend(new QwtLegend(), QwtPlot::RightLegend);
355
 
356
    QwtPlotGrid *Grid = new QwtPlotGrid();
357
    Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
358
 
359
    Grid->attach(qwtPlot);
360
 
166 KeyOz 361
    qwtPlot->setAxisScale(QwtPlot::xBottom,0,Settings->Data.Plotter_Count,0);
158 KeyOz 362
 
363
    for (int a = 0; a < MaxAnalog; a++)
364
    {
162 KeyOz 365
        Plot[a] = new QwtPlotCurve(Settings->Analog1.Label[a]);
366
        Plot[a]->setPen(QPen(QColor(Def_Colors[a])));
250 KeyOz 367
//        Plot[a]->setRenderHint(QwtPlotItem::RenderAntialiased);
158 KeyOz 368
 
162 KeyOz 369
        if (Settings->Analog1.PlotView[a])
158 KeyOz 370
            Plot[a]->attach(qwtPlot);
371
    }
372
    qwtPlot->replot();
373
}
374
 
306 KeyOz 375
void MKTool::slot_set_Settings(cSettings *t_Settings)
376
{
377
    Settings = t_Settings;
378
}
379
 
199 KeyOz 380
void MKTool::slot_Test()
158 KeyOz 381
{
272 KeyOz 382
    sRxData RX;
383
 
391 Brean 384
    RX.str = IN->text().toLatin1().data();
272 KeyOz 385
 
391 Brean 386
    RX.input = (char *)RX.str.c_str();
272 KeyOz 387
 
358 KeyOz 388
    slot_newData(RX);
250 KeyOz 389
}
158 KeyOz 390
 
272 KeyOz 391
// KML-Datei nach Wegpunkt parsen
392
// TODO: Richtigen KML-Parser bauen
250 KeyOz 393
void MKTool::parse_TargetKML()
394
{
395
    QString Tmp = te_KML->toPlainText().simplified();
396
    QStringList List;
158 KeyOz 397
 
250 KeyOz 398
    if ((Tmp.contains("<kml xmlns=\"http://earth.google.com/kml/2.2\">"))  && (Tmp.contains("<coordinates>")))
399
    {
400
        List = Tmp.split("<coordinates>");
401
        List = List[1].split(",");
402
 
314 KeyOz 403
        le_TarLong->setText(ToolBox::get_Float((List[0].toDouble() * 10000000), 7));
404
        le_TarLat->setText(ToolBox::get_Float((List[1].toDouble() * 10000000), 7));
250 KeyOz 405
    }
158 KeyOz 406
}
407
 
272 KeyOz 408
// Waypoint zur NC Senden.
358 KeyOz 409
void MKTool::slot_pb_SendTarget()
250 KeyOz 410
{
411
    if ((Navi.Current.Longitude == 0) && (Navi.Current.Latitude == 0))
412
    {
413
        QMessageBox msgB;
414
        QString msg;
358 KeyOz 415
        msgB.setText(tr("Fehler: Es konnten keine GPS-Daten vom Mikrokopter empfangen werden"));
250 KeyOz 416
        msgB.exec();
417
        return;
418
    }
272 KeyOz 419
 
250 KeyOz 420
    //erstelle einen Wegpunkt, den die NaviCtrl auswerten kann
421
    Waypoint_t desired_pos;
422
    bool ok_lat, ok_lon;
423
 
424
    //eingegebene Daten holen
425
    double desired_long, desired_lat;
426
 
427
    desired_long = le_TarLong->text().toDouble(&ok_lon);
428
    desired_lat  = le_TarLat->text().toDouble(&ok_lat);
429
 
430
    if (ok_lon && desired_long < 100)
431
        desired_long *= 10000000+0.5;
432
 
433
    if (ok_lat && desired_lat < 100)
434
        desired_lat *= 10000000+0.5;
435
 
436
    //fülle Wegpunkt-Daten
437
    desired_pos.Position.Altitude = 0;
438
    desired_pos.Position.Longitude = int32_t(desired_long);
439
    desired_pos.Position.Latitude =  int32_t(desired_lat);
440
    desired_pos.Position.Status = NEWDATA;
441
    desired_pos.Heading = -1;
334 KeyOz 442
    desired_pos.ToleranceRadius = 5;
358 KeyOz 443
    desired_pos.HoldTime = sb_TarTime->value();
250 KeyOz 444
    desired_pos.Event_Flag = 0;
445
    desired_pos.reserve[0] = 0; // reserve
446
    desired_pos.reserve[1] = 0; // reserve
447
    desired_pos.reserve[2] = 0; // reserve
448
    desired_pos.reserve[3] = 0; // reserve
449
 
450
    //...und sende ihn an die NaviCtrl
451
    int max_radius = 10000;
452
    if (ok_lat && ok_lon &&
391 Brean 453
        abs((double)(Navi.Current.Longitude - desired_pos.Position.Longitude)) < max_radius &&
454
        abs((double)(Navi.Current.Latitude  - desired_pos.Position.Latitude)) < max_radius)
250 KeyOz 455
    {
306 KeyOz 456
            o_Connection->send_Cmd('s', ADDRESS_NC, (char *)&desired_pos, sizeof(desired_pos), false);
250 KeyOz 457
    }
458
    else
459
    {
460
        QMessageBox msgB;
461
        QString msg;
358 KeyOz 462
        msg += tr("Bitte die Eingabe ueberpruefen!\n");
463
        msg += tr("Die Werte muessen sich in der Naehe der aktuellen Koordinaten befinden\n");
250 KeyOz 464
        msg += "(Lon: ";
314 KeyOz 465
        msg += ToolBox::get_Float(Navi.Current.Longitude,7);
250 KeyOz 466
        msg += ", ";
467
        msg += "Lat: ";
314 KeyOz 468
        msg += ToolBox::get_Float(Navi.Current.Latitude,7);
250 KeyOz 469
        msg += ")";
470
        msgB.setText(msg);
471
        msgB.exec();
472
    }
473
}
474
 
337 KeyOz 475
// Hardware-Auswahl im Menp
199 KeyOz 476
void MKTool::slot_ac_Hardware()
477
{
478
    QAction *Action = (QAction*)sender();
158 KeyOz 479
 
199 KeyOz 480
    if (Action->isChecked() == false)
481
    {
482
        Action->setChecked(true);
483
    }
484
 
485
    slot_rb_Hardware();
486
}
487
 
337 KeyOz 488
// Hardware Auswahl und umschalten
199 KeyOz 489
void MKTool::slot_rb_Hardware()
490
{
491
    if ((rb_SelNC->isChecked() == false) && (Mode.ID != ADDRESS_NC))
492
    {
493
        lb_Status->setText(tr("Schalte um auf NaviCtrl."));
494
        TX_Data[0] = 0x1B;
495
        TX_Data[1] = 0x1B;
496
        TX_Data[2] = 0x55;
497
        TX_Data[3] = 0xAA;
498
        TX_Data[4] = 0x00;
499
        TX_Data[5] = '\r';
306 KeyOz 500
        o_Connection->send_Cmd('#', ADDRESS_NC, TX_Data, 6, false);
391 Brean 501
        ToolBox::wait(SLEEP);
199 KeyOz 502
    }
503
 
504
    if (rb_SelFC->isChecked())
505
    {
506
        lb_Status->setText(tr("Schalte um auf FlightCtrl."));
507
        TX_Data[0] = 0;
306 KeyOz 508
        o_Connection->send_Cmd('u', ADDRESS_NC, TX_Data, 1, false);
199 KeyOz 509
    }
510
    else
511
    if (rb_SelMag->isChecked())
512
    {
513
        lb_Status->setText(tr("Schalte um auf MK3MAG."));
514
        TX_Data[0] = 1;
306 KeyOz 515
        o_Connection->send_Cmd('u', ADDRESS_NC, TX_Data, 1, false);
199 KeyOz 516
    }
517
    else
518
    if (rb_SelNC->isChecked())
519
    {
520
        lb_Status->setText(tr("Schalte um auf NaviCtrl."));
521
        TX_Data[0] = 0x1B;
522
        TX_Data[1] = 0x1B;
523
        TX_Data[2] = 0x55;
524
        TX_Data[3] = 0xAA;
525
        TX_Data[4] = 0x00;
526
        TX_Data[5] = '\r';
306 KeyOz 527
        o_Connection->send_Cmd('#', ADDRESS_NC, TX_Data, 6, false);
199 KeyOz 528
    }
391 Brean 529
    ToolBox::wait(SLEEP);
199 KeyOz 530
 
531
//    qDebug("Select RB Hardware");
306 KeyOz 532
    o_Connection->send_Cmd('v', ADDRESS_ALL, TX_Data, 0, true);
199 KeyOz 533
}
534
 
158 KeyOz 535
// Ticker-Event
536
///////////////
537
void MKTool::slot_Ticker()
538
{
539
    if (TickerDiv)
540
        TickerDiv = false;
541
    else
542
        TickerDiv = true;
337 KeyOz 543
/*
250 KeyOz 544
    if (cb_ClipBoard->isChecked())
545
    {
546
        QString s_OLD = te_KML->toPlainText();
547
        te_KML->clear();
548
        te_KML->paste();
549
        if (s_OLD != te_KML->toPlainText())
550
        {
551
            parse_TargetKML();
552
        }
553
    }
337 KeyOz 554
*/
158 KeyOz 555
    for (int a = 0; a < MaxTickerEvents; a++)
556
    {
557
        if (TickerEvent[a] == true)
558
        {
559
            switch(a)
560
            {
561
                case 0 :
562
                    {
563
                    }
564
                break;
565
                case 1 :
159 KeyOz 566
                    TX_Data[0] = 0;
306 KeyOz 567
                    o_Connection->send_Cmd('p', ADDRESS_FC, TX_Data, 0, false);
158 KeyOz 568
                break;
159 KeyOz 569
                case 2 :
227 KeyOz 570
                    if (f_LCD->cb_LCD->isChecked())
167 KeyOz 571
                    {
227 KeyOz 572
                        if (!f_LCD->isVisible())
573
                        {
574
                            Ticker->setInterval(2000);
575
                            TickerEvent[2] = false;
576
                        }
167 KeyOz 577
                        TX_Data[0] = LCD_Page;
578
                        TX_Data[1] = 0;
306 KeyOz 579
                        o_Connection->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true);
167 KeyOz 580
                    }
159 KeyOz 581
                break;
167 KeyOz 582
                case 3 :
199 KeyOz 583
                    if (ac_FastDebug->isChecked())
167 KeyOz 584
                    {
585
                        TX_Data[0] = Settings->Data.Debug_Fast / 10;
306 KeyOz 586
                        o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
167 KeyOz 587
                    }
588
                    else
589
                    {
590
                        TX_Data[0] = Settings->Data.Debug_Slow / 10;
306 KeyOz 591
                        o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
167 KeyOz 592
                    }
593
                break;
337 KeyOz 594
                case 4 :
595
                    {
596
                        for (int z = 0; z<12; z++)
597
                        {
598
                            TX_Data[z] = Motor.Speed[z];
599
                        }
600
                        o_Connection->send_Cmd('t', ADDRESS_FC, TX_Data, 12, false);
601
                    }
602
 
158 KeyOz 603
            }
604
        }
605
    }
606
}
607
 
337 KeyOz 608
// Zum QMK-Datenserver verbinden
227 KeyOz 609
void MKTool::slot_QMKS_Connect()
610
{
611
    if (ac_QMKServer->isChecked())
612
    {
613
        lb_Status->setText(tr("Verbinde zum QMK-Datenserver."));
158 KeyOz 614
 
272 KeyOz 615
        QMK_Server->Connect(Settings->Server.QMKS_Host, Settings->Server.QMKS_Port.toInt(), Settings->Server.QMKS_Login, Settings->Server.QMKS_Password);
227 KeyOz 616
 
272 KeyOz 617
        connect(QMK_Server, SIGNAL(sig_Connected()), this, SLOT(slot_QMKS_Connected()));
618
        connect(QMK_Server, SIGNAL(sig_Disconnected(int)), this, SLOT(slot_QMKS_Disconnected(int)));
227 KeyOz 619
    }
620
    else
621
    {
272 KeyOz 622
        if ((QMK_Server->property("Connect")) == true)
227 KeyOz 623
        {
272 KeyOz 624
            disconnect(QMK_Server, SIGNAL(sig_Disconnected(int)), 0, 0);
227 KeyOz 625
            lb_Status->setText(tr("Trenne vom QMK-Datenserver."));
626
 
272 KeyOz 627
            QMK_Server->Disconnect();
628
            QMK_Server->setProperty("Connect", false);
358 KeyOz 629
            ac_QMKServer->setText(tr("QMK-Server Verbinden"));
227 KeyOz 630
        }
631
    }
632
}
633
 
337 KeyOz 634
// Verbindung zum QMK-Server hergestellt.
227 KeyOz 635
void MKTool::slot_QMKS_Connected()
636
{
272 KeyOz 637
    QMK_Server->setProperty("Connect", true);
358 KeyOz 638
    ac_QMKServer->setText(tr("QMK-Server Trennnen"));
227 KeyOz 639
    lb_Status->setText(tr("Verbunden mit QMK-Datenserver."));
640
}
641
 
337 KeyOz 642
// QMK-Serververbindung getrennt
227 KeyOz 643
void MKTool::slot_QMKS_Disconnected(int Error)
644
{
272 KeyOz 645
    QMK_Server->setProperty("Connect", false);
358 KeyOz 646
    ac_QMKServer->setText(tr("QMK-Server Verbinden"));
227 KeyOz 647
    ac_QMKServer->setChecked(false);
648
 
272 KeyOz 649
    disconnect(QMK_Server, SIGNAL(sig_Disconnected(int)), 0, 0);
227 KeyOz 650
 
651
    switch (Error)
652
    {
653
        case 1 :
654
        {
655
            lb_Status->setText(tr("Verbindung vom Server beendet."));
358 KeyOz 656
            QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Verbindung wurde vom Server beendet."), QMessageBox::Ok);
227 KeyOz 657
        }
658
        break;
659
        case 2 :
660
        {
661
            lb_Status->setText(tr("Server nicht gefunden."));
358 KeyOz 662
            QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Kann nicht zum Server verbinden."), QMessageBox::Ok);
227 KeyOz 663
        }
664
        break;
665
        case 3 :
666
        {
667
            lb_Status->setText(tr("Serververbindung getrennt. Logindaten falsch."));
358 KeyOz 668
            QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Loginname oder Password falsch."), QMessageBox::Ok);
227 KeyOz 669
        }
670
        break;
671
        default :
672
        {
673
            lb_Status->setText(tr("Getrennt vom QMK-Datenserver."));
674
        }
675
        break;
676
    }
677
}
678
 
158 KeyOz 679
// Slots der Actions (Menüpunkte, Buttons)
680
//////////////////////////////////////////
681
void MKTool::slot_ac_Motortest()
682
{
683
    dlg_Motortest *f_Motortest = new dlg_Motortest(this);
684
 
337 KeyOz 685
//    connect(f_Motortest, SIGNAL(updateMotor(int, int, int, int)), this, SLOT(slot_Motortest(int, int, int, int)));
686
    connect(f_Motortest, SIGNAL(updateMotor(sMotor)), this, SLOT(slot_Motortest(sMotor)));
158 KeyOz 687
 
337 KeyOz 688
 
689
    Ticker->setInterval(500);
690
    TickerEvent[4] = true;
691
 
158 KeyOz 692
    if (f_Motortest->exec()==QDialog::Accepted)
693
    {
694
    }
695
 
696
    disconnect(f_Motortest, 0,0,0);
337 KeyOz 697
 
698
    for (int z = 0; z<12; z++)
699
    {
700
        Motor.Speed[z] = 0;
701
    }
702
 
703
    slot_Motortest(Motor);
704
 
705
    Ticker->setInterval(2000);
706
    TickerEvent[4] = false;
158 KeyOz 707
}
708
 
337 KeyOz 709
void MKTool::slot_Motortest(sMotor p_Motor)
710
{
711
    Motor = p_Motor;
712
 
713
    for (int z = 0; z<12; z++)
714
    {
715
        TX_Data[z] = Motor.Speed[z];
716
    }
717
    o_Connection->send_Cmd('t', ADDRESS_FC, TX_Data, 12, false);
718
}
719
 
720
// Motormixer-Einstellungen anzeigen
307 KeyOz 721
void MKTool::slot_ac_MotorMixer()
722
{
723
    f_MotorMixer->set_Objects(o_Connection, Settings);
724
    f_MotorMixer->read_Mixer();
725
 
726
    if (f_MotorMixer->exec()==QDialog::Accepted)
727
    {
728
    }
729
}
730
 
337 KeyOz 731
// LCD Anzeigen
227 KeyOz 732
void MKTool::slot_ac_LCD()
733
{
734
    if (!f_LCD->isVisible())
735
    {
306 KeyOz 736
        delete f_LCD;
227 KeyOz 737
        f_LCD = new dlg_LCD(this);
738
 
739
        // LCD auf / ab
740
        connect(f_LCD->pb_LCDup,   SIGNAL(clicked()), this, SLOT(slot_LCD_UP()));
741
        connect(f_LCD->pb_LCDdown, SIGNAL(clicked()), this, SLOT(slot_LCD_DOWN()));
742
 
743
        f_LCD->show();
744
        TX_Data[0] = 0;
745
        TX_Data[1] = 0;
306 KeyOz 746
        o_Connection->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true);
227 KeyOz 747
 
748
        Ticker->setInterval(500);
749
        TickerEvent[2] = true;
750
    }
751
}
752
 
337 KeyOz 753
// Map-Fenster anzeigen
305 KeyOz 754
void MKTool::slot_ac_Map()
755
{
756
    if (!f_Map->isVisible())
757
    {
758
        f_Map->show();
759
    }
760
}
761
 
358 KeyOz 762
void MKTool::slot_MAP_SetWayPoints(QList<sWayPoint> l_WayPoints)
763
{
764
    Waypoint_t WayPoint;
765
    double Longitude, Latitude;
766
 
767
    // Waypoint-Liste löschen
768
    WayPoint.Position.Status = INVALID;
769
    o_Connection->send_Cmd('w', ADDRESS_NC, (char *)&WayPoint, sizeof(WayPoint), false);
391 Brean 770
    ToolBox::wait(SLEEP);
358 KeyOz 771
 
772
    for (int z = 0; z < l_WayPoints.count(); z++)
773
    {
774
        Longitude = l_WayPoints[z].Longitude;
775
        Latitude  = l_WayPoints[z].Latitude;
776
 
777
        if (Longitude < 100)
778
            Longitude *= 10000000+0.5;
779
 
780
        if (Latitude < 100)
781
            Latitude *= 10000000+0.5;
782
 
783
        //fülle Wegpunkt-Daten
784
        WayPoint.Position.Altitude = 0;
785
        WayPoint.Position.Longitude = int32_t(Longitude);
786
        WayPoint.Position.Latitude =  int32_t(Latitude);
787
        WayPoint.Position.Status = NEWDATA;
788
        WayPoint.Heading = -1;
789
        WayPoint.ToleranceRadius = 5;
790
        WayPoint.HoldTime = l_WayPoints[z].Time;
791
        WayPoint.Event_Flag = 0;
792
        WayPoint.reserve[0] = 0; // reserve
793
        WayPoint.reserve[1] = 0; // reserve
794
        WayPoint.reserve[2] = 0; // reserve
795
        WayPoint.reserve[3] = 0; // reserve
796
 
797
        o_Connection->send_Cmd('w', ADDRESS_NC, (char *)&WayPoint, sizeof(WayPoint), false);
798
//        ToolBox::Wait(SLEEP);
799
    }
800
 
801
}
802
 
306 KeyOz 803
void MKTool::slot_MAP_SetTarget(sWayPoint Target)
804
{
315 KeyOz 805
 
806
    QString s_Lon, s_Lat;
807
    QTextStream t_Lon(&s_Lon);
808
    QTextStream t_Lat(&s_Lat);
809
 
810
    t_Lon.setRealNumberPrecision(9);
811
    t_Lat.setRealNumberPrecision(9);
812
    t_Lon << Target.Longitude;
813
    t_Lat << Target.Latitude;
814
 
815
    le_TarLong->setText(s_Lon);
816
    le_TarLat->setText(s_Lat);
306 KeyOz 817
    sb_TarTime->setValue(Target.Time);
305 KeyOz 818
 
358 KeyOz 819
    slot_pb_SendTarget();
306 KeyOz 820
}
821
 
158 KeyOz 822
void MKTool::slot_ac_Config()
823
{
162 KeyOz 824
    set_Analog Old_Analog1;
158 KeyOz 825
 
162 KeyOz 826
    Old_Analog1 = Settings->Analog1;
827
 
158 KeyOz 828
    dlg_Config *f_Config = new dlg_Config(this);
162 KeyOz 829
    f_Config->set_Settings(Settings, Mode.ID);
158 KeyOz 830
 
831
    if (f_Config->exec()==QDialog::Accepted)
832
    {
833
        Settings = f_Config->get_Settings();
162 KeyOz 834
        Settings->write_Settings_Analog(Mode.ID);
158 KeyOz 835
 
163 KeyOz 836
        // Plotter neu einrichten
837
        if (Old_Analog1.PlotView != Settings->Analog1.PlotView)
158 KeyOz 838
        {
163 KeyOz 839
            config_Plot();
158 KeyOz 840
        }
841
 
163 KeyOz 842
        // CVS-Datei neu anlegen.
241 KeyOz 843
        if ((logger->is_active()) && (Old_Analog1.LogView != Settings->Analog1.LogView))
158 KeyOz 844
        {
239 Brean 845
            logger->close();
240 Brean 846
            logger->start_Log();
158 KeyOz 847
        }
848
 
849
    }
850
}
851
 
239 Brean 852
//aktualisiere Logging-Status
241 KeyOz 853
void MKTool::update_Log()
854
{
239 Brean 855
    if (logger->is_active())
856
    {
272 KeyOz 857
 
358 KeyOz 858
        ac_RecordCSV->setText(tr("Log Stop"));
239 Brean 859
        lb_Status->setText(tr("Log-Record gestartet."));
860
    }
861
    else
862
    {
358 KeyOz 863
        ac_RecordCSV->setText(tr("Log Aufzeichnen"));
239 Brean 864
        lb_Status->setText(tr("Log-Record gestopt."));
865
    }
866
}
867
 
868
//starte/stoppe Logging, wenn auf den entsprechenden Button gedrückt wurde
869
void MKTool::slot_RecordLog()
870
{
871
    if (!logger->is_active())
872
        logger->start_Log();
873
    else
874
        logger->close();
241 KeyOz 875
 
239 Brean 876
    update_Log();
877
}
878
 
159 KeyOz 879
void MKTool::slot_ac_Preferences()
880
{
881
    dlg_Preferences *f_Preferences = new dlg_Preferences(this);
882
 
166 KeyOz 883
    Settings->TTY.Port = le_Port->text();
163 KeyOz 884
    f_Preferences->set_Settings(Settings);
885
 
159 KeyOz 886
    if (f_Preferences->exec()==QDialog::Accepted)
887
    {
163 KeyOz 888
        Settings = f_Preferences->get_Settings();
889
        Settings->write_Settings();
166 KeyOz 890
        le_Port->setText(Settings->TTY.Port);
891
        config_Plot();
159 KeyOz 892
    }
893
}
894
 
158 KeyOz 895
void MKTool::slot_ac_StartPlotter()
896
{
897
    if (ac_StartPlotter->isChecked())
898
    {
199 KeyOz 899
        lb_Status->setText(tr("Datenplotter gestartet."));
358 KeyOz 900
        ac_StartPlotter->setText(tr("Stop Plotter"));
901
        pb_StartPlotter->setText(tr("Stop Plotter"));
158 KeyOz 902
    }
903
    else
904
    {
199 KeyOz 905
        lb_Status->setText(tr("Datenplotter gestopt."));
358 KeyOz 906
        ac_StartPlotter->setText(tr("Start Plotter"));
907
        pb_StartPlotter->setText(tr("Start Plotter"));
158 KeyOz 908
    }
909
}
910
 
911
void MKTool::slot_ac_View()
912
{
227 KeyOz 913
    int Aktive = -1;
158 KeyOz 914
 
915
    QAction *Action = (QAction*)sender();
916
 
917
    if (Action->objectName() == QString("ac_View0"))
918
        Aktive = 0;
919
    if (Action->objectName() == QString("ac_View1"))
920
        Aktive = 1;
921
    if (Action->objectName() == QString("ac_View2"))
922
        Aktive = 2;
923
    if (Action->objectName() == QString("ac_View3"))
924
        Aktive = 3;
925
    if (Action->objectName() == QString("ac_View4"))
926
        Aktive = 4;
927
    if (Action->objectName() == QString("ac_View5"))
928
        Aktive = 5;
272 KeyOz 929
    if (Action->objectName() == QString("ac_View6"))
930
        Aktive = 6;
158 KeyOz 931
 
932
    QString TabName = QString("Tab_%1").arg(Aktive);
933
 
934
    if (!Action->isChecked())
935
    {
936
        for (int a = 0; a < tab_Main->count(); a++)
937
        {
938
            if (tab_Main->widget(a)->objectName() == TabName)
939
            {
940
                tab_Main->removeTab(a);
941
            }
942
        }
943
    }
944
    else
945
    {
227 KeyOz 946
        tab_Main->insertTab(Aktive, TabWidgets[Aktive], Action->icon(), Action->text());
158 KeyOz 947
    }
948
}
949
 
199 KeyOz 950
void MKTool::slot_ac_FastNavi() // DONE NC 0.12i
158 KeyOz 951
{
199 KeyOz 952
    if (!ac_NoNavi->isChecked())
158 KeyOz 953
    {
199 KeyOz 954
        if (ac_FastNavi->isChecked())
166 KeyOz 955
        {
199 KeyOz 956
            lb_Status->setText(tr("Fordere schnelle NaviDaten an."));
957
            TX_Data[0] = Settings->Data.Navi_Fast / 10;
958
        }
959
        else
960
        {
961
            lb_Status->setText(tr("Fordere langsame NaviDaten an."));
962
            TX_Data[0] = Settings->Data.Navi_Slow / 10;
963
        }
306 KeyOz 964
        o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false);
199 KeyOz 965
    }
966
}
967
 
968
void MKTool::slot_ac_NoNavi() // DONE NC 0.12i
969
{
970
    if (ac_NoNavi->isChecked())
971
    {
972
        lb_Status->setText(tr("NaviDaten abstellen."));
973
        TX_Data[0] = 0;
974
    }
975
    else
976
    {
977
        if (ac_FastNavi->isChecked())
978
        {
979
            lb_Status->setText(tr("Fordere schnelle NaviDaten an."));
980
            TX_Data[0] = Settings->Data.Navi_Fast / 10;
981
        }
982
        else
983
        {
984
            lb_Status->setText(tr("Fordere langsame NaviDaten an."));
985
            TX_Data[0] = Settings->Data.Navi_Slow / 10;
986
        }
987
    }
306 KeyOz 988
    o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false);
199 KeyOz 989
}
990
 
991
void MKTool::slot_ac_FastDebug() // DONE 0.71g
992
{
993
    if (!ac_NoDebug->isChecked())
994
    {
995
        if (ac_FastDebug->isChecked())
996
        {
997
            lb_Status->setText(tr("Fordere schnelle DebugDaten an."));
166 KeyOz 998
            TX_Data[0] = Settings->Data.Debug_Fast / 10;
999
        }
1000
        else
1001
        {
199 KeyOz 1002
            lb_Status->setText(tr("Fordere langsame DebugDaten an."));
166 KeyOz 1003
            TX_Data[0] = Settings->Data.Debug_Slow / 10;
1004
        }
306 KeyOz 1005
        o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
166 KeyOz 1006
    }
1007
}
1008
 
199 KeyOz 1009
void MKTool::slot_ac_NoDebug() // DONE 0.71g
166 KeyOz 1010
{
199 KeyOz 1011
    if (ac_NoDebug->isChecked())
166 KeyOz 1012
    {
199 KeyOz 1013
        lb_Status->setText(tr("DebugDaten abstellen."));
167 KeyOz 1014
        TickerEvent[3] = false;
166 KeyOz 1015
        TX_Data[0] = 0;
1016
    }
158 KeyOz 1017
    else
1018
    {
167 KeyOz 1019
        // Wenn MK3MAG dann andauernd Daten neu anfragen.
1020
        if (Mode.ID == ADDRESS_MK3MAG)
1021
            TickerEvent[3] = true;
1022
 
199 KeyOz 1023
        if (ac_FastDebug->isChecked())
166 KeyOz 1024
        {
199 KeyOz 1025
            lb_Status->setText(tr("Fordere schnelle DebugDaten an."));
166 KeyOz 1026
            TX_Data[0] = Settings->Data.Debug_Fast / 10;
1027
        }
1028
        else
1029
        {
199 KeyOz 1030
            lb_Status->setText(tr("Fordere langsame DebugDaten an."));
166 KeyOz 1031
            TX_Data[0] = Settings->Data.Debug_Slow / 10;
1032
        }
1033
    }
306 KeyOz 1034
    o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
158 KeyOz 1035
}
1036
 
1037
void MKTool::slot_ac_About()
1038
{
1039
    QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT);
1040
}
1041
 
159 KeyOz 1042
void MKTool::slot_ac_GetLabels() // DONE 0.71g
158 KeyOz 1043
{
199 KeyOz 1044
    lb_Status->setText(tr("Analoglabels auslesen."));
158 KeyOz 1045
    TX_Data[0] = 0;
306 KeyOz 1046
    o_Connection->send_Cmd('a', ADDRESS_ALL, TX_Data, 1, true);
158 KeyOz 1047
}
1048
 
199 KeyOz 1049
void MKTool::slot_ac_StartServer()
1050
{
1051
    if (ac_StartServer->isChecked())
1052
    {
306 KeyOz 1053
        lb_Status->setText(tr("KML-Server gestartet."));
1054
        KML_Server->start_Server(Settings->Server.Port.toInt(), Settings);
199 KeyOz 1055
    }
1056
    else
1057
    {
306 KeyOz 1058
        lb_Status->setText(tr("KML-Server gestopt."));
1059
        KML_Server->stop_Server();
199 KeyOz 1060
    }
1061
}
159 KeyOz 1062
 
227 KeyOz 1063
 
158 KeyOz 1064
//  Daten-Plotter
1065
/////////////////
1066
void MKTool::update_Plot()
1067
{
1068
    for (int a = 0; a < MaxAnalog; a++)
1069
    {
1070
        Plot[a]->setData(aID,aData[a],NextPlot - 1);
1071
    }
1072
 
166 KeyOz 1073
    if ((NextPlot > Settings->Data.Plotter_Count))
158 KeyOz 1074
    {
166 KeyOz 1075
        scroll_plot->setMaximum(NextPlot - Settings->Data.Plotter_Count);
158 KeyOz 1076
    }
1077
 
166 KeyOz 1078
    if ((scroll_plot->value() == NextPlot - (Settings->Data.Plotter_Count + 1)))
158 KeyOz 1079
    {
166 KeyOz 1080
        qwtPlot->setAxisScale(QwtPlot::xBottom,NextPlot - Settings->Data.Plotter_Count,NextPlot,0);
1081
        scroll_plot->setValue(NextPlot - Settings->Data.Plotter_Count);
158 KeyOz 1082
    }
1083
 
1084
    qwtPlot->replot();
1085
}
1086
 
1087
void MKTool::config_Plot()
1088
{
166 KeyOz 1089
//    qDebug("Plotter rekonfiguriert..!!");
1090
    qwtPlot->setAxisScale(QwtPlot::xBottom,0,Settings->Data.Plotter_Count,0);
1091
 
158 KeyOz 1092
    for (int a = 0; a < MaxAnalog; a++)
1093
    {
1094
        Plot[a]->detach();
162 KeyOz 1095
        Plot[a]->setPen(QPen(QColor(Def_Colors[a])));
158 KeyOz 1096
 
162 KeyOz 1097
        if (Settings->Analog1.PlotView[a])
1098
        {
1099
            Plot[a]->setTitle(Settings->Analog1.Label[a]);
158 KeyOz 1100
            Plot[a]->attach(qwtPlot);
162 KeyOz 1101
        }
158 KeyOz 1102
    }
166 KeyOz 1103
    qwtPlot->replot();
158 KeyOz 1104
}
1105
 
1106
void MKTool::slot_ScrollPlot(int Pos)
1107
{
166 KeyOz 1108
    qwtPlot->setAxisScale(QwtPlot::xBottom,Pos,Pos + Settings->Data.Plotter_Count,0);
158 KeyOz 1109
    qwtPlot->replot();
1110
}
1111
 
1112
 
1113
// Firmeware-Update
1114
///////////////////
1115
void MKTool::slot_pb_Update()
1116
{
167 KeyOz 1117
    QString Device;
1118
    QString Hardware;
158 KeyOz 1119
 
167 KeyOz 1120
    if (rb_FC->isChecked())
1121
    {
1122
        Device   = "m644";
1123
        Hardware = "FlightCtrl";
1124
    }
1125
    else if (rb_MK3MAG->isChecked())
1126
    {
1127
        Device   = "m168";
1128
        Hardware = "MK3MAG";
1129
    }
1130
    else if (rb_BL->isChecked())
1131
    {
1132
        Device   = "m8";
1133
        Hardware = "BL-Ctrl";
1134
    }
166 KeyOz 1135
 
358 KeyOz 1136
    QString Message = trUtf8("Firmeware-Datei \n\n");
166 KeyOz 1137
    Message = Message + le_HexFile->text() + "\n\n";
358 KeyOz 1138
    Message = Message + trUtf8("an ") + Hardware + trUtf8(" mit AVRDUDE - Seriel & Bootloader über ") + le_Port->text() + trUtf8(" übertragen?\n");
166 KeyOz 1139
 
1140
    if (le_HexFile->text() == "")
162 KeyOz 1141
    {
166 KeyOz 1142
        QMessageBox::warning(this, QA_NAME, trUtf8("Bitte Firmeware-Datei wählen."), QMessageBox::Ok);
162 KeyOz 1143
    }
166 KeyOz 1144
    else if (QMessageBox::warning(this, QA_NAME, Message, QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
1145
    {
306 KeyOz 1146
        QString Programm = Settings->DIR.AVRDUDE;
162 KeyOz 1147
 
166 KeyOz 1148
        QStringList Argumente;
162 KeyOz 1149
 
166 KeyOz 1150
        Update = new QProcess();
162 KeyOz 1151
 
306 KeyOz 1152
        if (o_Connection->isOpen())
166 KeyOz 1153
        {
1154
            slot_OpenPort();
1155
        }
1156
 
1157
        Argumente << "-P";
1158
        Argumente << le_Port->text();
1159
        Argumente << "-p";
1160
        Argumente << Device;
1161
        Argumente << "-c";
1162
        Argumente << "butterfly";
1163
        Argumente << "-b";
1164
        Argumente << "57600";
1165
        Argumente << "-U";
1166
        Argumente << "flash:w:" + le_HexFile->text();
1167
 
1168
//    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";
1169
 
1170
        te_Shell->setText(""); // Ausgabefenster säubern
1171
 
1172
        connect(Update, SIGNAL(readyReadStandardOutput()), this, SLOT(slot_UpdateShell()) );
1173
        connect(Update, SIGNAL(readyReadStandardError()), this, SLOT(slot_UpdateShell()) );
1174
 
1175
        Update->start(Programm, Argumente); // Programmaufruf
1176
    }
158 KeyOz 1177
}
1178
 
1179
void MKTool::slot_UpdateShell()
1180
{
162 KeyOz 1181
    QByteArray Output;
158 KeyOz 1182
 
166 KeyOz 1183
    Output = Update->readAllStandardError(); // Shellausgabe an Variable
162 KeyOz 1184
    te_Shell->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1185
    te_Shell->insertPlainText(QString::fromUtf8(Output));
158 KeyOz 1186
 
166 KeyOz 1187
    Output = Update->readAll();
1188
    te_Shell->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1189
    te_Shell->insertPlainText(QString::fromUtf8(Output));
158 KeyOz 1190
}
1191
 
166 KeyOz 1192
void MKTool::slot_pb_HexFile()
1193
{
1194
    QString FileName = QFileDialog::getOpenFileName(this,trUtf8(("Firmeware-Datei wählen")),"",
1195
                                tr("Intel Hex(*.hex);;Alle Dateien (*)"));
1196
    if (!FileName.isEmpty())
1197
    {
1198
        le_HexFile->setText(FileName);
1199
    }
1200
}
158 KeyOz 1201
 
1202
 
167 KeyOz 1203
// Wechsel der Tabs erkennen
159 KeyOz 1204
void MKTool::slot_TabChanged(int Tab) // DONE 0.71g
158 KeyOz 1205
{
1206
    Tab = Tab;
162 KeyOz 1207
    if (tab_Main->count() != 0)
158 KeyOz 1208
    {
306 KeyOz 1209
        if ((tab_Main->currentWidget()->objectName() == QString("Tab_2")) && (f_Settings->listWidget->currentRow() == 1))
162 KeyOz 1210
        {
1211
            TX_Data[0] = 0;
313 KeyOz 1212
            o_Connection->send_Cmd('p', ADDRESS_FC, TX_Data, 0, false);
159 KeyOz 1213
 
162 KeyOz 1214
            Ticker->setInterval(500);
1215
            TickerEvent[1] = true;
1216
        }
1217
        else
1218
        {
1219
            Ticker->setInterval(2000);
1220
            TickerEvent[1] = false;
1221
        }
159 KeyOz 1222
    }
158 KeyOz 1223
}
1224
 
167 KeyOz 1225
// LCD-Seiten weiterschalten
159 KeyOz 1226
void MKTool::slot_LCD_UP() // DONE 0.71g
158 KeyOz 1227
{
159 KeyOz 1228
    if (LCD_Page == LCD_MAX_Page)
1229
        TX_Data[0] = 0;
1230
    else
1231
        TX_Data[0] = LCD_Page + 1;
1232
 
1233
    TX_Data[1] = 0;
306 KeyOz 1234
    o_Connection->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true);
159 KeyOz 1235
}
1236
 
1237
void MKTool::slot_LCD_DOWN() // DONE 0.71g
1238
{
1239
    if (LCD_Page == 0)
1240
        TX_Data[0] = LCD_MAX_Page;
1241
    else
1242
        TX_Data[0] = LCD_Page - 1;
1243
 
1244
    TX_Data[1] = 0;
306 KeyOz 1245
    o_Connection->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true);
159 KeyOz 1246
}
1247
 
167 KeyOz 1248
// Settings aus MK lesen / in MK schreiben
199 KeyOz 1249
void MKTool::slot_GetFCSettings() // DONE 0.71g
159 KeyOz 1250
{
199 KeyOz 1251
    lb_Status->setText(tr("Lese FlightCtrl-Settings aus."));
167 KeyOz 1252
    TX_Data[0] = f_Settings->sb_Set->value();
158 KeyOz 1253
    TX_Data[1] = 0;
313 KeyOz 1254
    o_Connection->send_Cmd('q', ADDRESS_FC, TX_Data, 1, true);
158 KeyOz 1255
}
1256
 
199 KeyOz 1257
void MKTool::slot_SetFCSettings() // DONE 0.71g
158 KeyOz 1258
{
199 KeyOz 1259
    char *TX_Data2 = f_Settings->GetFCSettings();
158 KeyOz 1260
 
199 KeyOz 1261
    lb_Status->setText(tr("Schreibe FlightCtrl-Settings."));
167 KeyOz 1262
 
313 KeyOz 1263
    o_Connection->send_Cmd('s', ADDRESS_FC, TX_Data2, MaxParameter + 2, true);
158 KeyOz 1264
}
1265
 
159 KeyOz 1266
 
167 KeyOz 1267
// Save GUI-Preferences
1268
///////////////////////
1269
void MKTool::set_Preferences()
158 KeyOz 1270
{
163 KeyOz 1271
    Settings->GUI.TabViews.setBit(0, ac_View0->isChecked());
1272
    Settings->GUI.TabViews.setBit(1, ac_View1->isChecked());
1273
    Settings->GUI.TabViews.setBit(2, ac_View2->isChecked());
1274
    Settings->GUI.TabViews.setBit(3, ac_View3->isChecked());
1275
    Settings->GUI.TabViews.setBit(4, ac_View4->isChecked());
1276
    Settings->GUI.TabViews.setBit(5, ac_View5->isChecked());
227 KeyOz 1277
    Settings->GUI.TabViews.setBit(6, ac_View6->isChecked());
158 KeyOz 1278
 
227 KeyOz 1279
    Settings->GUI.ToolViews.setBit(0, tb_Allgemein->isVisibleTo(this));
1280
    Settings->GUI.ToolViews.setBit(1, tb_Werkzeuge->isVisibleTo(this));
1281
    Settings->GUI.ToolViews.setBit(2, tb_Debug->isVisibleTo(this));
1282
    Settings->GUI.ToolViews.setBit(3, tb_TTY->isVisibleTo(this));
1283
    Settings->GUI.ToolViews.setBit(4, tb_Hardware->isVisibleTo(this));
1284
 
162 KeyOz 1285
    Settings->GUI.Term_Info   = cb_ShowMSG->isChecked();
1286
    Settings->GUI.Term_Data   = cb_ShowData->isChecked();
1287
    Settings->GUI.Term_Always = cb_ShowAlways->isChecked();
166 KeyOz 1288
    Settings->GUI.Term_Send   = cb_ShowSend->isChecked();
167 KeyOz 1289
    Settings->GUI.isMax       = isMaximized();
1290
    Settings->GUI.Size        = size();
1291
    Settings->GUI.Point       = pos();
162 KeyOz 1292
 
163 KeyOz 1293
    Settings->TTY.Port = le_Port->text();
158 KeyOz 1294
}
1295
 
1296
void MKTool::show_DebugData()
1297
{
241 KeyOz 1298
    if (logger->is_active())
1299
        logger->write(AnalogData);
158 KeyOz 1300
 
1301
    if (ac_StartPlotter->isChecked())
1302
    {
1303
        aID[NextPlot] = NextPlot;
1304
 
1305
        for (int a = 0; a < MaxAnalog; a++)
1306
        {
1307
            aData[a][NextPlot] = AnalogData[a];
1308
        }
1309
        NextPlot++;
1310
 
1311
        if ((tab_Main->currentWidget()->objectName() == QString("Tab_1")))
1312
            update_Plot();
1313
    }
1314
 
1315
    le_A_0->setText(QString("%1").arg(AnalogData[0]));
1316
    le_A_1->setText(QString("%1").arg(AnalogData[1]));
1317
    le_A_2->setText(QString("%1").arg(AnalogData[2]));
1318
    le_A_3->setText(QString("%1").arg(AnalogData[3]));
1319
    le_A_4->setText(QString("%1").arg(AnalogData[4]));
1320
    le_A_5->setText(QString("%1").arg(AnalogData[5]));
1321
    le_A_6->setText(QString("%1").arg(AnalogData[6]));
1322
    le_A_7->setText(QString("%1").arg(AnalogData[7]));
1323
    le_A_8->setText(QString("%1").arg(AnalogData[8]));
1324
    le_A_9->setText(QString("%1").arg(AnalogData[9]));
1325
    le_A_10->setText(QString("%1").arg(AnalogData[10]));
1326
    le_A_11->setText(QString("%1").arg(AnalogData[11]));
1327
    le_A_12->setText(QString("%1").arg(AnalogData[12]));
1328
    le_A_13->setText(QString("%1").arg(AnalogData[13]));
1329
    le_A_14->setText(QString("%1").arg(AnalogData[14]));
1330
    le_A_15->setText(QString("%1").arg(AnalogData[15]));
1331
    le_A_16->setText(QString("%1").arg(AnalogData[16]));
1332
    le_A_17->setText(QString("%1").arg(AnalogData[17]));
1333
    le_A_18->setText(QString("%1").arg(AnalogData[18]));
1334
    le_A_19->setText(QString("%1").arg(AnalogData[19]));
1335
    le_A_20->setText(QString("%1").arg(AnalogData[20]));
1336
    le_A_21->setText(QString("%1").arg(AnalogData[21]));
1337
    le_A_22->setText(QString("%1").arg(AnalogData[22]));
1338
    le_A_23->setText(QString("%1").arg(AnalogData[23]));
1339
    le_A_24->setText(QString("%1").arg(AnalogData[24]));
1340
    le_A_25->setText(QString("%1").arg(AnalogData[25]));
1341
    le_A_26->setText(QString("%1").arg(AnalogData[26]));
1342
    le_A_27->setText(QString("%1").arg(AnalogData[27]));
1343
    le_A_28->setText(QString("%1").arg(AnalogData[28]));
1344
    le_A_29->setText(QString("%1").arg(AnalogData[29]));
1345
    le_A_30->setText(QString("%1").arg(AnalogData[30]));
1346
    le_A_31->setText(QString("%1").arg(AnalogData[31]));
227 KeyOz 1347
 
1348
    if ((Mode.ID == ADDRESS_FC) && (FCSettings[P_GYRO_ACC_FAKTOR] > 0))
1349
    {
1350
        bar_UBAT->setValue(AnalogData[9]);
1351
        bar_RX->setValue(AnalogData[10]);
1352
 
1353
        Compass->setValue(AnalogData[8]);
1354
 
1355
        int Roll = (AnalogData[1] * FCSettings[P_GYRO_ACC_FAKTOR]) / 1024;
1356
        int Nick = (AnalogData[0] * FCSettings[P_GYRO_ACC_FAKTOR]) / 1024;
1357
 
1358
        if (Roll > 128)
1359
            Roll = Roll - 255;
1360
 
1361
        if (Nick > 128)
1362
            Nick = Nick - 255;
1363
 
1364
        Attitude->setAngle(Roll);
1365
        Attitude->setGradient(double(double(Nick) / 100.0));
1366
    }
158 KeyOz 1367
}
1368
 
199 KeyOz 1369
void MKTool::new_NaviData(sRxData RX)
1370
{
306 KeyOz 1371
//    qDebug("Navi-Data");
1372
 
391 Brean 1373
    switch(RX.decode[N_NC_FLAGS])
306 KeyOz 1374
    {
358 KeyOz 1375
        case 0x01 : lb_Mode->setText(tr("Free")); break;
1376
        case 0x02 : lb_Mode->setText(tr("Position Hold")); break;
1377
        case 0x04 : lb_Mode->setText(tr("Coming Home")); break;
1378
        case 0x08 : lb_Mode->setText(tr("Range Limit")); break;
1379
        case 0x10 : lb_Mode->setText(tr("Serial Error")); break;
1380
        case 0x20 : lb_Mode->setText(tr("Target reached")); break;
1381
        case 0x40 : lb_Mode->setText(tr("Manual Control")); break;
306 KeyOz 1382
    }
1383
 
391 Brean 1384
    Navi.Current.Longitude = Parser::dataToLong(RX.decode, N_CUR_LONGITUDE, true);
1385
    Navi.Current.Latitude  = Parser::dataToLong(RX.decode, N_CUR_LATITUDE,  true);
1386
    Navi.Current.Altitude  = Parser::dataToLong(RX.decode, N_CUR_ALTITUDE,  true);
1387
    Navi.Target.Longitude  = Parser::dataToLong(RX.decode, N_TAR_LONGITUDE, true);
1388
    Navi.Target.Latitude   = Parser::dataToLong(RX.decode, N_TAR_LATITUDE,  true);
1389
    Navi.Target.Altitude   = Parser::dataToLong(RX.decode, N_TAR_ALTITUDE,  true);
199 KeyOz 1390
 
391 Brean 1391
    le_CDistance->setText(QString("%1 cm").arg(Parser::dataToInt(RX.decode, N_HOME_DISTANCE)));
1392
    le_CWPA->setText(QString("%1").arg(RX.decode[N_WP_INDEX]));
1393
    le_CWPT->setText(QString("%1").arg(RX.decode[N_WP_NUMBER]));
1394
    le_CSats->setText(QString("%1").arg(RX.decode[N_SATS_IN_USER]));
227 KeyOz 1395
 
391 Brean 1396
    qwt_Rate->setValue(double(Parser::dataToInt(RX.decode, N_VARIOMETER, true)));
227 KeyOz 1397
 
391 Brean 1398
    le_CTime->setText(QString("%1 sec.").arg(Parser::dataToInt(RX.decode, N_FLYING_TIME)));
227 KeyOz 1399
 
391 Brean 1400
    bar_UBAT->setValue(RX.decode[N_UBAT]);
227 KeyOz 1401
 
391 Brean 1402
    double Speed = double((Parser::dataToLong(RX.decode, N_GROUND_SPEED)) / 10.0);
227 KeyOz 1403
 
1404
    if ((Speed > 4.5) && SpeedMeter->property("END") == 5)
1405
    {
1406
        SpeedMeter->setRange(0.0, 10.0);
1407
        SpeedMeter->setScale(1, 2, 1);
1408
        SpeedMeter->setProperty("END", 10);
1409
    }
1410
 
1411
    if ((Speed > 9) && SpeedMeter->property("END") == 10)
1412
    {
1413
        SpeedMeter->setRange(0.0, 20.0);
1414
        SpeedMeter->setScale(1, 2, 2);
1415
        SpeedMeter->setProperty("END", 20);
1416
    }
1417
 
1418
    SpeedMeter->setValue(Speed);
1419
 
391 Brean 1420
    Compass->setValue(Parser::dataToInt(RX.decode, N_COMAPSS_HEADING)); //(68)
227 KeyOz 1421
 
391 Brean 1422
    bar_RX->setValue(RX.decode[N_RC_QUALITY]);
227 KeyOz 1423
 
391 Brean 1424
    int Nick = RX.decode[N_ANGLE_NICK];
1425
    int Roll = RX.decode[N_ANGLE_ROLL];
227 KeyOz 1426
 
1427
    if (Roll > 128)
1428
        Roll = Roll - 255;
1429
 
1430
    if (Nick > 128)
1431
        Nick = Nick - 255;
1432
 
1433
    Attitude->setAngle(Roll);
234 KeyOz 1434
    Attitude->setGradient(double(0.0 - (double(Nick) / 100.0)));
227 KeyOz 1435
 
199 KeyOz 1436
    sNaviString NaviString;
1437
 
391 Brean 1438
    NaviString.Longitude = Parser::getFloat(Navi.Current.Longitude,7);
1439
    NaviString.Latitude  = Parser::getFloat(Navi.Current.Latitude,7);
1440
    NaviString.Altitude  = Parser::getFloat(Navi.Current.Altitude,3);
199 KeyOz 1441
 
391 Brean 1442
    le_CurLong->setText(QString::number(NaviString.Longitude));
1443
    le_CurLat->setText(QString::number(NaviString.Latitude));
199 KeyOz 1444
 
306 KeyOz 1445
    KML_Server->store_NaviString(NaviString);
1446
 
391 Brean 1447
    f_Map->add_Position(NaviString.Longitude, NaviString.Latitude);
305 KeyOz 1448
 
272 KeyOz 1449
    if ((QMK_Server->property("Connect")) == true)
227 KeyOz 1450
    {
272 KeyOz 1451
//        qDebug("Send Data to Server..!!");
1452
        QMK_Server->NewPosition(NaviString);
227 KeyOz 1453
    }
199 KeyOz 1454
}
1455
 
272 KeyOz 1456
// Kopter-Kommunikations-Bereich, Befehle senden und Daten empfangen
1457
////////////////////////////////////////////////////////////////////
158 KeyOz 1458
 
1459
// Neues Datenpacket empfangen -> Verarbeiten
250 KeyOz 1460
void MKTool::slot_newData(sRxData RX) // DONE 0.71g
158 KeyOz 1461
{
393 Brean 1462
    //handler->receiveData(RX)
162 KeyOz 1463
 
272 KeyOz 1464
    // TODO: Roh-Daten senden zum QMK-Server dazu Sendebuffer bauen.
1465
    if ((QMK_Server->property("Connect")) == true)
1466
    {
1467
//        QMK_Server->send_RawData(RX.String);
1468
    }
1469
 
393 Brean 1470
    slot_showTerminal(1, QString(RX.str.c_str()));
158 KeyOz 1471
}
1472
 
250 KeyOz 1473
void MKTool::slot_showTerminal(int Typ, QString Text)
158 KeyOz 1474
{
250 KeyOz 1475
    switch(Typ)
158 KeyOz 1476
    {
250 KeyOz 1477
        case 1 :
158 KeyOz 1478
        {
250 KeyOz 1479
            if ((cb_ShowData->isChecked()) && ((tab_Main->currentWidget()->objectName() == QString("Tab_3")) || (cb_ShowAlways->isChecked())))
158 KeyOz 1480
            {
250 KeyOz 1481
                te_RX->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1482
                te_RX->insertHtml("<span style=\"color:#00008b;\">" + Text + "<br /></span>");
158 KeyOz 1483
            }
250 KeyOz 1484
        }
1485
        break;
1486
        case 2 :
1487
        {
1488
            if ((cb_ShowMSG->isChecked()) && ((tab_Main->currentWidget()->objectName() == QString("Tab_3")) || (cb_ShowAlways->isChecked())))
158 KeyOz 1489
            {
307 KeyOz 1490
                if (Text.length() > 0)
1491
                {
1492
                    te_RX->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1493
                    te_RX->insertHtml("<span style=\"color:#008b00;\">" + Text + "</span><br />");
1494
                }
158 KeyOz 1495
            }
1496
        }
250 KeyOz 1497
        break;
1498
        case 3 :
158 KeyOz 1499
        {
250 KeyOz 1500
            if (cb_ShowSend->isChecked())
158 KeyOz 1501
            {
250 KeyOz 1502
                te_RX->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1503
                te_RX->insertHtml("<span style='color:#8b0000;'>" + Text + "<br /></span>");
158 KeyOz 1504
            }
1505
        }
250 KeyOz 1506
        break;
158 KeyOz 1507
    }
1508
}
1509
 
272 KeyOz 1510
// Verbindung zum Kopter herstellen / Trennen
158 KeyOz 1511
void MKTool::slot_OpenPort()
1512
{
306 KeyOz 1513
    if (o_Connection->isOpen())
250 KeyOz 1514
    {
199 KeyOz 1515
        TX_Data[0] = Settings->Data.Debug_Off / 10;
306 KeyOz 1516
        o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
391 Brean 1517
        ToolBox::wait(SLEEP);
158 KeyOz 1518
 
199 KeyOz 1519
        if (Mode.ID == ADDRESS_NC)
1520
        {
1521
            TX_Data[0] = Settings->Data.Navi_Off / 10;
306 KeyOz 1522
            o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false);
391 Brean 1523
            ToolBox::wait(SLEEP);
199 KeyOz 1524
        }
1525
 
272 KeyOz 1526
        if (Mode.ID == ADDRESS_FC)
199 KeyOz 1527
        {
1528
            TX_Data[0] = 0;
1529
            TX_Data[1] = 0;
1530
            TX_Data[2] = 0;
1531
            TX_Data[3] = 0;
306 KeyOz 1532
            o_Connection->send_Cmd('t', ADDRESS_FC, TX_Data, 4, false);
391 Brean 1533
            ToolBox::wait(SLEEP);
199 KeyOz 1534
        }
250 KeyOz 1535
 
306 KeyOz 1536
        o_Connection->Close();
250 KeyOz 1537
 
358 KeyOz 1538
        ac_ConnectTTY->setText(tr("Kopter Verbinden"));
199 KeyOz 1539
        le_Port->setEnabled(true);
1540
 
167 KeyOz 1541
        Ticker->stop();
158 KeyOz 1542
    }
1543
    else
1544
    {
263 KeyOz 1545
        int i_Type;
1546
        if (le_Port->text().contains(QString("IP:")))
158 KeyOz 1547
        {
263 KeyOz 1548
            i_Type = C_IP;
1549
        }
1550
        else
1551
        {
1552
            i_Type = C_TTY;
1553
        }
1554
 
306 KeyOz 1555
        if (o_Connection->Open(i_Type, le_Port->text()))
263 KeyOz 1556
        {
358 KeyOz 1557
            ac_ConnectTTY->setText(tr("Kopter Trennen"));
199 KeyOz 1558
            le_Port->setEnabled(false);
158 KeyOz 1559
 
306 KeyOz 1560
            o_Connection->send_Cmd('v', ADDRESS_ALL, TX_Data, 0, true);
159 KeyOz 1561
 
167 KeyOz 1562
            Ticker->start(2000);
158 KeyOz 1563
        }
1564
    }
1565
}
1566
 
1567
// Programm beenden
1568
///////////////////
162 KeyOz 1569
 
1570
MKTool::~MKTool()
158 KeyOz 1571
{
306 KeyOz 1572
    if (o_Connection->isOpen())
158 KeyOz 1573
    {
306 KeyOz 1574
        o_Connection->Close();
158 KeyOz 1575
    }
1576
 
167 KeyOz 1577
    set_Preferences();
162 KeyOz 1578
    Settings->write_Settings();
158 KeyOz 1579
 
239 Brean 1580
    logger->close();
158 KeyOz 1581
}