Subversion Repositories Projects

Rev

Rev 711 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 711 Rev 750
1
/***************************************************************************
1
/***************************************************************************
2
 *   Copyright (C) 2009 by Manuel Schrape                                  *
2
 *   Copyright (C) 2009 by Manuel Schrape                                  *
3
 *   manuel.schrape@gmx.de                                                 *
3
 *   manuel.schrape@gmx.de                                                 *
4
 *                                                                         *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
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  *
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.        *
7
 *   the Free Software Foundation; either version 2 of the License.        *
8
 *                                                                         *
8
 *                                                                         *
9
 *   This program is distributed in the hope that it will be useful,       *
9
 *   This program is distributed in the hope that it will be useful,       *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU General Public License for more details.                          *
12
 *   GNU General Public License for more details.                          *
13
 *                                                                         *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
18
 ***************************************************************************/
19
 
19
 
20
#include <QMessageBox>
20
#include <QMessageBox>
21
#include <QCryptographicHash>
21
#include <QCryptographicHash>
22
 
22
 
23
#include "dlg_Main.h"
23
#include "dlg_Main.h"
24
 
24
 
25
// Konstruktor Main-Form
25
// Konstruktor Main-Form
26
dlg_Main::dlg_Main()
26
dlg_Main::dlg_Main()
27
{
27
{
28
    setupUi(this);
28
    setupUi(this);
-
 
29
 
29
 
30
 
30
    o_Settings = new cSettings();
31
    o_Settings = new cSettings();
31
 
32
 
32
    o_Settings->read_DebugLabels(0);
33
    o_Settings->read_DebugLabels(0);
33
 
34
 
34
    o_Input = new Input();
35
    wg_Connection->set_Client(ID_SCOPE, QA_NAME + " " + QA_VERSION, DataFields);
35
 
36
 
36
    init_GUI();
37
    init_GUI();
37
    init_Connections();
38
    init_Connections();
38
    init_Plotter();
39
    init_Plotter();
39
}
40
}
40
 
41
 
41
// Grafische Oberfläche initialisieren
42
// Grafische Oberfläche initialisieren
42
void dlg_Main::init_GUI()
43
void dlg_Main::init_GUI()
43
{
44
{
44
    setWindowTitle(QA_NAME + " " + QA_VERSION);
45
    setWindowTitle(QA_NAME + " " + QA_VERSION);
45
 
46
 
46
    resize(o_Settings->GUI.Size);
47
    resize(o_Settings->GUI.Size);
47
    move(o_Settings->GUI.Point);
48
    move(o_Settings->GUI.Point);
48
 
49
 
49
    if (o_Settings->GUI.isMax)
50
    if (o_Settings->GUI.isMax)
50
    {
51
    {
51
        showMaximized();
52
        showMaximized();
52
    }
53
    }
53
 
-
 
54
    for(int z = 0; z < o_Settings->SERVER.IP_MAX; z++)
-
 
55
    {
-
 
56
        if (cb_Server->findText(o_Settings->SERVER.IP[z]) == -1)
-
 
57
        {
-
 
58
            cb_Server->addItem(o_Settings->SERVER.IP[z]);
-
 
59
        }
-
 
60
    }
-
 
61
 
-
 
62
    cb_Server->setCurrentIndex(o_Settings->SERVER.IP_ID);
-
 
63
 
54
 
64
    le_Password->setText(o_Settings->SERVER.Password);
-
 
65
 
55
    wg_Connection->set_SelectVisible(false);
66
    sb_Intervall->setValue(o_Settings->DATA.Debug_Intervall);
56
    wg_Connection->set_ButtonVisible(false);
67
 
57
 
68
    btn_Start->setCheckable(true);
58
    btn_Start->setCheckable(true);
69
 
59
 
70
    ac_Plotter->setChecked(true);
60
    ac_Plotter->setChecked(true);
71
 
61
 
72
    Font_1.setFamily(QString::fromUtf8("Adobe Courier"));
62
    Font_1.setFamily(QString::fromUtf8("Adobe Courier"));
73
    Font_1.setBold(true);
63
    Font_1.setBold(true);
74
    Font_1.setWeight(75);
64
    Font_1.setWeight(75);
75
 
65
 
76
    for(int z = 0; z < MAX_DebugData; z++)
66
    for(int z = 0; z < MAX_DebugData; z++)
77
    {
67
    {
78
 
68
 
79
        lb_Debug[z] = new QLabel(wg_Debug);
69
        lb_Debug[z] = new QLabel(wg_Debug);
80
        le_Debug[z] = new QLineEdit(wg_Debug);
70
        le_Debug[z] = new QLineEdit(wg_Debug);
81
        cb_Debug[z] = new QCheckBox(wg_Config);
71
        cb_Debug[z] = new QCheckBox(wg_Config);
82
        le_Debug[z]->setFont(Font_1);
72
        le_Debug[z]->setFont(Font_1);
83
        le_Debug[z]->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
73
        le_Debug[z]->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
84
        le_Debug[z]->setReadOnly(true);
74
        le_Debug[z]->setReadOnly(true);
85
 
75
 
86
        wg_Grid->addWidget(lb_Debug[z], (z % 8), z / 8 * 2, 0);
76
        wg_Grid->addWidget(lb_Debug[z], (z % 8), z / 8 * 2, 0);
87
        wg_Grid->addWidget(le_Debug[z], (z % 8), z / 8 * 2 + 1 , 0);
77
        wg_Grid->addWidget(le_Debug[z], (z % 8), z / 8 * 2 + 1 , 0);
88
 
78
 
89
        wg_Grid_2->addWidget(cb_Debug[z], (z % 8), z / 8, 0);
79
        wg_Grid_2->addWidget(cb_Debug[z], (z % 8), z / 8, 0);
90
 
80
 
91
        lb_Debug[z]->setText(o_Settings->DebugData.Label[z]);
81
        lb_Debug[z]->setText(o_Settings->DebugData.Label[z]);
92
        cb_Debug[z]->setText(o_Settings->DebugData.Label[z]);
82
        cb_Debug[z]->setText(o_Settings->DebugData.Label[z]);
93
 
83
 
94
        cb_Debug[z]->setChecked(o_Settings->DebugData.Show_Plotter[z]);
84
        cb_Debug[z]->setChecked(o_Settings->DebugData.Show_Plotter[z]);
95
    }
85
    }
96
}
86
}
97
 
