Rev 715 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
674 | KeyOz | 1 | /*************************************************************************** |
2 | * Copyright (C) 2009 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 * |
||
711 | KeyOz | 7 | * the Free Software Con_Server; either version 2 of the License. * |
674 | KeyOz | 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 * |
||
711 | KeyOz | 16 | * Free Software Con_Server, Inc., * |
674 | KeyOz | 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | ***************************************************************************/ |
||
19 | |||
20 | #include <QMessageBox> |
||
711 | KeyOz | 21 | #include <QCryptographicHash> |
674 | KeyOz | 22 | |
23 | #include "dlg_Main.h" |
||
24 | |||
25 | // Konstruktor Main-Form |
||
26 | //////////////////////// |
||
27 | dlg_Main::dlg_Main() |
||
28 | { |
||
29 | setupUi(this); |
||
30 | |||
715 | KeyOz | 31 | s_Buffer = ""; |
674 | KeyOz | 32 | o_Settings = new cSettings(); |
33 | |||
34 | o_Input = new Input(); |
||
711 | KeyOz | 35 | o_Output = new Input(); |
674 | KeyOz | 36 | |
37 | f_Terminal = new dlg_Terminal(this); |
||
38 | |||
39 | init_GUI(); |
||
40 | init_Connections(); |
||
41 | |||
42 | init_TCP(); |
||
43 | } |
||
44 | |||
45 | void dlg_Main::set_ARGV(char *Programm) |
||
46 | { |
||
47 | QString tmp = QString(Programm); |
||
48 | QMK_Dir = tmp.left(tmp.lastIndexOf("/")); |
||
49 | } |
||
50 | |||
51 | // Grafische Oberfläche initialisieren |
||
52 | ////////////////////////////////////// |
||
53 | void dlg_Main::init_GUI() |
||
54 | { |
||
55 | setWindowTitle(QA_NAME + " " + QA_VERSION); |
||
56 | |||
57 | resize(o_Settings->GUI.Size); |
||
58 | move(o_Settings->GUI.Point); |
||
59 | |||
750 | KeyOz | 60 | f_Terminal->resize(o_Settings->TERMINAL.Size); |
61 | f_Terminal->move(o_Settings->TERMINAL.Point); |
||
62 | |||
63 | f_Terminal->cb_Data->setChecked(o_Settings->DATA.Data); |
||
64 | f_Terminal->cb_Info->setChecked(o_Settings->DATA.Info); |
||
65 | f_Terminal->cb_Send->setChecked(o_Settings->DATA.Send); |
||
66 | f_Terminal->cb_TCP->setChecked(o_Settings->DATA.TCP); |
||
67 | |||
674 | KeyOz | 68 | if (o_Settings->GUI.isMax) |
69 | { |
||
70 | showMaximized(); |
||
71 | } |
||
72 | |||
73 | // todo: In abhängigkeit von Settings |
||
74 | wg_IP->setVisible(false); |
||
75 | rb_Device->setChecked(true); |
||
76 | |||
77 | for (int z = 0; z < DEV_IP_MAX; z++) |
||
78 | { |
||
711 | KeyOz | 79 | Item[z] = new QListWidgetItem(); |
674 | KeyOz | 80 | } |
81 | |||
711 | KeyOz | 82 | // Liste der Devices |
674 | KeyOz | 83 | for(int z = 0; z < o_Settings->CLIENT.TTY_MAX; z++) |
84 | { |
||
85 | if (cb_Device->findText(o_Settings->CLIENT.TTY_DEVICES[z]) == -1) |
||
86 | { |
||
87 | cb_Device->addItem(o_Settings->CLIENT.TTY_DEVICES[z]); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | cb_Device->setCurrentIndex(o_Settings->CLIENT.TTY_ID); |
||
711 | KeyOz | 92 | |
93 | // Liste der IP-Server |
||
94 | for(int z = 0; z < o_Settings->CLIENT.TCP_MAX; z++) |
||
95 | { |
||
96 | if (cb_Server->findText(o_Settings->CLIENT.TCP_SERVER[z]) == -1) |
||
97 | { |
||
98 | cb_Server->addItem(o_Settings->CLIENT.TCP_SERVER[z]); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | cb_Server->setCurrentIndex(o_Settings->CLIENT.TCP_ID); |
||
103 | |||
104 | // Password für IP-Verbindung. |
||
105 | le_Password->setText(o_Settings->CLIENT.TCP_Password); |
||
106 | |||
750 | KeyOz | 107 | btn_Debug->setVisible(false); |
108 | btn_ConnectServer->setVisible(false); |
||
674 | KeyOz | 109 | } |
110 | |||
111 | // Signale mit Slots verbinden |
||
112 | ////////////////////////////// |
||
113 | void dlg_Main::init_Connections() |
||
114 | { |
||
115 | // Connect-Button |
||
116 | connect(btn_Connect, SIGNAL(clicked()), this, SLOT(slot_btn_Connect())); |
||
117 | |||
118 | connect(btn_cScope, SIGNAL(clicked()), this, SLOT(slot_btn_cScope())); |
||
119 | connect(btn_cSettings, SIGNAL(clicked()), this, SLOT(slot_btn_cSettings())); |
||
120 | connect(btn_cMaps, SIGNAL(clicked()), this, SLOT(slot_btn_cMaps())); |
||
121 | connect(btn_cVoice, SIGNAL(clicked()), this, SLOT(slot_btn_cVoice())); |
||
122 | connect(btn_cLogger, SIGNAL(clicked()), this, SLOT(slot_btn_cLogger())); |
||
123 | |||
711 | KeyOz | 124 | connect(btn_Terminal, SIGNAL(clicked()), this, SLOT(slot_btn_Terminal())); |
125 | connect(btn_ConnectServer, SIGNAL(clicked()), this, SLOT(slot_btn_ConnectServer())); |
||
674 | KeyOz | 126 | |
750 | KeyOz | 127 | connect(btn_Debug, SIGNAL(clicked()), this, SLOT(slot_btn_Debug())); |
128 | |||
129 | connect(rb_NC, SIGNAL(clicked()), this, SLOT(slot_rb_Hardware())); |
||
130 | connect(rb_FC, SIGNAL(clicked()), this, SLOT(slot_rb_Hardware())); |
||
131 | connect(rb_MK3MAG, SIGNAL(clicked()), this, SLOT(slot_rb_Hardware())); |
||
132 | |||
674 | KeyOz | 133 | // About QMK-Kernel & About-QT Dialog einfügen |
134 | connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About())); |
||
135 | connect(ac_Server, SIGNAL(triggered()), this, SLOT(slot_ac_Server())); |
||
136 | menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt())); |
||
137 | } |
||
138 | |||
139 | // IP-Ports initialisiern |
||
140 | ///////////////////////// |
||
141 | // todo: Port und Anzahl aus Settings |
||
142 | bool dlg_Main::init_TCP() |
||
143 | { |
||
144 | Connect_Count = 0; |
||
145 | |||
711 | KeyOz | 146 | Con_Server[0].Status = 0; |
147 | |||
148 | Con_Server[0].TCP = false; |
||
149 | Con_Server[0].UDP = false; |
||
150 | |||
674 | KeyOz | 151 | for (int a = 0; a < DEV_IP_MAX; a++) |
152 | { |
||
711 | KeyOz | 153 | Con_Server[a].Status = 0; |
674 | KeyOz | 154 | } |
155 | |||
156 | TCP_Server = new QTcpServer(this); |
||
157 | |||
158 | if (TCP_Server->listen(QHostAddress::Any, qint16(o_Settings->SERVER.TCP_PORT))) |
||
159 | { |
||
160 | connect(TCP_Server, SIGNAL(newConnection()), this, SLOT(slot_TCP_NewConnection())); |
||
161 | } |
||
162 | |||
163 | return true; |
||
164 | } |
||
165 | |||
166 | // Eingangsdaten verarbeiten |
||
167 | //////////////////////////// |
||
168 | void dlg_Main::parse_Input_Data(QString t_Data) |
||
169 | { |
||
750 | KeyOz | 170 | unsigned char OutData[180]; |
674 | KeyOz | 171 | char *InData = t_Data.toLatin1().data(); |
172 | |||
173 | if (HandlerMK::Decode_64(InData, t_Data.length(), OutData) != 0) |
||
174 | { |
||
175 | switch(InData[2]) |
||
176 | { |
||
177 | case 'V' : // Versions-Info |
||
178 | { |
||
179 | o_Input->stop_Resend(DATA_VERSION); |
||
180 | VersionInfo = HandlerMK::parse_Version(OutData, InData[1] - 'a'); |
||
181 | lb_Info->setText(tr("Verbunden mit ") + VersionInfo.Hardware + " " + VersionInfo.Version + trUtf8(" über ") + s_Input.Main + "."); |
||
182 | |||
183 | if (VersionInfo.ID == ADDRESS_FC) |
||
184 | { |
||
185 | rb_FC->setChecked(true); |
||
186 | } |
||
187 | if (VersionInfo.ID == ADDRESS_NC) |
||
188 | { |
||
189 | rb_NC->setChecked(true); |
||
190 | } |
||
191 | if (VersionInfo.ID == ADDRESS_MK3MAG) |
||
192 | { |
||
193 | rb_MK3MAG->setChecked(true); |
||
194 | } |
||
195 | } |
||
196 | break; |
||
197 | } |
||
198 | } |
||
199 | } |
||
200 | |||
201 | void dlg_Main::route_Input_Data(QString t_Data) |
||
202 | { |
||
203 | // An alle offenen TCP-Sockets senden. |
||
204 | for (int a = 1; a < DEV_IP_MAX; a++) |
||
205 | { |
||
711 | KeyOz | 206 | if (Con_Server[a].Status > 0) |
674 | KeyOz | 207 | { |
711 | KeyOz | 208 | if (Con_Server[a].TCP == true) |
674 | KeyOz | 209 | { |
711 | KeyOz | 210 | if ((Con_Server[a].Fields == "") || (Con_Server[a].Fields.contains(t_Data.at(2)) == true)) |
211 | { |
||
212 | if (o_Input->Mode() == TTY) |
||
213 | { |
||
214 | send_TCP(o_TCP[a], t_Data + "\r"); |
||
215 | } |
||
216 | else |
||
217 | { |
||
218 | send_TCP(o_TCP[a], t_Data); |
||
219 | } |
||
220 | } |
||
221 | else |
||
222 | { |
||
223 | // qDebug("Not Send Data"); |
||
224 | // qDebug(t_Data.toLatin1().data()); |
||
225 | } |
||
674 | KeyOz | 226 | } |
227 | } |
||
228 | } |
||
711 | KeyOz | 229 | if ((o_Output->IsOpen()) && ((Con_Output.Fields == "") || (Con_Output.Fields.contains(t_Data.at(2)) == true))) |
230 | { |
||
231 | o_Output->send_Data(t_Data); |
||
232 | } |
||
674 | KeyOz | 233 | } |
234 | |||
711 | KeyOz | 235 | void dlg_Main::parse_TCP_Server_Data(QString t_Data, int t_ID) |
674 | KeyOz | 236 | { |
237 | QStringList Data; |
||
238 | Data = t_Data.split(":"); |
||
239 | |||
240 | if (Data.count() > 1) |
||
241 | { |
||
242 | int CMD = Data[2].toInt(); |
||
711 | KeyOz | 243 | QString A = Data[2]; |
244 | // qDebug(A.toLatin1().data()); |
||
674 | KeyOz | 245 | |
246 | switch(CMD) |
||
247 | { |
||
248 | case 101 : |
||
249 | { |
||
711 | KeyOz | 250 | Con_Server[t_ID].Version = Data[3]; |
251 | Item[t_ID]->setText(" " + QString(o_TCP[t_ID]->peerAddress().toString()).leftJustified(15,' ') + " - " + Con_Server[t_ID].Version); |
||
252 | |||
253 | if (Con_Server[t_ID].Status == 2) |
||
254 | { |
||
255 | Item[t_ID]->setText("*" + QString(o_TCP[t_ID]->peerAddress().toString()).leftJustified(15,' ') + " - " + Con_Server[t_ID].Version); |
||
256 | } |
||
257 | else |
||
258 | { |
||
259 | send_TCP(o_TCP[t_ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 502, "105")); |
||
260 | } |
||
261 | |||
262 | send_TCP(o_TCP[t_ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 502, "106")); |
||
674 | KeyOz | 263 | } |
264 | break; |
||
265 | case 105 : |
||
266 | { |
||
711 | KeyOz | 267 | if (Con_Server[t_ID].Status != 2) |
674 | KeyOz | 268 | { |
711 | KeyOz | 269 | // qDebug("Get 105"); |
270 | QString s_MD5PW; |
||
271 | QByteArray a_MD5PW; |
||
272 | |||
273 | a_MD5PW = QCryptographicHash::hash(o_Settings->SERVER.Password.toAscii(),QCryptographicHash::Md5); |
||
274 | |||
275 | s_MD5PW = QString(a_MD5PW.toHex().data()); |
||
276 | |||
277 | if ((o_Settings->SERVER.Password != "") && (Data[3] == s_MD5PW)) |
||
674 | KeyOz | 278 | { |
711 | KeyOz | 279 | // qDebug("Set 505 OK"); |
674 | KeyOz | 280 | send_TCP(o_TCP[t_ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 505, "OK")); |
281 | |||
711 | KeyOz | 282 | Con_Server[t_ID].Status = 2; |
283 | Item[t_ID]->setText("*" + QString(o_TCP[t_ID]->peerAddress().toString()).leftJustified(15,' ') + " - " + Con_Server[t_ID].Version); |
||
674 | KeyOz | 284 | } |
285 | else |
||
286 | { |
||
711 | KeyOz | 287 | // qDebug("Set 505 NO"); |
674 | KeyOz | 288 | send_TCP(o_TCP[t_ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 505, "NO")); |
289 | } |
||
290 | } |
||
711 | KeyOz | 291 | else |
292 | { |
||
293 | send_TCP(o_TCP[t_ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 505, "OK")); |
||
294 | } |
||
674 | KeyOz | 295 | } |
296 | break; |
||
711 | KeyOz | 297 | case 106 : // Datenfelder anfordern. |
298 | { |
||
299 | if (Con_Server[t_ID].Status == 2) |
||
300 | { |
||
301 | Con_Server[t_ID].Fields = Data[3]; |
||
302 | Item[t_ID]->setText("*" + QString(o_TCP[t_ID]->peerAddress().toString()).leftJustified(15,' ') + " - " + Con_Server[t_ID].Version + " - " + Con_Server[t_ID].Fields); |
||
303 | // send_TCP(o_TCP[t_ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 506, Con_Server[t_ID].Fields)); |
||
304 | } |
||
305 | } |
||
674 | KeyOz | 306 | } |
307 | } |
||
308 | } |
||
309 | |||
711 | KeyOz | 310 | // IP-Input-Daten verarbeiten. |
311 | void dlg_Main::parse_TCP_Input_Data(QString t_Data) |
||
312 | { |
||
313 | QStringList Data; |
||
314 | Data = t_Data.split(":"); |
||
315 | |||
316 | if (Data.count() > 1) |
||
317 | { |
||
318 | int CMD = Data[2].toInt(); |
||
319 | |||
320 | switch(CMD) |
||
321 | { |
||
322 | case 502 : |
||
323 | { |
||
324 | // qDebug("Request Data"); |
||
325 | switch (Data[3].toInt()) |
||
326 | { |
||
327 | case 105 : |
||
328 | { |
||
329 | QString s_MD5PW; |
||
330 | QByteArray a_MD5PW; |
||
331 | |||
332 | a_MD5PW = QCryptographicHash::hash(le_Password->text().toAscii(),QCryptographicHash::Md5); |
||
333 | |||
334 | s_MD5PW = QString(a_MD5PW.toHex().data()); |
||
335 | |||
336 | o_Input->send_Data(HandlerIP::make_Frame(ID_COMMUNICATOR, 105, s_MD5PW)); |
||
337 | } |
||
338 | break; |
||
339 | } |
||
340 | } |
||
341 | break; |
||
342 | case 505 : |
||
343 | { |
||
344 | if (Data[3] == "OK") |
||
345 | { |
||
346 | } |
||
347 | else |
||
348 | { |
||
349 | QMessageBox::warning(this, QA_NAME, trUtf8("Authentifizierung fehlgeschlagen. <br />Daten senden zum Mikrokopter nicht möglich."), QMessageBox::Ok); |
||
350 | } |
||
351 | } |
||
352 | break; |
||
353 | } |
||
354 | } |
||
355 | } |
||
356 | |||
750 | KeyOz | 357 | // IP-Output-Daten verarbeiten. (Live-Data) |
711 | KeyOz | 358 | void dlg_Main::parse_TCP_Output_Data(QString t_Data) |
359 | { |
||
360 | QStringList Data; |
||
361 | Data = t_Data.split(":"); |
||
362 | |||
363 | if (Data.count() > 1) |
||
364 | { |
||
365 | int CMD = Data[2].toInt(); |
||
366 | |||
367 | switch(CMD) |
||
368 | { |
||
369 | case 101 : |
||
370 | { |
||
371 | Con_Output.Version = Data[3]; |
||
372 | o_Output->send_Data(HandlerIP::make_Frame(ID_COMMUNICATOR, 101, QA_NAME + " " + QA_VERSION)); |
||
373 | } |
||
374 | break; |
||
375 | case 106 : // Datenfelder anfordern. |
||
376 | { |
||
377 | Con_Output.Fields = Data[3]; |
||
378 | // send_TCP(o_TCP[t_ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 506, Con_Server[t_ID].Fields)); |
||
379 | } |
||
380 | break; |
||
381 | case 502 : |
||
382 | { |
||
383 | switch (Data[3].toInt()) |
||
384 | { |
||
385 | case 104 : |
||
386 | { |
||
387 | // qDebug("Request PW"); |
||
388 | QString s_MD5PW; |
||
389 | QByteArray a_MD5PW; |
||
390 | |||
750 | KeyOz | 391 | a_MD5PW = QCryptographicHash::hash(QString(QByteArray::fromBase64(Base64Hash.toLatin1()) + o_Settings->LIVEDATA.Password).toAscii(),QCryptographicHash::Md5); |
711 | KeyOz | 392 | |
393 | s_MD5PW = QString(a_MD5PW.toHex().data()); |
||
394 | |||
750 | KeyOz | 395 | o_Output->send_Data(HandlerIP::make_Frame(ID_COMMUNICATOR, 104, o_Settings->LIVEDATA.User + ";" + s_MD5PW)); |
711 | KeyOz | 396 | } |
397 | break; |
||
398 | } |
||
399 | } |
||
400 | break; |
||
401 | case 504 : |
||
402 | { |
||
403 | if (Data[3] == "OK") |
||
404 | { |
||
405 | Con_Output.Status = 2; |
||
406 | o_Output->send_Data(HandlerIP::make_Frame(ID_COMMUNICATOR, 502, "106")); |
||
407 | } |
||
408 | else |
||
409 | { |
||
410 | QMessageBox::warning(this, QA_NAME, trUtf8("Authentifizierung fehlgeschlagen."), QMessageBox::Ok); |
||
411 | } |
||
412 | } |
||
413 | break; |
||
414 | } |
||
415 | } |
||
416 | } |
||
417 | |||
674 | KeyOz | 418 | // Freies IP-Socket ermitteln |
419 | int dlg_Main::get_FreeSocket() |
||
420 | { |
||
421 | for (int a = 1; a < DEV_IP_MAX; a++) |
||
422 | { |
||
711 | KeyOz | 423 | if (Con_Server[a].Status == 0) |
674 | KeyOz | 424 | return a; |
425 | } |
||
426 | return 0; |
||
427 | } |
||
428 | |||
429 | // Daten auf TCP Senden |
||
430 | void dlg_Main::send_TCP(QTcpSocket *Socket, QString Data) |
||
431 | { |
||
432 | QByteArray SendText = Data.toAscii(); |
||
433 | |||
434 | Socket->write(SendText + "\n"); |
||
711 | KeyOz | 435 | Socket->flush(); |
436 | |||
437 | // qDebug(SendText.data()); |
||
674 | KeyOz | 438 | } |
439 | |||
711 | KeyOz | 440 | /////////// |
674 | KeyOz | 441 | // Slots // |
442 | /////////// |
||
443 | |||
444 | void dlg_Main::slot_btn_cScope() |
||
445 | { |
||
446 | QString Programm = QMK_Dir + "/QMK-Scope"; |
||
447 | |||
448 | QStringList Argumente; |
||
449 | |||
450 | o_cScope = new QProcess(); |
||
451 | |||
452 | Argumente << ""; |
||
453 | |||
454 | o_cScope->start(Programm, Argumente); // Programmaufruf |
||
455 | } |
||
456 | |||
457 | void dlg_Main::slot_btn_cSettings() |
||
458 | { |
||
459 | QString Programm = QMK_Dir + "/QMK-Settings"; |
||
460 | |||
461 | QStringList Argumente; |
||
462 | |||
463 | o_cSettings = new QProcess(); |
||
464 | |||
465 | Argumente << ""; |
||
466 | |||
467 | o_cSettings->start(Programm, Argumente); // Programmaufruf |
||
468 | } |
||
469 | |||
470 | void dlg_Main::slot_btn_cMaps() |
||
471 | { |
||
472 | QString Programm = QMK_Dir + "/QMK-Maps"; |
||
473 | |||
474 | QStringList Argumente; |
||
475 | |||
476 | o_cMaps = new QProcess(); |
||
477 | |||
478 | Argumente << ""; |
||
479 | |||
480 | o_cMaps->start(Programm, Argumente); // Programmaufruf |
||
481 | } |
||
482 | |||
483 | void dlg_Main::slot_btn_cVoice() |
||
484 | { |
||
485 | QString Programm = QMK_Dir + "/QMK-Voice"; |
||
486 | |||
487 | QStringList Argumente; |
||
488 | |||
489 | o_cVoice = new QProcess(); |
||
490 | |||
491 | Argumente << ""; |
||
492 | |||
493 | o_cVoice->start(Programm, Argumente); // Programmaufruf |
||
494 | } |
||
495 | |||
496 | void dlg_Main::slot_btn_cLogger() |
||
497 | { |
||
498 | QString Programm = QMK_Dir + "/QMK-Logger"; |
||
499 | |||
500 | QStringList Argumente; |
||
501 | |||
502 | o_cLogger = new QProcess(); |
||
503 | |||
504 | Argumente << ""; |
||
505 | |||
506 | o_cLogger->start(Programm, Argumente); // Programmaufruf |
||
507 | } |
||
508 | |||
509 | void dlg_Main::slot_btn_Terminal() |
||
510 | { |
||
511 | if (!f_Terminal->isVisible()) |
||
512 | { |
||
513 | f_Terminal->show(); |
||
514 | } |
||
515 | } |
||
516 | |||
711 | KeyOz | 517 | // Verbindung herstellen zum Datenserver |
518 | void dlg_Main::slot_btn_ConnectServer() |
||
519 | { |
||
520 | if (!o_Output->IsOpen()) |
||
521 | { |
||
522 | Con_Output = Con_Server[0]; |
||
523 | |||
750 | KeyOz | 524 | s_Output.Main = o_Settings->LIVEDATA.Server;//Server[0]; |
525 | s_Output.Sub = o_Settings->LIVEDATA.Port;//Server[1]; |
||
711 | KeyOz | 526 | |
527 | o_Output = new Input_TCP(); |
||
528 | o_Output->Init(); |
||
529 | |||
530 | if (o_Output->Open(s_Output) == true) |
||
531 | { |
||
532 | connect(o_Output, SIGNAL(sig_Disconnected(int)), this, SLOT(slot_Output_Disconnected(int))); |
||
533 | connect(o_Output, SIGNAL(sig_Connected()), this, SLOT(slot_Output_Connected())); |
||
534 | } |
||
535 | btn_ConnectServer->setText(tr("Trenne Server")); |
||
536 | Con_Output.Status = 1; |
||
537 | } |
||
538 | else |
||
539 | { |
||
540 | btn_ConnectServer->setText(tr("Verbinde Server")); |
||
541 | |||
542 | o_Output->Close(); |
||
543 | disconnect(o_Output, SIGNAL(sig_NewData(QString)), 0, 0); |
||
544 | if (o_Output->Mode() == TCP) |
||
545 | { |
||
546 | disconnect(o_Output, SIGNAL(sig_Disconnected(int)), 0, 0); |
||
547 | disconnect(o_Output, SIGNAL(sig_Connected()), 0, 0); |
||
548 | } |
||
549 | } |
||
550 | } |
||
551 | |||
750 | KeyOz | 552 | void dlg_Main::slot_btn_Debug() |
553 | { |
||
554 | if (o_Output->IsOpen()) |
||
555 | { |
||
556 | o_Output->send_Data("#cO=M======wWMrSCuD==A===============================================A=GM======[M=====@==@|p==O=CM=========kN"); |
||
557 | } |
||
558 | } |
||
559 | |||
560 | void dlg_Main::slot_rb_Hardware() |
||
561 | { |
||
562 | // if ((rb_NC->isChecked() == false) && (VersionInfo.ID != ADDRESS_NC)) |
||
563 | // { |
||
564 | // o_Input->send_Data(HandlerMK::get_SelectNC()); |
||
565 | // } |
||
566 | |||
567 | if (rb_FC->isChecked()) |
||
568 | { |
||
569 | o_Input->send_Data(HandlerMK::get_SelectFC()); |
||
570 | } |
||
571 | else |
||
572 | if (rb_MK3MAG->isChecked()) |
||
573 | { |
||
574 | o_Input->send_Data(HandlerMK::get_SelectMK3MAG()); |
||
575 | } |
||
576 | else |
||
577 | if (rb_NC->isChecked()) |
||
578 | { |
||
579 | o_Input->send_Data(HandlerMK::get_SelectNC()); |
||
580 | } |
||
581 | |||
582 | o_Input->send_Data(HandlerMK::make_Frame('v', 0, c_Data, 0).toLatin1().data(), DATA_VERSION); |
||
583 | } |
||
584 | |||
711 | KeyOz | 585 | void dlg_Main::slot_Output_Disconnected(int Error) |
586 | { |
||
587 | disconnect(o_Output, SIGNAL(sig_NewData(QString)), 0, 0); |
||
588 | if (o_Output->Mode() == TCP) |
||
589 | { |
||
590 | disconnect(o_Output, SIGNAL(sig_Disconnected(int)), 0, 0); |
||
591 | disconnect(o_Output, SIGNAL(sig_Connected()), 0, 0); |
||
592 | } |
||
593 | |||
594 | btn_ConnectServer->setText(tr("Verbinde Server")); |
||
595 | |||
596 | /* switch (Error) |
||
597 | { |
||
598 | case REMOTECLOSED : |
||
599 | { |
||
600 | // lb_Status->setText(tr("Verbindung vom Server beendet.")); |
||
601 | QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Verbindung wurde vom Server beendet."), QMessageBox::Ok); |
||
602 | } |
||
603 | break; |
||
604 | case REFUSED : |
||
605 | { |
||
606 | // lb_Status->setText(tr("Server nicht gefunden.")); |
||
607 | QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Kann nicht zum Server verbinden."), QMessageBox::Ok); |
||
608 | } |
||
609 | break; |
||
610 | case 3 : |
||
611 | { |
||
612 | // lb_Status->setText(tr("Serververbindung getrennt. Logindaten falsch.")); |
||
613 | QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Loginname oder Password falsch."), QMessageBox::Ok); |
||
614 | } |
||
615 | break; |
||
616 | default : |
||
617 | { |
||
618 | // lb_Status->setText(tr("Getrennt vom QMK-Datenserver.")); |
||
619 | } |
||
620 | break; |
||
621 | } |
||
622 | */ |
||
623 | |||
624 | } |
||
625 | |||
626 | void dlg_Main::slot_Output_Connected() |
||
627 | { |
||
628 | connect(o_Output, SIGNAL(sig_NewData(QString)), this, SLOT(slot_Output_Data(QString))); |
||
629 | } |
||
630 | |||
631 | void dlg_Main::slot_Output_Data(QString t_Data) |
||
632 | { |
||
633 | if ((t_Data[0] == '#')) |
||
634 | { |
||
635 | } |
||
636 | else if (o_Output->Mode() == TCP) |
||
637 | { |
||
750 | KeyOz | 638 | show_Terminal(6, "IP:" + t_Data); |
711 | KeyOz | 639 | parse_TCP_Output_Data(t_Data); |
640 | } |
||
641 | } |
||
642 | |||
643 | // Verbindung herstellen zum Kopter |
||
674 | KeyOz | 644 | void dlg_Main::slot_btn_Connect() |
645 | { |
||
646 | if (!o_Input->IsOpen()) |
||
647 | { |
||
648 | if (rb_Device->isChecked()) |
||
649 | { |
||
650 | if (cb_Device->findText(cb_Device->currentText()) == -1) |
||
651 | { |
||
652 | cb_Device->addItem(cb_Device->currentText()); |
||
653 | cb_Device->setCurrentIndex(cb_Device->findText(cb_Device->currentText())); |
||
654 | } |
||
655 | |||
656 | s_Input.Main = cb_Device->currentText(); |
||
657 | |||
658 | o_Input = new Input_TTY(); |
||
659 | o_Input->Init(); |
||
660 | |||
661 | if (o_Input->Open(s_Input) == true) |
||
662 | { |
||
663 | connect(o_Input, SIGNAL(sig_NewData(QString)), this, SLOT(slot_Input_Data(QString))); |
||
664 | |||
665 | o_Input->send_Data(HandlerMK::make_Frame('v', 0, c_Data, 0).toLatin1().data(), DATA_VERSION); |
||
666 | |||
667 | btn_Connect->setText(tr("Trennen")); |
||
668 | cb_Device->setEnabled(false); |
||
669 | } |
||
670 | } |
||
711 | KeyOz | 671 | else if (rb_TCP->isChecked()) |
672 | { |
||
673 | if (cb_Server->findText(cb_Device->currentText()) == -1) |
||
674 | { |
||
675 | cb_Server->addItem(cb_Server->currentText()); |
||
676 | cb_Server->setCurrentIndex(cb_Server->findText(cb_Server->currentText())); |
||
677 | } |
||
678 | |||
679 | cb_Server->setEnabled(false); |
||
680 | le_Password->setEnabled(false); |
||
681 | |||
682 | o_Input = new Input_TCP(); |
||
683 | o_Input->Init(); |
||
684 | |||
685 | set_Input s_Input; |
||
686 | |||
687 | QStringList Server = cb_Server->currentText().split(":"); |
||
688 | |||
689 | s_Input.Main = Server[0]; |
||
690 | s_Input.Sub = Server[1]; |
||
691 | |||
692 | if (o_Input->Open(s_Input) == true) |
||
693 | { |
||
694 | connect(o_Input, SIGNAL(sig_Disconnected(int)), this, SLOT(slot_Input_Disconnected(int))); |
||
695 | connect(o_Input, SIGNAL(sig_Connected()), this, SLOT(slot_Input_Connected())); |
||
696 | } |
||
697 | } |
||
698 | |||
674 | KeyOz | 699 | } |
700 | else |
||
701 | { |
||
702 | { |
||
711 | KeyOz | 703 | cb_Device->setEnabled(true); |
704 | cb_Server->setEnabled(true); |
||
705 | le_Password->setEnabled(true); |
||
706 | |||
674 | KeyOz | 707 | o_Input->Close(); |
708 | btn_Connect->setText(tr("Verbinden")); |
||
711 | KeyOz | 709 | disconnect(o_Input, SIGNAL(sig_NewData(QString)), 0, 0); |
710 | if (o_Input->Mode() == TCP) |
||
711 | { |
||
712 | disconnect(o_Input, SIGNAL(sig_Disconnected(int)), 0, 0); |
||
713 | disconnect(o_Input, SIGNAL(sig_Connected()), 0, 0); |
||
714 | } |
||
674 | KeyOz | 715 | } |
716 | } |
||
717 | } |
||
718 | |||
711 | KeyOz | 719 | // Neue Daten empfangen. |
720 | void dlg_Main::slot_Input_Data(QString t_Data) |
||
721 | { |
||
722 | if ((t_Data[0] == '#')) |
||
723 | { |
||
724 | |||
725 | 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())))) |
||
726 | { |
||
727 | show_Terminal(1, "MK: " + t_Data); |
||
728 | parse_Input_Data(t_Data); |
||
729 | route_Input_Data(t_Data); |
||
730 | } |
||
731 | else |
||
732 | { |
||
733 | show_Terminal(2, t_Data); |
||
734 | } |
||
735 | } |
||
736 | else if ((o_Input->Mode() == TCP) && (t_Data[0] == '$')) |
||
737 | { |
||
738 | show_Terminal(4, t_Data); |
||
739 | parse_TCP_Input_Data(t_Data); |
||
740 | } |
||
741 | else |
||
742 | { |
||
743 | show_Terminal(2, t_Data); |
||
744 | } |
||
745 | |||
746 | |||
747 | } |
||
748 | |||
749 | void dlg_Main::slot_Input_Disconnected(int Error) |
||
750 | { |
||
751 | cb_Server->setEnabled(true); |
||
752 | le_Password->setEnabled(true); |
||
753 | |||
754 | disconnect(o_Input, SIGNAL(sig_NewData(QString)), 0, 0); |
||
755 | if (o_Input->Mode() == TCP) |
||
756 | { |
||
757 | disconnect(o_Input, SIGNAL(sig_Disconnected(int)), 0, 0); |
||
758 | disconnect(o_Input, SIGNAL(sig_Connected()), 0, 0); |
||
759 | } |
||
760 | |||
761 | btn_Connect->setText(tr("Verbinden")); |
||
762 | |||
763 | /* switch (Error) |
||
764 | { |
||
765 | case REMOTECLOSED : |
||
766 | { |
||
767 | // lb_Status->setText(tr("Verbindung vom Server beendet.")); |
||
768 | QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Verbindung wurde vom Server beendet."), QMessageBox::Ok); |
||
769 | } |
||
770 | break; |
||
771 | case REFUSED : |
||
772 | { |
||
773 | // lb_Status->setText(tr("Server nicht gefunden.")); |
||
774 | QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Kann nicht zum Server verbinden."), QMessageBox::Ok); |
||
775 | } |
||
776 | break; |
||
777 | case 3 : |
||
778 | { |
||
779 | // lb_Status->setText(tr("Serververbindung getrennt. Logindaten falsch.")); |
||
780 | QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Loginname oder Password falsch."), QMessageBox::Ok); |
||
781 | } |
||
782 | break; |
||
783 | default : |
||
784 | { |
||
785 | // lb_Status->setText(tr("Getrennt vom QMK-Datenserver.")); |
||
786 | } |
||
787 | break; |
||
788 | } |
||
789 | */ |
||
790 | |||
791 | } |
||
792 | |||
793 | void dlg_Main::slot_Input_Connected() |
||
794 | { |
||
795 | connect(o_Input, SIGNAL(sig_NewData(QString)), this, SLOT(slot_Input_Data(QString))); |
||
796 | |||
797 | o_Input->send_Data(HandlerIP::make_Frame(ID_COMMUNICATOR, 101, QA_NAME + " " + QA_VERSION)); |
||
715 | KeyOz | 798 | o_Input->send_Data(HandlerMK::make_Frame('v', 0, c_Data, 0).toLatin1().data(), DATA_VERSION); |
711 | KeyOz | 799 | btn_Connect->setText(tr("Trennen")); |
800 | } |
||
801 | |||
674 | KeyOz | 802 | // About-Dialog |
803 | void dlg_Main::slot_ac_About() |
||
804 | { |
||
805 | QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT); |
||
806 | } |
||
807 | |||
808 | void dlg_Main::slot_ac_Server() |
||
809 | { |
||
810 | dlg_Preferences *f_Preferences = new dlg_Preferences(this); |
||
811 | |||
812 | f_Preferences->set_Settings(o_Settings); |
||
813 | |||
814 | if (f_Preferences->exec()==QDialog::Accepted) |
||
815 | { |
||
816 | o_Settings = f_Preferences->get_Settings(); |
||
817 | o_Settings->write_Settings(); |
||
818 | } |
||
819 | } |
||
820 | |||
821 | void dlg_Main::show_Terminal(int t_Typ, QString t_Data) |
||
822 | { |
||
823 | if (f_Terminal->isVisible()) |
||
824 | { |
||
825 | f_Terminal->show_Data(t_Typ, t_Data); |
||
826 | } |
||
827 | } |
||
828 | |||
711 | KeyOz | 829 | ///////////////////// |
830 | // IP-Slots Server // |
||
831 | ///////////////////// |
||
674 | KeyOz | 832 | |
833 | void dlg_Main::slot_TCP_NewConnection() |
||
834 | { |
||
835 | if (!o_Input->IsOpen()) |
||
711 | KeyOz | 836 | { |
674 | KeyOz | 837 | slot_btn_Connect(); |
711 | KeyOz | 838 | } |
674 | KeyOz | 839 | |
840 | int ID = get_FreeSocket(); |
||
841 | |||
842 | if (ID != 0) |
||
843 | { |
||
844 | Connect_Count++; |
||
845 | |||
711 | KeyOz | 846 | // Leeres Con_Server erzeugen |
847 | Con_Server[ID] = Con_Server[0]; |
||
848 | |||
849 | Con_Server[ID].Status = 1; |
||
850 | Con_Server[ID].TCP = true; |
||
851 | |||
852 | Con_Server[ID].Fields = ""; |
||
853 | Con_Server[ID].Version = "n/a"; |
||
854 | |||
674 | KeyOz | 855 | o_TCP[ID] = TCP_Server->nextPendingConnection(); |
856 | o_TCP[ID]->setProperty("ID", ID); |
||
857 | |||
711 | KeyOz | 858 | send_TCP(o_TCP[ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 101, QA_NAME + " " + QA_VERSION)); |
674 | KeyOz | 859 | |
860 | connect(o_TCP[ID], SIGNAL(disconnected()),o_TCP[ID], SLOT(deleteLater())); |
||
861 | connect(o_TCP[ID], SIGNAL(disconnected()),this, SLOT(slot_TCP_Disconnect())); |
||
862 | connect(o_TCP[ID], SIGNAL(readyRead()),this, SLOT(slot_TCP_Read())); |
||
863 | |||
711 | KeyOz | 864 | Item[ID]->setText(" " + QString(o_TCP[ID]->peerAddress().toString()).leftJustified(15,' ') + " - n/a"); |
865 | lw_Clients->addItem(Item[ID]); |
||
674 | KeyOz | 866 | |
711 | KeyOz | 867 | if (o_TCP[ID]->peerAddress().toString() == "127.0.0.1") |
868 | { |
||
869 | Con_Server[ID].Status = 2; |
||
870 | Item[ID]->setText("*" + QString(o_TCP[ID]->peerAddress().toString()).leftJustified(15,' ') + " - n/a"); |
||
871 | } |
||
674 | KeyOz | 872 | |
711 | KeyOz | 873 | if (o_Input->IsOpen()) |
874 | { |
||
875 | // send_TCP(o_TCP[ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 520, cb_Device->currentText())); |
||
876 | } |
||
674 | KeyOz | 877 | |
878 | } |
||
711 | KeyOz | 879 | else // Server voll |
880 | { |
||
674 | KeyOz | 881 | o_TCP[ID] = TCP_Server->nextPendingConnection(); |
882 | o_TCP[ID]->setProperty("ID", ID); |
||
883 | |||
711 | KeyOz | 884 | send_TCP(o_TCP[ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 521, "Sorry, Server full.")); |
674 | KeyOz | 885 | o_TCP[ID]->disconnectFromHost(); |
886 | } |
||
887 | } |
||
888 | |||
889 | void dlg_Main::slot_TCP_Read() |
||
890 | { |
||
891 | QTcpSocket *Socket = (QTcpSocket*)sender(); |
||
892 | |||
893 | // if (Socket->canReadLine()) |
||
894 | { |
||
895 | int ID = Socket->property("ID").toUInt(); |
||
896 | ID = ID; |
||
897 | |||
711 | KeyOz | 898 | // QString t_Data = QString(TCP_Socket->readLine(TCP_Socket->bytesAvailable())).remove(QChar('\n')); |
750 | KeyOz | 899 | QString t_Data = s_Buffer + QString(Socket->readAll()).remove(QChar('\n')); |
715 | KeyOz | 900 | s_Buffer = ""; |
711 | KeyOz | 901 | |
750 | KeyOz | 902 | t_Data = t_Data.replace('\r', "\r\n"); |
903 | |||
715 | KeyOz | 904 | QStringList l_Data = t_Data.split('\n'); |
711 | KeyOz | 905 | |
906 | for (int z = 0; z < l_Data.count(); z++) |
||
907 | { |
||
715 | KeyOz | 908 | if ((l_Data[z][l_Data[z].length() - 1] == '\r')) |
711 | KeyOz | 909 | { |
715 | KeyOz | 910 | l_Data[z].remove(QChar('\r')); |
711 | KeyOz | 911 | if (l_Data[z][0] == '$') |
912 | { |
||
913 | parse_TCP_Server_Data(l_Data[z], ID); |
||
914 | show_Terminal(5, "IP: " + l_Data[z]); |
||
915 | } |
||
916 | else |
||
917 | { |
||
918 | if ((Con_Server[ID].Status >= 2)) |
||
919 | { |
||
920 | show_Terminal(3, "MK> " + l_Data[z]); |
||
921 | o_Input->send_Data(l_Data[z]); |
||
922 | } |
||
923 | } |
||
924 | } |
||
715 | KeyOz | 925 | else |
750 | KeyOz | 926 | { if (l_Data[z].length() > 1) |
927 | { |
||
928 | qDebug(QString("Ohne Ende: " + l_Data[z]).toLatin1().data()); |
||
929 | s_Buffer = s_Buffer + l_Data[z]; |
||
930 | } |
||
715 | KeyOz | 931 | } |
932 | |||
711 | KeyOz | 933 | } |
934 | |||
935 | /* |
||
674 | KeyOz | 936 | QString t_Data = QString(Socket->readLine((Socket->bytesAvailable()))); |
937 | |||
938 | QStringList s_Data = t_Data.split('\r'); |
||
939 | |||
711 | KeyOz | 940 | for (int z = 0; z < s_Data.count() - 1; z++) |
674 | KeyOz | 941 | { |
942 | if (s_Data[z][0] == '$') |
||
943 | { |
||
711 | KeyOz | 944 | parse_TCP_Server_Data(s_Data[z], ID); |
945 | show_Terminal(5, "IP: " + s_Data[z]); |
||
946 | |||
674 | KeyOz | 947 | } |
711 | KeyOz | 948 | else |
949 | { |
||
950 | if ((Con_Server[ID].Status >= 2)) |
||
674 | KeyOz | 951 | { |
952 | show_Terminal(3, s_Data[z]); |
||
953 | o_Input->send_Data(s_Data[z]); |
||
954 | } |
||
955 | } |
||
956 | } |
||
957 | } |
||
711 | KeyOz | 958 | */ |
959 | } |
||
674 | KeyOz | 960 | } |
961 | |||
962 | void dlg_Main::slot_TCP_Disconnect() |
||
963 | { |
||
964 | QTcpSocket *Socket = (QTcpSocket*)sender(); |
||
965 | |||
966 | int ID = Socket->property("ID").toUInt(); |
||
967 | |||
711 | KeyOz | 968 | Item[ID]->setText(" " + QString(o_TCP[ID]->peerAddress().toString()).leftJustified(15,' ') + " - Disconected"); |
674 | KeyOz | 969 | |
711 | KeyOz | 970 | Con_Server[ID] = Con_Server[0]; |
971 | Con_Server[ID].Status = 0; |
||
674 | KeyOz | 972 | |
973 | Connect_Count--; |
||
974 | |||
975 | Socket->setProperty("ID", 0); |
||
976 | |||
711 | KeyOz | 977 | if ((Connect_Count == 0) && (o_Input->IsOpen())) |
674 | KeyOz | 978 | slot_btn_Connect(); |
979 | } |
||
980 | |||
981 | |||
982 | // Programm Ende |
||
983 | //////////////// |
||
984 | dlg_Main::~dlg_Main() |
||
985 | { |
||
986 | o_Settings->GUI.isMax = isMaximized(); |
||
987 | o_Settings->GUI.Size = size(); |
||
988 | o_Settings->GUI.Point = pos(); |
||
989 | |||
750 | KeyOz | 990 | // o_Settings->GUI.isMax = isMaximized(); |
991 | o_Settings->TERMINAL.Size = f_Terminal->size(); |
||
992 | o_Settings->TERMINAL.Point = f_Terminal->pos(); |
||
993 | |||
674 | KeyOz | 994 | o_Settings->CLIENT.TTY_MAX = cb_Device->count(); |
995 | o_Settings->CLIENT.TTY_ID = cb_Device->currentIndex(); |
||
996 | |||
997 | for (int z = 0; z < cb_Device->count(); z++) |
||
998 | { |
||
999 | if (z < 10) |
||
1000 | { |
||
1001 | o_Settings->CLIENT.TTY_DEVICES[z] = cb_Device->itemText(z); |
||
1002 | } |
||
1003 | } |
||
1004 | |||
711 | KeyOz | 1005 | o_Settings->CLIENT.TCP_MAX = cb_Server->count(); |
1006 | o_Settings->CLIENT.TCP_ID = cb_Server->currentIndex(); |
||
674 | KeyOz | 1007 | |
711 | KeyOz | 1008 | for (int z = 0; z < cb_Server->count(); z++) |
1009 | { |
||
1010 | if (z < 10) |
||
1011 | { |
||
1012 | o_Settings->CLIENT.TCP_SERVER[z] = cb_Server->itemText(z); |
||
1013 | } |
||
1014 | } |
||
1015 | |||
750 | KeyOz | 1016 | o_Settings->DATA.Data = f_Terminal->cb_Data->isChecked(); |
1017 | o_Settings->DATA.Info = f_Terminal->cb_Info->isChecked(); |
||
1018 | o_Settings->DATA.Send = f_Terminal->cb_Send->isChecked(); |
||
1019 | o_Settings->DATA.TCP = f_Terminal->cb_TCP->isChecked(); |
||
1020 | |||
674 | KeyOz | 1021 | o_Settings->write_Settings(); |
1022 | |||
1023 | // qDebug("Ende."); |
||
1024 | } |