Subversion Repositories Projects

Rev

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

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