Subversion Repositories Projects

Rev

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