Subversion Repositories Projects

Rev

Rev 750 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 750 Rev 801
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 <QSettings>
20
#include <QSettings>
21
#include <QMessageBox>
21
#include <QMessageBox>
22
#include <QCryptographicHash>
22
#include <QCryptographicHash>
23
 
23
 
24
#include "wgt_Connection.h"
24
#include "wgt_Connection.h"
25
 
25
 
26
wgt_Connection::wgt_Connection(QWidget *parent) : QWidget(parent)
26
wgt_Connection::wgt_Connection(QWidget *parent) : QWidget(parent)
27
{
27
{
28
    setupUi(this);
28
    setupUi(this);
29
 
29
 
30
    o_Input = new Input();
30
    o_Input = new Input();
31
 
31
 
32
    o_AboTimer = new QTimer();
32
    o_AboTimer = new QTimer();
33
    o_AboTimer->setInterval(3500);
33
    o_AboTimer->setInterval(3500);
34
 
34
 
35
    connect(btn_Connect, SIGNAL(clicked()), this, SLOT(slot_btn_Connect()));
35
    connect(btn_Connect, SIGNAL(clicked()), this, SLOT(slot_btn_Connect()));
36
    connect(sb_Intervall, SIGNAL(valueChanged(int)), this, SLOT(slot_sb_Intervall(int)));
36
    connect(sb_Intervall, SIGNAL(valueChanged(int)), this, SLOT(slot_sb_Intervall(int)));
37
 
37
 
38
    connect(o_AboTimer, SIGNAL(timeout()), this, SLOT(slot_TimeOut_AboTimer()));
38
    connect(o_AboTimer, SIGNAL(timeout()), this, SLOT(slot_TimeOut_AboTimer()));
39
}
39
}
40
 
40
 
41
void wgt_Connection::read_Settings()
41
void wgt_Connection::read_Settings()
42
{
42
{
43
    QSettings Setting("QMK", "QMK-Connection");
43
    QSettings Setting("QMK", "QMK-Connection");
44
 
44
 
45
    Setting.beginGroup("DATA");
45
    Setting.beginGroup("DATA");
46
        SERVER.Intervall  = Setting.value(QString("Intervall_%1").arg(gi_ID), 500).toInt();
46
        SERVER.Intervall  = Setting.value(QString("Intervall_%1").arg(gi_ID), 500).toInt();
47
    Setting.endGroup();
47
    Setting.endGroup();
48
 
48
 
49
    Setting.beginGroup("SERVER");
49
    Setting.beginGroup("SERVER");
50
        SERVER.Password = Setting.value("Password", QString("")).toString();
50
        SERVER.Password = Setting.value("Password", QString("")).toString();
51
        SERVER.IP_MAX = Setting.value("IP_MAX", 1).toInt();
51
        SERVER.IP_MAX = Setting.value("IP_MAX", 1).toInt();
52
        SERVER.IP_ID  = Setting.value("IP_ID",  0).toInt();
52
        SERVER.IP_ID  = Setting.value("IP_ID",  0).toInt();
53
 
53
 
54
        for (int z = 0; z < SERVER.IP_MAX; z++)
54
        for (int z = 0; z < SERVER.IP_MAX; z++)
55
        {
55
        {
56
            SERVER.IP[z] = Setting.value("IP_" + QString("%1").arg(z), QString("127.0.0.1:64400")).toString();
56
            SERVER.IP[z] = Setting.value("IP_" + QString("%1").arg(z), QString("127.0.0.1:64400")).toString();
57
        }
57
        }
58
    Setting.endGroup();
58
    Setting.endGroup();
59
 
59
 
60
    for(int z = 0; z < SERVER.IP_MAX; z++)
60
    for(int z = 0; z < SERVER.IP_MAX; z++)
61
    {
61
    {
62
        if (cb_Server->findText(SERVER.IP[z]) == -1)
62
        if (cb_Server->findText(SERVER.IP[z]) == -1)
63
        {
63
        {
64
            cb_Server->addItem(SERVER.IP[z]);
64
            cb_Server->addItem(SERVER.IP[z]);
65
        }
65
        }
66
    }
66
    }
67
 
67
 
68
    cb_Server->setCurrentIndex(SERVER.IP_ID);
68
    cb_Server->setCurrentIndex(SERVER.IP_ID);
69
 
69
 
70
    le_Password->setText(SERVER.Password);
70
    le_Password->setText(SERVER.Password);
71
 
71
 
72
    sb_Intervall->setValue(SERVER.Intervall);
72
    sb_Intervall->setValue(SERVER.Intervall);
73
 
73
 
74
}
74
}
75
 
75
 