87
 
98
// Signale mit Slots verbinden
88
// Signale mit Slots verbinden
99
void dlg_Main::init_Connections()
89
void dlg_Main::init_Connections()
100
{
90
{
101
    connect(sb_Intervall, SIGNAL(valueChanged(int)), this, SLOT(slot_sb_Intervall(int)));
91
    connect(ac_Connect, SIGNAL(triggered()), wg_Connection, SLOT(slot_btn_Connect()));
102
 
-
 
103
    connect(ac_Connect, SIGNAL(triggered()), this, SLOT(slot_ac_Connect()));
92
 
104
    connect(ac_Plotter, SIGNAL(triggered()), this, SLOT(slot_ac_Plotter()));
93
    connect(ac_Plotter, SIGNAL(triggered()), this, SLOT(slot_ac_Plotter()));
105
    connect(ac_Debug,   SIGNAL(triggered()), this, SLOT(slot_ac_Debug()));
94
    connect(ac_Debug,   SIGNAL(triggered()), this, SLOT(slot_ac_Debug()));
106
    connect(ac_Chose,   SIGNAL(triggered()), this, SLOT(slot_ac_Chose()));
95
    connect(ac_Chose,   SIGNAL(triggered()), this, SLOT(slot_ac_Chose()));
107
 
96
 
108
    connect(ac_ReadLabels, SIGNAL(triggered()), this, SLOT(slot_ac_ReadLabels()));
97
    connect(ac_ReadLabels, SIGNAL(triggered()), this, SLOT(slot_ac_ReadLabels()));
109
 
-
 
110
    connect(rb_NC,      SIGNAL(clicked()), this, SLOT(slot_rb_Hardware()));
-
 
111
    connect(rb_FC,      SIGNAL(clicked()), this, SLOT(slot_rb_Hardware()));
-
 
112
    connect(rb_MK3MAG,  SIGNAL(clicked()), this, SLOT(slot_rb_Hardware()));
-
 
113
 
98
 
114
    connect(Plotter_Scroll, SIGNAL(valueChanged(int)), this, SLOT(slot_Plotter_Scroll(int)));
99
    connect(Plotter_Scroll, SIGNAL(valueChanged(int)), this, SLOT(slot_Plotter_Scroll(int)));
115
 
100
 
116
    connect(btn_Start, SIGNAL(clicked()), this, SLOT(slot_Plotter_Start()));
101
    connect(btn_Start, SIGNAL(clicked()), this, SLOT(slot_Plotter_Start()));
117
    connect(btn_ChoseOK, SIGNAL(clicked()), this, SLOT(slot_btn_ChoseOK()));
102
    connect(btn_ChoseOK, SIGNAL(clicked()), this, SLOT(slot_btn_ChoseOK()));
118
 
103
 
119
    // About QMK-Kernel & About-QT Dialog einfügen
104
    // About QMK-Kernel & About-QT Dialog einfügen
120
    connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About()));
105
    connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About()));
121
    menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt()));
106
    menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt()));
-
 
107
 
-
 
108
    connect(wg_Connection, SIGNAL(sig_Status(int)), this, SLOT(slot_ConnectionStatus(int)));
-
 
109
    connect(wg_Connection, SIGNAL(sig_MK_Version(s_Hardware)), this, SLOT(slot_MK_Version(s_Hardware)));
-
 
110
    connect(wg_Connection, SIGNAL(sig_MK_Debug(s_MK_Debug)), this, SLOT(slot_MK_Debug(s_MK_Debug)));
-
 
111
    connect(wg_Connection, SIGNAL(sig_MK_DebugLabels(s_MK_DebugLabels)), this, SLOT(slot_MK_DebugLabels(s_MK_DebugLabels)));
122
}
112
}
123
 
113
 
