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