76
void wgt_Connection::write_Settings()
76
void wgt_Connection::write_Settings()
77
{
77
{
78
    SERVER.Intervall = sb_Intervall->value();
78
    SERVER.Intervall = sb_Intervall->value();
79
 
79
 
80
    SERVER.Password = le_Password->text();
80
    SERVER.Password = le_Password->text();
81
    SERVER.IP_MAX  = cb_Server->count();
81
    SERVER.IP_MAX  = cb_Server->count();
82
    SERVER.IP_ID   = cb_Server->currentIndex();
82
    SERVER.IP_ID   = cb_Server->currentIndex();
83
 
83
 
84
    for (int z = 0; z < cb_Server->count(); z++)
84
    for (int z = 0; z < cb_Server->count(); z++)
85
    {
85
    {
86
        if (z < 10)
86
        if (z < 10)
87
        {
87
        {
88
            SERVER.IP[z] = cb_Server->itemText(z);
88
            SERVER.IP[z] = cb_Server->itemText(z);
89
        }
89
        }
90
    }
90
    }
91
 
91
 
92
    QSettings Setting("QMK", "QMK-Connection");
92
    QSettings Setting("QMK", "QMK-Connection");
93
 
93
 
94
    Setting.beginGroup("DATA");
94
    Setting.beginGroup("DATA");
95
        Setting.setValue(QString("Intervall_%1").arg(gi_ID), SERVER.Intervall);
95
        Setting.setValue(QString("Intervall_%1").arg(gi_ID), SERVER.Intervall);
96
    Setting.endGroup();
96
    Setting.endGroup();
97
 
97
 
98
    Setting.beginGroup("SERVER");
98
    Setting.beginGroup("SERVER");
99
        Setting.setValue("Password", SERVER.Password);
99
        Setting.setValue("Password", SERVER.Password);
100
        Setting.setValue("IP_MAX", SERVER.IP_MAX);
100
        Setting.setValue("IP_MAX", SERVER.IP_MAX);
101
        Setting.setValue("IP_ID",  SERVER.IP_ID);
101
        Setting.setValue("IP_ID",  SERVER.IP_ID);
102
 
102
 
103
        for (int z = 0; z < SERVER.IP_MAX; z++)
103
        for (int z = 0; z < SERVER.IP_MAX; z++)
104
        {
104
        {
105
            Setting.setValue("IP_" + QString("%1").arg(z), SERVER.IP[z]);
105
            Setting.setValue("IP_" + QString("%1").arg(z), SERVER.IP[z]);
106
        }
106
        }
107
    Setting.endGroup();
107
    Setting.endGroup();
108
}
108
}
109
 
109
 
110
void wgt_Connection::set_Client(int li_ID, QString ls_Client, QString ls_Fields)
110
void wgt_Connection::set_Client(int li_ID, QString ls_Client, QString ls_Fields)
111
{
111
{
112
    gi_Interval[0] = false;
112
    gi_Interval[0] = false;
113
    gi_Interval[1] = false;
113
    gi_Interval[1] = false;
114
 
114
 
115
    gs_Client = ls_Client;
115
    gs_Client = ls_Client;
116
    gs_Fields = ls_Fields;
116
    gs_Fields = ls_Fields;
117
    gi_ID     = li_ID;
117
    gi_ID     = li_ID;
118
 
118
 
119
    if (ls_Fields.contains('D'))
119
    if (ls_Fields.contains('D'))
120
        gi_Interval[0] = true;
120
        gi_Interval[0] = true;
121
 
121
 
122
    if (ls_Fields.contains('O'))
122
    if (ls_Fields.contains('O'))
123
        gi_Interval[1] = true;
123
        gi_Interval[1] = true;
124
 
124
 
125
    read_Settings();
125
    read_Settings();
126
}
126
}
127
 
127
 
128
void wgt_Connection::set_SelectVisible(bool pi_Visible)
128
void wgt_Connection::set_SelectVisible(bool pi_Visible)
129
{
129
{
130
    wg_Select->setVisible(pi_Visible);
130
    wg_Select->setVisible(pi_Visible);
131
}
131
}
132
 
132
 
133
void wgt_Connection::set_IntervalVisible(bool pi_Visible)
133
void wgt_Connection::set_IntervalVisible(bool pi_Visible)
134
{
134
{
135
    wg_Interval->setVisible(pi_Visible);
135
    wg_Interval->setVisible(pi_Visible);
136
}
136
}
137
 
137
 
138
void wgt_Connection::set_ButtonVisible(bool pi_Visible)
138
void wgt_Connection::set_ButtonVisible(bool pi_Visible)
139
{
139
{
140
    btn_Connect->setVisible(pi_Visible);
140
    btn_Connect->setVisible(pi_Visible);
141
}
141
}
142
 
142
 
143
void wgt_Connection::send_Data(QString ps_Data, int pi_ID)
143
void wgt_Connection::send_Data(QString ps_Data, int pi_ID)
144
{
144
{
-
 
145
//    qDebug(ps_Data.toLatin1().data());
145
    o_Input->send_Data(ps_Data, pi_ID);
146
    o_Input->send_Data(ps_Data, pi_ID);
146
}
147
}
147
 
