Subversion Repositories Projects

Rev

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

Rev Author Line No. Line
158 KeyOz 1
/***************************************************************************
2
 *   Copyright (C) 2008 by Manuel Schrape                                  *
3
 *   manuel.schrape@gmx.de                                                 *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation; either version 2 of the License.        *
8
 *                                                                         *
9
 *   This program is distributed in the hope that it will be useful,       *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU General Public License for more details.                          *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
19
 
250 KeyOz 20
// TODO: Wiederholungssenden wieder einbauen
21
 
158 KeyOz 22
#include <QtGui>
23
 
24
#include <QLineEdit>
25
#include <QString>
26
#include <QTimer>
27
#include <QIcon>
28
#include <QToolButton>
29
#include <QSpinBox>
199 KeyOz 30
#include <QAction>
227 KeyOz 31
#include <QPalette>
158 KeyOz 32
 
33
#include "mktool.h"
34
#include "dlg_Config.h"
35
#include "dlg_Motortest.h"
159 KeyOz 36
#include "dlg_Preferences.h"
158 KeyOz 37
#include "../global.h"
227 KeyOz 38
#include "../Classes/ToolBox.h"
158 KeyOz 39
 
40
#include <stdlib.h>
41
 
42
MKTool::MKTool()
43
{
44
    setupUi(this);
45
 
46
    Settings = new cSettings;
47
 
48
    init_Arrays();
49
    init_GUI();
306 KeyOz 50
    init_Cockpit();
158 KeyOz 51
 
52
    init_Objects();
53
    init_Connections();
54
 
55
    init_Plot();
56
}
57
 
58
void MKTool::init_GUI()
59
{
60
    setWindowTitle(QA_NAME + " v" + QA_VERSION);
61
 
167 KeyOz 62
    // Tab mit Debug-Elementen verbergen
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();
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
    {
406
        List = Tmp.split("<coordinates>");
407
        List = List[1].split(",");
408
 
314 KeyOz 409
        le_TarLong->setText(ToolBox::get_Float((List[0].toDouble() * 10000000), 7));
410
        le_TarLat->setText(ToolBox::get_Float((List[1].toDouble() * 10000000), 7));
250 KeyOz 411
    }
158 KeyOz 412
}
413
 
272 KeyOz 414
// Waypoint zur NC Senden.
396 Brean 415
//FIXME: put this in cpp/NaviCtrl.cpp
358 KeyOz 416
void MKTool::slot_pb_SendTarget()
250 KeyOz 417
{
418
    if ((Navi.Current.Longitude == 0) && (Navi.Current.Latitude == 0))
419
    {
420
        QMessageBox msgB;
421
        QString msg;
358 KeyOz 422
        msgB.setText(tr("Fehler: Es konnten keine GPS-Daten vom Mikrokopter empfangen werden"));
250 KeyOz 423
        msgB.exec();
424
        return;
425
    }
272 KeyOz 426
 
250 KeyOz 427
    //erstelle einen Wegpunkt, den die NaviCtrl auswerten kann
428
    Waypoint_t desired_pos;
429
    bool ok_lat, ok_lon;
430
 
431
    //eingegebene Daten holen
432
    double desired_long, desired_lat;
433
 
434
    desired_long = le_TarLong->text().toDouble(&ok_lon);
435
    desired_lat  = le_TarLat->text().toDouble(&ok_lat);
436
 
437
    if (ok_lon && desired_long < 100)
438
        desired_long *= 10000000+0.5;
439
 
440
    if (ok_lat && desired_lat < 100)
441
        desired_lat *= 10000000+0.5;
442
 
443
    //fülle Wegpunkt-Daten
444
    desired_pos.Position.Altitude = 0;
445
    desired_pos.Position.Longitude = int32_t(desired_long);
446
    desired_pos.Position.Latitude =  int32_t(desired_lat);
447
    desired_pos.Position.Status = NEWDATA;
448
    desired_pos.Heading = -1;
334 KeyOz 449
    desired_pos.ToleranceRadius = 5;
358 KeyOz 450
    desired_pos.HoldTime = sb_TarTime->value();
250 KeyOz 451
    desired_pos.Event_Flag = 0;
452
    desired_pos.reserve[0] = 0; // reserve
453
    desired_pos.reserve[1] = 0; // reserve
454
    desired_pos.reserve[2] = 0; // reserve
455
    desired_pos.reserve[3] = 0; // reserve
456
 
457
    //...und sende ihn an die NaviCtrl
458
    int max_radius = 10000;
459
    if (ok_lat && ok_lon &&
391 Brean 460
        abs((double)(Navi.Current.Longitude - desired_pos.Position.Longitude)) < max_radius &&
461
        abs((double)(Navi.Current.Latitude  - desired_pos.Position.Latitude)) < max_radius)
250 KeyOz 462
    {
396 Brean 463
//FIXME: Put this in com/Handler.cpp
464
//            o_Connection->send_Cmd('s', ADDRESS_NC, (char *)&desired_pos, sizeof(desired_pos), false);
250 KeyOz 465
    }
466
    else
467
    {
468
        QMessageBox msgB;
469
        QString msg;
358 KeyOz 470
        msg += tr("Bitte die Eingabe ueberpruefen!\n");
471
        msg += tr("Die Werte muessen sich in der Naehe der aktuellen Koordinaten befinden\n");
250 KeyOz 472
        msg += "(Lon: ";
314 KeyOz 473
        msg += ToolBox::get_Float(Navi.Current.Longitude,7);
250 KeyOz 474
        msg += ", ";
475
        msg += "Lat: ";
314 KeyOz 476
        msg += ToolBox::get_Float(Navi.Current.Latitude,7);
250 KeyOz 477
        msg += ")";
478
        msgB.setText(msg);
479
        msgB.exec();
480
    }
481
}
482
 
337 KeyOz 483
// Hardware-Auswahl im Menp
199 KeyOz 484
void MKTool::slot_ac_Hardware()
485
{
486
    QAction *Action = (QAction*)sender();
158 KeyOz 487
 
199 KeyOz 488
    if (Action->isChecked() == false)
489
    {
490
        Action->setChecked(true);
491
    }
492
 
493
    slot_rb_Hardware();
494
}
495
 
337 KeyOz 496
// Hardware Auswahl und umschalten
199 KeyOz 497
void MKTool::slot_rb_Hardware()
498
{
396 Brean 499
//FIXME:put this in Handler.cpp
199 KeyOz 500
    if ((rb_SelNC->isChecked() == false) && (Mode.ID != ADDRESS_NC))
501
    {
502
        lb_Status->setText(tr("Schalte um auf NaviCtrl."));
396 Brean 503
        /*TX_Data[0] = 0x1B;
199 KeyOz 504
        TX_Data[1] = 0x1B;
505
        TX_Data[2] = 0x55;
506
        TX_Data[3] = 0xAA;
507
        TX_Data[4] = 0x00;
508
        TX_Data[5] = '\r';
306 KeyOz 509
        o_Connection->send_Cmd('#', ADDRESS_NC, TX_Data, 6, false);
396 Brean 510
        ToolBox::wait(SLEEP);*/
199 KeyOz 511
    }
512
 
513
    if (rb_SelFC->isChecked())