124
void dlg_Main::init_Plotter()
114
void dlg_Main::init_Plotter()
125
{
115
{
126
    NextPlot = 0;
116
    NextPlot = 0;
127
 
117
 
128
    qwt_Plotter->setCanvasBackground(QColor(QRgb(0x00000000)));
118
    qwt_Plotter->setCanvasBackground(QColor(QRgb(0x00000000)));
129
 
119
 
130
    qwt_Plotter->insertLegend(new QwtLegend(), QwtPlot::RightLegend);
120
    qwt_Plotter->insertLegend(new QwtLegend(), QwtPlot::RightLegend);
131
 
121
 
132
    QwtPlotGrid *Grid = new QwtPlotGrid();
122
    QwtPlotGrid *Grid = new QwtPlotGrid();
133
    Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
123
    Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
134
 
124
 
135
    Grid->attach(qwt_Plotter);
125
    Grid->attach(qwt_Plotter);
136
 
126
 
137
    qwt_Plotter->setAxisScale(QwtPlot::xBottom,0,o_Settings->DATA.Plotter_Count,0);
127
    qwt_Plotter->setAxisScale(QwtPlot::xBottom,0,o_Settings->DATA.Plotter_Count,0);
138
 
128
 
139
    for (int a = 0; a < MAX_DebugData; a++)
129
    for (int a = 0; a < MAX_DebugData; a++)
140
    {
130
    {
141
        Plot[a] = new QwtPlotCurve(o_Settings->DebugData.Label[a]);
131
        Plot[a] = new QwtPlotCurve(o_Settings->DebugData.Label[a]);
142
        Plot[a]->setPen(QPen(QColor(DEF_DebugColors[a])));
132
        Plot[a]->setPen(QPen(QColor(DEF_DebugColors[a])));
143
        Plot[a]->setRenderHint(QwtPlotItem::RenderAntialiased);
133
        Plot[a]->setRenderHint(QwtPlotItem::RenderAntialiased);
144
 
134
 
145
        if (o_Settings->DebugData.Show_Plotter[a])
135
        if (o_Settings->DebugData.Show_Plotter[a])
146
            Plot[a]->attach(qwt_Plotter);
136
            Plot[a]->attach(qwt_Plotter);
147
    }
137
    }
148
    qwt_Plotter->replot();
138
    qwt_Plotter->replot();
149
}
139
}
150
 
140
 
151
void dlg_Main::update_Plotter()
141
void dlg_Main::update_Plotter()
152
{
142
{
153
    pl_ID[NextPlot] = NextPlot;
143
    pl_ID[NextPlot] = NextPlot;
154
 
144
 
155
    for (int a = 0; a < MAX_DebugData; a++)
145
    for (int a = 0; a < MAX_DebugData; a++)
156
    {
146
    {
157
        pl_Data[a][NextPlot] = Debug_Data[a];
147
        pl_Data[a][NextPlot] = Debug_Data[a];
158
        Plot[a]->setData(pl_ID,pl_Data[a],NextPlot);
148
        Plot[a]->setData(pl_ID,pl_Data[a],NextPlot);
159
    }
149
    }
160
 
150
 
161
    NextPlot++;
151
    NextPlot++;
162
 
152
 
163
    if ((NextPlot > o_Settings->DATA.Plotter_Count))
153
    if ((NextPlot > o_Settings->DATA.Plotter_Count))
164
    {
154
    {
165
        Plotter_Scroll->setMaximum(NextPlot - o_Settings->DATA.Plotter_Count);
155
        Plotter_Scroll->setMaximum(NextPlot - o_Settings->DATA.Plotter_Count);
166
    }
156
    }
167
 
157
 
168
    if ((Plotter_Scroll->value() == NextPlot - (o_Settings->DATA.Plotter_Count + 1)))
158
    if ((Plotter_Scroll->value() == NextPlot - (o_Settings->DATA.Plotter_Count + 1)))
169
    {
159
    {
170
        qwt_Plotter->setAxisScale(QwtPlot::xBottom,NextPlot - o_Settings->DATA.Plotter_Count,NextPlot,0);
160
        qwt_Plotter->setAxisScale(QwtPlot::xBottom,NextPlot - o_Settings->DATA.Plotter_Count,NextPlot,0);
171
        Plotter_Scroll->setValue(NextPlot - o_Settings->DATA.Plotter_Count);
161
        Plotter_Scroll->setValue(NextPlot - o_Settings->DATA.Plotter_Count);
172
    }
162
    }
173
 
163
 
174
    qwt_Plotter->replot();
164
    qwt_Plotter->replot();
175
}
165
}
176
 
166
 
177
void dlg_Main::config_Plotter()
167
void dlg_Main::config_Plotter()
178
{
168
{
179
    qwt_Plotter->setAxisScale(QwtPlot::xBottom,0,o_Settings->DATA.Plotter_Count,0);
169
    qwt_Plotter->setAxisScale(QwtPlot::xBottom,0,o_Settings->DATA.Plotter_Count,0);
180
 
170
 
181
    for (int a = 0; a < MAX_DebugData; a++)
171
    for (int a = 0; a < MAX_DebugData; a++)
182
    {
172
    {
183
        Plot[a]->detach();
173
        Plot[a]->detach();
184
        Plot[a]->setPen(QPen(QColor(DEF_DebugColors[a])));
174
        Plot[a]->setPen(QPen(QColor(DEF_DebugColors[a])));
185
 
175
 
186
        if (o_Settings->DebugData.Show_Plotter[a])
176
        if (o_Settings->DebugData.Show_Plotter[a])
187
        {
177
        {
188
            Plot[a]->setTitle(o_Settings->DebugData.Label[a]);
178
            Plot[a]->setTitle(o_Settings->DebugData.Label[a]);
189
            Plot[a]->attach(qwt_Plotter);
179
            Plot[a]->attach(qwt_Plotter);
190
        }
180
        }
191
    }
181
    }
192
    qwt_Plotter->replot();
182
    qwt_Plotter->replot();
193
}
183
}
194
 
184
 