148
 
148
// MK-Eingangsdaten verarbeiten
149
// MK-Eingangsdaten verarbeiten
149
void wgt_Connection::parse_MK_Data(QString t_Data)
150
void wgt_Connection::parse_MK_Data(QString t_Data)
150
{
151
{
151
    unsigned char OutData[200];
152
    unsigned char OutData[200];
152
    char *InData = t_Data.toLatin1().data();
153
    char *InData = t_Data.toLatin1().data();
153
 
154
 
154
    if (HandlerMK::Decode_64(InData, t_Data.length(), OutData) != 0)
155
    if (HandlerMK::Decode_64(InData, t_Data.length(), OutData) != 0)
155
    {
156
    {
156
 
157
 
157
        switch(InData[2])
158
        switch(InData[2])
158
        {
159
        {
159
            case 'A' : // Analog-Labels
160
            case 'A' : // Analog-Labels
160
                {
161
                {
161
                    o_Input->stop_Resend(DATA_READ_LABEL);
162
                    o_Input->stop_Resend(DATA_READ_LABEL);
162
 
163
 
163
                    s_MK_DebugLabels MK_DebugLabels;
164
                    s_MK_DebugLabels MK_DebugLabels;
164
 
165
 
165
                    MK_DebugLabels.Position = OutData[0];
166
                    MK_DebugLabels.Position = OutData[0];
166
 
167
 
167
                    if (MK_DebugLabels.Position < 32)
168
                    if (MK_DebugLabels.Position < 32)
168
                    {
169
                    {
169
                        MK_DebugLabels.Text = HandlerMK::Data2QString(OutData,1,17).trimmed();
170
                        MK_DebugLabels.Text = HandlerMK::Data2QString(OutData,1,17).trimmed();
170
                        if (MK_DebugLabels.Text == "")
171
                        if (MK_DebugLabels.Text == "")
171
                        {
172
                        {
172
                            MK_DebugLabels.Text = "Debug-" + QString("%1").arg(MK_DebugLabels.Position);
173
                            MK_DebugLabels.Text = "Debug-" + QString("%1").arg(MK_DebugLabels.Position);
173
                        }
174
                        }
174
 
175
 
175
                        if (((MK_DebugLabels.Position + 1) < 32))// && (get_Analoglabels == true))
176
                        if (((MK_DebugLabels.Position + 1) < 32))// && (get_Analoglabels == true))
176
                        {
177
                        {
177
                            c_Data[0] = MK_DebugLabels.Position + 1;
178
                            c_Data[0] = MK_DebugLabels.Position + 1;
178
                            o_Input->send_Data(HandlerMK::make_Frame('a', ADDRESS_ALL, c_Data, 1).toLatin1().data(), DATA_READ_LABEL);
179
                            o_Input->send_Data(HandlerMK::make_Frame('a', ADDRESS_ALL, c_Data, 1).toLatin1().data(), DATA_READ_LABEL);
179
                        }
180
                        }
180
 
181
 
181
                        emit(sig_MK_DebugLabels(MK_DebugLabels));
182
                        emit(sig_MK_DebugLabels(MK_DebugLabels));
182
                    }
183
                    }
183
                }
184
                }
184
            break;
185
            break;
185
            case 'D' : // Debug-Daten
186
            case 'D' : // Debug-Daten
186
                {
187
                {
187
                    s_MK_Debug MK_Debug;
188
                    s_MK_Debug MK_Debug;
188
 
189
 
189
                    memcpy((unsigned char *)&MK_Debug, (unsigned char *)&OutData, sizeof(MK_Debug));
190
                    memcpy((unsigned char *)&MK_Debug, (unsigned char *)&OutData, sizeof(MK_Debug));
190
 
191
 
191
                    emit(sig_MK_Debug(MK_Debug));
192
                    emit(sig_MK_Debug(MK_Debug));
192
                    emit(sig_RawData(t_Data));
193
                    emit(sig_RawData(t_Data));
193
                }
194
                }
194
            break;
195
            break;
195
            case 'N' : // MotorMixer lesen
196
            case 'N' : // MotorMixer lesen
196
                {
197
                {
197
                    o_Input->stop_Resend(DATA_READ_MIXER);
198
                    o_Input->stop_Resend(DATA_READ_MIXER);
198
 
199
 
199
                    s_MK_Mixer MK_Mixer;
200
                    s_MK_Mixer MK_Mixer;
200
 
201
 
201
                    memcpy((unsigned char *)&MK_Mixer, (unsigned char *)&OutData, sizeof(MK_Mixer));
202
                    memcpy((unsigned char *)&MK_Mixer, (unsigned char *)&OutData, sizeof(MK_Mixer));
202
 
203
 
203
                    emit (sig_MK_ReadMotorMixer(MK_Mixer));
204
                    emit (sig_MK_ReadMotorMixer(MK_Mixer));
204
                }
205
                }
205
            break;
206
            break;
206
            case 'M' : // MotorMixer geschrieben
207
            case 'M' : // MotorMixer geschrieben
207
                {
208
                {
208
                    o_Input->stop_Resend(DATA_WRITE_MIXER);
209
                    o_Input->stop_Resend(DATA_WRITE_MIXER);
209
 
210
 
210
                    emit (sig_MK_WriteMotorMixer(OutData[0]));
211
                    emit (sig_MK_WriteMotorMixer(OutData[0]));
211
                }
212
                }
212
            break;
213
            break;
213
 
214
 
214
            case 'O' : // Navi-OSD-Data
215
            case 'O' : // Navi-OSD-Data
215
                {
216
                {
216
                    if (InData[1] - 'a' == ADDRESS_NC)
217
                    if (InData[1] - 'a' == ADDRESS_NC)
217
                    {
218
                    {
218
                        s_MK_NaviData MK_NaviData;
219
                        s_MK_NaviData MK_NaviData;
219
 
220
 
220
                        memcpy((unsigned char *)&MK_NaviData, (unsigned char *)&OutData, sizeof(MK_NaviData));
221
                        memcpy((unsigned char *)&MK_NaviData, (unsigned char *)&OutData, sizeof(MK_NaviData));
221
                        if (MK_NaviData.Version == MK_VERSION_NAVI)
222
                        if (MK_NaviData.Version == MK_VERSION_NAVI)
222
                        {
223
                        {
223
                            emit(sig_MK_NaviData(MK_NaviData));
224
                            emit(sig_MK_NaviData(MK_NaviData));
224
                            emit(sig_RawData(t_Data));
225
                            emit(sig_RawData(t_Data));
225
                        }
226
                        }
226
                    }
227
                    }
227
                }
228
                }
228
            break;
229
            break;
229
 
230
 
230
            case 'P' : // RC-Kanäle
231
            case 'P' : // RC-Kanäle
231
                {
232
                {
232
                    s_MK_PPM_Data PPM_in;
233
                    s_MK_PPM_Data PPM_in;
233
 
234
 
234
                    memcpy((unsigned char *)&PPM_in, (unsigned char *)&OutData, sizeof(PPM_in));
235
                    memcpy((unsigned char *)&PPM_in, (unsigned char *)&OutData, sizeof(PPM_in));
235
 
236
 
236
//                    qDebug() << PPM_in[0] << ", " << PPM_in[1] << ", " << PPM_in[2] << ", " << PPM_in[3];
237
//                    qDebug() << PPM_in[0] << ", " << PPM_in[1] << ", " << PPM_in[2] << ", " << PPM_in[3];
237
 
238
 
238
                    emit(sig_MK_PPMData(PPM_in));
239
                    emit(sig_MK_PPMData(PPM_in));
239
                }
240
                }
240
            break;
241
            break;
241
 
242
 
242
            case 'Q' : // Settings lesen
243
            case 'Q' : // Settings lesen
243
                {
244
                {
244
                    o_Input->stop_Resend(DATA_READ_SETTINGS);
245
                    o_Input->stop_Resend(DATA_READ_SETTINGS);
245
 
246
 
246
                    s_MK_Settings MK_Set;
247
                    s_MK_Settings MK_Set;
247
 
248
 
248
                    memcpy((unsigned char *)&MK_Set, (unsigned char *)&OutData, sizeof(MK_Set));
249
                    memcpy((unsigned char *)&MK_Set, (unsigned char *)&OutData, sizeof(MK_Set));
249
 
250
 
250
                    emit (sig_MK_ReadSettings(MK_Set));
251
                    emit (sig_MK_ReadSettings(MK_Set));
251
                }
252
                }
252
            break;
253
            break;
253
            case 'S' : // Settings geschrieben
254
            case 'S' : // Settings geschrieben
254
                {
255
                {
255
                    o_Input->stop_Resend(DATA_WRITE_SETTINGS);
256
                    o_Input->stop_Resend(DATA_WRITE_SETTINGS);
256
 
257
 
257
                    emit (sig_MK_WriteSettings(OutData[0]));
258
                    emit (sig_MK_WriteSettings(OutData[0]));
258
                }
259
                }
259
            break;
260
            break;
260
 
261
 
261
            case 'V' : // Versions-Info
262
            case 'V' : // Versions-Info
262
                {
263
                {
263
                    o_Input->stop_Resend(DATA_VERSION);
264
                    o_Input->stop_Resend(DATA_VERSION);
264
                    VersionInfo = HandlerMK::parse_Version(OutData, InData[1] - 'a');
265
                    VersionInfo = HandlerMK::parse_Version(OutData, InData[1] - 'a');
265
 
266
 
266
                    if (VersionInfo.ID == ADDRESS_FC)
267
                    if (VersionInfo.ID == ADDRESS_FC)
267
                    {
268
                    {
268
                        rb_FC->setChecked(true);
269
                        rb_FC->setChecked(true);
269
                    }
270
                    }
270
                    if (VersionInfo.ID == ADDRESS_NC)
271
                    if (VersionInfo.ID == ADDRESS_NC)
271
                    {
272
                    {
272
                        rb_NC->setChecked(true);
273
                        rb_NC->setChecked(true);
273
                    }
274
                    }
274
                    if (VersionInfo.ID == ADDRESS_MK3MAG)
275
                    if (VersionInfo.ID == ADDRESS_MK3MAG)
275
                    {
276
                    {
276
                        rb_MK3MAG->setChecked(true);
277
                        rb_MK3MAG->setChecked(true);
277
                    }
278
                    }
278
 
279
 
279
                    slot_sb_Intervall(sb_Intervall->value());
280
                    slot_sb_Intervall(sb_Intervall->value());
280
 
281
 
281
                    emit sig_MK_Version(VersionInfo);
282
                    emit sig_MK_Version(VersionInfo);
282
                }
283
                }
283
            break;
284
            break;
284
            case 'W' : // WayPoints
285
            case 'W' : // WayPoints
285
                {
286
                {
286
                    o_Input->stop_Resend(DATA_WRITE_WAYPOINT);
287
                    o_Input->stop_Resend(DATA_WRITE_WAYPOINT);
287
 
288
 
288
                    emit(sig_MK_WayPoint(OutData[0]));
289
                    emit(sig_MK_WayPoint(OutData[0]));
289
                }
290
                }
290
            break;
291
            break;
291
        }
292
        }
292
    }
293
    }
293
}
294
}
294
 