514
    {
515
        lb_Status->setText(tr("Schalte um auf FlightCtrl."));
396 Brean 516
        /*TX_Data[0] = 0;
517
        o_Connection->send_Cmd('u', ADDRESS_NC, TX_Data, 1, false);*/
199 KeyOz 518
    }
519
    else
520
    if (rb_SelMag->isChecked())
521
    {
522
        lb_Status->setText(tr("Schalte um auf MK3MAG."));
396 Brean 523
        /*TX_Data[0] = 1;
524
        o_Connection->send_Cmd('u', ADDRESS_NC, TX_Data, 1, false);*/
199 KeyOz 525
    }
526
    else
527
    if (rb_SelNC->isChecked())
528
    {
529
        lb_Status->setText(tr("Schalte um auf NaviCtrl."));
396 Brean 530
        /*TX_Data[0] = 0x1B;
199 KeyOz 531
        TX_Data[1] = 0x1B;
532
        TX_Data[2] = 0x55;
533
        TX_Data[3] = 0xAA;
534
        TX_Data[4] = 0x00;
535
        TX_Data[5] = '\r';
396 Brean 536
        o_Connection->send_Cmd('#', ADDRESS_NC, TX_Data, 6, false);*/
199 KeyOz 537
    }
391 Brean 538
    ToolBox::wait(SLEEP);
199 KeyOz 539
 
540
//    qDebug("Select RB Hardware");
396 Brean 541
    //o_Connection->send_Cmd('v', ADDRESS_ALL, TX_Data, 0, true);
199 KeyOz 542
}
543
 
158 KeyOz 544
// Ticker-Event
545
///////////////
546
void MKTool::slot_Ticker()
547
{
396 Brean 548
//FIXME: Put this somewhere in Handler.cpp
549
/*
158 KeyOz 550
    if (TickerDiv)
551
        TickerDiv = false;
552
    else
553
        TickerDiv = true;
396 Brean 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
    }
396 Brean 606
*/
158 KeyOz 607
}
608
 
337 KeyOz 609
// Zum QMK-Datenserver verbinden
227 KeyOz 610
void MKTool::slot_QMKS_Connect()
611
{
612
    if (ac_QMKServer->isChecked())
613
    {
614
        lb_Status->setText(tr("Verbinde zum QMK-Datenserver."));
158 KeyOz 615
 
272 KeyOz 616
        QMK_Server->Connect(Settings->Server.QMKS_Host, Settings->Server.QMKS_Port.toInt(), Settings->Server.QMKS_Login, Settings->Server.QMKS_Password);
227 KeyOz 617
 
272 KeyOz 618
        connect(QMK_Server, SIGNAL(sig_Connected()), this, SLOT(slot_QMKS_Connected()));
619
        connect(QMK_Server, SIGNAL(sig_Disconnected(int)), this, SLOT(slot_QMKS_Disconnected(int)));
227 KeyOz 620
    }
621
    else
622
    {
272 KeyOz 623
        if ((QMK_Server->property("Connect")) == true)
227 KeyOz 624
        {
272 KeyOz 625
            disconnect(QMK_Server, SIGNAL(sig_Disconnected(int)), 0, 0);
227 KeyOz 626
            lb_Status->setText(tr("Trenne vom QMK-Datenserver."));
627
 
272 KeyOz 628
            QMK_Server->Disconnect();
629
            QMK_Server->setProperty("Connect", false);
358 KeyOz 630
            ac_QMKServer->setText(tr("QMK-Server Verbinden"));
227 KeyOz 631
        }
632
    }
633
}
634
 
337 KeyOz 635
// Verbindung zum QMK-Server hergestellt.
227 KeyOz 636
void MKTool::slot_QMKS_Connected()
637
{
272 KeyOz 638
    QMK_Server->setProperty("Connect", true);
358 KeyOz 639
    ac_QMKServer->setText(tr("QMK-Server Trennnen"));
227 KeyOz 640
    lb_Status->setText(tr("Verbunden mit QMK-Datenserver."));
641
}
642
 
337 KeyOz 643
// QMK-Serververbindung getrennt
227 KeyOz 644
void MKTool::slot_QMKS_Disconnected(int Error)
645
{
272 KeyOz 646
    QMK_Server->setProperty("Connect", false);
358 KeyOz 647
    ac_QMKServer->setText(tr("QMK-Server Verbinden"));
227 KeyOz 648
    ac_QMKServer->setChecked(false);
649
 
272 KeyOz 650
    disconnect(QMK_Server, SIGNAL(sig_Disconnected(int)), 0, 0);
227 KeyOz 651
 
652
    switch (Error)
653
    {
654
        case 1 :
655
        {
656
            lb_Status->setText(tr("Verbindung vom Server beendet."));
358 KeyOz 657
            QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Verbindung wurde vom Server beendet."), QMessageBox::Ok);
227 KeyOz 658
        }
659
        break;
660
        case 2 :
661
        {
662
            lb_Status->setText(tr("Server nicht gefunden."));
358 KeyOz 663
            QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Kann nicht zum Server verbinden."), QMessageBox::Ok);
227 KeyOz 664
        }
665
        break;
666
        case 3 :
667
        {
668
            lb_Status->setText(tr("Serververbindung getrennt. Logindaten falsch."));
358 KeyOz 669
            QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Loginname oder Password falsch."), QMessageBox::Ok);
227 KeyOz 670
        }
671
        break;
672
        default :
673
        {
674
            lb_Status->setText(tr("Getrennt vom QMK-Datenserver."));
675
        }
676
        break;
677
    }
678
}
679
 
158 KeyOz 680
// Slots der Actions (Menüpunkte, Buttons)
681
//////////////////////////////////////////
682
void MKTool::slot_ac_Motortest()
683
{
684
    dlg_Motortest *f_Motortest = new dlg_Motortest(this);
685
 
337 KeyOz 686
//    connect(f_Motortest, SIGNAL(updateMotor(int, int, int, int)), this, SLOT(slot_Motortest(int, int, int, int)));
687
    connect(f_Motortest, SIGNAL(updateMotor(sMotor)), this, SLOT(slot_Motortest(sMotor)));
158 KeyOz 688
 
337 KeyOz 689
 
690
    Ticker->setInterval(500);
691
    TickerEvent[4] = true;
692
 
158 KeyOz 693
    if (f_Motortest->exec()==QDialog::Accepted)
694
    {
695
    }
696
 
697
    disconnect(f_Motortest, 0,0,0);
337 KeyOz 698
 
699
    for (int z = 0; z<12; z++)
700
    {
701
        Motor.Speed[z] = 0;
702
    }
703
 
704
    slot_Motortest(Motor);
705
 
706
    Ticker->setInterval(2000);
707
    TickerEvent[4] = false;
158 KeyOz 708
}
709
 
337 KeyOz 710
void MKTool::slot_Motortest(sMotor p_Motor)
711
{
396 Brean 712
//FIXME: put this in com/Handler.cpp
713
/*
337 KeyOz 714
    Motor = p_Motor;
715
 
716
    for (int z = 0; z<12; z++)
717
    {
718
        TX_Data[z] = Motor.Speed[z];
719
    }
720
    o_Connection->send_Cmd('t', ADDRESS_FC, TX_Data, 12, false);
396 Brean 721
*/
337 KeyOz 722
}
723
 
