Rev 674 | 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 * |
||
7 | * the Free Software Foundation; either version 2 of the License. * |
||
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 * |
||
16 | * Free Software Foundation, Inc., * |
||
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 | dlg_Main::dlg_Main() |
||
27 | { |
||
28 | setupUi(this); |
||
29 | |||
30 | o_Settings = new cSettings(); |
||
31 | |||
32 | o_Settings->read_DebugLabels(0); |
||
33 | |||
34 | o_Input = new Input(); |
||
35 | |||
36 | init_GUI(); |
||
37 | init_Connections(); |
||
38 | init_Plotter(); |
||
39 | } |
||
40 | |||
41 | // Grafische Oberfläche initialisieren |
||
42 | void dlg_Main::init_GUI() |
||
43 | { |
||
44 | setWindowTitle(QA_NAME + " " + QA_VERSION); |
||
45 | |||
46 | resize(o_Settings->GUI.Size); |
||
47 | move(o_Settings->GUI.Point); |
||
48 | |||
49 | if (o_Settings->GUI.isMax) |
||
50 | { |
||
51 | showMaximized(); |
||
52 | } |
||
53 | |||
54 | for(int z = 0; z < o_Settings->SERVER.IP_MAX; z++) |
||
55 | { |
||
56 | if (cb_Server->findText(o_Settings->SERVER.IP[z]) == -1) |
||
57 | { |
||
58 | cb_Server->addItem(o_Settings->SERVER.IP[z]); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | cb_Server->setCurrentIndex(o_Settings->SERVER.IP_ID); |
||
63 | |||
64 | le_Password->setText(o_Settings->SERVER.Password); |
||
65 | |||
66 | sb_Intervall->setValue(o_Settings->DATA.Debug_Intervall); |
||
67 | |||
68 | btn_Start->setCheckable(true); |
||
69 | |||
70 | ac_Plotter->setChecked(true); |
||
71 | |||
72 | Font_1.setFamily(QString::fromUtf8("Adobe Courier")); |
||
73 | Font_1.setBold(true); |
||
74 | Font_1.setWeight(75); |
||
75 | |||
76 | for(int z = 0; z < MAX_DebugData; z++) |
||
77 | { |
||
78 | |||
79 | lb_Debug[z] = new QLabel(wg_Debug); |
||
80 | le_Debug[z] = new QLineEdit(wg_Debug); |
||
81 | cb_Debug[z] = new QCheckBox(wg_Config); |
||
82 | le_Debug[z]->setFont(Font_1); |
||
83 | le_Debug[z]->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
||
84 | le_Debug[z]->setReadOnly(true); |
||
85 | |||
86 | wg_Grid->addWidget(lb_Debug[z], (z % 8), z / 8 * 2, 0); |
||
87 | wg_Grid->addWidget(le_Debug[z], (z % 8), z / 8 * 2 + 1 , 0); |
||
88 | |||
89 | wg_Grid_2->addWidget(cb_Debug[z], (z % 8), z / 8, 0); |
||
90 | |||
91 | lb_Debug[z]->setText(o_Settings->DebugData.Label[z]); |
||
92 | cb_Debug[z]->setText(o_Settings->DebugData.Label[z]); |
||
93 | |||
94 | cb_Debug[z]->setChecked(o_Settings->DebugData.Show_Plotter[z]); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | // Signale mit Slots verbinden |
||
99 | void dlg_Main::init_Connections() |
||
100 | { |
||
101 | connect(sb_Intervall, SIGNAL(valueChanged(int)), this, SLOT(slot_sb_Intervall(int))); |
||
102 | |||
103 | connect(ac_Connect, SIGNAL(triggered()), this, SLOT(slot_ac_Connect())); |
||
104 | connect(ac_Plotter, SIGNAL(triggered()), this, SLOT(slot_ac_Plotter())); |
||
105 | connect(ac_Debug, SIGNAL(triggered()), this, SLOT(slot_ac_Debug())); |
||
106 | connect(ac_Chose, SIGNAL(triggered()), this, SLOT(slot_ac_Chose())); |
||
107 | |||
108 | connect(ac_ReadLabels, SIGNAL(triggered()), this, SLOT(slot_ac_ReadLabels())); |
||
109 | |||
110 | connect(rb_NC, SIGNAL(clicked()), this, SLOT(slot_rb_Hardware())); |
||
111 | connect(rb_FC, SIGNAL(clicked()), this, SLOT(slot_rb_Hardware())); |
||
112 | connect(rb_MK3MAG, SIGNAL(clicked()), this, SLOT(slot_rb_Hardware())); |
||
113 | |||
114 | connect(Plotter_Scroll, SIGNAL(valueChanged(int)), this, SLOT(slot_Plotter_Scroll(int))); |
||
115 | |||
116 | connect(btn_Start, SIGNAL(clicked()), this, SLOT(slot_Plotter_Start())); |
||
117 | connect(btn_ChoseOK, SIGNAL(clicked()), this, SLOT(slot_btn_ChoseOK())); |
||
118 | |||
119 | // About QMK-Kernel & About-QT Dialog einfügen |
||
120 | connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About())); |
||
121 | menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt())); |
||
122 | } |
||
123 | |||
124 | void dlg_Main::init_Plotter() |
||
125 | { |
||
126 | NextPlot = 0; |
||
127 | |||
128 | qwt_Plotter->setCanvasBackground(QColor(QRgb(0x00000000))); |
||
129 | |||
130 | qwt_Plotter->insertLegend(new QwtLegend(), QwtPlot::RightLegend); |
||
131 | |||
132 | QwtPlotGrid *Grid = new QwtPlotGrid(); |
||
133 | Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine)); |
||
134 | |||
135 | Grid->attach(qwt_Plotter); |
||
136 | |||
137 | qwt_Plotter->setAxisScale(QwtPlot::xBottom,0,o_Settings->DATA.Plotter_Count,0); |
||
138 | |||
139 | for (int a = 0; a < MAX_DebugData; a++) |
||
140 | { |
||
141 | Plot[a] = new QwtPlotCurve(o_Settings->DebugData.Label[a]); |
||
142 | Plot[a]->setPen(QPen(QColor(DEF_DebugColors[a]))); |
||
143 | Plot[a]->setRenderHint(QwtPlotItem::RenderAntialiased); |
||
144 | |||
145 | if (o_Settings->DebugData.Show_Plotter[a]) |
||
146 | Plot[a]->attach(qwt_Plotter); |
||
147 | } |
||
148 | qwt_Plotter->replot(); |
||
149 | } |
||
150 | |||
151 | void dlg_Main::update_Plotter() |
||
152 | { |
||
153 | pl_ID[NextPlot] = NextPlot; |
||
154 | |||
155 | for (int a = 0; a < MAX_DebugData; a++) |
||
156 | { |
||
157 | pl_Data[a][NextPlot] = Debug_Data[a]; |
||
158 | Plot[a]->setData(pl_ID,pl_Data[a],NextPlot); |
||
159 | } |
||
160 | |||
161 | NextPlot++; |
||
162 | |||
163 | if ((NextPlot > o_Settings->DATA.Plotter_Count)) |
||
164 | { |
||
165 | Plotter_Scroll->setMaximum(NextPlot - o_Settings->DATA.Plotter_Count); |
||
166 | } |
||
167 | |||
168 | if ((Plotter_Scroll->value() == NextPlot - (o_Settings->DATA.Plotter_Count + 1))) |
||
169 | { |
||
170 | qwt_Plotter->setAxisScale(QwtPlot::xBottom,NextPlot - o_Settings->DATA.Plotter_Count,NextPlot,0); |
||
171 | Plotter_Scroll->setValue(NextPlot - o_Settings->DATA.Plotter_Count); |
||
172 | } |
||
173 | |||
174 | qwt_Plotter->replot(); |
||
175 | } |
||
176 | |||
177 | void dlg_Main::config_Plotter() |
||
178 | { |
||
179 | qwt_Plotter->setAxisScale(QwtPlot::xBottom,0,o_Settings->DATA.Plotter_Count,0); |
||
180 | |||
181 | for (int a = 0; a < MAX_DebugData; a++) |
||
182 | { |
||
183 | Plot[a]->detach(); |
||
184 | Plot[a]->setPen(QPen(QColor(DEF_DebugColors[a]))); |
||
185 | |||
186 | if (o_Settings->DebugData.Show_Plotter[a]) |
||
187 | { |
||
188 | Plot[a]->setTitle(o_Settings->DebugData.Label[a]); |
||
189 | Plot[a]->attach(qwt_Plotter); |
||
190 | } |
||
191 | } |
||
192 | qwt_Plotter->replot(); |
||
193 | } |
||
194 | |||
195 | void dlg_Main::slot_Plotter_Scroll(int Position) |
||
196 | { |
||
197 | qwt_Plotter->setAxisScale(QwtPlot::xBottom,Position,Position + o_Settings->DATA.Plotter_Count,0); |
||
198 | qwt_Plotter->replot(); |
||
199 | } |
||
200 | |||
711 | KeyOz | 201 | // IP-Input-Daten verarbeiten. |
674 | KeyOz | 202 | void dlg_Main::parse_IP_Data(QString t_Data) |
203 | { |
||
204 | QStringList Data; |
||
205 | Data = t_Data.split(":"); |
||
206 | |||
207 | if (Data.count() > 1) |
||
208 | { |
||
209 | int CMD = Data[2].toInt(); |
||
210 | |||
211 | switch(CMD) |
||
212 | { |
||
711 | KeyOz | 213 | case 101 : |
674 | KeyOz | 214 | { |
711 | KeyOz | 215 | o_Input->send_Data(HandlerIP::make_Frame(ID_SCOPE, 101, QA_NAME + " " + QA_VERSION)); |
674 | KeyOz | 216 | } |
711 | KeyOz | 217 | case 502 : |
218 | { |
||
219 | switch (Data[3].toInt()) |
||
220 | { |
||
221 | case 105 : |
||
222 | { |
||
223 | QString s_MD5PW; |
||
224 | QByteArray a_MD5PW; |
||
225 | |||
226 | a_MD5PW = QCryptographicHash::hash(le_Password->text().toAscii(),QCryptographicHash::Md5); |
||
227 | |||
228 | s_MD5PW = QString(a_MD5PW.toHex().data()); |
||
229 | |||
230 | o_Input->send_Data(HandlerIP::make_Frame(ID_SCOPE, 105, s_MD5PW)); |
||
231 | } |
||
232 | break; |
||
233 | case 106 : |
||
234 | { |
||
235 | o_Input->send_Data(HandlerIP::make_Frame(ID_SCOPE, 106, DataFields)); |
||
236 | } |
||
237 | break; |
||
238 | } |
||
239 | } |
||
674 | KeyOz | 240 | break; |
241 | case 505 : |
||
242 | { |
||
243 | if (Data[3] == "OK") |
||
244 | { |
||
245 | } |
||
246 | else |
||
247 | { |
||
248 | QMessageBox::warning(this, QA_NAME, trUtf8("Authentifizierung fehlgeschlagen. <br />Daten senden zum Mikrokopter nicht möglich."), QMessageBox::Ok); |
||
249 | } |
||
250 | } |
||
251 | break; |
||
252 | } |
||
253 | } |
||
254 | } |
||
255 | |||
711 | KeyOz | 256 | // MK-Eingangsdaten verarbeiten |
674 | KeyOz | 257 | void dlg_Main::parse_MK_Data(QString t_Data) |
258 | { |
||
259 | unsigned char OutData[150]; |
||
260 | char *InData = t_Data.toLatin1().data(); |
||
261 | |||
262 | if (HandlerMK::Decode_64(InData, t_Data.length(), OutData) != 0) |
||
263 | { |
||
264 | switch(InData[2]) |
||
265 | { |
||
266 | case 'A' : // 0.76e - Debug-Labels |
||
267 | { |
||
268 | o_Input->stop_Resend(DATA_READ_LABEL); |
||
269 | int Position = OutData[0]; |
||
270 | if (Position < 32) |
||
271 | { |
||
272 | o_Settings->DebugData.Label[Position] = HandlerMK::Data2QString(OutData,1,17).trimmed(); |
||
273 | if (o_Settings->DebugData.Label[Position] == "") |
||
274 | { |
||
275 | o_Settings->DebugData.Label[Position] = "Debug-" + QString("%1").arg(Position); |
||
276 | } |
||
277 | lb_Debug[Position]->setText("" + o_Settings->DebugData.Label[Position]); |
||
278 | cb_Debug[Position]->setText("" + o_Settings->DebugData.Label[Position]); |
||
279 | |||
280 | Position ++; |
||
281 | |||
282 | if ((Position < 32) && (get_Analoglabels == true)) |
||
283 | { |
||
284 | c_Data[0] = Position; |
||
285 | o_Input->send_Data(HandlerMK::make_Frame('a', ADDRESS_ALL, c_Data, 1).toLatin1().data(), DATA_READ_LABEL); |
||
286 | } |
||
287 | } |
||
288 | if (Position == 32) |
||
289 | { |
||
290 | o_Settings->DebugData.Version = VersionInfo.Version; |
||
291 | o_Settings->write_DebugLabels(VersionInfo.ID); |
||
292 | config_Plotter(); |
||
293 | get_Analoglabels = false; |
||
294 | } |
||
295 | } |
||
296 | break; |
||
297 | |||
298 | case 'D' : // 0.75a - Debug-Daten |
||
299 | { |
||
300 | for (int z = 0; z < MAX_DebugData; z++) |
||
301 | { |
||
302 | Debug_Data[z] = HandlerMK::Data2Int(OutData, (z * 2) + 2); |
||
303 | if (ac_Debug->isChecked()) |
||
304 | { |
||
305 | le_Debug[z]->setText(QString("%1").arg(Debug_Data[z])); |
||
306 | } |
||
307 | } |
||
308 | if (btn_Start->isChecked()) |
||
309 | { |
||
310 | update_Plotter(); |
||
311 | } |
||
312 | } |
||
313 | break; |
||
314 | |||
315 | case 'V' : // 0.75a - Versions-Info |
||
316 | { |
||
317 | o_Input->stop_Resend(DATA_VERSION); |
||
318 | VersionInfo = HandlerMK::parse_Version(OutData, InData[1] - 'a'); |
||
319 | setWindowTitle(QA_NAME + " " + QA_VERSION + " - " + VersionInfo.Hardware + " " + VersionInfo.Version); |
||
320 | |||
321 | if (VersionInfo.ID == ADDRESS_FC) |
||
322 | { |
||
323 | rb_FC->setChecked(true); |
||
324 | } |
||
325 | if (VersionInfo.ID == ADDRESS_NC) |
||
326 | { |
||
327 | rb_NC->setChecked(true); |
||
328 | } |
||
329 | if (VersionInfo.ID == ADDRESS_MK3MAG) |
||
330 | { |
||
331 | rb_MK3MAG->setChecked(true); |
||
332 | } |
||
333 | |||
334 | o_Settings->read_DebugLabels(VersionInfo.ID); |
||
335 | |||
336 | if (o_Settings->DebugData.Version != VersionInfo.Version) |
||
337 | { |
||
338 | // qDebug(QString("Debug-Labels unterschiedlich. Neue anforden. " + o_Settings->DebugData.Version + " <> " + VersionInfo.Version).toLatin1().data()); |
||
339 | |||
340 | usleep(50000); |
||
341 | |||
342 | slot_ac_ReadLabels(); |
||
343 | // o_Input->send_Data(HandlerMK::make_Frame('a', ADDRESS_ALL, c_Data, 1).toLatin1().data()); |
||
344 | } |
||
345 | else |
||
346 | { |
||
347 | for(int z = 0; z < MAX_DebugData; z++) |
||
348 | { |
||
349 | lb_Debug[z]->setText(o_Settings->DebugData.Label[z]); |
||
350 | cb_Debug[z]->setText(o_Settings->DebugData.Label[z]); |
||
351 | cb_Debug[z]->setChecked(o_Settings->DebugData.Show_Plotter[z]); |
||
352 | } |
||
353 | config_Plotter(); |
||
354 | } |
||
355 | c_Data[0] = sb_Intervall->value() / 10; |
||
356 | o_Input->send_Data(HandlerMK::make_Frame('d', ADDRESS_ALL, c_Data, 1).toLatin1().data()); |
||
357 | } |
||
358 | break; |
||
359 | } |
||
360 | } |
||
361 | } |
||
362 | |||
363 | /////////// |
||
364 | // Slots // |
||
365 | /////////// |
||
366 | void dlg_Main::slot_Plotter_Start() |
||
367 | { |
||
368 | if (btn_Start->isChecked()) |
||
369 | { |
||
370 | btn_Start->setText(tr("Plotter stoppen")); |
||
371 | } |
||
372 | else |
||
373 | { |
||
374 | btn_Start->setText(tr("Plotter starten")); |
||
375 | } |
||
376 | } |
||
377 | |||
378 | void dlg_Main::slot_btn_ChoseOK() |
||
379 | { |
||
380 | for(int z = 0; z < MAX_DebugData; z++) |
||
381 | { |
||
382 | o_Settings->DebugData.Show_Plotter[z] = cb_Debug[z]->isChecked(); |
||
383 | } |
||
384 | config_Plotter(); |
||
385 | o_Settings->write_DebugLabels(VersionInfo.ID); |
||
386 | } |
||
387 | |||
388 | void dlg_Main::slot_ac_Chose() |
||
389 | { |
||
390 | |||
391 | for(int z = 0; z < MAX_DebugData; z++) |
||
392 | { |
||
393 | cb_Debug[z]->setChecked(o_Settings->DebugData.Show_Plotter[z]); |
||
394 | } |
||
395 | |||
396 | ac_Chose->setChecked(true); |
||
397 | ac_Debug->setChecked(false); |
||
398 | ac_Plotter->setChecked(false); |
||
399 | wg_Pages->setCurrentIndex(2); |
||
400 | } |
||
401 | |||
402 | void dlg_Main::slot_ac_Debug() |
||
403 | { |
||
404 | ac_Debug->setChecked(true); |
||
405 | ac_Chose->setChecked(false); |
||
406 | ac_Plotter->setChecked(false); |
||
407 | wg_Pages->setCurrentIndex(1); |
||
408 | } |
||
409 | |||
410 | void dlg_Main::slot_ac_Plotter() |
||
411 | { |
||
412 | ac_Plotter->setChecked(true); |
||
413 | ac_Debug->setChecked(false); |
||
414 | ac_Chose->setChecked(false); |
||
415 | wg_Pages->setCurrentIndex(0); |
||
416 | } |
||
417 | |||
418 | void dlg_Main::slot_ac_ReadLabels() |
||
419 | { |
||
420 | get_Analoglabels = true; |
||
421 | c_Data[0] = 0; |
||
422 | o_Input->send_Data(HandlerMK::make_Frame('a', ADDRESS_ALL, c_Data, 1).toLatin1().data(), DATA_READ_LABEL); |
||
423 | } |
||
424 | |||
425 | // About-Dialog |
||
426 | void dlg_Main::slot_ac_About() |
||
427 | { |
||
428 | QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT); |
||
429 | } |
||
430 | |||
431 | // Datenintervall geändert. |
||
432 | void dlg_Main::slot_sb_Intervall(int t_Intervall) |
||
433 | { |
||
434 | if (t_Intervall == 0) |
||
435 | { |
||
436 | c_Data[0] = 0; |
||
437 | } |
||
438 | else |
||
439 | { |
||
440 | c_Data[0] = t_Intervall / 10; |
||
441 | } |
||
442 | o_Input->send_Data(HandlerMK::make_Frame('d', ADDRESS_ALL, c_Data, 1).toLatin1().data()); |
||
443 | } |
||
444 | |||
445 | // Hardware auswählen. |
||
446 | void dlg_Main::slot_rb_Hardware() |
||
447 | { |
||
448 | if ((rb_NC->isChecked() == false) && (VersionInfo.ID != ADDRESS_NC)) |
||
449 | { |
||
450 | o_Input->send_Data(HandlerMK::get_SelectNC()); |
||
451 | } |
||
452 | |||
453 | if (rb_FC->isChecked()) |
||
454 | { |
||
455 | o_Input->send_Data(HandlerMK::get_SelectFC()); |
||
456 | } |
||
457 | else |
||
458 | if (rb_MK3MAG->isChecked()) |
||
459 | { |
||
460 | o_Input->send_Data(HandlerMK::get_SelectMK3MAG()); |
||
461 | } |
||
462 | else |
||
463 | if (rb_NC->isChecked()) |
||
464 | { |
||
465 | o_Input->send_Data(HandlerMK::get_SelectNC()); |
||
466 | } |
||
467 | |||
468 | o_Input->send_Data(HandlerMK::make_Frame('v', 0, c_Data, 0).toLatin1().data(), DATA_VERSION); |
||
469 | } |
||
470 | |||
471 | // Verbindung zum Server aufbauen |
||
472 | void dlg_Main::slot_ac_Connect() |
||
473 | { |
||
474 | if (!o_Input->IsOpen()) |
||
475 | { |
||
476 | if (cb_Server->findText(cb_Server->currentText()) == -1) |
||
477 | { |
||
478 | cb_Server->addItem(cb_Server->currentText()); |
||
479 | cb_Server->setCurrentIndex(cb_Server->findText(cb_Server->currentText())); |
||
480 | } |
||
481 | |||
482 | cb_Server->setEnabled(false); |
||
483 | le_Password->setEnabled(false); |
||
484 | |||
711 | KeyOz | 485 | // Connect über Device |
674 | KeyOz | 486 | if (cb_Server->currentText().startsWith('/')) |
487 | { |
||
488 | o_Input = new Input_TTY(); |
||
489 | o_Input->Init(); |
||
490 | |||
491 | set_Input s_Input; |
||
492 | s_Input.Main = cb_Server->currentText(); |
||
493 | |||
494 | if (o_Input->Open(s_Input) == true) |
||
495 | { |
||
496 | ac_Connect->setText(tr("Trennen")); |
||
497 | connect(o_Input, SIGNAL(sig_NewData(QString)), this, SLOT(slot_Input_Data(QString))); |
||
498 | |||
499 | o_Input->send_Data(HandlerMK::make_Frame('v', 0, c_Data, 0).toLatin1().data(), DATA_VERSION); |
||
500 | } |
||
501 | else |
||
502 | { |
||
503 | cb_Server->setEnabled(true); |
||
504 | le_Password->setEnabled(true); |
||
505 | } |
||
506 | |||
507 | } |
||
711 | KeyOz | 508 | else // Connect über TCPIP |
674 | KeyOz | 509 | { |
510 | o_Input = new Input_TCP(); |
||
511 | o_Input->Init(); |
||
512 | |||
513 | set_Input s_Input; |
||
514 | |||
515 | QStringList Server = cb_Server->currentText().split(":"); |
||
516 | |||
517 | s_Input.Main = Server[0]; |
||
518 | s_Input.Sub = Server[1]; |
||
519 | |||
520 | if (o_Input->Open(s_Input) == true) |
||
521 | { |
||
522 | connect(o_Input, SIGNAL(sig_Disconnected(int)), this, SLOT(slot_Input_Disconnected(int))); |
||
523 | connect(o_Input, SIGNAL(sig_Connected()), this, SLOT(slot_Input_Connected())); |
||
524 | } |
||
525 | } |
||
526 | } |
||
527 | else |
||
528 | { |
||
529 | cb_Server->setEnabled(true); |
||
530 | le_Password->setEnabled(true); |
||
531 | |||
532 | ac_Connect->setText(tr("Verbinden")); |
||
533 | o_Input->Close(); |
||
534 | disconnect(o_Input, SIGNAL(sig_NewData(QString)), 0, 0); |
||
535 | if (o_Input->Mode() == TCP) |
||
536 | { |
||
537 | disconnect(o_Input, SIGNAL(sig_Disconnected(int)), 0, 0); |
||
538 | disconnect(o_Input, SIGNAL(sig_Connected()), 0, 0); |
||
539 | } |
||
540 | } |
||
541 | } |
||
542 | |||
543 | // Neue Daten empfangen. |
||
544 | void dlg_Main::slot_Input_Data(QString t_Data) |
||
545 | { |
||
546 | if ((t_Data[0] == '#')) |
||
547 | { |
||
548 | 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())))) |
||
549 | { |
||
550 | parse_MK_Data(t_Data); |
||
551 | } |
||
552 | else |
||
553 | { |
||
711 | KeyOz | 554 | qDebug(QString("CRC-Error - " + t_Data).toLatin1().data()); |
674 | KeyOz | 555 | } |
556 | } |
||
711 | KeyOz | 557 | else if ((o_Input->Mode() == TCP) && (t_Data[0] == '$')) |
674 | KeyOz | 558 | { |
559 | parse_IP_Data(t_Data); |
||
560 | } |
||
561 | } |
||
562 | |||
563 | void dlg_Main::slot_Input_Disconnected(int Error) |
||
564 | { |
||
565 | cb_Server->setEnabled(true); |
||
566 | le_Password->setEnabled(true); |
||
567 | |||
568 | disconnect(o_Input, SIGNAL(sig_NewData(QString)), 0, 0); |
||
711 | KeyOz | 569 | disconnect(o_Input, SIGNAL(sig_Disconnected(int)), 0, 0); |
570 | disconnect(o_Input, SIGNAL(sig_Connected()), 0, 0); |
||
571 | |||
674 | KeyOz | 572 | ac_Connect->setChecked(false); |
573 | ac_Connect->setText(tr("Verbinden")); |
||
574 | |||
575 | switch (Error) |
||
576 | { |
||
577 | case REMOTECLOSED : |
||
578 | { |
||
579 | // lb_Status->setText(tr("Verbindung vom Server beendet.")); |
||
580 | QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Verbindung wurde vom Server beendet."), QMessageBox::Ok); |
||
581 | } |
||
582 | break; |
||
583 | case REFUSED : |
||
584 | { |
||
585 | // lb_Status->setText(tr("Server nicht gefunden.")); |
||
586 | QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Kann nicht zum Server verbinden."), QMessageBox::Ok); |
||
587 | } |
||
588 | break; |
||
589 | case 3 : |
||
590 | { |
||
591 | // lb_Status->setText(tr("Serververbindung getrennt. Logindaten falsch.")); |
||
592 | QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Loginname oder Password falsch."), QMessageBox::Ok); |
||
593 | } |
||
594 | break; |
||
595 | default : |
||
596 | { |
||
597 | // lb_Status->setText(tr("Getrennt vom QMK-Datenserver.")); |
||
598 | } |
||
599 | break; |
||
600 | } |
||
601 | |||
602 | } |
||
603 | |||
604 | void dlg_Main::slot_Input_Connected() |
||
605 | { |
||
606 | connect(o_Input, SIGNAL(sig_NewData(QString)), this, SLOT(slot_Input_Data(QString))); |
||
607 | |||
711 | KeyOz | 608 | // o_Input->send_Data(HandlerIP::make_Frame(ID_SCOPE, 101, QA_NAME + " " + QA_VERSION)); |
674 | KeyOz | 609 | o_Input->send_Data(HandlerMK::make_Frame('v', 0, c_Data, 0).toLatin1().data(), DATA_VERSION); |
610 | ac_Connect->setText(tr("Trennen")); |
||
611 | } |
||
612 | |||
613 | // Programm Ende |
||
614 | dlg_Main::~dlg_Main() |
||
615 | { |
||
616 | o_Settings->GUI.isMax = isMaximized(); |
||
617 | o_Settings->GUI.Size = size(); |
||
618 | o_Settings->GUI.Point = pos(); |
||
619 | |||
620 | o_Settings->DATA.Debug_Intervall = sb_Intervall->value(); |
||
621 | |||
622 | o_Settings->SERVER.Password = le_Password->text(); |
||
623 | o_Settings->SERVER.IP_MAX = cb_Server->count(); |
||
624 | o_Settings->SERVER.IP_ID = cb_Server->currentIndex(); |
||
625 | |||
626 | for (int z = 0; z < cb_Server->count(); z++) |
||
627 | { |
||
628 | if (z < 10) |
||
629 | { |
||
630 | o_Settings->SERVER.IP[z] = cb_Server->itemText(z); |
||
631 | } |
||
632 | } |
||
633 | |||
634 | o_Settings->write_Settings(); |
||
635 | |||
636 | // qDebug("Ende."); |
||
637 | } |