295
 
295
// IP-Daten verarbeiten..
296
// IP-Daten verarbeiten..
296
void wgt_Connection::parse_IP_Data(QString t_Data)
297
void wgt_Connection::parse_IP_Data(QString t_Data)
297
{
298
{
298
    QStringList Data;
299
    QStringList Data;
299
    Data = t_Data.split(":");
300
    Data = t_Data.split(":");
300
 
301
 
301
    if (Data.count() > 1)
302
    if (Data.count() > 1)
302
    {
303
    {
303
        int CMD = Data[2].toInt();
304
        int CMD = Data[2].toInt();
304
 
305
 
305
        switch(CMD)
306
        switch(CMD)
306
        {
307
        {
307
            case 101 :
308
            case 101 :
308
            {
309
            {
309
                o_Input->send_Data(HandlerIP::make_Frame(gi_ID, 101, gs_Client));
310
                o_Input->send_Data(HandlerIP::make_Frame(gi_ID, 101, gs_Client));
310
            }
311
            }
311
            break;
312
            break;
312
            case 502 :
313
            case 502 :
313
            {
314
            {
314
                switch (Data[3].toInt())
315
                switch (Data[3].toInt())
315
                {
316
                {
316
                    case 105 :
317
                    case 105 :
317
                    {
318
                    {
318
                        QString s_MD5PW;
319
                        QString s_MD5PW;
319
                        QByteArray a_MD5PW;
320
                        QByteArray a_MD5PW;
320
 
321
 
321
                        a_MD5PW = QCryptographicHash::hash(le_Password->text().toAscii(),QCryptographicHash::Md5);
322
                        a_MD5PW = QCryptographicHash::hash(le_Password->text().toAscii(),QCryptographicHash::Md5);
322
 
323
 
323
                        s_MD5PW = QString(a_MD5PW.toHex().data());
324
                        s_MD5PW = QString(a_MD5PW.toHex().data());
324
 
325
 
325
                        o_Input->send_Data(HandlerIP::make_Frame(gi_ID, 105, s_MD5PW));
326
                        o_Input->send_Data(HandlerIP::make_Frame(gi_ID, 105, s_MD5PW));
326
                    }
327
                    }
327
                    break;
328
                    break;
328
                    case 106 :
329
                    case 106 :
329
                    {
330
                    {
330
                        o_Input->send_Data(HandlerIP::make_Frame(gi_ID, 106, gs_Fields));
331
                        o_Input->send_Data(HandlerIP::make_Frame(gi_ID, 106, gs_Fields));
331
                    }
332
                    }
332
                    break;
333
                    break;
333
                }
334
                }
334
            }
335
            }
335
            break;
336
            break;
336
            case 505 :
337
            case 505 :
337
            {
338
            {
338
                if (Data[3] == "OK")
339
                if (Data[3] == "OK")
339
                {
340
                {
340
                }
341
                }
341
                else
342
                else
342
                {
343
                {
343
                    QMessageBox::warning(this, gs_Client, trUtf8("Authentifizierung fehlgeschlagen. <br />Daten senden zum Mikrokopter nicht möglich."), QMessageBox::Ok);
344
                    QMessageBox::warning(this, gs_Client, trUtf8("Authentifizierung fehlgeschlagen. <br />Daten senden zum Mikrokopter nicht möglich."), QMessageBox::Ok);
344
                }
345
                }
345
            }
346
            }
346
            break;
347
            break;
347
        }
348
        }
348
    }
349
    }
349
}
350
}
350
 
