Subversion Repositories Projects

Rev

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