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