351
 
351
// Datenintervall geändert.
352
// Datenintervall geändert.
352
void wgt_Connection::slot_sb_Intervall(int t_Intervall)
353
void wgt_Connection::slot_sb_Intervall(int t_Intervall)
353
{
354
{
354
    if (t_Intervall == 0)
355
    if (t_Intervall == 0)
355
    {
356
    {
356
        c_Data[0] = 0;
357
        c_Data[0] = 0;
357
    }
358
    }
358
    else
359
    else
359
    {
360
    {
360
        c_Data[0] = t_Intervall / 10;
361
        c_Data[0] = t_Intervall / 10;
361
    }
362
    }
362
 
363
 
363
//    if (wg_Interval->isVisible())
364
//    if (wg_Interval->isVisible())
364
    {
365
    {
365
        if (gi_Interval[0])
366
        if (gi_Interval[0])
366
        {
367
        {
367
           o_Input->send_Data(HandlerMK::make_Frame('d', ADDRESS_ALL, c_Data, 1).toLatin1().data());
368
           o_Input->send_Data(HandlerMK::make_Frame('d', ADDRESS_ALL, c_Data, 1).toLatin1().data());
368
        }
369
        }
369
 
370
 
370
        if (gi_Interval[1])
371
        if (gi_Interval[1])
371
        {
372
        {
372
           o_Input->send_Data(HandlerMK::make_Frame('o', ADDRESS_ALL, c_Data, 1).toLatin1().data());
373
           o_Input->send_Data(HandlerMK::make_Frame('o', ADDRESS_ALL, c_Data, 1).toLatin1().data());
373
        }
374
        }
374
    }
375
    }
375
}
376
}
376
 