195
void dlg_Main::slot_Plotter_Scroll(int Position)
185
void dlg_Main::slot_Plotter_Scroll(int Position)
196
{
186
{
197
    qwt_Plotter->setAxisScale(QwtPlot::xBottom,Position,Position + o_Settings->DATA.Plotter_Count,0);
187
    qwt_Plotter->setAxisScale(QwtPlot::xBottom,Position,Position + o_Settings->DATA.Plotter_Count,0);
198
    qwt_Plotter->replot();
188
    qwt_Plotter->replot();
199
}
189
}
-
 
190
 
-
 
191
///////////
-
 
192
// Slots //
-
 
193
///////////
200
 
194
 
201
// IP-Input-Daten verarbeiten.
195
// About-Dialog
202
void dlg_Main::parse_IP_Data(QString t_Data)
196
void dlg_Main::slot_ac_About()
203
{
-
 
204
    QStringList Data;
197
{
-
 
198
    QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT);
-
 
199
}
-
 
200
 
205
    Data = t_Data.split(":");
201
void dlg_Main::slot_ConnectionStatus(int li_Status)
206
 
202
{
207
    if (Data.count() > 1)
203
    if (li_Status)
-
 
204
    {
-
 
205
        ac_Connect->setChecked(true);
-
 
206
        ac_Connect->setText(tr("Trennen"));
-
 
207
    }
-
 
208
    else
-
 
209
    {
-
 
210
        ac_Connect->setChecked(false);
-
 
211
        ac_Connect->setText(tr("Verbinden"));
-
 
212
    }
-
 
213
}
-
 
214
 
-
 
215
void dlg_Main::slot_MK_Version(s_Hardware ls_Version)
-
 
216
{
-
 
217
    gs_Version = ls_Version;
-
 
218
    setWindowTitle(QA_NAME + " " + QA_VERSION + " - " + ls_Version.Hardware + " " + ls_Version.Version);
-
 
219
 
-
 
220
    o_Settings->read_DebugLabels(gs_Version.ID);
-
 
221
 
208
    {
222
    if (o_Settings->DebugData.Version != gs_Version.Version)
-
 
223
    {
-
 
224
        qDebug(QString("Debug-Labels unterschiedlich. Neue anforden. " + o_Settings->DebugData.Version + " <> " + gs_Version.Version).toLatin1().data());
-
 
225
        usleep(50000);
-
 
226
 
-
 
227
        slot_ac_ReadLabels();
-
 
228
    }
209
        int CMD = Data[2].toInt();
229
    else
210
 
-
 
211
        switch(CMD)
-
 
212
        {
-
 
213
            case 101 :
-
 
214
            {
-
 
215
                o_Input->send_Data(HandlerIP::make_Frame(ID_SCOPE, 101, QA_NAME + " " + QA_VERSION));
-
 
216
            }
-
 
217
            case 502 :
-
 
218
            {
-
 
219
                switch (Data[3].toInt())
-
 
220
                {
230
    {
221
                    case 105 :
-
 
222
                    {
-
 
223
                        QString s_MD5PW;
-
 
224
                        QByteArray a_MD5PW;
-
 
225
 
231
        for(int z = 0; z < MAX_DebugData; z++)
226
                        a_MD5PW = QCryptographicHash::hash(le_Password->text().toAscii(),QCryptographicHash::Md5);
-
 
227
 
-
 
228
                        s_MD5PW = QString(a_MD5PW.toHex().data());
-
 
229
 
-
 
230
                        o_Input->send_Data(HandlerIP::make_Frame(ID_SCOPE, 105, s_MD5PW));
-
 
231
                    }
-
 
232
                    break;
232
        {
233
                    case 106 :
-
 
234
                    {
-
 
235
                        o_Input->send_Data(HandlerIP::make_Frame(ID_SCOPE, 106, DataFields));
-
 
236
                    }
-
 
237
                    break;
-
 
238
                }
-
 
239
            }
-
 
240
            break;
-
 
241
            case 505 :
-
 
242
            {
-
 
243
                if (Data[3] == "OK")
-
 
244
                {
-
 
245
                }
-
 
246
                else
-
 
247
                {
-
 
248
                    QMessageBox::warning(this, QA_NAME, trUtf8("Authentifizierung fehlgeschlagen. <br />Daten senden zum Mikrokopter nicht möglich."), QMessageBox::Ok);
-
 
249
                }
233
            lb_Debug[z]->setText(o_Settings->DebugData.Label[z]);
-
 
234
            cb_Debug[z]->setText(o_Settings->DebugData.Label[z]);
250
            }
235
            cb_Debug[z]->setChecked(o_Settings->DebugData.Show_Plotter[z]);
251
            break;
236
        }
252
        }
237
        config_Plotter();
253
    }
238
    }
254
}
239
}
255
 
-
 
256
// MK-Eingangsdaten verarbeiten
240
 