724
// Motormixer-Einstellungen anzeigen
307 KeyOz 725
void MKTool::slot_ac_MotorMixer()
726
{
396 Brean 727
    f_MotorMixer->set_Objects(handler, Settings);
728
    handler->read_mixer();
307 KeyOz 729
 
730
    if (f_MotorMixer->exec()==QDialog::Accepted)
731
    {
732
    }
733
}
734
 
337 KeyOz 735
// LCD Anzeigen
227 KeyOz 736
void MKTool::slot_ac_LCD()
737
{
738
    if (!f_LCD->isVisible())
739
    {
306 KeyOz 740
        delete f_LCD;
227 KeyOz 741
        f_LCD = new dlg_LCD(this);
742
 
743
        // LCD auf / ab
744
        connect(f_LCD->pb_LCDup,   SIGNAL(clicked()), this, SLOT(slot_LCD_UP()));
745
        connect(f_LCD->pb_LCDdown, SIGNAL(clicked()), this, SLOT(slot_LCD_DOWN()));
396 Brean 746
        //FIXME: put this in com/Handler.cpp
227 KeyOz 747
        f_LCD->show();
396 Brean 748
        /*TX_Data[0] = 0;
227 KeyOz 749
        TX_Data[1] = 0;
306 KeyOz 750
        o_Connection->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true);
396 Brean 751
        */
752
        //FIXME: replace ticker with something else
227 KeyOz 753
        Ticker->setInterval(500);
754
        TickerEvent[2] = true;
755
    }
756
}
757
 
337 KeyOz 758
// Map-Fenster anzeigen
305 KeyOz 759
void MKTool::slot_ac_Map()
760
{
761
    if (!f_Map->isVisible())
762
    {
763
        f_Map->show();
764
    }
765
}
766
 
358 KeyOz 767
void MKTool::slot_MAP_SetWayPoints(QList<sWayPoint> l_WayPoints)
768
{
396 Brean 769
//FIXME: Put this in com/Handler.cpp or com/NaviCtrlHandler.cpp
770
/*
358 KeyOz 771
    Waypoint_t WayPoint;
772
    double Longitude, Latitude;
773
 
774
    // Waypoint-Liste löschen
775
    WayPoint.Position.Status = INVALID;
776
    o_Connection->send_Cmd('w', ADDRESS_NC, (char *)&WayPoint, sizeof(WayPoint), false);
391 Brean 777
    ToolBox::wait(SLEEP);
358 KeyOz 778
 
779
    for (int z = 0; z < l_WayPoints.count(); z++)
780
    {
781
        Longitude = l_WayPoints[z].Longitude;
782
        Latitude  = l_WayPoints[z].Latitude;
783
 
784
        if (Longitude < 100)
785
            Longitude *= 10000000+0.5;
786
 
787
        if (Latitude < 100)
788
            Latitude *= 10000000+0.5;
789
 
790
        //fülle Wegpunkt-Daten
791
        WayPoint.Position.Altitude = 0;
792
        WayPoint.Position.Longitude = int32_t(Longitude);
793
        WayPoint.Position.Latitude =  int32_t(Latitude);
794
        WayPoint.Position.Status = NEWDATA;
795
        WayPoint.Heading = -1;
796
        WayPoint.ToleranceRadius = 5;
797
        WayPoint.HoldTime = l_WayPoints[z].Time;
798
        WayPoint.Event_Flag = 0;
799
        WayPoint.reserve[0] = 0; // reserve
800
        WayPoint.reserve[1] = 0; // reserve
801
        WayPoint.reserve[2] = 0; // reserve
802
        WayPoint.reserve[3] = 0; // reserve
803
 
804
        o_Connection->send_Cmd('w', ADDRESS_NC, (char *)&WayPoint, sizeof(WayPoint), false);
805
//        ToolBox::Wait(SLEEP);
806
    }
396 Brean 807
*/
358 KeyOz 808
}
809
 
306 KeyOz 810
void MKTool::slot_MAP_SetTarget(sWayPoint Target)
811
{
315 KeyOz 812
 
813
    QString s_Lon, s_Lat;
814
    QTextStream t_Lon(&s_Lon);
815
    QTextStream t_Lat(&s_Lat);
816
 
817
    t_Lon.setRealNumberPrecision(9);
818
    t_Lat.setRealNumberPrecision(9);
819
    t_Lon << Target.Longitude;
820
    t_Lat << Target.Latitude;
821
 
822
    le_TarLong->setText(s_Lon);
823
    le_TarLat->setText(s_Lat);
306 KeyOz 824
    sb_TarTime->setValue(Target.Time);
305 KeyOz 825
 
358 KeyOz 826
    slot_pb_SendTarget();
306 KeyOz 827
}
828
 
158 KeyOz 829
void MKTool::slot_ac_Config()
830
{
162 KeyOz 831
    set_Analog Old_Analog1;
158 KeyOz 832
 
162 KeyOz 833
    Old_Analog1 = Settings->Analog1;
834
 
158 KeyOz 835
    dlg_Config *f_Config = new dlg_Config(this);
162 KeyOz 836
    f_Config->set_Settings(Settings, Mode.ID);
158 KeyOz 837
 
838
    if (f_Config->exec()==QDialog::Accepted)
839
    {
840
        Settings = f_Config->get_Settings();
162 KeyOz 841
        Settings->write_Settings_Analog(Mode.ID);
158 KeyOz 842
 
163 KeyOz 843
        // Plotter neu einrichten
844
        if (Old_Analog1.PlotView != Settings->Analog1.PlotView)
158 KeyOz 845
        {
163 KeyOz 846
            config_Plot();
158 KeyOz 847
        }
848
 
163 KeyOz 849
        // CVS-Datei neu anlegen.
241 KeyOz 850
        if ((logger->is_active()) && (Old_Analog1.LogView != Settings->Analog1.LogView))
158 KeyOz 851
        {
239 Brean 852
            logger->close();
240 Brean 853
            logger->start_Log();
158 KeyOz 854
        }
855
 
856
    }
857
}
858
 
239 Brean 859
//aktualisiere Logging-Status
241 KeyOz 860
void MKTool::update_Log()
861
{
239 Brean 862
    if (logger->is_active())
863
    {
272 KeyOz 864
 
358 KeyOz 865
        ac_RecordCSV->setText(tr("Log Stop"));
239 Brean 866
        lb_Status->setText(tr("Log-Record gestartet."));
867
    }
868
    else
869
    {
358 KeyOz 870
        ac_RecordCSV->setText(tr("Log Aufzeichnen"));
239 Brean 871
        lb_Status->setText(tr("Log-Record gestopt."));
872
    }
873
}
874
 
875
//starte/stoppe Logging, wenn auf den entsprechenden Button gedrückt wurde
876
void MKTool::slot_RecordLog()
877
{
878
    if (!logger->is_active())
879
        logger->start_Log();
880
    else
881
        logger->close();
241 KeyOz 882
 
239 Brean 883
    update_Log();
884
}
885
 
159 KeyOz 886
void MKTool::slot_ac_Preferences()
887
{
888
    dlg_Preferences *f_Preferences = new dlg_Preferences(this);
889
 
166 KeyOz 890
    Settings->TTY.Port = le_Port->text();
163 KeyOz 891
    f_Preferences->set_Settings(Settings);
892
 
159 KeyOz 893
    if (f_Preferences->exec()==QDialog::Accepted)
894
    {
163 KeyOz 895
        Settings = f_Preferences->get_Settings();
896
        Settings->write_Settings();
166 KeyOz 897
        le_Port->setText(Settings->TTY.Port);
898
        config_Plot();
159 KeyOz 899
    }
900
}
901
 