377
 
377
void wgt_Connection::slot_send_Data(QString ps_Data, int pi_ID)
378
void wgt_Connection::slot_send_Data(QString ps_Data, int pi_ID)
378
{
379
{
379
    send_Data(ps_Data, pi_ID);
380
    send_Data(ps_Data, pi_ID);
380
}
381
}
381
 
382
 
382
void wgt_Connection::slot_TimeOut_AboTimer()
383
void wgt_Connection::slot_TimeOut_AboTimer()
383
{
384
{
384
//    qDebug("Timer");
385
//    qDebug("Timer");
385
    slot_sb_Intervall(sb_Intervall->value());
386
    slot_sb_Intervall(sb_Intervall->value());
386
}
387
}
387
 
388
 
388
void wgt_Connection::slot_btn_Connect()
389
void wgt_Connection::slot_btn_Connect()
389
{
390
{
390
    if (!o_Input->IsOpen())
391
    if (!o_Input->IsOpen())
391
    {
392
    {
392
        if (cb_Server->findText(cb_Server->currentText()) == -1)
393
        if (cb_Server->findText(cb_Server->currentText()) == -1)
393
        {
394
        {
394
            cb_Server->addItem(cb_Server->currentText());
395
            cb_Server->addItem(cb_Server->currentText());
395
            cb_Server->setCurrentIndex(cb_Server->findText(cb_Server->currentText()));
396
            cb_Server->setCurrentIndex(cb_Server->findText(cb_Server->currentText()));
396
        }
397
        }
397
 
398
 
398
        cb_Server->setEnabled(false);
399
        cb_Server->setEnabled(false);
399
        le_Password->setEnabled(false);
400
        le_Password->setEnabled(false);
400
 
401
 
401
        if (cb_Server->currentText().startsWith('/'))
402
        if (cb_Server->currentText().startsWith('/'))
402
        {
403
        {
403
            o_Input = new Input_TTY();
404
            o_Input = new Input_TTY();
404
            o_Input->Init();
405
            o_Input->Init();
405
 
406
 
406
            set_Input s_Input;
407
            set_Input s_Input;
407
            s_Input.Main = cb_Server->currentText();
408
            s_Input.Main = cb_Server->currentText();
408
 
409
 
409
            if (o_Input->Open(s_Input) == true)
410
            if (o_Input->Open(s_Input) == true)
410
            {
411
            {
411
                emit sig_Status(true);
412
                emit sig_Status(true);
412
                btn_Connect->setChecked(true);
413
                btn_Connect->setChecked(true);
413
                o_AboTimer->start();
414
                o_AboTimer->start();
414
 
415
 
415
                connect(o_Input, SIGNAL(sig_NewData(QString)), this, SLOT(slot_Input_Data(QString)));
416
                connect(o_Input, SIGNAL(sig_NewData(QString)), this, SLOT(slot_Input_Data(QString)));
416
 
417
 
417
                o_Input->send_Data(HandlerMK::make_Frame('v', 0, c_Data, 0).toLatin1().data(), DATA_VERSION);
418
                o_Input->send_Data(HandlerMK::make_Frame('v', 0, c_Data, 0).toLatin1().data(), DATA_VERSION);
418
            }
419
            }
419
            else
420
            else
420
            {
421
            {
421
                cb_Server->setEnabled(true);
422
                cb_Server->setEnabled(true);
422
                le_Password->setEnabled(true);
423
                le_Password->setEnabled(true);
423
            }
424
            }
424
 
425
 
425
        }
426
        }
426
        else
427
        else
427
        {
428
        {
428
            o_Input = new Input_TCP();
429
            o_Input = new Input_TCP();
429
            o_Input->Init();
430
            o_Input->Init();
430
 
431
 
431
            set_Input s_Input;
432
            set_Input s_Input;
432
 
433
 
433
            QStringList Server = cb_Server->currentText().split(":");
434
            QStringList Server = cb_Server->currentText().split(":");
434
 
435
 
435
            s_Input.Main = Server[0];
436
            s_Input.Main = Server[0];
436
            s_Input.Sub  = Server[1];
437
            s_Input.Sub  = Server[1];
437
 
438
 
438
            if (o_Input->Open(s_Input) == true)
439
            if (o_Input->Open(s_Input) == true)
439
            {
440
            {
440
                connect(o_Input, SIGNAL(sig_Disconnected(int)), this, SLOT(slot_Input_Disconnected(int)));
441
                connect(o_Input, SIGNAL(sig_Disconnected(int)), this, SLOT(slot_Input_Disconnected(int)));
441
                connect(o_Input, SIGNAL(sig_Connected()), this, SLOT(slot_Input_Connected()));
442
                connect(o_Input, SIGNAL(sig_Connected()), this, SLOT(slot_Input_Connected()));
442
            }
443
            }
443
        }
444
        }
444
    }
445
    }
445
    else
446
    else
446
    {
447
    {
447
        cb_Server->setEnabled(true);
448
        cb_Server->setEnabled(true);
448
        le_Password->setEnabled(true);
449
        le_Password->setEnabled(true);
449
 
450
 
450
        emit sig_Status(false);
451
        emit sig_Status(false);
451
        btn_Connect->setChecked(false);
452
        btn_Connect->setChecked(false);
452
        o_AboTimer->stop();
453
        o_AboTimer->stop();
453
 
454
 
454
        o_Input->Close();
455
        o_Input->Close();
455
        disconnect(o_Input, SIGNAL(sig_NewData(QString)), 0, 0);
456
        disconnect(o_Input, SIGNAL(sig_NewData(QString)), 0, 0);
456
        if (o_Input->Mode() == TCP)
457
        if (o_Input->Mode() == TCP)
457
        {
458
        {
458
            disconnect(o_Input, SIGNAL(sig_Disconnected(int)), 0, 0);
459
            disconnect(o_Input, SIGNAL(sig_Disconnected(int)), 0, 0);
459
            disconnect(o_Input, SIGNAL(sig_Connected()), 0, 0);
460
            disconnect(o_Input, SIGNAL(sig_Connected()), 0, 0);
460
        }
461
        }
461
    }
462
    }
462
}
463
}
463
 