257
void dlg_Main::parse_MK_Data(QString t_Data)
241
void dlg_Main::slot_MK_Debug(s_MK_Debug ls_Debug)
258
{
242
{
259
    unsigned char OutData[150];
-
 
260
    char *InData = t_Data.toLatin1().data();
243
    gs_Debug = ls_Debug;
261
 
244
 
-
 
245
    for (int z = 0; z < MAX_DebugData; z++)
262
    if (HandlerMK::Decode_64(InData, t_Data.length(), OutData) != 0)
246
    {
263
    {
247
        Debug_Data[z] = ls_Debug.Analog[z];
264
        switch(InData[2])
-
 
265
        {
-
 
266
            case 'A' : // 0.76e - Debug-Labels
-
 
267
                {
-
 
268
                    o_Input->stop_Resend(DATA_READ_LABEL);
-
 
269
                    int Position = OutData[0];
-
 
270
                    if (Position < 32)
-
 
271
                    {
-
 
272
                        o_Settings->DebugData.Label[Position] = HandlerMK::Data2QString(OutData,1,17).trimmed();
-
 
273
                        if (o_Settings->DebugData.Label[Position] == "")
-
 
274
                        {
-
 
275
                            o_Settings->DebugData.Label[Position] = "Debug-" + QString("%1").arg(Position);
-
 
276
                        }
-
 
277
                        lb_Debug[Position]->setText("" + o_Settings->DebugData.Label[Position]);
-
 
278
                        cb_Debug[Position]->setText("" + o_Settings->DebugData.Label[Position]);
-
 
279
 
-
 
280
                        Position ++;
-
 
281
 
-
 
282
                        if ((Position < 32) && (get_Analoglabels == true))
-
 
283
                        {
-
 
284
                            c_Data[0] = Position;
-
 
285
                            o_Input->send_Data(HandlerMK::make_Frame('a', ADDRESS_ALL, c_Data, 1).toLatin1().data(), DATA_READ_LABEL);
-
 
286
                        }
-
 
287
                    }
-
 
288
                    if (Position == 32)
-
 
289
                    {
-
 
290
                        o_Settings->DebugData.Version = VersionInfo.Version;
-
 
291
                        o_Settings->write_DebugLabels(VersionInfo.ID);
-
 
292
                        config_Plotter();
-
 
293
                        get_Analoglabels = false;
-
 
294
                    }
-
 
295
                }
-
 
296
            break;
-
 
297
 
-
 
298
            case 'D' : // 0.75a - Debug-Daten
-
 
299
                {
-
 
300
                    for (int z = 0; z < MAX_DebugData; z++)
-
 
301
                    {
-
 
302
                        Debug_Data[z] = HandlerMK::Data2Int(OutData, (z * 2) + 2);
-
 
303
                        if (ac_Debug->isChecked())
248
        if (ac_Debug->isChecked())
304
                        {
-
 
305
                            le_Debug[z]->setText(QString("%1").arg(Debug_Data[z]));
-
 
306
                        }
-
 
307
                    }
-
 
308
                    if (btn_Start->isChecked())
-
 
309
                    {
-
 
310
                        update_Plotter();
-
 
311
                    }
-
 
312
                }
-
 
313
            break;
-
 
314
 
-
 
315
            case 'V' : // 0.75a - Versions-Info
-
 
316
                {
-
 
317
                    o_Input->stop_Resend(DATA_VERSION);
-
 
318
                    VersionInfo = HandlerMK::parse_Version(OutData, InData[1] - 'a');
-
 
319
                    setWindowTitle(QA_NAME + " " + QA_VERSION + " - " + VersionInfo.Hardware + " " + VersionInfo.Version);
-
 
320
 
-
 
321
                    if (VersionInfo.ID == ADDRESS_FC)
-
 
322
                    {
-
 
323
                        rb_FC->setChecked(true);
-
 
324
                    }
-
 
325
                    if (VersionInfo.ID == ADDRESS_NC)
-
 
326
                    {
-
 
327
                        rb_NC->setChecked(true);
-
 
328
                    }
-
 
329
                    if (VersionInfo.ID == ADDRESS_MK3MAG)
-
 
330
                    {
-
 
331
                        rb_MK3MAG->setChecked(true);
-
 
332
                    }
-
 
333
 
-
 
334
                    o_Settings->read_DebugLabels(VersionInfo.ID);
-
 
335
 
-
 
336
                    if (o_Settings->DebugData.Version != VersionInfo.Version)
-
 
337
                    {
-
 
338
//                        qDebug(QString("Debug-Labels unterschiedlich. Neue anforden. " + o_Settings->DebugData.Version + " <> " + VersionInfo.Version).toLatin1().data());
-
 
339
 
-
 
340
                        usleep(50000);
-
 
341
 
-
 
342
                        slot_ac_ReadLabels();
-
 
343
//                        o_Input->send_Data(HandlerMK::make_Frame('a', ADDRESS_ALL, c_Data, 1).toLatin1().data());
-
 
344
                    }
-
 
345
                    else
-
 
346
                    {
-
 
347
                        for(int z = 0; z < MAX_DebugData; z++)
-
 
348
                        {
-
 
349
                            lb_Debug[z]->setText(o_Settings->DebugData.Label[z]);
-
 
350
                            cb_Debug[z]->setText(o_Settings->DebugData.Label[z]);
-
 
351
                            cb_Debug[z]->setChecked(o_Settings->DebugData.Show_Plotter[z]);
-
 
352
                        }
-
 
353
                        config_Plotter();
-
 
354
                    }
-
 
355
                    c_Data[0] = sb_Intervall->value() / 10;
-
 
356
                    o_Input->send_Data(HandlerMK::make_Frame('d', ADDRESS_ALL, c_Data, 1).toLatin1().data());
-
 
357
                }
249
        {
358
            break;
250
           le_Debug[z]->setText(QString("%1").arg(Debug_Data[z]));
-
 
251
        }
-
 
252
    }
-
 
253
    if (btn_Start->isChecked())
-
 
254
    {
-
 
255
       update_Plotter();
-
 
256
    }
-
 
257
}
-
 
258
 
-
 
259
void dlg_Main::slot_MK_DebugLabels(s_MK_DebugLabels MK_DebugLabels)
-
 
260
{
-
 
261
    if (MK_DebugLabels.Position < 32)
-
 
262
    {
-
 
263
        o_Settings->DebugData.Label[MK_DebugLabels.Position] = MK_DebugLabels.Text;
-
 
264
        if (o_Settings->DebugData.Label[MK_DebugLabels.Position] == "")
-
 
265
        {
-
 
266
            o_Settings->DebugData.Label[MK_DebugLabels.Position] = "Debug-" + QString("%1").arg(MK_DebugLabels.Position);
-
 
267
        }
-
 
268
        lb_Debug[MK_DebugLabels.Position]->setText("" + o_Settings->DebugData.Label[MK_DebugLabels.Position]);
-
 
269
        cb_Debug[MK_DebugLabels.Position]->setText("" + o_Settings->DebugData.Label[MK_DebugLabels.Position]);
-
 
270
 
-
 
271
    }
-
 
272
    if (MK_DebugLabels.Position == 31)
-
 
273
    {
-
 
274
        o_Settings->DebugData.Version = gs_Version.Version;
-
 
275
        o_Settings->write_DebugLabels(gs_Version.ID);
359
        }
276
        config_Plotter();
360
    }
-
 
361
}
-
 
362
 
-
 
363
///////////
277
    }
364
// Slots //
278
}
365
///////////
279
 
