Rev 674 | Rev 715 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 674 | Rev 711 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | * Copyright (C) 2009 by Manuel Schrape * |
2 | * Copyright (C) 2009 by Manuel Schrape * |
3 | * manuel.schrape@gmx.de * |
3 | * manuel.schrape@gmx.de * |
4 | * * |
4 | * * |
5 | * This program is free software; you can redistribute it and/or modify * |
5 | * This program is free software; you can redistribute it and/or modify * |
6 | * it under the terms of the GNU General Public License as published by * |
6 | * it under the terms of the GNU General Public License as published by * |
7 | * the Free Software Foundation; either version 2 of the License. * |
7 | * the Free Software Con_Server; either version 2 of the License. * |
8 | * * |
8 | * * |
9 | * This program is distributed in the hope that it will be useful, * |
9 | * This program is distributed in the hope that it will be useful, * |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * GNU General Public License for more details. * |
12 | * GNU General Public License for more details. * |
13 | * * |
13 | * * |
14 | * You should have received a copy of the GNU General Public License * |
14 | * You should have received a copy of the GNU General Public License * |
15 | * along with this program; if not, write to the * |
15 | * along with this program; if not, write to the * |
16 | * Free Software Foundation, Inc., * |
16 | * Free Software Con_Server, Inc., * |
17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | ***************************************************************************/ |
18 | ***************************************************************************/ |
Line 19... | Line 19... | ||
19 | 19 | ||
- | 20 | #include <QMessageBox> |
|
Line 20... | Line 21... | ||
20 | #include <QMessageBox> |
21 | #include <QCryptographicHash> |
Line 21... | Line 22... | ||
21 | 22 | ||
22 | #include "dlg_Main.h" |
23 | #include "dlg_Main.h" |
Line 28... | Line 29... | ||
28 | setupUi(this); |
29 | setupUi(this); |
Line 29... | Line 30... | ||
29 | 30 | ||
Line 30... | Line 31... | ||
30 | o_Settings = new cSettings(); |
31 | o_Settings = new cSettings(); |
- | 32 | ||
Line 31... | Line 33... | ||
31 | 33 | o_Input = new Input(); |
|
Line 32... | Line 34... | ||
32 | o_Input = new Input(); |
34 | o_Output = new Input(); |
33 | 35 | ||
Line 63... | Line 65... | ||
63 | wg_IP->setVisible(false); |
65 | wg_IP->setVisible(false); |
64 | rb_Device->setChecked(true); |
66 | rb_Device->setChecked(true); |
Line 65... | Line 67... | ||
65 | 67 | ||
66 | for (int z = 0; z < DEV_IP_MAX; z++) |
68 | for (int z = 0; z < DEV_IP_MAX; z++) |
67 | { |
- | |
68 | Item[z][0] = new QListWidgetItem(); |
69 | { |
69 | Item[z][1] = new QListWidgetItem(); |
70 | Item[z] = new QListWidgetItem(); |
Line -... | Line 71... | ||
- | 71 | } |
|
70 | } |
72 | |
71 | 73 | // Liste der Devices |
|
72 | for(int z = 0; z < o_Settings->CLIENT.TTY_MAX; z++) |
74 | for(int z = 0; z < o_Settings->CLIENT.TTY_MAX; z++) |
73 | { |
75 | { |
74 | if (cb_Device->findText(o_Settings->CLIENT.TTY_DEVICES[z]) == -1) |
76 | if (cb_Device->findText(o_Settings->CLIENT.TTY_DEVICES[z]) == -1) |
75 | { |
77 | { |
76 | cb_Device->addItem(o_Settings->CLIENT.TTY_DEVICES[z]); |
78 | cb_Device->addItem(o_Settings->CLIENT.TTY_DEVICES[z]); |
Line 77... | Line 79... | ||
77 | } |
79 | } |
- | 80 | } |
|
- | 81 | ||
- | 82 | cb_Device->setCurrentIndex(o_Settings->CLIENT.TTY_ID); |
|
- | 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 | ||
78 | } |
95 | // Password für IP-Verbindung. |
Line 79... | Line 96... | ||
79 | 96 | le_Password->setText(o_Settings->CLIENT.TCP_Password); |
|
80 | cb_Device->setCurrentIndex(o_Settings->CLIENT.TTY_ID); |
97 | |
81 | } |
98 | } |
Line 91... | Line 108... | ||
91 | connect(btn_cSettings, SIGNAL(clicked()), this, SLOT(slot_btn_cSettings())); |
108 | connect(btn_cSettings, SIGNAL(clicked()), this, SLOT(slot_btn_cSettings())); |
92 | connect(btn_cMaps, SIGNAL(clicked()), this, SLOT(slot_btn_cMaps())); |
109 | connect(btn_cMaps, SIGNAL(clicked()), this, SLOT(slot_btn_cMaps())); |
93 | connect(btn_cVoice, SIGNAL(clicked()), this, SLOT(slot_btn_cVoice())); |
110 | connect(btn_cVoice, SIGNAL(clicked()), this, SLOT(slot_btn_cVoice())); |
94 | connect(btn_cLogger, SIGNAL(clicked()), this, SLOT(slot_btn_cLogger())); |
111 | connect(btn_cLogger, SIGNAL(clicked()), this, SLOT(slot_btn_cLogger())); |
Line 95... | Line 112... | ||
95 | 112 | ||
- | 113 | connect(btn_Terminal, SIGNAL(clicked()), this, SLOT(slot_btn_Terminal())); |
|
Line 96... | Line 114... | ||
96 | connect(btn_Terminal, SIGNAL(clicked()), this, SLOT(slot_btn_Terminal())); |
114 | connect(btn_ConnectServer, SIGNAL(clicked()), this, SLOT(slot_btn_ConnectServer())); |
97 | 115 | ||
98 | // About QMK-Kernel & About-QT Dialog einfügen |
116 | // About QMK-Kernel & About-QT Dialog einfügen |
99 | connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About())); |
117 | connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About())); |
Line 105... | Line 123... | ||
105 | ///////////////////////// |
123 | ///////////////////////// |
106 | // todo: Port und Anzahl aus Settings |
124 | // todo: Port und Anzahl aus Settings |
107 | bool dlg_Main::init_TCP() |
125 | bool dlg_Main::init_TCP() |
108 | { |
126 | { |
109 | Connect_Count = 0; |
127 | Connect_Count = 0; |
- | 128 | ||
- | 129 | Con_Server[0].Status = 0; |
|
- | 130 | ||
110 | Connection[0].TCP = false; |
131 | Con_Server[0].TCP = false; |
111 | Connection[0].UDP = false; |
132 | Con_Server[0].UDP = false; |
Line 112... | Line 133... | ||
112 | 133 | ||
113 | for (int a = 0; a < DEV_IP_MAX; a++) |
134 | for (int a = 0; a < DEV_IP_MAX; a++) |
114 | { |
135 | { |
115 | Connection[a].Open = false; |
136 | Con_Server[a].Status = 0; |
Line 116... | Line 137... | ||
116 | } |
137 | } |
Line 117... | Line 138... | ||
117 | 138 | ||
Line 163... | Line 184... | ||
163 | void dlg_Main::route_Input_Data(QString t_Data) |
184 | void dlg_Main::route_Input_Data(QString t_Data) |
164 | { |
185 | { |
165 | // An alle offenen TCP-Sockets senden. |
186 | // An alle offenen TCP-Sockets senden. |
166 | for (int a = 1; a < DEV_IP_MAX; a++) |
187 | for (int a = 1; a < DEV_IP_MAX; a++) |
167 | { |
188 | { |
168 | if (Connection[a].Open == true) |
189 | if (Con_Server[a].Status > 0) |
169 | { |
190 | { |
170 | if (Connection[a].TCP == true) |
191 | if (Con_Server[a].TCP == true) |
171 | { |
192 | { |
- | 193 | if ((Con_Server[a].Fields == "") || (Con_Server[a].Fields.contains(t_Data.at(2)) == true)) |
|
- | 194 | { |
|
- | 195 | if (o_Input->Mode() == TTY) |
|
- | 196 | { |
|
172 | send_TCP(o_TCP[a], t_Data + "\r"); |
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 | } |
|
173 | } |
209 | } |
174 | } |
210 | } |
175 | } |
211 | } |
- | 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 | } |
|
176 | } |
216 | } |
Line 177... | Line 217... | ||
177 | 217 | ||
178 | void dlg_Main::parse_TCP_Data(QString t_Data, int t_ID) |
218 | void dlg_Main::parse_TCP_Server_Data(QString t_Data, int t_ID) |
179 | { |
219 | { |
180 | QStringList Data; |
220 | QStringList Data; |
Line 181... | Line 221... | ||
181 | Data = t_Data.split(":"); |
221 | Data = t_Data.split(":"); |
182 | 222 | ||
183 | if (Data.count() > 1) |
223 | if (Data.count() > 1) |
- | 224 | { |
|
- | 225 | int CMD = Data[2].toInt(); |
|
Line 184... | Line 226... | ||
184 | { |
226 | QString A = Data[2]; |
185 | int CMD = Data[2].toInt(); |
227 | // qDebug(A.toLatin1().data()); |
186 | 228 | ||
187 | switch(CMD) |
229 | switch(CMD) |
188 | { |
230 | { |
- | 231 | case 101 : |
|
- | 232 | { |
|
189 | case 101 : |
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); |
|
190 | { |
239 | } |
- | 240 | else |
|
- | 241 | { |
|
- | 242 | send_TCP(o_TCP[t_ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 502, "105")); |
|
191 | Item[t_ID][1]->setText(Data[3]); |
243 | } |
192 | if (Connection[t_ID].Auth == true) |
244 | |
193 | Item[t_ID][1]->setText("* " + Data[3]); |
245 | send_TCP(o_TCP[t_ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 502, "106")); |
194 | } |
246 | } |
195 | break; |
247 | break; |
196 | case 105 : |
248 | case 105 : |
- | 249 | { |
|
- | 250 | if (Con_Server[t_ID].Status != 2) |
|
- | 251 | { |
|
- | 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); |
|
197 | { |
257 | |
198 | if (Connection[t_ID].Auth == false) |
258 | s_MD5PW = QString(a_MD5PW.toHex().data()); |
- | 259 | ||
199 | { |
260 | if ((o_Settings->SERVER.Password != "") && (Data[3] == s_MD5PW)) |
Line 200... | Line 261... | ||
200 | if ((o_Settings->SERVER.Password != "") && (Data[3] == o_Settings->SERVER.Password)) |
261 | { |
201 | { |
262 | // qDebug("Set 505 OK"); |
202 | send_TCP(o_TCP[t_ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 505, "OK")); |
263 | send_TCP(o_TCP[t_ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 505, "OK")); |
203 | 264 | ||
204 | Connection[t_ID].Auth = true; |
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); |
|
205 | Item[t_ID][1]->setText("* " + Item[t_ID][1]->text()); |
267 | } |
206 | } |
268 | else |
207 | else |
269 | { |
- | 270 | // qDebug("Set 505 NO"); |
|
- | 271 | send_TCP(o_TCP[t_ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 505, "NO")); |
|
- | 272 | } |
|
- | 273 | } |
|
- | 274 | else |
|
- | 275 | { |
|
- | 276 | send_TCP(o_TCP[t_ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 505, "OK")); |
|
- | 277 | } |
|
- | 278 | } |
|
- | 279 | break; |
|
- | 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 | } |
|
- | 289 | } |
|
- | 290 | } |
|
- | 291 | } |
|
- | 292 | ||
- | 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 | } |
|
208 | { |
391 | else |
209 | send_TCP(o_TCP[t_ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 505, "NO")); |
392 | { |
210 | } |
393 | QMessageBox::warning(this, QA_NAME, trUtf8("Authentifizierung fehlgeschlagen."), QMessageBox::Ok); |
211 | } |
394 | } |
212 | } |
395 | } |
Line 218... | Line 401... | ||
218 | // Freies IP-Socket ermitteln |
401 | // Freies IP-Socket ermitteln |
219 | int dlg_Main::get_FreeSocket() |
402 | int dlg_Main::get_FreeSocket() |
220 | { |
403 | { |
221 | for (int a = 1; a < DEV_IP_MAX; a++) |
404 | for (int a = 1; a < DEV_IP_MAX; a++) |
222 | { |
405 | { |
223 | if (Connection[a].Open == false) |
406 | if (Con_Server[a].Status == 0) |
224 | return a; |
407 | return a; |
225 | } |
408 | } |
226 | return 0; |
409 | return 0; |
227 | } |
410 | } |
Line 230... | Line 413... | ||
230 | void dlg_Main::send_TCP(QTcpSocket *Socket, QString Data) |
413 | void dlg_Main::send_TCP(QTcpSocket *Socket, QString Data) |
231 | { |
414 | { |
232 | QByteArray SendText = Data.toAscii(); |
415 | QByteArray SendText = Data.toAscii(); |
Line 233... | Line 416... | ||
233 | 416 | ||
- | 417 | Socket->write(SendText + "\n"); |
|
- | 418 | Socket->flush(); |
|
- | 419 | ||
234 | Socket->write(SendText + "\n"); |
420 | // qDebug(SendText.data()); |
Line 235... | Line 421... | ||
235 | } |
421 | } |
236 | 422 | ||
237 | ///////////ettings |
423 | /////////// |
Line 238... | Line 424... | ||
238 | // Slots // |
424 | // Slots // |
239 | /////////// |
425 | /////////// |
Line 309... | Line 495... | ||
309 | { |
495 | { |
310 | f_Terminal->show(); |
496 | f_Terminal->show(); |
311 | } |
497 | } |
312 | } |
498 | } |
Line -... | Line 499... | ||
- | 499 | ||
- | 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 | } |
|
313 | 599 | ||
314 | // Verbindung herstellen |
600 | // Verbindung herstellen zum Kopter |
315 | void dlg_Main::slot_btn_Connect() |
601 | void dlg_Main::slot_btn_Connect() |
316 | { |
602 | { |
317 | if (!o_Input->IsOpen()) |
603 | if (!o_Input->IsOpen()) |
318 | { |
604 | { |
Line 337... | Line 623... | ||
337 | 623 | ||
338 | btn_Connect->setText(tr("Trennen")); |
624 | btn_Connect->setText(tr("Trennen")); |
339 | cb_Device->setEnabled(false); |
625 | cb_Device->setEnabled(false); |
340 | } |
626 | } |
- | 627 | } |
|
- | 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 | } |
|
341 | } |
655 | |
342 | } |
656 | } |
343 | else |
657 | else |
344 | { |
- | |
345 | if (rb_Device->isChecked()) |
658 | { |
- | 659 | { |
|
- | 660 | cb_Device->setEnabled(true); |
|
- | 661 | cb_Server->setEnabled(true); |
|
- | 662 | le_Password->setEnabled(true); |
|
346 | { |
663 | |
347 | o_Input->Close(); |
664 | o_Input->Close(); |
- | 665 | btn_Connect->setText(tr("Verbinden")); |
|
- | 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 | } |
|
- | 672 | } |
|
- | 673 | } |
|
- | 674 | } |
|
- | 675 | ||
- | 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) |
|
348 | btn_Connect->setText(tr("Verbinden")); |
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 | { |
|
349 | cb_Device->setEnabled(true); |
742 | // lb_Status->setText(tr("Getrennt vom QMK-Datenserver.")); |
- | 743 | } |
|
350 | } |
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); |
|
351 | } |
756 | btn_Connect->setText(tr("Trennen")); |
Line 352... | Line 757... | ||
352 | } |
757 | } |
353 | 758 | ||
354 | // About-Dialog |
759 | // About-Dialog |
Line 368... | Line 773... | ||
368 | o_Settings = f_Preferences->get_Settings(); |
773 | o_Settings = f_Preferences->get_Settings(); |
369 | o_Settings->write_Settings(); |
774 | o_Settings->write_Settings(); |
370 | } |
775 | } |
371 | } |
776 | } |
Line 372... | Line -... | ||
372 | - | ||
373 | // Neue Daten empfangen. |
777 | |
374 | void dlg_Main::show_Terminal(int t_Typ, QString t_Data) |
778 | void dlg_Main::show_Terminal(int t_Typ, QString t_Data) |
375 | { |
779 | { |
376 | if (f_Terminal->isVisible()) |
780 | if (f_Terminal->isVisible()) |
377 | { |
781 | { |
378 | f_Terminal->show_Data(t_Typ, t_Data); |
782 | f_Terminal->show_Data(t_Typ, t_Data); |
379 | } |
783 | } |
Line 380... | Line -... | ||
380 | } |
- | |
381 | - | ||
382 | void dlg_Main::slot_Input_Data(QString t_Data) |
- | |
383 | { |
- | |
384 | if (HandlerMK::Check_CRC(t_Data.toLatin1().data(), t_Data.length())) |
- | |
385 | { |
- | |
386 | show_Terminal(1, t_Data); |
- | |
387 | parse_Input_Data(t_Data); |
- | |
388 | route_Input_Data(t_Data); |
- | |
389 | } |
- | |
390 | else |
- | |
391 | { |
- | |
392 | show_Terminal(2, t_Data); |
- | |
393 | } |
- | |
394 | } |
784 | } |
395 | 785 | ||
396 | ////////////// |
786 | ///////////////////// |
Line 397... | Line 787... | ||
397 | // IP-Slots // |
787 | // IP-Slots Server // |
398 | ////////////// |
788 | ///////////////////// |
399 | 789 | ||
- | 790 | void dlg_Main::slot_TCP_NewConnection() |
|
400 | void dlg_Main::slot_TCP_NewConnection() |
791 | { |
- | 792 | if (!o_Input->IsOpen()) |
|
Line 401... | Line 793... | ||
401 | { |
793 | { |
Line 402... | Line 794... | ||
402 | if (!o_Input->IsOpen()) |
794 | slot_btn_Connect(); |
403 | slot_btn_Connect(); |
795 | } |
404 | 796 | ||
- | 797 | int ID = get_FreeSocket(); |
|
405 | int ID = get_FreeSocket(); |
798 | |
406 | 799 | if (ID != 0) |
|
- | 800 | { |
|
407 | if (ID != 0) |
801 | Connect_Count++; |
408 | { |
802 | |
- | 803 | // Leeres Con_Server erzeugen |
|
409 | Connect_Count++; |
804 | Con_Server[ID] = Con_Server[0]; |
- | 805 | ||
Line 410... | Line 806... | ||
410 | // Leeres Connection erzeugen |
806 | Con_Server[ID].Status = 1; |
411 | Connection[ID] = Connection[0]; |
807 | Con_Server[ID].TCP = true; |
Line 412... | Line 808... | ||
412 | Connection[ID].Open = true; |
808 | |
Line 413... | Line 809... | ||
413 | Connection[ID].TCP = true; |
809 | Con_Server[ID].Fields = ""; |
414 | Connection[ID].Auth = false; |
810 | Con_Server[ID].Version = "n/a"; |
415 | 811 | ||
Line 416... | Line 812... | ||
416 | o_TCP[ID] = TCP_Server->nextPendingConnection(); |
812 | o_TCP[ID] = TCP_Server->nextPendingConnection(); |
417 | o_TCP[ID]->setProperty("ID", ID); |
- | |
418 | - | ||
419 | send_TCP(o_TCP[ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 501, QA_NAME + " " + QA_VERSION)); |
813 | o_TCP[ID]->setProperty("ID", ID); |
Line 420... | Line 814... | ||
420 | 814 | ||
- | 815 | send_TCP(o_TCP[ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 101, QA_NAME + " " + QA_VERSION)); |
|
421 | connect(o_TCP[ID], SIGNAL(disconnected()),o_TCP[ID], SLOT(deleteLater())); |
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())); |
|
Line 422... | Line 819... | ||
422 | connect(o_TCP[ID], SIGNAL(disconnected()),this, SLOT(slot_TCP_Disconnect())); |
819 | connect(o_TCP[ID], SIGNAL(readyRead()),this, SLOT(slot_TCP_Read())); |
- | 820 | ||
423 | connect(o_TCP[ID], SIGNAL(readyRead()),this, SLOT(slot_TCP_Read())); |
821 | Item[ID]->setText(" " + QString(o_TCP[ID]->peerAddress().toString()).leftJustified(15,' ') + " - n/a"); |
- | 822 | lw_Clients->addItem(Item[ID]); |
|
Line 424... | Line 823... | ||
424 | 823 | ||
425 | Item[ID][0]->setText(o_TCP[ID]->peerAddress().toString()); |
- | |
426 | lw_ClientsIP->addItem(Item[ID][0]); |
824 | if (o_TCP[ID]->peerAddress().toString() == "127.0.0.1") |
- | 825 | { |
|
427 | Item[ID][1]->setText("n/a"); |
826 | Con_Server[ID].Status = 2; |
428 | lw_Clients->addItem(Item[ID][1]); |
827 | Item[ID]->setText("*" + QString(o_TCP[ID]->peerAddress().toString()).leftJustified(15,' ') + " - n/a"); |
Line 429... | Line 828... | ||
429 | 828 | } |
|
430 | if (Item[ID][0]->text() == "127.0.0.1") |
829 | |
431 | Connection[ID].Auth = true; |
830 | if (o_Input->IsOpen()) |
432 | 831 | { |
|
Line 433... | Line 832... | ||
433 | if (Connection[ID].Auth) |
832 | // send_TCP(o_TCP[ID],HandlerIP::make_Frame(ID_COMMUNICATOR, 520, cb_Device->currentText())); |
Line 451... | Line 850... | ||
451 | // if (Socket->canReadLine()) |
850 | // if (Socket->canReadLine()) |
452 | { |
851 | { |
453 | int ID = Socket->property("ID").toUInt(); |
852 | int ID = Socket->property("ID").toUInt(); |
454 | ID = ID; |
853 | ID = ID; |
Line -... | Line 854... | ||
- | 854 | ||
- | 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 | ||
455 | 880 | /* |
|
Line 456... | Line 881... | ||
456 | QString t_Data = QString(Socket->readLine((Socket->bytesAvailable()))); |
881 | QString t_Data = QString(Socket->readLine((Socket->bytesAvailable()))); |
Line 457... | Line 882... | ||
457 | 882 | ||
458 | QStringList s_Data = t_Data.split('\r'); |
883 | QStringList s_Data = t_Data.split('\r'); |
459 | 884 | ||
460 | for (int z = 0; z < s_Data.length() - 1; z++) |
885 | for (int z = 0; z < s_Data.count() - 1; z++) |
461 | { |
886 | { |
462 | if (s_Data[z][0] == '$') |
887 | if (s_Data[z][0] == '$') |
- | 888 | { |
|
463 | { |
889 | parse_TCP_Server_Data(s_Data[z], ID); |
464 | // qDebug(QString("TCP: " + s_Data[z]).toLatin1().data()); |
890 | show_Terminal(5, "IP: " + s_Data[z]); |
465 | parse_TCP_Data(s_Data[z], ID); |
891 | |
466 | } |
892 | } |
467 | else |
893 | else |
468 | { // Daten vom Client an den MK. todo: Nur erlauben wenn autemtifiziert oder Localhost |
894 | { |
469 | if ((Connection[ID].Auth == true)) |
895 | if ((Con_Server[ID].Status >= 2)) |
470 | { |
896 | { |
471 | show_Terminal(3, s_Data[z]); |
897 | show_Terminal(3, s_Data[z]); |
472 | o_Input->send_Data(s_Data[z]); |
898 | o_Input->send_Data(s_Data[z]); |
473 | } |
899 | } |
- | 900 | } |
|
- | 901 | } |
|
474 | } |
902 | } |
Line 475... | Line 903... | ||
475 | } |
903 | */ |
476 | } |
904 | } |
477 | } |
905 | } |
Line 478... | Line 906... | ||
478 | 906 | ||
Line 479... | Line 907... | ||
479 | void dlg_Main::slot_TCP_Disconnect() |
907 | void dlg_Main::slot_TCP_Disconnect() |
Line 480... | Line 908... | ||
480 | { |
908 | { |
481 | QTcpSocket *Socket = (QTcpSocket*)sender(); |
909 | QTcpSocket *Socket = (QTcpSocket*)sender(); |
Line 482... | Line 910... | ||
482 | 910 | ||
Line 483... | Line 911... | ||
483 | int ID = Socket->property("ID").toUInt(); |
911 | int ID = Socket->property("ID").toUInt(); |
Line 484... | Line 912... | ||
484 | 912 | ||
485 | Item[ID][1]->setText("Disconected"); |
913 | Item[ID]->setText(" " + QString(o_TCP[ID]->peerAddress().toString()).leftJustified(15,' ') + " - Disconected"); |
486 | 914 | ||
Line 487... | Line 915... | ||
487 | Connection[ID] = Connection[0]; |
915 | Con_Server[ID] = Con_Server[0]; |
Line 513... | Line 941... | ||
513 | { |
941 | { |
514 | o_Settings->CLIENT.TTY_DEVICES[z] = cb_Device->itemText(z); |
942 | o_Settings->CLIENT.TTY_DEVICES[z] = cb_Device->itemText(z); |
515 | } |
943 | } |
516 | } |
944 | } |
Line -... | Line 945... | ||
- | 945 | ||
- | 946 | o_Settings->CLIENT.TCP_MAX = cb_Server->count(); |
|
- | 947 | o_Settings->CLIENT.TCP_ID = cb_Server->currentIndex(); |
|
- | 948 | ||
- | 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 | } |
|
Line 517... | Line 955... | ||
517 | 955 | } |
|
Line 518... | Line 956... | ||
518 | 956 | ||
519 | o_Settings->write_Settings(); |
957 | o_Settings->write_Settings(); |