464
 
464
// Neue Daten empfangen.
465
// Neue Daten empfangen.
465
void wgt_Connection::slot_Input_Data(QString t_Data)
466
void wgt_Connection::slot_Input_Data(QString t_Data)
466
{
467
{
467
    if ((t_Data[0] == '#'))
468
    if ((t_Data[0] == '#'))
468
    {
469
    {
469
        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()))))
470
        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()))))
470
        {
471
        {
471
            parse_MK_Data(t_Data);
472
            parse_MK_Data(t_Data);
472
        }
473
        }
473
        else
474
        else
474
        {
475
        {
475
//            qDebug(QString("CRC-Error - " + t_Data).toLatin1().data());
476
//            qDebug(QString("CRC-Error - " + t_Data).toLatin1().data());
476
        }
477
        }
477
    }
478
    }
478
    else if ((o_Input->Mode() == TCP) && (t_Data[0] == '$'))
479
    else if ((o_Input->Mode() == TCP) && (t_Data[0] == '$'))
479
    {
480
    {
480
        parse_IP_Data(t_Data);
481
        parse_IP_Data(t_Data);
481
    }
482
    }
482
}
483
}
483
 
484
 
484
// Neue Serververbindung.
485
// Neue Serververbindung.
485
void wgt_Connection::slot_Input_Connected()
486
void wgt_Connection::slot_Input_Connected()
486
{
487
{
487
    connect(o_Input, SIGNAL(sig_NewData(QString)), this, SLOT(slot_Input_Data(QString)));
488
    connect(o_Input, SIGNAL(sig_NewData(QString)), this, SLOT(slot_Input_Data(QString)));
488
 
489
 
489
    o_Input->send_Data(HandlerMK::make_Frame('v', 0, c_Data, 0).toLatin1().data(), DATA_VERSION);
490
    o_Input->send_Data(HandlerMK::make_Frame('v', 0, c_Data, 0).toLatin1().data(), DATA_VERSION);
490
    emit sig_Status(true);
491
    emit sig_Status(true);
491
    btn_Connect->setChecked(true);
492
    btn_Connect->setChecked(true);
492
    o_AboTimer->start();
493
    o_AboTimer->start();
493
}
494
}
494
 