366
void dlg_Main::slot_Plotter_Start()
280
void dlg_Main::slot_Plotter_Start()
367
{
281
{
368
    if (btn_Start->isChecked())
282
    if (btn_Start->isChecked())
369
    {
283
    {
370
        btn_Start->setText(tr("Plotter stoppen"));
284
        btn_Start->setText(tr("Plotter stoppen"));
371
    }
285
    }
372
    else
286
    else
373
    {
287
    {
374
        btn_Start->setText(tr("Plotter starten"));
288
        btn_Start->setText(tr("Plotter starten"));
375
    }
289
    }
376
}
290
}
377
 
291
 
378
void dlg_Main::slot_btn_ChoseOK()
292
void dlg_Main::slot_btn_ChoseOK()
379
{
293
{
380
    for(int z = 0; z < MAX_DebugData; z++)
294
    for(int z = 0; z < MAX_DebugData; z++)
381
    {
295
    {
382
        o_Settings->DebugData.Show_Plotter[z] = cb_Debug[z]->isChecked();
296
        o_Settings->DebugData.Show_Plotter[z] = cb_Debug[z]->isChecked();
383
    }
297
    }
384
    config_Plotter();
298
    config_Plotter();
385
    o_Settings->write_DebugLabels(VersionInfo.ID);
299
    o_Settings->write_DebugLabels(gs_Version.ID);
386
}
300
}
387
 
301
 
388
void dlg_Main::slot_ac_Chose()
302
void dlg_Main::slot_ac_Chose()
389
{
303
{
390
 
-
 
391
    for(int z = 0; z < MAX_DebugData; z++)
304
    for(int z = 0; z < MAX_DebugData; z++)
392
    {
305
    {
393
        cb_Debug[z]->setChecked(o_Settings->DebugData.Show_Plotter[z]);
306
        cb_Debug[z]->setChecked(o_Settings->DebugData.Show_Plotter[z]);
394
    }
307
    }
395
 
308
 
396
    ac_Chose->setChecked(true);
309
    ac_Chose->setChecked(true);
397
    ac_Debug->setChecked(false);
310
    ac_Debug->setChecked(false);
398
    ac_Plotter->setChecked(false);
311
    ac_Plotter->setChecked(false);
399
    wg_Pages->setCurrentIndex(2);
312
    wg_Pages->setCurrentIndex(2);
400
}
313
}
401
 
314
 
402
void dlg_Main::slot_ac_Debug()
315
void dlg_Main::slot_ac_Debug()
403
{
316
{
404
    ac_Debug->setChecked(true);
317
    ac_Debug->setChecked(true);
405
    ac_Chose->setChecked(false);
318
    ac_Chose->setChecked(false);
406
    ac_Plotter->setChecked(false);
319
    ac_Plotter->setChecked(false);
407
    wg_Pages->setCurrentIndex(1);
320
    wg_Pages->setCurrentIndex(1);
408
}
321
}
409
 
322
 
410
void dlg_Main::slot_ac_Plotter()
323
void dlg_Main::slot_ac_Plotter()
411
{
324
{
412
    ac_Plotter->setChecked(true);
325
    ac_Plotter->setChecked(true);
413
    ac_Debug->setChecked(false);
326
    ac_Debug->setChecked(false);
414
    ac_Chose->setChecked(false);
327
    ac_Chose->setChecked(false);
415
    wg_Pages->setCurrentIndex(0);
328
    wg_Pages->setCurrentIndex(0);
416
}
329
}
417
 
330
 