158 KeyOz 902
void MKTool::slot_ac_StartPlotter()
903
{
904
    if (ac_StartPlotter->isChecked())
905
    {
199 KeyOz 906
        lb_Status->setText(tr("Datenplotter gestartet."));
358 KeyOz 907
        ac_StartPlotter->setText(tr("Stop Plotter"));
908
        pb_StartPlotter->setText(tr("Stop Plotter"));
158 KeyOz 909
    }
910
    else
911
    {
199 KeyOz 912
        lb_Status->setText(tr("Datenplotter gestopt."));
358 KeyOz 913
        ac_StartPlotter->setText(tr("Start Plotter"));
914
        pb_StartPlotter->setText(tr("Start Plotter"));
158 KeyOz 915
    }
916
}
917
 
918
void MKTool::slot_ac_View()
919
{
227 KeyOz 920
    int Aktive = -1;
158 KeyOz 921
 
922
    QAction *Action = (QAction*)sender();
923
 
924
    if (Action->objectName() == QString("ac_View0"))
925
        Aktive = 0;
926
    if (Action->objectName() == QString("ac_View1"))
927
        Aktive = 1;
928
    if (Action->objectName() == QString("ac_View2"))
929
        Aktive = 2;
930
    if (Action->objectName() == QString("ac_View3"))
931
        Aktive = 3;
932
    if (Action->objectName() == QString("ac_View4"))
933
        Aktive = 4;
934
    if (Action->objectName() == QString("ac_View5"))
935
        Aktive = 5;
272 KeyOz 936
    if (Action->objectName() == QString("ac_View6"))
937
        Aktive = 6;
158 KeyOz 938
 
939
    QString TabName = QString("Tab_%1").arg(Aktive);
940
 
941
    if (!Action->isChecked())
942
    {
943
        for (int a = 0; a < tab_Main->count(); a++)
944
        {
945
            if (tab_Main->widget(a)->objectName() == TabName)
946
            {
947
                tab_Main->removeTab(a);
948
            }
949
        }
950
    }
951
    else
952
    {
227 KeyOz 953
        tab_Main->insertTab(Aktive, TabWidgets[Aktive], Action->icon(), Action->text());
158 KeyOz 954
    }
955
}
956
 
199 KeyOz 957
void MKTool::slot_ac_FastNavi() // DONE NC 0.12i
158 KeyOz 958
{
199 KeyOz 959
    if (!ac_NoNavi->isChecked())
158 KeyOz 960
    {
199 KeyOz 961
        if (ac_FastNavi->isChecked())
166 KeyOz 962
        {
199 KeyOz 963
            lb_Status->setText(tr("Fordere schnelle NaviDaten an."));
396 Brean 964
            //TX_Data[0] = Settings->Data.Navi_Fast / 10;
199 KeyOz 965
        }
966
        else
967
        {
968
            lb_Status->setText(tr("Fordere langsame NaviDaten an."));
396 Brean 969
            //TX_Data[0] = Settings->Data.Navi_Slow / 10;
199 KeyOz 970
        }
396 Brean 971
        //FIXME: put this in com/Handler.cpp / com/NaviCtrl.cpp
972
        //o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false);
199 KeyOz 973
    }
974
}
975
 
976
void MKTool::slot_ac_NoNavi() // DONE NC 0.12i
977
{
978
    if (ac_NoNavi->isChecked())
979
    {
980
        lb_Status->setText(tr("NaviDaten abstellen."));
396 Brean 981
//        TX_Data[0] = 0;
199 KeyOz 982
    }
983
    else
984
    {
985
        if (ac_FastNavi->isChecked())
986
        {
987
            lb_Status->setText(tr("Fordere schnelle NaviDaten an."));
396 Brean 988
//            TX_Data[0] = Settings->Data.Navi_Fast / 10;
199 KeyOz 989
        }
990
        else
991
        {
992
            lb_Status->setText(tr("Fordere langsame NaviDaten an."));
396 Brean 993
//            TX_Data[0] = Settings->Data.Navi_Slow / 10;
199 KeyOz 994
        }
995
    }
396 Brean 996
//FIXME: Put this in com/Handler.cpp
997
//    o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false);
199 KeyOz 998
}
999
 
1000
void MKTool::slot_ac_FastDebug() // DONE 0.71g
1001
{
1002
    if (!ac_NoDebug->isChecked())
1003
    {
1004
        if (ac_FastDebug->isChecked())
1005
        {
1006
            lb_Status->setText(tr("Fordere schnelle DebugDaten an."));
396 Brean 1007
            //TX_Data[0] = Settings->Data.Debug_Fast / 10;
166 KeyOz 1008
        }
1009
        else
1010
        {
199 KeyOz 1011
            lb_Status->setText(tr("Fordere langsame DebugDaten an."));
396 Brean 1012
            //TX_Data[0] = Settings->Data.Debug_Slow / 10;
166 KeyOz 1013
        }
396 Brean 1014
//FIXME: Put this in com/Handler.cpp
1015
//        o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
166 KeyOz 1016
    }
1017
}
1018
 
199 KeyOz 1019
void MKTool::slot_ac_NoDebug() // DONE 0.71g
166 KeyOz 1020
{
199 KeyOz 1021
    if (ac_NoDebug->isChecked())
166 KeyOz 1022
    {
199 KeyOz 1023
        lb_Status->setText(tr("DebugDaten abstellen."));
167 KeyOz 1024
        TickerEvent[3] = false;
396 Brean 1025
        //TX_Data[0] = 0;
166 KeyOz 1026
    }
158 KeyOz 1027
    else
1028
    {
167 KeyOz 1029
        // Wenn MK3MAG dann andauernd Daten neu anfragen.
1030
        if (Mode.ID == ADDRESS_MK3MAG)
1031
            TickerEvent[3] = true;
1032
 
199 KeyOz 1033
        if (ac_FastDebug->isChecked())
166 KeyOz 1034
        {
199 KeyOz 1035
            lb_Status->setText(tr("Fordere schnelle DebugDaten an."));
396 Brean 1036
            //TX_Data[0] = Settings->Data.Debug_Fast / 10;
166 KeyOz 1037
        }
1038
        else
1039
        {
199 KeyOz 1040
            lb_Status->setText(tr("Fordere langsame DebugDaten an."));
396 Brean 1041
            //TX_Data[0] = Settings->Data.Debug_Slow / 10;
166 KeyOz 1042
        }
1043
    }
396 Brean 1044
//FIXME: Put this in com/Handler.cpp
1045
//    o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
158 KeyOz 1046
}
1047
 
1048
void MKTool::slot_ac_About()
1049
{
1050
    QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT);
1051
}
1052
 
159 KeyOz 1053
void MKTool::slot_ac_GetLabels() // DONE 0.71g
158 KeyOz 1054
{
199 KeyOz 1055
    lb_Status->setText(tr("Analoglabels auslesen."));
396 Brean 1056
//FIXME: Put this in com/Handler.cpp
1057
//    TX_Data[0] = 0;
1058
//    o_Connection->send_Cmd('a', ADDRESS_ALL, TX_Data, 1, true);
158 KeyOz 1059
}
1060
 