495
 
495
// Serververbindung beendet
496
// Serververbindung beendet
496
void wgt_Connection::slot_Input_Disconnected(int Error)
497
void wgt_Connection::slot_Input_Disconnected(int Error)
497
{
498
{
498
    cb_Server->setEnabled(true);
499
    cb_Server->setEnabled(true);
499
    le_Password->setEnabled(true);
500
    le_Password->setEnabled(true);
500
 
501
 
501
    disconnect(o_Input, SIGNAL(sig_NewData(QString)), 0, 0);
502
    disconnect(o_Input, SIGNAL(sig_NewData(QString)), 0, 0);
502
    disconnect(o_Input, SIGNAL(sig_Disconnected(int)), 0, 0);
503
    disconnect(o_Input, SIGNAL(sig_Disconnected(int)), 0, 0);
503
    disconnect(o_Input, SIGNAL(sig_Connected()), 0, 0);
504
    disconnect(o_Input, SIGNAL(sig_Connected()), 0, 0);
504
 
505
 
505
    emit sig_Status(false);
506
    emit sig_Status(false);
506
    btn_Connect->setChecked(false);
507
    btn_Connect->setChecked(false);
507
    o_AboTimer->stop();
508
    o_AboTimer->stop();
508
 
509
 
509
    switch (Error)
510
    switch (Error)
510
    {
511
    {
511
        case REMOTECLOSED :
512
        case REMOTECLOSED :
512
        {
513
        {
513
//            lb_Status->setText(tr("Verbindung vom Server beendet."));
514
//            lb_Status->setText(tr("Verbindung vom Server beendet."));
514
            QMessageBox::warning(this, gs_Client,tr("QMK-Datenserver: Verbindung wurde vom Server beendet."), QMessageBox::Ok);
515
            QMessageBox::warning(this, gs_Client,tr("QMK-Datenserver: Verbindung wurde vom Server beendet."), QMessageBox::Ok);
515
        }
516
        }
516
        break;
517
        break;
517
        case REFUSED :
518
        case REFUSED :
518
        {
519
        {
519
//            lb_Status->setText(tr("Server nicht gefunden."));
520
//            lb_Status->setText(tr("Server nicht gefunden."));
520
            QMessageBox::warning(this, gs_Client,tr("QMK-Datenserver: Kann nicht zum Server verbinden."), QMessageBox::Ok);
521
            QMessageBox::warning(this, gs_Client,tr("QMK-Datenserver: Kann nicht zum Server verbinden."), QMessageBox::Ok);
521
        }
522
        }
522
        break;
523
        break;
523
        case 3 :
524
        case 3 :
524
        {
525
        {
525
//            lb_Status->setText(tr("Serververbindung getrennt. Logindaten falsch."));
526
//            lb_Status->setText(tr("Serververbindung getrennt. Logindaten falsch."));
526
            QMessageBox::warning(this, gs_Client,tr("QMK-Datenserver: Loginname oder Password falsch."), QMessageBox::Ok);
527
            QMessageBox::warning(this, gs_Client,tr("QMK-Datenserver: Loginname oder Password falsch."), QMessageBox::Ok);
527
        }
528
        }
528
        break;
529
        break;
529
        default :
530
        default :
530
        {
531
        {
531
//            lb_Status->setText(tr("Getrennt vom QMK-Datenserver."));
532
//            lb_Status->setText(tr("Getrennt vom QMK-Datenserver."));
532
        }
533
        }
533
        break;
534
        break;
534
    }
535
    }
535
 
536
 
536
}
537
}
537
 
538
 
538
wgt_Connection::~wgt_Connection()
539
wgt_Connection::~wgt_Connection()
539
{
540
{
540
    write_Settings();
541
    write_Settings();
541
}
542
}
542
 
543