418
void dlg_Main::slot_ac_ReadLabels()
331
void dlg_Main::slot_ac_ReadLabels()
419
{
332
{
420
    get_Analoglabels = true;
-
 
421
    c_Data[0] = 0;
333
    c_Data[0] = 0;
422
    o_Input->send_Data(HandlerMK::make_Frame('a', ADDRESS_ALL, c_Data, 1).toLatin1().data(), DATA_READ_LABEL);
334
    wg_Connection->send_Data(HandlerMK::make_Frame('a', ADDRESS_ALL, c_Data, 1).toLatin1().data(), DATA_READ_LABEL);
423
}
-
 
424
 
-
 
425
// About-Dialog
-
 
426
void dlg_Main::slot_ac_About()
-
 
427
{
-
 
428
    QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT);
-
 
429
}
-
 
430
 
-
 
431
// Datenintervall geändert.
-
 
432
void dlg_Main::slot_sb_Intervall(int t_Intervall)
-
 
433
{
-
 
434
    if (t_Intervall == 0)
-
 
435
    {
-
 
436
        c_Data[0] = 0;
-
 
437
    }
-
 
438
    else
-
 
439
    {
-
 
440
        c_Data[0] = t_Intervall / 10;
-
 
441
    }
-
 
442
    o_Input->send_Data(HandlerMK::make_Frame('d', ADDRESS_ALL, c_Data, 1).toLatin1().data());
-
 
443
}
-
 
444
 
-
 
445
// Hardware auswählen.
-
 
446
void dlg_Main::slot_rb_Hardware()
-
 
447
{
-
 
448
    if ((rb_NC->isChecked() == false) && (VersionInfo.ID != ADDRESS_NC))
-
 
449
    {
-
 
450
        o_Input->send_Data(HandlerMK::get_SelectNC());
-
 
451
    }
-
 
452
 
-
 
453
    if (rb_FC->isChecked())
-
 
454
    {
-
 
455
        o_Input->send_Data(HandlerMK::get_SelectFC());
-
 
456
    }
-
 
457
    else
-
 
458
    if (rb_MK3MAG->isChecked())
-
 
459
    {
-
 
460
        o_Input->send_Data(HandlerMK::get_SelectMK3MAG());
-
 
461
    }
-
 
462
    else
-
 
463
    if (rb_NC->isChecked())
-
 
464
    {
-
 
465
        o_Input->send_Data(HandlerMK::get_SelectNC());
-
 
466
    }
-
 
467
 
-
 
468
    o_Input->send_Data(HandlerMK::make_Frame('v', 0, c_Data, 0).toLatin1().data(), DATA_VERSION);
-
 
469
}
-
 
470
 
-
 
471
// Verbindung zum Server aufbauen
-
 
472
void dlg_Main::slot_ac_Connect()
-
 
473
{
-
 
474
    if (!o_Input->IsOpen())
-
 
475
    {
-
 
476
        if (cb_Server->findText(cb_Server->currentText()) == -1)
-
 
477
        {
-
 
478
            cb_Server->addItem(cb_Server->currentText());
-
 
479
            cb_Server->setCurrentIndex(cb_Server->findText(cb_Server->currentText()));
-
 
480
        }
-
 
481
 
-
 
482
        cb_Server->setEnabled(false);
-
 
483
        le_Password->setEnabled(false);
-
 
484
 
-
 
485
        // Connect über Device
-
 
486
        if (cb_Server->currentText().startsWith('/'))
-
 
487
        {
-
 
488
            o_Input = new Input_TTY();
-
 
489
            o_Input->Init();
-
 
490
 
-
 
491
            set_Input s_Input;
-
 
492
            s_Input.Main = cb_Server->currentText();
-
 
493
 
-
 
494
            if (o_Input->Open(s_Input) == true)
-
 
495
            {
-
 
496
                ac_Connect->setText(tr("Trennen"));
-
 
497
                connect(o_Input, SIGNAL(sig_NewData(QString)), this, SLOT(slot_Input_Data(QString)));
-
 
498
 
-
 
499
                o_Input->send_Data(HandlerMK::make_Frame('v', 0, c_Data, 0).toLatin1().data(), DATA_VERSION);
-
 
500
            }
-
 
501
            else
-
 
502
            {
-
 
503
                cb_Server->setEnabled(true);
-
 
504
                le_Password->setEnabled(true);
-
 
505
            }
-
 
506
 
-
 
507
        }
-
 
508
        else // Connect über TCPIP
-
 
509
        {
-
 
510
            o_Input = new Input_TCP();
-
 
511
            o_Input->Init();
-
 
512
 
-
 
513
            set_Input s_Input;
-
 
514
 
-
 
515
            QStringList Server = cb_Server->currentText().split(":");
-
 
516
 
-
 
517
            s_Input.Main = Server[0];
-
 
518
            s_Input.Sub  = Server[1];
-
 
519
 
-
 
520
            if (o_Input->Open(s_Input) == true)
-
 
521
            {
-
 
522
                connect(o_Input, SIGNAL(sig_Disconnected(int)), this, SLOT(slot_Input_Disconnected(int)));
-
 
523
                connect(o_Input, SIGNAL(sig_Connected()), this, SLOT(slot_Input_Connected()));
-
 
524
            }
-
 
525
        }
-
 
526
    }
-
 
527
    else
-
 
528
    {
-
 
529
        cb_Server->setEnabled(true);
-
 
530
        le_Password->setEnabled(true);
-
 
531
 
-
 
532
        ac_Connect->setText(tr("Verbinden"));
-
 
533
        o_Input->Close();
-
 
534
        disconnect(o_Input, SIGNAL(sig_NewData(QString)), 0, 0);
-
 
535
        if (o_Input->Mode() == TCP)
-
 
536
        {
-
 
537
            disconnect(o_Input, SIGNAL(sig_Disconnected(int)), 0, 0);
-
 
538
            disconnect(o_Input, SIGNAL(sig_Connected()), 0, 0);
-
 
539
        }
-
 
540
    }
-
 
541
}
-
 