199 KeyOz 1061
void MKTool::slot_ac_StartServer()
1062
{
1063
    if (ac_StartServer->isChecked())
1064
    {
306 KeyOz 1065
        lb_Status->setText(tr("KML-Server gestartet."));
1066
        KML_Server->start_Server(Settings->Server.Port.toInt(), Settings);
199 KeyOz 1067
    }
1068
    else
1069
    {
306 KeyOz 1070
        lb_Status->setText(tr("KML-Server gestopt."));
1071
        KML_Server->stop_Server();
199 KeyOz 1072
    }
1073
}
159 KeyOz 1074
 
227 KeyOz 1075
 
158 KeyOz 1076
//  Daten-Plotter
1077
/////////////////
1078
void MKTool::update_Plot()
1079
{
1080
    for (int a = 0; a < MaxAnalog; a++)
1081
    {
1082
        Plot[a]->setData(aID,aData[a],NextPlot - 1);
1083
    }
1084
 
166 KeyOz 1085
    if ((NextPlot > Settings->Data.Plotter_Count))
158 KeyOz 1086
    {
166 KeyOz 1087
        scroll_plot->setMaximum(NextPlot - Settings->Data.Plotter_Count);
158 KeyOz 1088
    }
1089
 
166 KeyOz 1090
    if ((scroll_plot->value() == NextPlot - (Settings->Data.Plotter_Count + 1)))
158 KeyOz 1091
    {
166 KeyOz 1092
        qwtPlot->setAxisScale(QwtPlot::xBottom,NextPlot - Settings->Data.Plotter_Count,NextPlot,0);
1093
        scroll_plot->setValue(NextPlot - Settings->Data.Plotter_Count);
158 KeyOz 1094
    }
1095
 
1096
    qwtPlot->replot();
1097
}
1098
 
1099
void MKTool::config_Plot()
1100
{
166 KeyOz 1101
//    qDebug("Plotter rekonfiguriert..!!");
1102
    qwtPlot->setAxisScale(QwtPlot::xBottom,0,Settings->Data.Plotter_Count,0);
1103
 
158 KeyOz 1104
    for (int a = 0; a < MaxAnalog; a++)
1105
    {
1106
        Plot[a]->detach();
162 KeyOz 1107
        Plot[a]->setPen(QPen(QColor(Def_Colors[a])));
158 KeyOz 1108
 
162 KeyOz 1109
        if (Settings->Analog1.PlotView[a])
1110
        {
1111
            Plot[a]->setTitle(Settings->Analog1.Label[a]);
158 KeyOz 1112
            Plot[a]->attach(qwtPlot);
162 KeyOz 1113
        }
158 KeyOz 1114
    }
166 KeyOz 1115
    qwtPlot->replot();
158 KeyOz 1116
}
1117
 
1118
void MKTool::slot_ScrollPlot(int Pos)
1119
{
166 KeyOz 1120
    qwtPlot->setAxisScale(QwtPlot::xBottom,Pos,Pos + Settings->Data.Plotter_Count,0);
158 KeyOz 1121
    qwtPlot->replot();
1122
}
1123
 
1124
 
