Subversion Repositories Projects

Rev

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