542
 
-
 
543
// Neue Daten empfangen.
-
 
544
void dlg_Main::slot_Input_Data(QString t_Data)
-
 
545
{
-
 
546
    if ((t_Data[0] == '#'))
-
 
547
    {
-
 
548
        if ((HandlerMK::Check_CRC(t_Data.toLatin1().data(), t_Data.length() - 1)) || ((o_Input->Mode() == TTY)  && (HandlerMK::Check_CRC(t_Data.toLatin1().data(), t_Data.length()))))
-
 
549
        {
-
 
550
            parse_MK_Data(t_Data);
-
 
551
        }
-
 
552
        else
-
 
553
        {
-
 
554
            qDebug(QString("CRC-Error - " + t_Data).toLatin1().data());
-
 
555
        }
-
 
556
    }
-
 
557
    else if ((o_Input->Mode() == TCP) && (t_Data[0] == '$'))
-
 
558
    {
-
 
559
        parse_IP_Data(t_Data);
-
 
560
    }
-
 
561
}
-
 
562
 
-
 
563
void dlg_Main::slot_Input_Disconnected(int Error)
-
 
564
{
-
 
565
    cb_Server->setEnabled(true);
-
 
566
    le_Password->setEnabled(true);
-
 
567
 
-
 
568
    disconnect(o_Input, SIGNAL(sig_NewData(QString)), 0, 0);
-
 
569
    disconnect(o_Input, SIGNAL(sig_Disconnected(int)), 0, 0);
-
 
570
    disconnect(o_Input, SIGNAL(sig_Connected()), 0, 0);
-
 
571
 
-
 
572
    ac_Connect->setChecked(false);
-
 
573
    ac_Connect->setText(tr("Verbinden"));
-
 
574
 
-
 
575
    switch (Error)
-
 
576
    {
-
 
577
        case REMOTECLOSED :
-
 
578
        {
-
 
579
//            lb_Status->setText(tr("Verbindung vom Server beendet."));
-
 
580
            QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Verbindung wurde vom Server beendet."), QMessageBox::Ok);
-
 
581
        }
-
 
582
        break;
-
 
583
        case REFUSED :
-
 
584
        {
-
 
585
//            lb_Status->setText(tr("Server nicht gefunden."));
-
 
586
            QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Kann nicht zum Server verbinden."), QMessageBox::Ok);
-
 
587
        }
-
 
588
        break;
-
 
589
        case 3 :
-
 
590
        {
-
 
591
//            lb_Status->setText(tr("Serververbindung getrennt. Logindaten falsch."));
-
 
592
            QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Loginname oder Password falsch."), QMessageBox::Ok);
-
 
593
        }
-
 
594
        break;
-
 
595
        default :
-
 
596
        {
-
 
597
//            lb_Status->setText(tr("Getrennt vom QMK-Datenserver."));
-
 
598
        }
-
 
599
        break;
-
 
600
    }
-
 
601
 
-
 
602
}
-
 
603
 
-
 
604
void dlg_Main::slot_Input_Connected()
-
 
605
{
-
 
606
    connect(o_Input, SIGNAL(sig_NewData(QString)), this, SLOT(slot_Input_Data(QString)));
-
 
607
 
-
 
608
//    o_Input->send_Data(HandlerIP::make_Frame(ID_SCOPE, 101, QA_NAME + " " + QA_VERSION));
-
 
609
    o_Input->send_Data(HandlerMK::make_Frame('v', 0, c_Data, 0).toLatin1().data(), DATA_VERSION);
-
 
610
    ac_Connect->setText(tr("Trennen"));
-
 
611
}
335
}
612
 
336
 
613
// Programm Ende
337
// Programm Ende
614
dlg_Main::~dlg_Main()
338
dlg_Main::~dlg_Main()
615
{
339
{
616
    o_Settings->GUI.isMax       = isMaximized();
340
    o_Settings->GUI.isMax       = isMaximized();
617
    o_Settings->GUI.Size        = size();
341
    o_Settings->GUI.Size        = size();
618
    o_Settings->GUI.Point       = pos();
342
    o_Settings->GUI.Point       = pos();
619
 
-
 
620
    o_Settings->DATA.Debug_Intervall = sb_Intervall->value();
-
 
621
 
-
 
622
    o_Settings->SERVER.Password = le_Password->text();
-
 
623
    o_Settings->SERVER.IP_MAX  = cb_Server->count();
-
 
624
    o_Settings->SERVER.IP_ID   = cb_Server->currentIndex();
-
 
625
 
-
 
626
    for (int z = 0; z < cb_Server->count(); z++)
-
 
627
    {
-
 
628
        if (z < 10)
-
 
629
        {
-
 
630
            o_Settings->SERVER.IP[z] = cb_Server->itemText(z);
-
 
631
        }
-
 
632
    }
-
 
633
 
343
 
634
    o_Settings->write_Settings();
-
 
635
 
-
 
636
//    qDebug("Ende.");
344
    o_Settings->write_Settings();
637
}
345
}
638
 
346