1125
// Firmeware-Update
1126
///////////////////
1127
void MKTool::slot_pb_Update()
1128
{
167 KeyOz 1129
    QString Device;
1130
    QString Hardware;
158 KeyOz 1131
 
167 KeyOz 1132
    if (rb_FC->isChecked())
1133
    {
1134
        Device   = "m644";
1135
        Hardware = "FlightCtrl";
1136
    }
1137
    else if (rb_MK3MAG->isChecked())
1138
    {
1139
        Device   = "m168";
1140
        Hardware = "MK3MAG";
1141
    }
1142
    else if (rb_BL->isChecked())
1143
    {
1144
        Device   = "m8";
1145
        Hardware = "BL-Ctrl";
1146
    }
166 KeyOz 1147
 
358 KeyOz 1148
    QString Message = trUtf8("Firmeware-Datei \n\n");
166 KeyOz 1149
    Message = Message + le_HexFile->text() + "\n\n";
358 KeyOz 1150
    Message = Message + trUtf8("an ") + Hardware + trUtf8(" mit AVRDUDE - Seriel & Bootloader über ") + le_Port->text() + trUtf8(" übertragen?\n");
166 KeyOz 1151
 
1152
    if (le_HexFile->text() == "")
162 KeyOz 1153
    {
166 KeyOz 1154
        QMessageBox::warning(this, QA_NAME, trUtf8("Bitte Firmeware-Datei wählen."), QMessageBox::Ok);
162 KeyOz 1155
    }
166 KeyOz 1156
    else if (QMessageBox::warning(this, QA_NAME, Message, QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
1157
    {
306 KeyOz 1158
        QString Programm = Settings->DIR.AVRDUDE;
162 KeyOz 1159
 
166 KeyOz 1160
        QStringList Argumente;
162 KeyOz 1161
 
166 KeyOz 1162
        Update = new QProcess();
162 KeyOz 1163
 
396 Brean 1164
//FIXME: put this in QTCommunication.cpp
1165
/*        if (o_Connection->isOpen())
166 KeyOz 1166
        {
1167
            slot_OpenPort();
1168
        }
396 Brean 1169
*/
166 KeyOz 1170
        Argumente << "-P";
1171
        Argumente << le_Port->text();
1172
        Argumente << "-p";
1173
        Argumente << Device;
1174
        Argumente << "-c";
1175
        Argumente << "butterfly";
1176
        Argumente << "-b";
1177
        Argumente << "57600";
1178
        Argumente << "-U";
1179
        Argumente << "flash:w:" + le_HexFile->text();
1180
 
1181
//    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";
1182
 
1183
        te_Shell->setText(""); // Ausgabefenster säubern
1184
 
1185
        connect(Update, SIGNAL(readyReadStandardOutput()), this, SLOT(slot_UpdateShell()) );
1186
        connect(Update, SIGNAL(readyReadStandardError()), this, SLOT(slot_UpdateShell()) );
1187
 
1188
        Update->start(Programm, Argumente); // Programmaufruf
1189
    }
158 KeyOz 1190
}
1191
 
1192
void MKTool::slot_UpdateShell()
1193
{
162 KeyOz 1194
    QByteArray Output;
158 KeyOz 1195
 
166 KeyOz 1196
    Output = Update->readAllStandardError(); // Shellausgabe an Variable
162 KeyOz 1197
    te_Shell->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1198
    te_Shell->insertPlainText(QString::fromUtf8(Output));
158 KeyOz 1199
 
166 KeyOz 1200
    Output = Update->readAll();
1201
    te_Shell->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1202
    te_Shell->insertPlainText(QString::fromUtf8(Output));
158 KeyOz 1203
}
1204
 
166 KeyOz 1205
void MKTool::slot_pb_HexFile()
1206
{
1207
    QString FileName = QFileDialog::getOpenFileName(this,trUtf8(("Firmeware-Datei wählen")),"",
1208
                                tr("Intel Hex(*.hex);;Alle Dateien (*)"));
1209
    if (!FileName.isEmpty())
1210
    {
1211
        le_HexFile->setText(FileName);
1212
    }
1213
}
158 KeyOz 1214
 
1215
 
167 KeyOz 1216
// Wechsel der Tabs erkennen
159 KeyOz 1217
void MKTool::slot_TabChanged(int Tab) // DONE 0.71g
158 KeyOz 1218
{
1219
    Tab = Tab;
162 KeyOz 1220
    if (tab_Main->count() != 0)
158 KeyOz 1221
    {
306 KeyOz 1222
        if ((tab_Main->currentWidget()->objectName() == QString("Tab_2")) && (f_Settings->listWidget->currentRow() == 1))
162 KeyOz 1223
        {
396 Brean 1224
//            TX_Data[0] = 0;
1225
//FIXME: Put this in com/Handler.cpp
1226
//            o_Connection->send_Cmd('p', ADDRESS_FC, TX_Data, 0, false);
159 KeyOz 1227
 
162 KeyOz 1228
            Ticker->setInterval(500);
1229
            TickerEvent[1] = true;
1230
        }
1231
        else
1232
        {
1233
            Ticker->setInterval(2000);
1234
            TickerEvent[1] = false;
1235
        }
159 KeyOz 1236
    }
158 KeyOz 1237
}
1238
 
167 KeyOz 1239
// LCD-Seiten weiterschalten
159 KeyOz 1240
void MKTool::slot_LCD_UP() // DONE 0.71g
158 KeyOz 1241
{
396 Brean 1242
//FIXME: Put this in com/Handler.cpp
1243
/*    if (LCD_Page == LCD_MAX_Page)
159 KeyOz 1244
        TX_Data[0] = 0;
1245
    else
1246
        TX_Data[0] = LCD_Page + 1;
1247
 
1248
    TX_Data[1] = 0;
306 KeyOz 1249
    o_Connection->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true);
396 Brean 1250
*/
159 KeyOz 1251
}
1252
 
1253
void MKTool::slot_LCD_DOWN() // DONE 0.71g
1254
{
396 Brean 1255
//FIXME: Put this in com/Handler.cpp
1256
/*
159 KeyOz 1257
    if (LCD_Page == 0)
1258
        TX_Data[0] = LCD_MAX_Page;
1259
    else
1260
        TX_Data[0] = LCD_Page - 1;
1261
 
1262
    TX_Data[1] = 0;
306 KeyOz 1263
    o_Connection->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true);
396 Brean 1264
*/
159 KeyOz 1265
}
1266
 
167 KeyOz 1267
// Settings aus MK lesen / in MK schreiben
199 KeyOz 1268
void MKTool::slot_GetFCSettings() // DONE 0.71g
159 KeyOz 1269
{
199 KeyOz 1270
    lb_Status->setText(tr("Lese FlightCtrl-Settings aus."));
396 Brean 1271
//FIXME: Put this in com/Handler.cpp
1272
/*
167 KeyOz 1273
    TX_Data[0] = f_Settings->sb_Set->value();
158 KeyOz 1274
    TX_Data[1] = 0;
313 KeyOz 1275
    o_Connection->send_Cmd('q', ADDRESS_FC, TX_Data, 1, true);
396 Brean 1276
*/
158 KeyOz 1277
}
1278
 
199 KeyOz 1279
void MKTool::slot_SetFCSettings() // DONE 0.71g
158 KeyOz 1280
{
396 Brean 1281
//FIXME: Put this in com/Handler.cpp
1282
/*
199 KeyOz 1283
    char *TX_Data2 = f_Settings->GetFCSettings();
158 KeyOz 1284
 
199 KeyOz 1285
    lb_Status->setText(tr("Schreibe FlightCtrl-Settings."));
167 KeyOz 1286
 
313 KeyOz 1287
    o_Connection->send_Cmd('s', ADDRESS_FC, TX_Data2, MaxParameter + 2, true);
396 Brean 1288
*/
158 KeyOz 1289
}
1290
 
159 KeyOz 1291
 
167 KeyOz 1292
// Save GUI-Preferences
1293
///////////////////////
1294
void MKTool::set_Preferences()
158 KeyOz 1295
{
163 KeyOz 1296
    Settings->GUI.TabViews.setBit(0, ac_View0->isChecked());
1297
    Settings->GUI.TabViews.setBit(1, ac_View1->isChecked());
1298
    Settings->GUI.TabViews.setBit(2, ac_View2->isChecked());
1299
    Settings->GUI.TabViews.setBit(3, ac_View3->isChecked());
1300
    Settings->GUI.TabViews.setBit(4, ac_View4->isChecked());
1301
    Settings->GUI.TabViews.setBit(5, ac_View5->isChecked());
227 KeyOz 1302
    Settings->GUI.TabViews.setBit(6, ac_View6->isChecked());
158 KeyOz 1303
 
227 KeyOz 1304
    Settings->GUI.ToolViews.setBit(0, tb_Allgemein->isVisibleTo(this));
1305
    Settings->GUI.ToolViews.setBit(1, tb_Werkzeuge->isVisibleTo(this));
1306
    Settings->GUI.ToolViews.setBit(2, tb_Debug->isVisibleTo(this));
1307
    Settings->GUI.ToolViews.setBit(3, tb_TTY->isVisibleTo(this));
1308
    Settings->GUI.ToolViews.setBit(4, tb_Hardware->isVisibleTo(this));
1309
 
162 KeyOz 1310
    Settings->GUI.Term_Info   = cb_ShowMSG->isChecked();
1311
    Settings->GUI.Term_Data   = cb_ShowData->isChecked();
1312
    Settings->GUI.Term_Always = cb_ShowAlways->isChecked();
166 KeyOz 1313
    Settings->GUI.Term_Send   = cb_ShowSend->isChecked();
167 KeyOz 1314
    Settings->GUI.isMax       = isMaximized();
1315
    Settings->GUI.Size        = size();
1316
    Settings->GUI.Point       = pos();
162 KeyOz 1317
 
163 KeyOz 1318
    Settings->TTY.Port = le_Port->text();
158 KeyOz 1319
}
1320
 
1321
void MKTool::show_DebugData()
1322
{
241 KeyOz 1323
    if (logger->is_active())
1324
        logger->write(AnalogData);
158 KeyOz 1325
 
1326
    if (ac_StartPlotter->isChecked())
1327
    {
1328
        aID[NextPlot] = NextPlot;
1329
 
1330
        for (int a = 0; a < MaxAnalog; a++)
1331
        {
1332
            aData[a][NextPlot] = AnalogData[a];
1333
        }
1334
        NextPlot++;
1335
 
1336
        if ((tab_Main->currentWidget()->objectName() == QString("Tab_1")))
1337
            update_Plot();
1338
    }
1339
 
1340
    le_A_0->setText(QString("%1").arg(AnalogData[0]));
1341
    le_A_1->setText(QString("%1").arg(AnalogData[1]));
1342
    le_A_2->setText(QString("%1").arg(AnalogData[2]));
1343
    le_A_3->setText(QString("%1").arg(AnalogData[3]));
1344
    le_A_4->setText(QString("%1").arg(AnalogData[4]));
1345
    le_A_5->setText(QString("%1").arg(AnalogData[5]));
1346
    le_A_6->setText(QString("%1").arg(AnalogData[6]));
1347
    le_A_7->setText(QString("%1").arg(AnalogData[7]));
1348
    le_A_8->setText(QString("%1").arg(AnalogData[8]));
1349
    le_A_9->setText(QString("%1").arg(AnalogData[9]));
1350
    le_A_10->setText(QString("%1").arg(AnalogData[10]));
1351
    le_A_11->setText(QString("%1").arg(AnalogData[11]));
1352
    le_A_12->setText(QString("%1").arg(AnalogData[12]));
1353
    le_A_13->setText(QString("%1").arg(AnalogData[13]));
1354
    le_A_14->setText(QString("%1").arg(AnalogData[14]));
1355
    le_A_15->setText(QString("%1").arg(AnalogData[15]));
1356
    le_A_16->setText(QString("%1").arg(AnalogData[16]));
1357
    le_A_17->setText(QString("%1").arg(AnalogData[17]));
1358
    le_A_18->setText(QString("%1").arg(AnalogData[18]));
1359
    le_A_19->setText(QString("%1").arg(AnalogData[19]));
1360
    le_A_20->setText(QString("%1").arg(AnalogData[20]));
1361
    le_A_21->setText(QString("%1").arg(AnalogData[21]));
1362
    le_A_22->setText(QString("%1").arg(AnalogData[22]));
1363
    le_A_23->setText(QString("%1").arg(AnalogData[23]));
1364
    le_A_24->setText(QString("%1").arg(AnalogData[24]));
1365
    le_A_25->setText(QString("%1").arg(AnalogData[25]));
1366
    le_A_26->setText(QString("%1").arg(AnalogData[26]));
1367
    le_A_27->setText(QString("%1").arg(AnalogData[27]));
1368
    le_A_28->setText(QString("%1").arg(AnalogData[28]));
1369
    le_A_29->setText(QString("%1").arg(AnalogData[29]));
1370
    le_A_30->setText(QString("%1").arg(AnalogData[30]));
1371
    le_A_31->setText(QString("%1").arg(AnalogData[31]));
227 KeyOz 1372
 
1373
    if ((Mode.ID == ADDRESS_FC) && (FCSettings[P_GYRO_ACC_FAKTOR] > 0))
1374
    {
1375
        bar_UBAT->setValue(AnalogData[9]);
1376
        bar_RX->setValue(AnalogData[10]);
1377
 
1378
        Compass->setValue(AnalogData[8]);
1379
 
1380
        int Roll = (AnalogData[1] * FCSettings[P_GYRO_ACC_FAKTOR]) / 1024;
1381
        int Nick = (AnalogData[0] * FCSettings[P_GYRO_ACC_FAKTOR]) / 1024;
1382
 
1383
        if (Roll > 128)
1384
            Roll = Roll - 255;
1385
 
1386
        if (Nick > 128)
1387
            Nick = Nick - 255;
1388
 
1389
        Attitude->setAngle(Roll);
1390
        Attitude->setGradient(double(double(Nick) / 100.0));
1391
    }
158 KeyOz 1392
}
1393
 
199 KeyOz 1394
void MKTool::new_NaviData(sRxData RX)
1395
{
306 KeyOz 1396
//    qDebug("Navi-Data");
1397
 
391 Brean 1398
    switch(RX.decode[N_NC_FLAGS])
306 KeyOz 1399
    {
358 KeyOz 1400
        case 0x01 : lb_Mode->setText(tr("Free")); break;
1401
        case 0x02 : lb_Mode->setText(tr("Position Hold")); break;
1402
        case 0x04 : lb_Mode->setText(tr("Coming Home")); break;
1403
        case 0x08 : lb_Mode->setText(tr("Range Limit")); break;
1404
        case 0x10 : lb_Mode->setText(tr("Serial Error")); break;
1405
        case 0x20 : lb_Mode->setText(tr("Target reached")); break;
1406
        case 0x40 : lb_Mode->setText(tr("Manual Control")); break;
306 KeyOz 1407
    }
1408
 
391 Brean 1409
    Navi.Current.Longitude = Parser::dataToLong(RX.decode, N_CUR_LONGITUDE, true);
1410
    Navi.Current.Latitude  = Parser::dataToLong(RX.decode, N_CUR_LATITUDE,  true);
1411
    Navi.Current.Altitude  = Parser::dataToLong(RX.decode, N_CUR_ALTITUDE,  true);
1412
    Navi.Target.Longitude  = Parser::dataToLong(RX.decode, N_TAR_LONGITUDE, true);
1413
    Navi.Target.Latitude   = Parser::dataToLong(RX.decode, N_TAR_LATITUDE,  true);
1414
    Navi.Target.Altitude   = Parser::dataToLong(RX.decode, N_TAR_ALTITUDE,  true);
199 KeyOz 1415
 
391 Brean 1416
    le_CDistance->setText(QString("%1 cm").arg(Parser::dataToInt(RX.decode, N_HOME_DISTANCE)));
1417
    le_CWPA->setText(QString("%1").arg(RX.decode[N_WP_INDEX]));
1418
    le_CWPT->setText(QString("%1").arg(RX.decode[N_WP_NUMBER]));
1419
    le_CSats->setText(QString("%1").arg(RX.decode[N_SATS_IN_USER]));
227 KeyOz 1420
 
391 Brean 1421
    qwt_Rate->setValue(double(Parser::dataToInt(RX.decode, N_VARIOMETER, true)));
227 KeyOz 1422
 
391 Brean 1423
    le_CTime->setText(QString("%1 sec.").arg(Parser::dataToInt(RX.decode, N_FLYING_TIME)));
227 KeyOz 1424
 
391 Brean 1425
    bar_UBAT->setValue(RX.decode[N_UBAT]);
227 KeyOz 1426
 
391 Brean 1427
    double Speed = double((Parser::dataToLong(RX.decode, N_GROUND_SPEED)) / 10.0);
227 KeyOz 1428
 
1429
    if ((Speed > 4.5) && SpeedMeter->property("END") == 5)
1430
    {
1431
        SpeedMeter->setRange(0.0, 10.0);
1432
        SpeedMeter->setScale(1, 2, 1);
1433
        SpeedMeter->setProperty("END", 10);
1434
    }
1435
 
1436
    if ((Speed > 9) && SpeedMeter->property("END") == 10)
1437
    {
1438
        SpeedMeter->setRange(0.0, 20.0);
1439
        SpeedMeter->setScale(1, 2, 2);
1440
        SpeedMeter->setProperty("END", 20);
1441
    }
1442
 
1443
    SpeedMeter->setValue(Speed);
1444
 
391 Brean 1445
    Compass->setValue(Parser::dataToInt(RX.decode, N_COMAPSS_HEADING)); //(68)
227 KeyOz 1446
 
391 Brean 1447
    bar_RX->setValue(RX.decode[N_RC_QUALITY]);
227 KeyOz 1448
 
391 Brean 1449
    int Nick = RX.decode[N_ANGLE_NICK];
1450
    int Roll = RX.decode[N_ANGLE_ROLL];
227 KeyOz 1451
 
1452
    if (Roll > 128)
1453
        Roll = Roll - 255;
1454
 
1455
    if (Nick > 128)
1456
        Nick = Nick - 255;
1457
 
1458
    Attitude->setAngle(Roll);
234 KeyOz 1459
    Attitude->setGradient(double(0.0 - (double(Nick) / 100.0)));
227 KeyOz 1460
 
199 KeyOz 1461
    sNaviString NaviString;
1462
 
391 Brean 1463
    NaviString.Longitude = Parser::getFloat(Navi.Current.Longitude,7);
1464
    NaviString.Latitude  = Parser::getFloat(Navi.Current.Latitude,7);
1465
    NaviString.Altitude  = Parser::getFloat(Navi.Current.Altitude,3);
199 KeyOz 1466
 
391 Brean 1467
    le_CurLong->setText(QString::number(NaviString.Longitude));
1468
    le_CurLat->setText(QString::number(NaviString.Latitude));
199 KeyOz 1469
 
306 KeyOz 1470
    KML_Server->store_NaviString(NaviString);
1471
 
391 Brean 1472
    f_Map->add_Position(NaviString.Longitude, NaviString.Latitude);
305 KeyOz 1473
 
272 KeyOz 1474
    if ((QMK_Server->property("Connect")) == true)
227 KeyOz 1475
    {
272 KeyOz 1476
//        qDebug("Send Data to Server..!!");
1477
        QMK_Server->NewPosition(NaviString);
227 KeyOz 1478
    }
199 KeyOz 1479
}
1480
 
272 KeyOz 1481
// Kopter-Kommunikations-Bereich, Befehle senden und Daten empfangen
1482
////////////////////////////////////////////////////////////////////
158 KeyOz 1483
 
1484
// Neues Datenpacket empfangen -> Verarbeiten
250 KeyOz 1485
void MKTool::slot_newData(sRxData RX) // DONE 0.71g
158 KeyOz 1486
{
393 Brean 1487
    //handler->receiveData(RX)
162 KeyOz 1488
 
272 KeyOz 1489
    // TODO: Roh-Daten senden zum QMK-Server dazu Sendebuffer bauen.
1490
    if ((QMK_Server->property("Connect")) == true)
1491
    {
1492
//        QMK_Server->send_RawData(RX.String);
1493
    }
1494
 
393 Brean 1495
    slot_showTerminal(1, QString(RX.str.c_str()));
158 KeyOz 1496
}
1497
 
250 KeyOz 1498
void MKTool::slot_showTerminal(int Typ, QString Text)
158 KeyOz 1499
{
250 KeyOz 1500
    switch(Typ)
158 KeyOz 1501
    {
250 KeyOz 1502
        case 1 :
158 KeyOz 1503
        {
250 KeyOz 1504
            if ((cb_ShowData->isChecked()) && ((tab_Main->currentWidget()->objectName() == QString("Tab_3")) || (cb_ShowAlways->isChecked())))
158 KeyOz 1505
            {
250 KeyOz 1506
                te_RX->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1507
                te_RX->insertHtml("<span style=\"color:#00008b;\">" + Text + "<br /></span>");
158 KeyOz 1508
            }
250 KeyOz 1509
        }
1510
        break;
1511
        case 2 :
1512
        {
1513
            if ((cb_ShowMSG->isChecked()) && ((tab_Main->currentWidget()->objectName() == QString("Tab_3")) || (cb_ShowAlways->isChecked())))
158 KeyOz 1514
            {
307 KeyOz 1515
                if (Text.length() > 0)
1516
                {
1517
                    te_RX->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1518
                    te_RX->insertHtml("<span style=\"color:#008b00;\">" + Text + "</span><br />");
1519
                }
158 KeyOz 1520
            }
1521
        }
250 KeyOz 1522
        break;
1523
        case 3 :
158 KeyOz 1524
        {
250 KeyOz 1525
            if (cb_ShowSend->isChecked())
158 KeyOz 1526
            {
250 KeyOz 1527
                te_RX->moveCursor(QTextCursor::End,  QTextCursor::MoveAnchor);
1528
                te_RX->insertHtml("<span style='color:#8b0000;'>" + Text + "<br /></span>");
158 KeyOz 1529
            }
1530
        }
250 KeyOz 1531
        break;
158 KeyOz 1532
    }
1533
}
1534
 
272 KeyOz 1535
// Verbindung zum Kopter herstellen / Trennen
158 KeyOz 1536
void MKTool::slot_OpenPort()
1537
{
396 Brean 1538
//FIXME: Put this in com/QTCommunication.cpp
1539
/*
306 KeyOz 1540
    if (o_Connection->isOpen())
250 KeyOz 1541
    {
199 KeyOz 1542
        TX_Data[0] = Settings->Data.Debug_Off / 10;
306 KeyOz 1543
        o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
391 Brean 1544
        ToolBox::wait(SLEEP);
158 KeyOz 1545
 
199 KeyOz 1546
        if (Mode.ID == ADDRESS_NC)
1547
        {
1548
            TX_Data[0] = Settings->Data.Navi_Off / 10;
306 KeyOz 1549
            o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false);
391 Brean 1550
            ToolBox::wait(SLEEP);
199 KeyOz 1551
        }
1552
 
272 KeyOz 1553
        if (Mode.ID == ADDRESS_FC)
199 KeyOz 1554
        {
1555
            TX_Data[0] = 0;
1556
            TX_Data[1] = 0;
1557
            TX_Data[2] = 0;
1558
            TX_Data[3] = 0;
306 KeyOz 1559
            o_Connection->send_Cmd('t', ADDRESS_FC, TX_Data, 4, false);
391 Brean 1560
            ToolBox::wait(SLEEP);
199 KeyOz 1561
        }
250 KeyOz 1562
 
306 KeyOz 1563
        o_Connection->Close();
250 KeyOz 1564
 
358 KeyOz 1565
        ac_ConnectTTY->setText(tr("Kopter Verbinden"));
199 KeyOz 1566
        le_Port->setEnabled(true);
1567
 
167 KeyOz 1568
        Ticker->stop();
158 KeyOz 1569
    }
1570
    else
1571
    {
263 KeyOz 1572
        int i_Type;
1573
        if (le_Port->text().contains(QString("IP:")))
158 KeyOz 1574
        {
263 KeyOz 1575
            i_Type = C_IP;
1576
        }
1577
        else
1578
        {
1579
            i_Type = C_TTY;
1580
        }
1581
 
306 KeyOz 1582
        if (o_Connection->Open(i_Type, le_Port->text()))
263 KeyOz 1583
        {
358 KeyOz 1584
            ac_ConnectTTY->setText(tr("Kopter Trennen"));
199 KeyOz 1585
            le_Port->setEnabled(false);
158 KeyOz 1586
 
306 KeyOz 1587
            o_Connection->send_Cmd('v', ADDRESS_ALL, TX_Data, 0, true);
159 KeyOz 1588
 
167 KeyOz 1589
            Ticker->start(2000);
158 KeyOz 1590
        }
1591
    }
396 Brean 1592
*/
158 KeyOz 1593
}
1594
 
1595
// Programm beenden
1596
///////////////////
162 KeyOz 1597
 
1598
MKTool::~MKTool()
158 KeyOz 1599
{
396 Brean 1600
//FIXME: Put this in com/QTCommunication.cpp
1601
/*
306 KeyOz 1602
    if (o_Connection->isOpen())
158 KeyOz 1603
    {
306 KeyOz 1604
        o_Connection->Close();
158 KeyOz 1605
    }
396 Brean 1606
*/
167 KeyOz 1607
    set_Preferences();
162 KeyOz 1608
    Settings->write_Settings();
158 KeyOz 1609
 
239 Brean 1610
    logger->close();
158 KeyOz 1611
}