Rev 166 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
158 | KeyOz | 1 | /*************************************************************************** |
2 | * Copyright (C) 2008 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 <QtGui> |
||
21 | |||
22 | #include <QLineEdit> |
||
23 | #include <QString> |
||
24 | #include <QTimer> |
||
25 | #include <QIcon> |
||
26 | #include <QToolButton> |
||
27 | #include <QSpinBox> |
||
28 | |||
29 | #include "mktool.h" |
||
30 | #include "dlg_Config.h" |
||
31 | #include "dlg_Motortest.h" |
||
159 | KeyOz | 32 | #include "dlg_Preferences.h" |
158 | KeyOz | 33 | #include "../global.h" |
34 | #include "../ToolBox.h" |
||
35 | |||
36 | #include <stdlib.h> |
||
37 | |||
38 | MKTool::MKTool() |
||
39 | { |
||
40 | setupUi(this); |
||
41 | |||
42 | Settings = new cSettings; |
||
43 | |||
44 | init_Arrays(); |
||
45 | init_Icons(); |
||
46 | init_GUI(); |
||
47 | |||
48 | init_Objects(); |
||
49 | init_Connections(); |
||
50 | |||
51 | init_Plot(); |
||
52 | } |
||
53 | |||
54 | void MKTool::init_GUI() |
||
55 | { |
||
56 | setWindowTitle(QA_NAME + " v" + QA_VERSION); |
||
57 | |||
167 | KeyOz | 58 | // Tab mit Debug-Elementen verbergen |
59 | tab_Main->removeTab(5); |
||
60 | // tab_Main->removeTab(2); |
||
61 | |||
62 | // Settings-Tab hinzufügen. |
||
63 | f_Settings = new wdg_Settings( this ); |
||
64 | |||
65 | tab_Main->insertTab ( 2, f_Settings, "Parameter"); |
||
66 | tab_Main->widget(2)->setObjectName("Tab_2"); |
||
67 | |||
68 | // Develop - Nicht gebrauchte sachen abschalten. |
||
69 | ac_StartServer->setVisible(false); |
||
70 | box_Flugdaten->hide(); |
||
71 | box_System->hide(); |
||
72 | pb_SettingsReset->hide(); |
||
73 | pb_Flash->hide(); |
||
74 | rb_NC->hide(); |
||
75 | |||
76 | // Zusätzliche Widgets in die Toolbar. |
||
166 | KeyOz | 77 | toolBar->addWidget(lb_Port); |
78 | toolBar->addWidget(le_Port); |
||
79 | toolBar->addSeparator(); |
||
167 | KeyOz | 80 | // toolBar->addWidget(cb_Hardware); |
166 | KeyOz | 81 | |
167 | KeyOz | 82 | lb_Status->setText("Hallo bei QMK-Groundstation...!!!"); |
166 | KeyOz | 83 | |
158 | KeyOz | 84 | #ifdef _EEEPC_ |
85 | toolBar->hide(); |
||
166 | KeyOz | 86 | lb_Status->hide(); |
158 | KeyOz | 87 | #endif |
88 | |||
89 | resize(Settings->GUI.Size); |
||
90 | move(Settings->GUI.Point); |
||
91 | |||
92 | if (Settings->GUI.isMax) |
||
93 | { |
||
94 | showMaximized(); |
||
95 | } |
||
96 | |||
97 | for (int a = 0; a < MaxAnalog; a++) |
||
98 | { |
||
162 | KeyOz | 99 | lb_Analog[a]->setText(Settings->Analog1.Label[a]); |
158 | KeyOz | 100 | } |
101 | |||
102 | for (int b = 0; b < 6; b++) |
||
103 | { |
||
104 | TabWidgets[b] = tab_Main->widget(b); |
||
105 | } |
||
106 | |||
107 | for (int c = 0; c < 6; c++) |
||
108 | { |
||
109 | if (Settings->GUI.TabViews[c] == false) |
||
110 | { |
||
111 | QString TabName = QString("Tab_%1").arg(c); |
||
112 | |||
113 | for (int d = 0; d < tab_Main->count(); d++) |
||
114 | { |
||
115 | if (tab_Main->widget(d)->objectName() == TabName) |
||
116 | { |
||
117 | tab_Main->removeTab(d); |
||
118 | } |
||
119 | } |
||
120 | } |
||
121 | } |
||
122 | |||
123 | ac_View0->setChecked(Settings->GUI.TabViews[0]); |
||
124 | ac_View1->setChecked(Settings->GUI.TabViews[1]); |
||
125 | ac_View2->setChecked(Settings->GUI.TabViews[2]); |
||
126 | ac_View3->setChecked(Settings->GUI.TabViews[3]); |
||
127 | ac_View4->setChecked(Settings->GUI.TabViews[4]); |
||
128 | ac_View5->setChecked(Settings->GUI.TabViews[5]); |
||
129 | |||
130 | le_Port->setText(Settings->TTY.Port); |
||
162 | KeyOz | 131 | |
132 | cb_ShowMSG->setChecked(Settings->GUI.Term_Info); |
||
133 | cb_ShowData->setChecked(Settings->GUI.Term_Data); |
||
134 | cb_ShowAlways->setChecked(Settings->GUI.Term_Always); |
||
158 | KeyOz | 135 | } |
136 | |||
137 | void MKTool::init_Objects() |
||
138 | { |
||
139 | // QTimer-Instanzen |
||
140 | Ticker = new QTimer(this); |
||
141 | |||
142 | // Seriell-Port |
||
143 | serialPort = new ManageSerialPort; |
||
144 | |||
145 | // QFile-Instanz (Log-Datei) |
||
146 | CSVFile = new QFile(""); |
||
159 | KeyOz | 147 | |
148 | AllowSend = true; |
||
158 | KeyOz | 149 | } |
150 | |||
151 | void MKTool::init_Connections() |
||
152 | { |
||
153 | // Seriel-Port Empfang |
||
154 | connect(serialPort, SIGNAL(newDataReceived(const QByteArray &)), this, SLOT(slot_newDataReceived(const QByteArray &))); |
||
155 | |||
167 | KeyOz | 156 | // Buttons Settings lesen / schreiben |
157 | connect(f_Settings->pb_Read, SIGNAL(clicked()), this, SLOT(slot_GetParameter())); |
||
158 | connect(f_Settings->pb_Write, SIGNAL(clicked()), this, SLOT(slot_SetParameter())); |
||
158 | KeyOz | 159 | |
167 | KeyOz | 160 | // LCD auf / ab |
159 | KeyOz | 161 | connect(pb_LCDup, SIGNAL(clicked()), this, SLOT(slot_LCD_UP())); |
162 | connect(pb_LCDdown, SIGNAL(clicked()), this, SLOT(slot_LCD_DOWN())); |
||
163 | |||
158 | KeyOz | 164 | // Actions |
165 | connect(ac_Config, SIGNAL(triggered()), this, SLOT(slot_ac_Config())); |
||
159 | KeyOz | 166 | connect(ac_Preferences, SIGNAL(triggered()), this, SLOT(slot_ac_Preferences())); |
158 | KeyOz | 167 | connect(ac_Motortest, SIGNAL(triggered()), this, SLOT(slot_ac_Motortest())); |
168 | connect(ac_MehrDaten, SIGNAL(triggered()), this, SLOT(slot_ac_MehrDaten())); |
||
166 | KeyOz | 169 | connect(ac_KeineDaten, SIGNAL(triggered()), this, SLOT(slot_ac_KeineDaten())); |
158 | KeyOz | 170 | connect(ac_GetLabels, SIGNAL(triggered()), this, SLOT(slot_ac_GetLabels())); |
171 | |||
167 | KeyOz | 172 | // Plotter starten / scrollen |
173 | connect(scroll_plot, SIGNAL(valueChanged(int)), this, SLOT(slot_ScrollPlot(int))); |
||
174 | connect(ac_StartPlotter, SIGNAL(triggered()), this, SLOT(slot_ac_StartPlotter())); |
||
175 | |||
158 | KeyOz | 176 | // Tabs ein & ausblenden |
177 | connect(ac_View0, SIGNAL(triggered()), this, SLOT(slot_ac_View())); |
||
178 | connect(ac_View1, SIGNAL(triggered()), this, SLOT(slot_ac_View())); |
||
179 | connect(ac_View2, SIGNAL(triggered()), this, SLOT(slot_ac_View())); |
||
180 | connect(ac_View3, SIGNAL(triggered()), this, SLOT(slot_ac_View())); |
||
181 | connect(ac_View4, SIGNAL(triggered()), this, SLOT(slot_ac_View())); |
||
182 | connect(ac_View5, SIGNAL(triggered()), this, SLOT(slot_ac_View())); |
||
183 | |||
167 | KeyOz | 184 | // firmeware Updateen / flashen |
166 | KeyOz | 185 | connect(pb_Update, SIGNAL(clicked()), this, SLOT(slot_pb_Update())); |
186 | connect(pb_HexFile, SIGNAL(clicked()), this, SLOT(slot_pb_HexFile())); |
||
158 | KeyOz | 187 | |
167 | KeyOz | 188 | // Serielle Verbundung öffnen / schließen |
158 | KeyOz | 189 | connect(ac_ConnectTTY, SIGNAL(triggered()), this, SLOT(slot_OpenPort())); |
167 | KeyOz | 190 | |
191 | // CVS-Record starten / stoppen |
||
158 | KeyOz | 192 | connect(ac_RecordCSV, SIGNAL(triggered()), this, SLOT(slot_RecordCSV())); |
193 | |||
194 | // Timer-Events |
||
195 | connect(Ticker, SIGNAL(timeout()), SLOT(slot_Ticker())); |
||
196 | |||
167 | KeyOz | 197 | // Seitenwechsel |
158 | KeyOz | 198 | connect(tab_Main, SIGNAL(currentChanged(int)), this, SLOT(slot_TabChanged(int))); |
167 | KeyOz | 199 | connect(f_Settings->tab_Par, SIGNAL(currentChanged(int)), this, SLOT(slot_TabChanged(int))); |
158 | KeyOz | 200 | |
167 | KeyOz | 201 | // About QMK & About-QT Dialog einfügen |
202 | connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About())); |
||
158 | KeyOz | 203 | menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt())); |
204 | } |
||
205 | |||
206 | void MKTool::init_Arrays() |
||
207 | { |
||
208 | lb_Analog[0] = lb_A_0; |
||
209 | lb_Analog[1] = lb_A_1; |
||
210 | lb_Analog[2] = lb_A_2; |
||
211 | lb_Analog[3] = lb_A_3; |
||
212 | lb_Analog[4] = lb_A_4; |
||
213 | lb_Analog[5] = lb_A_5; |
||
214 | lb_Analog[6] = lb_A_6; |
||
215 | lb_Analog[7] = lb_A_7; |
||
216 | lb_Analog[8] = lb_A_8; |
||
217 | lb_Analog[9] = lb_A_9; |
||
218 | lb_Analog[10] = lb_A_10; |
||
219 | lb_Analog[11] = lb_A_11; |
||
220 | lb_Analog[12] = lb_A_12; |
||
221 | lb_Analog[13] = lb_A_13; |
||
222 | lb_Analog[14] = lb_A_14; |
||
223 | lb_Analog[15] = lb_A_15; |
||
224 | lb_Analog[16] = lb_A_16; |
||
225 | lb_Analog[17] = lb_A_17; |
||
226 | lb_Analog[18] = lb_A_18; |
||
227 | lb_Analog[19] = lb_A_19; |
||
228 | lb_Analog[20] = lb_A_20; |
||
229 | lb_Analog[21] = lb_A_21; |
||
230 | lb_Analog[22] = lb_A_22; |
||
231 | lb_Analog[23] = lb_A_23; |
||
232 | lb_Analog[24] = lb_A_24; |
||
233 | lb_Analog[25] = lb_A_25; |
||
234 | lb_Analog[26] = lb_A_26; |
||
235 | lb_Analog[27] = lb_A_27; |
||
236 | lb_Analog[28] = lb_A_28; |
||
237 | lb_Analog[29] = lb_A_29; |
||
238 | lb_Analog[30] = lb_A_30; |
||
239 | lb_Analog[31] = lb_A_31; |
||
240 | } |
||
241 | |||
242 | void MKTool::init_Plot() |
||
243 | { |
||
244 | NextPlot = 0; |
||
245 | |||
246 | qwtPlot->setCanvasBackground(QColor(QRgb(0x00000000))); |
||
247 | |||
248 | qwtPlot->insertLegend(new QwtLegend(), QwtPlot::RightLegend); |
||
249 | |||
250 | QwtPlotGrid *Grid = new QwtPlotGrid(); |
||
251 | Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine)); |
||
252 | |||
253 | Grid->attach(qwtPlot); |
||
254 | |||
166 | KeyOz | 255 | qwtPlot->setAxisScale(QwtPlot::xBottom,0,Settings->Data.Plotter_Count,0); |
158 | KeyOz | 256 | |
257 | for (int a = 0; a < MaxAnalog; a++) |
||
258 | { |
||
162 | KeyOz | 259 | Plot[a] = new QwtPlotCurve(Settings->Analog1.Label[a]); |
260 | Plot[a]->setPen(QPen(QColor(Def_Colors[a]))); |
||
167 | KeyOz | 261 | Plot[a]->setRenderHint(QwtPlotItem::RenderAntialiased); |
158 | KeyOz | 262 | |
162 | KeyOz | 263 | if (Settings->Analog1.PlotView[a]) |
158 | KeyOz | 264 | Plot[a]->attach(qwtPlot); |
265 | } |
||
266 | qwtPlot->replot(); |
||
267 | } |
||
268 | |||
269 | void MKTool::init_Icons() |
||
270 | { |
||
271 | Icons[0].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledred.png")), QIcon::Normal, QIcon::Off); |
||
272 | Icons[1].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledyellow.png")), QIcon::Normal, QIcon::Off); |
||
273 | Icons[3].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledyellow.png")), QIcon::Normal, QIcon::Off); |
||
274 | Icons[4].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledoff.png")), QIcon::Normal, QIcon::Off); |
||
275 | |||
276 | Icons[5].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/application-exit.png")), QIcon::Normal, QIcon::Off); |
||
277 | Icons[6].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/media-playback-stop.png")), QIcon::Normal, QIcon::Off); |
||
278 | Icons[7].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/media-record.png")), QIcon::Normal, QIcon::Off); |
||
279 | Icons[8].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/network-connect.png")), QIcon::Normal, QIcon::Off); |
||
280 | Icons[9].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/network-disconnect.png")), QIcon::Normal, QIcon::Off); |
||
281 | Icons[10].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/utilities-system-monitor.png")), QIcon::Normal, QIcon::Off); |
||
282 | |||
283 | Icons[20].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-up-double.png")), QIcon::Normal, QIcon::Off); |
||
284 | Icons[21].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-up.png")), QIcon::Normal, QIcon::Off); |
||
285 | Icons[22].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-down-double.png")), QIcon::Normal, QIcon::Off); |
||
286 | Icons[23].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-down.png")), QIcon::Normal, QIcon::Off); |
||
287 | Icons[24].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-left-double.png")), QIcon::Normal, QIcon::Off); |
||
288 | Icons[25].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-left.png")), QIcon::Normal, QIcon::Off); |
||
289 | Icons[26].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-right-double.png")), QIcon::Normal, QIcon::Off); |
||
290 | Icons[27].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-right.png")), QIcon::Normal, QIcon::Off); |
||
291 | } |
||
292 | |||
293 | |||
294 | // Ticker-Event |
||
295 | /////////////// |
||
296 | void MKTool::slot_Ticker() |
||
297 | { |
||
298 | if (TickerDiv) |
||
299 | TickerDiv = false; |
||
300 | else |
||
301 | TickerDiv = true; |
||
302 | |||
303 | for (int a = 0; a < MaxTickerEvents; a++) |
||
304 | { |
||
305 | if (TickerEvent[a] == true) |
||
306 | { |
||
307 | switch(a) |
||
308 | { |
||
309 | case 0 : |
||
310 | if (TickerDiv) |
||
311 | { |
||
312 | QByteArray Temp(LastSend.toUtf8()); |
||
313 | serialPort->sendData(Temp); |
||
314 | } |
||
315 | break; |
||
316 | case 1 : |
||
159 | KeyOz | 317 | TX_Data[0] = 0; |
318 | send_Data('p', ADDRESS_FC, TX_Data, 0, false); |
||
158 | KeyOz | 319 | break; |
159 | KeyOz | 320 | case 2 : |
167 | KeyOz | 321 | if (cb_LCD->isChecked()) |
322 | { |
||
323 | TX_Data[0] = LCD_Page; |
||
324 | TX_Data[1] = 0; |
||
325 | send_Data('l', ADDRESS_ALL, TX_Data, 1, true); |
||
326 | } |
||
159 | KeyOz | 327 | break; |
167 | KeyOz | 328 | case 3 : |
329 | if (ac_MehrDaten->isChecked()) |
||
330 | { |
||
331 | TX_Data[0] = Settings->Data.Debug_Fast / 10; |
||
332 | send_Data('d', ADDRESS_ALL, TX_Data, 1, false); |
||
333 | } |
||
334 | else |
||
335 | { |
||
336 | TX_Data[0] = Settings->Data.Debug_Slow / 10; |
||
337 | send_Data('d', ADDRESS_ALL, TX_Data, 1, false); |
||
338 | } |
||
339 | break; |
||
158 | KeyOz | 340 | } |
341 | } |
||
342 | } |
||
343 | } |
||
344 | |||
345 | |||
346 | // Slots der Actions (Menüpunkte, Buttons) |
||
347 | ////////////////////////////////////////// |
||
348 | void MKTool::slot_ac_Motortest() |
||
349 | { |
||
350 | dlg_Motortest *f_Motortest = new dlg_Motortest(this); |
||
351 | |||
352 | connect(f_Motortest, SIGNAL(updateMotor(int, int, int, int)), this, SLOT(slot_Motortest(int, int, int, int))); |
||
353 | |||
354 | if (f_Motortest->exec()==QDialog::Accepted) |
||
355 | { |
||
356 | } |
||
357 | |||
358 | disconnect(f_Motortest, 0,0,0); |
||
359 | slot_Motortest(0,0,0,0); |
||
360 | } |
||
361 | |||
362 | void MKTool::slot_Motortest(int Motor1, int Motor2, int Motor3, int Motor4) |
||
363 | { |
||
364 | TX_Data[0] = Motor1; |
||
365 | TX_Data[1] = Motor2; |
||
366 | TX_Data[2] = Motor3; |
||
367 | TX_Data[3] = Motor4; |
||
159 | KeyOz | 368 | send_Data('t', ADDRESS_FC, TX_Data, 4, false); |
158 | KeyOz | 369 | } |
370 | |||
371 | void MKTool::slot_ac_Config() |
||
372 | { |
||
162 | KeyOz | 373 | set_Analog Old_Analog1; |
158 | KeyOz | 374 | |
162 | KeyOz | 375 | Old_Analog1 = Settings->Analog1; |
376 | |||
158 | KeyOz | 377 | dlg_Config *f_Config = new dlg_Config(this); |
162 | KeyOz | 378 | f_Config->set_Settings(Settings, Mode.ID); |
158 | KeyOz | 379 | |
380 | if (f_Config->exec()==QDialog::Accepted) |
||
381 | { |
||
382 | Settings = f_Config->get_Settings(); |
||
162 | KeyOz | 383 | Settings->write_Settings_Analog(Mode.ID); |
158 | KeyOz | 384 | |
163 | KeyOz | 385 | // Plotter neu einrichten |
386 | if (Old_Analog1.PlotView != Settings->Analog1.PlotView) |
||
158 | KeyOz | 387 | { |
163 | KeyOz | 388 | config_Plot(); |
158 | KeyOz | 389 | } |
390 | |||
163 | KeyOz | 391 | // CVS-Datei neu anlegen. |
392 | if ((CSVFile->isOpen()) && (Old_Analog1.LogView != Settings->Analog1.LogView)) |
||
158 | KeyOz | 393 | { |
163 | KeyOz | 394 | slot_RecordCSV(); |
395 | slot_RecordCSV(); |
||
158 | KeyOz | 396 | } |
397 | |||
398 | } |
||
399 | } |
||
400 | |||
159 | KeyOz | 401 | void MKTool::slot_ac_Preferences() |
402 | { |
||
403 | dlg_Preferences *f_Preferences = new dlg_Preferences(this); |
||
404 | |||
166 | KeyOz | 405 | Settings->TTY.Port = le_Port->text(); |
163 | KeyOz | 406 | f_Preferences->set_Settings(Settings); |
407 | |||
159 | KeyOz | 408 | if (f_Preferences->exec()==QDialog::Accepted) |
409 | { |
||
163 | KeyOz | 410 | Settings = f_Preferences->get_Settings(); |
411 | Settings->write_Settings(); |
||
166 | KeyOz | 412 | le_Port->setText(Settings->TTY.Port); |
413 | config_Plot(); |
||
159 | KeyOz | 414 | } |
415 | } |
||
416 | |||
158 | KeyOz | 417 | void MKTool::slot_ac_StartPlotter() |
418 | { |
||
419 | if (ac_StartPlotter->isChecked()) |
||
420 | { |
||
421 | ac_StartPlotter->setText("Stop Plotter"); |
||
422 | pb_StartPlotter->setText("Stop Plotter"); |
||
423 | } |
||
424 | else |
||
425 | { |
||
426 | ac_StartPlotter->setText("Start Plotter"); |
||
427 | pb_StartPlotter->setText("Start Plotter"); |
||
428 | } |
||
429 | } |
||
430 | |||
431 | void MKTool::slot_ac_View() |
||
432 | { |
||
433 | int Aktive; |
||
434 | |||
435 | QAction *Action = (QAction*)sender(); |
||
436 | |||
437 | if (Action->objectName() == QString("ac_View0")) |
||
438 | Aktive = 0; |
||
439 | if (Action->objectName() == QString("ac_View1")) |
||
440 | Aktive = 1; |
||
441 | if (Action->objectName() == QString("ac_View2")) |
||
442 | Aktive = 2; |
||
443 | if (Action->objectName() == QString("ac_View3")) |
||
444 | Aktive = 3; |
||
445 | if (Action->objectName() == QString("ac_View4")) |
||
446 | Aktive = 4; |
||
447 | if (Action->objectName() == QString("ac_View5")) |
||
448 | Aktive = 5; |
||
449 | |||
450 | QString TabName = QString("Tab_%1").arg(Aktive); |
||
451 | |||
452 | if (!Action->isChecked()) |
||
453 | { |
||
454 | for (int a = 0; a < tab_Main->count(); a++) |
||
455 | { |
||
456 | if (tab_Main->widget(a)->objectName() == TabName) |
||
457 | { |
||
458 | tab_Main->removeTab(a); |
||
459 | } |
||
460 | } |
||
461 | |||
462 | // Action->setChecked(false); |
||
463 | } |
||
464 | else |
||
465 | { |
||
466 | // Action->setChecked(true); |
||
467 | tab_Main->insertTab(Aktive, TabWidgets[Aktive], Action->text()); |
||
468 | } |
||
469 | } |
||
470 | |||
159 | KeyOz | 471 | void MKTool::slot_ac_MehrDaten() // DONE 0.71g |
158 | KeyOz | 472 | { |
166 | KeyOz | 473 | if (!ac_KeineDaten->isChecked()) |
158 | KeyOz | 474 | { |
166 | KeyOz | 475 | if (ac_MehrDaten->isChecked()) |
476 | { |
||
477 | TX_Data[0] = Settings->Data.Debug_Fast / 10; |
||
478 | send_Data('d', ADDRESS_ALL, TX_Data, 1, false); |
||
479 | } |
||
480 | else |
||
481 | { |
||
482 | TX_Data[0] = Settings->Data.Debug_Slow / 10; |
||
483 | send_Data('d', ADDRESS_ALL, TX_Data, 1, false); |
||
484 | } |
||
485 | } |
||
486 | } |
||
487 | |||
488 | void MKTool::slot_ac_KeineDaten() // DONE 0.71g |
||
489 | { |
||
490 | if (ac_KeineDaten->isChecked()) |
||
491 | { |
||
167 | KeyOz | 492 | TickerEvent[3] = false; |
166 | KeyOz | 493 | TX_Data[0] = 0; |
494 | send_Data('d', ADDRESS_ALL, TX_Data, 1, false); |
||
495 | } |
||
158 | KeyOz | 496 | else |
497 | { |
||
167 | KeyOz | 498 | // Wenn MK3MAG dann andauernd Daten neu anfragen. |
499 | if (Mode.ID == ADDRESS_MK3MAG) |
||
500 | TickerEvent[3] = true; |
||
501 | |||
166 | KeyOz | 502 | if (ac_MehrDaten->isChecked()) |
503 | { |
||
504 | TX_Data[0] = Settings->Data.Debug_Fast / 10; |
||
505 | send_Data('d', ADDRESS_ALL, TX_Data, 1, false); |
||
506 | } |
||
507 | else |
||
508 | { |
||
509 | TX_Data[0] = Settings->Data.Debug_Slow / 10; |
||
510 | send_Data('d', ADDRESS_ALL, TX_Data, 1, false); |
||
511 | } |
||
512 | } |
||
158 | KeyOz | 513 | } |
514 | |||
515 | void MKTool::slot_ac_About() |
||
516 | { |
||
517 | QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT); |
||
518 | } |
||
519 | |||
159 | KeyOz | 520 | void MKTool::slot_ac_GetLabels() // DONE 0.71g |
158 | KeyOz | 521 | { |
522 | TX_Data[0] = 0; |
||
167 | KeyOz | 523 | send_Data('a', ADDRESS_ALL, TX_Data, 1, true); |
158 | KeyOz | 524 | } |
525 | |||
159 | KeyOz | 526 | |
158 | KeyOz | 527 | // Daten-Plotter |
528 | ///////////////// |
||
529 | void MKTool::update_Plot() |
||
530 | { |
||
531 | for (int a = 0; a < MaxAnalog; a++) |
||
532 | { |
||
533 | Plot[a]->setData(aID,aData[a],NextPlot - 1); |
||
534 | } |
||
535 | |||
166 | KeyOz | 536 | if ((NextPlot > Settings->Data.Plotter_Count)) |
158 | KeyOz | 537 | { |
166 | KeyOz | 538 | scroll_plot->setMaximum(NextPlot - Settings->Data.Plotter_Count); |
158 | KeyOz | 539 | } |
540 | |||
166 | KeyOz | 541 | if ((scroll_plot->value() == NextPlot - (Settings->Data.Plotter_Count + 1))) |
158 | KeyOz | 542 | { |
166 | KeyOz | 543 | qwtPlot->setAxisScale(QwtPlot::xBottom,NextPlot - Settings->Data.Plotter_Count,NextPlot,0); |
544 | scroll_plot->setValue(NextPlot - Settings->Data.Plotter_Count); |
||
158 | KeyOz | 545 | } |
546 | |||
547 | qwtPlot->replot(); |
||
548 | } |
||
549 | |||
550 | void MKTool::config_Plot() |
||
551 | { |
||
166 | KeyOz | 552 | // qDebug("Plotter rekonfiguriert..!!"); |
553 | qwtPlot->setAxisScale(QwtPlot::xBottom,0,Settings->Data.Plotter_Count,0); |
||
554 | |||
158 | KeyOz | 555 | for (int a = 0; a < MaxAnalog; a++) |
556 | { |
||
557 | Plot[a]->detach(); |
||
162 | KeyOz | 558 | Plot[a]->setPen(QPen(QColor(Def_Colors[a]))); |
158 | KeyOz | 559 | |
162 | KeyOz | 560 | if (Settings->Analog1.PlotView[a]) |
561 | { |
||
562 | Plot[a]->setTitle(Settings->Analog1.Label[a]); |
||
158 | KeyOz | 563 | Plot[a]->attach(qwtPlot); |
162 | KeyOz | 564 | } |
158 | KeyOz | 565 | } |
166 | KeyOz | 566 | qwtPlot->replot(); |
158 | KeyOz | 567 | } |
568 | |||
569 | void MKTool::slot_ScrollPlot(int Pos) |
||
570 | { |
||
166 | KeyOz | 571 | qwtPlot->setAxisScale(QwtPlot::xBottom,Pos,Pos + Settings->Data.Plotter_Count,0); |
158 | KeyOz | 572 | qwtPlot->replot(); |
573 | } |
||
574 | |||
575 | |||
576 | // Firmeware-Update |
||
577 | /////////////////// |
||
578 | void MKTool::slot_pb_Update() |
||
579 | { |
||
167 | KeyOz | 580 | QString Device; |
581 | QString Hardware; |
||
158 | KeyOz | 582 | |
167 | KeyOz | 583 | if (rb_FC->isChecked()) |
584 | { |
||
585 | Device = "m644"; |
||
586 | Hardware = "FlightCtrl"; |
||
587 | } |
||
588 | else if (rb_MK3MAG->isChecked()) |
||
589 | { |
||
590 | Device = "m168"; |
||
591 | Hardware = "MK3MAG"; |
||
592 | } |
||
593 | else if (rb_BL->isChecked()) |
||
594 | { |
||
595 | Device = "m8"; |
||
596 | Hardware = "BL-Ctrl"; |
||
597 | } |
||
166 | KeyOz | 598 | |
599 | QString Message = "Firmeware-Datei \n\n"; |
||
600 | Message = Message + le_HexFile->text() + "\n\n"; |
||
167 | KeyOz | 601 | Message = Message + "an " + Hardware + trUtf8(" mit AVRDUDE - Seriel & Bootloader über ") + le_Port->text() + trUtf8(" übertragen?\n"); |
166 | KeyOz | 602 | |
603 | if (le_HexFile->text() == "") |
||
162 | KeyOz | 604 | { |
166 | KeyOz | 605 | QMessageBox::warning(this, QA_NAME, trUtf8("Bitte Firmeware-Datei wählen."), QMessageBox::Ok); |
162 | KeyOz | 606 | } |
166 | KeyOz | 607 | else if (QMessageBox::warning(this, QA_NAME, Message, QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) |
608 | { |
||
609 | QString Programm = "avrdude" ; |
||
162 | KeyOz | 610 | |
166 | KeyOz | 611 | QStringList Argumente; |
162 | KeyOz | 612 | |
166 | KeyOz | 613 | Update = new QProcess(); |
162 | KeyOz | 614 | |
166 | KeyOz | 615 | if (serialPort->isOpen()) |
616 | { |
||
617 | slot_OpenPort(); |
||
618 | } |
||
619 | |||
620 | Argumente << "-P"; |
||
621 | Argumente << le_Port->text(); |
||
622 | Argumente << "-p"; |
||
623 | Argumente << Device; |
||
624 | Argumente << "-c"; |
||
625 | Argumente << "butterfly"; |
||
626 | Argumente << "-b"; |
||
627 | Argumente << "57600"; |
||
628 | Argumente << "-U"; |
||
629 | Argumente << "flash:w:" + le_HexFile->text(); |
||
630 | |||
631 | // QString Programm = "/home/Manuel/bin/avrdude -p m644 -P /dev/ttyS0 -c butterfly -b 57600 -U flash:w:/home/Manuel/Documents/Mikrokopter/Firmeware/FlightCtrl/Flight-Ctrl_MEGA644_V0_71h.hex"; |
||
632 | |||
633 | te_Shell->setText(""); // Ausgabefenster säubern |
||
634 | |||
635 | connect(Update, SIGNAL(readyReadStandardOutput()), this, SLOT(slot_UpdateShell()) ); |
||
636 | connect(Update, SIGNAL(readyReadStandardError()), this, SLOT(slot_UpdateShell()) ); |
||
637 | |||
638 | Update->start(Programm, Argumente); // Programmaufruf |
||
639 | } |
||
158 | KeyOz | 640 | } |
641 | |||
642 | void MKTool::slot_UpdateShell() |
||
643 | { |
||
162 | KeyOz | 644 | QByteArray Output; |
158 | KeyOz | 645 | |
166 | KeyOz | 646 | Output = Update->readAllStandardError(); // Shellausgabe an Variable |
162 | KeyOz | 647 | te_Shell->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); |
648 | te_Shell->insertPlainText(QString::fromUtf8(Output)); |
||
158 | KeyOz | 649 | |
166 | KeyOz | 650 | Output = Update->readAll(); |
651 | te_Shell->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); |
||
652 | te_Shell->insertPlainText(QString::fromUtf8(Output)); |
||
158 | KeyOz | 653 | } |
654 | |||
166 | KeyOz | 655 | void MKTool::slot_pb_HexFile() |
656 | { |
||
657 | QString FileName = QFileDialog::getOpenFileName(this,trUtf8(("Firmeware-Datei wählen")),"", |
||
658 | tr("Intel Hex(*.hex);;Alle Dateien (*)")); |
||
659 | if (!FileName.isEmpty()) |
||
660 | { |
||
661 | le_HexFile->setText(FileName); |
||
662 | } |
||
663 | } |
||
158 | KeyOz | 664 | |
665 | |||
167 | KeyOz | 666 | // Wechsel der Tabs erkennen |
159 | KeyOz | 667 | void MKTool::slot_TabChanged(int Tab) // DONE 0.71g |
158 | KeyOz | 668 | { |
669 | Tab = Tab; |
||
162 | KeyOz | 670 | if (tab_Main->count() != 0) |
158 | KeyOz | 671 | { |
167 | KeyOz | 672 | if ((tab_Main->currentWidget()->objectName() == QString("Tab_2")) && (f_Settings->tab_Par->currentIndex() == 1)) |
162 | KeyOz | 673 | { |
674 | TX_Data[0] = 0; |
||
675 | send_Data('p', ADDRESS_FC, TX_Data, 0, true); |
||
159 | KeyOz | 676 | |
162 | KeyOz | 677 | Ticker->setInterval(500); |
678 | TickerEvent[1] = true; |
||
679 | } |
||
680 | else |
||
681 | { |
||
682 | Ticker->setInterval(2000); |
||
683 | TickerEvent[1] = false; |
||
684 | } |
||
159 | KeyOz | 685 | |
162 | KeyOz | 686 | if ((tab_Main->currentWidget()->objectName() == QString("Tab_4"))) |
687 | { |
||
688 | TX_Data[0] = 0; |
||
689 | TX_Data[1] = 0; |
||
690 | send_Data('l', ADDRESS_ALL, TX_Data, 1, true); |
||
159 | KeyOz | 691 | |
162 | KeyOz | 692 | Ticker->setInterval(500); |
693 | TickerEvent[2] = true; |
||
694 | } |
||
695 | else |
||
696 | { |
||
697 | Ticker->setInterval(2000); |
||
698 | TickerEvent[2] = false; |
||
699 | } |
||
159 | KeyOz | 700 | } |
158 | KeyOz | 701 | } |
702 | |||
167 | KeyOz | 703 | // LCD-Seiten weiterschalten |
159 | KeyOz | 704 | void MKTool::slot_LCD_UP() // DONE 0.71g |
158 | KeyOz | 705 | { |
159 | KeyOz | 706 | if (LCD_Page == LCD_MAX_Page) |
707 | TX_Data[0] = 0; |
||
708 | else |
||
709 | TX_Data[0] = LCD_Page + 1; |
||
710 | |||
711 | TX_Data[1] = 0; |
||
712 | send_Data('l', ADDRESS_ALL, TX_Data, 1, true); |
||
713 | } |
||
714 | |||
715 | void MKTool::slot_LCD_DOWN() // DONE 0.71g |
||
716 | { |
||
717 | if (LCD_Page == 0) |
||
718 | TX_Data[0] = LCD_MAX_Page; |
||
719 | else |
||
720 | TX_Data[0] = LCD_Page - 1; |
||
721 | |||
722 | TX_Data[1] = 0; |
||
723 | send_Data('l', ADDRESS_ALL, TX_Data, 1, true); |
||
724 | } |
||
725 | |||
167 | KeyOz | 726 | // Settings aus MK lesen / in MK schreiben |
159 | KeyOz | 727 | void MKTool::slot_GetParameter() // DONE 0.71g |
728 | { |
||
167 | KeyOz | 729 | TX_Data[0] = f_Settings->sb_Set->value(); |
158 | KeyOz | 730 | TX_Data[1] = 0; |
159 | KeyOz | 731 | send_Data('q', ADDRESS_FC, TX_Data, 1); |
158 | KeyOz | 732 | } |
733 | |||
159 | KeyOz | 734 | void MKTool::slot_SetParameter() // DONE 0.71g |
158 | KeyOz | 735 | { |
167 | KeyOz | 736 | // store_ParameterSet(sb_Set->value()); |
737 | /* |
||
158 | KeyOz | 738 | |
167 | KeyOz | 739 | |
159 | KeyOz | 740 | TX_Data[0] = sb_Set->value(); |
741 | TX_Data[1] = VERSION_SETTINGS; |
||
742 | |||
743 | for (int a = 0; a < MaxParameter; a++) |
||
158 | KeyOz | 744 | { |
159 | KeyOz | 745 | TX_Data[a + 2] = ParameterSet[sb_Set->value()][a]; |
158 | KeyOz | 746 | } |
747 | |||
167 | KeyOz | 748 | // store_ParameterSet(sb_Set->value()); |
749 | */ |
||
158 | KeyOz | 750 | |
167 | KeyOz | 751 | char *TX_Data2 = f_Settings->SetParameter(); |
752 | |||
753 | send_Data('s', ADDRESS_FC, TX_Data2, MaxParameter + 2, false); |
||
158 | KeyOz | 754 | } |
755 | |||
159 | KeyOz | 756 | |
167 | KeyOz | 757 | // Save GUI-Preferences |
758 | /////////////////////// |
||
759 | void MKTool::set_Preferences() |
||
158 | KeyOz | 760 | { |
163 | KeyOz | 761 | Settings->GUI.TabViews.setBit(0, ac_View0->isChecked()); |
762 | Settings->GUI.TabViews.setBit(1, ac_View1->isChecked()); |
||
763 | Settings->GUI.TabViews.setBit(2, ac_View2->isChecked()); |
||
764 | Settings->GUI.TabViews.setBit(3, ac_View3->isChecked()); |
||
765 | Settings->GUI.TabViews.setBit(4, ac_View4->isChecked()); |
||
766 | Settings->GUI.TabViews.setBit(5, ac_View5->isChecked()); |
||
158 | KeyOz | 767 | |
162 | KeyOz | 768 | Settings->GUI.Term_Info = cb_ShowMSG->isChecked(); |
769 | Settings->GUI.Term_Data = cb_ShowData->isChecked(); |
||
770 | Settings->GUI.Term_Always = cb_ShowAlways->isChecked(); |
||
166 | KeyOz | 771 | Settings->GUI.Term_Send = cb_ShowSend->isChecked(); |
167 | KeyOz | 772 | Settings->GUI.isMax = isMaximized(); |
773 | Settings->GUI.Size = size(); |
||
774 | Settings->GUI.Point = pos(); |
||
162 | KeyOz | 775 | |
163 | KeyOz | 776 | Settings->TTY.Port = le_Port->text(); |
158 | KeyOz | 777 | } |
778 | |||
159 | KeyOz | 779 | |
158 | KeyOz | 780 | // Debug-Daten anzeigen und Aufzeichnen |
781 | /////////////////////////////////////// |
||
782 | void MKTool::write_CSV() |
||
783 | { |
||
784 | QTextStream Out(CSVFile); |
||
785 | for (int a=0; a<MaxAnalog; a++) |
||
786 | { |
||
162 | KeyOz | 787 | if (Settings->Analog1.LogView[a]) |
158 | KeyOz | 788 | { |
789 | Out << AnalogData[a]; |
||
790 | if (a < MaxAnalog - 1) |
||
791 | Out << ';'; |
||
792 | } |
||
793 | } |
||
794 | Out << "\n"; |
||
795 | } |
||
796 | |||
159 | KeyOz | 797 | void MKTool::slot_RecordCSV() // DONE 0.71g |
158 | KeyOz | 798 | { |
799 | if (!CSVFile->isOpen()) |
||
800 | { |
||
159 | KeyOz | 801 | QString Filename = Settings->DIR.Logging + Mode.Hardware + " - " + QDate::currentDate().toString(("yyyy-MM-dd")) + " -- " + QTime::currentTime().toString("hh-mm") + ".csv"; |
158 | KeyOz | 802 | |
803 | CSVFile = new QFile(Filename); |
||
804 | if (!CSVFile->exists()) |
||
805 | { |
||
806 | CSVFile->open(QIODevice::Append | QIODevice::Text); |
||
807 | |||
808 | QTextStream Out(CSVFile); |
||
809 | |||
810 | for (int a = 0; a < MaxAnalog; a++) |
||
811 | { |
||
162 | KeyOz | 812 | if (Settings->Analog1.LogView[a]) |
158 | KeyOz | 813 | { |
162 | KeyOz | 814 | Out << Settings->Analog1.Label[a]; |
158 | KeyOz | 815 | |
816 | if (a < MaxAnalog - 1) |
||
817 | Out << ';'; |
||
818 | } |
||
819 | } |
||
820 | Out << "\n"; |
||
821 | } |
||
822 | else |
||
823 | { |
||
824 | CSVFile->open(QIODevice::Append | QIODevice::Text); |
||
825 | } |
||
826 | |||
827 | pb_Record->setIcon(Icons[6]); |
||
828 | pb_Record->setText("CSV Stop"); |
||
829 | ac_RecordCSV->setIcon(Icons[6]); |
||
830 | ac_RecordCSV->setText("CSV Stop"); |
||
831 | } |
||
832 | else |
||
833 | { |
||
834 | CSVFile->close(); |
||
835 | pb_Record->setIcon(Icons[7]); |
||
836 | pb_Record->setText("CSV Aufzeichnen"); |
||
837 | ac_RecordCSV->setIcon(Icons[7]); |
||
838 | ac_RecordCSV->setText("CSV Aufzeichnen"); |
||
839 | } |
||
840 | } |
||
841 | |||
842 | void MKTool::show_DebugData() |
||
843 | { |
||
844 | if (CSVFile->isOpen()) |
||
845 | { |
||
846 | write_CSV(); |
||
847 | } |
||
848 | |||
849 | if (ac_StartPlotter->isChecked()) |
||
850 | { |
||
851 | aID[NextPlot] = NextPlot; |
||
852 | |||
853 | for (int a = 0; a < MaxAnalog; a++) |
||
854 | { |
||
855 | aData[a][NextPlot] = AnalogData[a]; |
||
856 | } |
||
857 | NextPlot++; |
||
858 | |||
859 | if ((tab_Main->currentWidget()->objectName() == QString("Tab_1"))) |
||
860 | update_Plot(); |
||
861 | } |
||
862 | |||
863 | le_A_0->setText(QString("%1").arg(AnalogData[0])); |
||
864 | le_A_1->setText(QString("%1").arg(AnalogData[1])); |
||
865 | le_A_2->setText(QString("%1").arg(AnalogData[2])); |
||
866 | le_A_3->setText(QString("%1").arg(AnalogData[3])); |
||
867 | le_A_4->setText(QString("%1").arg(AnalogData[4])); |
||
868 | le_A_5->setText(QString("%1").arg(AnalogData[5])); |
||
869 | le_A_6->setText(QString("%1").arg(AnalogData[6])); |
||
870 | le_A_7->setText(QString("%1").arg(AnalogData[7])); |
||
871 | le_A_8->setText(QString("%1").arg(AnalogData[8])); |
||
872 | le_A_9->setText(QString("%1").arg(AnalogData[9])); |
||
873 | le_A_10->setText(QString("%1").arg(AnalogData[10])); |
||
874 | le_A_11->setText(QString("%1").arg(AnalogData[11])); |
||
875 | le_A_12->setText(QString("%1").arg(AnalogData[12])); |
||
876 | le_A_13->setText(QString("%1").arg(AnalogData[13])); |
||
877 | le_A_14->setText(QString("%1").arg(AnalogData[14])); |
||
878 | le_A_15->setText(QString("%1").arg(AnalogData[15])); |
||
879 | le_A_16->setText(QString("%1").arg(AnalogData[16])); |
||
880 | le_A_17->setText(QString("%1").arg(AnalogData[17])); |
||
881 | le_A_18->setText(QString("%1").arg(AnalogData[18])); |
||
882 | le_A_19->setText(QString("%1").arg(AnalogData[19])); |
||
883 | le_A_20->setText(QString("%1").arg(AnalogData[20])); |
||
884 | le_A_21->setText(QString("%1").arg(AnalogData[21])); |
||
885 | le_A_22->setText(QString("%1").arg(AnalogData[22])); |
||
886 | le_A_23->setText(QString("%1").arg(AnalogData[23])); |
||
887 | le_A_24->setText(QString("%1").arg(AnalogData[24])); |
||
888 | le_A_25->setText(QString("%1").arg(AnalogData[25])); |
||
889 | le_A_26->setText(QString("%1").arg(AnalogData[26])); |
||
890 | le_A_27->setText(QString("%1").arg(AnalogData[27])); |
||
891 | le_A_28->setText(QString("%1").arg(AnalogData[28])); |
||
892 | le_A_29->setText(QString("%1").arg(AnalogData[29])); |
||
893 | le_A_30->setText(QString("%1").arg(AnalogData[30])); |
||
894 | le_A_31->setText(QString("%1").arg(AnalogData[31])); |
||
895 | } |
||
896 | |||
159 | KeyOz | 897 | |
158 | KeyOz | 898 | // Seriel-Port Bereich, Befehle senden und Daten empfangen |
899 | ////////////////////////////////////////////////////////// |
||
900 | |||
901 | // Neues Datenpacket empfangen -> Verarbeiten |
||
159 | KeyOz | 902 | void MKTool::new_RXData(sRxData RX) // DONE 0.71g |
158 | KeyOz | 903 | { |
904 | |||
905 | if (LastSend.length() > 2) |
||
906 | { |
||
907 | } |
||
908 | |||
162 | KeyOz | 909 | int HardwareID = RX.Input[1] - 'a'; |
910 | |||
167 | KeyOz | 911 | switch(HardwareID) |
158 | KeyOz | 912 | { |
167 | KeyOz | 913 | case ADDRESS_FC : |
914 | switch(RX.Input[2]) |
||
915 | { |
||
916 | // Stick-Belegung der Fernsteuerung |
||
917 | case 'P' : // DONE 0.71g |
||
918 | if (ToolBox::Decode64(RX)) |
||
158 | KeyOz | 919 | { |
167 | KeyOz | 920 | f_Settings->pb_K1->setValue(ToolBox::Data2Int(RX.Decode, 2,true)); |
921 | f_Settings->pb_K2->setValue(ToolBox::Data2Int(RX.Decode, 4,true)); |
||
922 | f_Settings->pb_K3->setValue(ToolBox::Data2Int(RX.Decode, 6,true)); |
||
923 | f_Settings->pb_K4->setValue(ToolBox::Data2Int(RX.Decode, 8,true)); |
||
924 | f_Settings->pb_K5->setValue(ToolBox::Data2Int(RX.Decode, 10 ,true)); |
||
925 | f_Settings->pb_K6->setValue(ToolBox::Data2Int(RX.Decode, 12,true)); |
||
926 | f_Settings->pb_K7->setValue(ToolBox::Data2Int(RX.Decode, 14,true)); |
||
927 | f_Settings->pb_K8->setValue(ToolBox::Data2Int(RX.Decode, 16,true)); |
||
928 | } |
||
929 | break; |
||
930 | // Settings lesen |
||
931 | case 'Q' : // DONE 0.71g |
||
932 | if (ToolBox::Decode64(RX)) |
||
933 | { |
||
934 | TickerEvent[0] = false; |
||
935 | |||
936 | if (RX.Decode[1] == VERSION_SETTINGS) |
||
937 | { |
||
938 | int Settings_ID = RX.Decode[0]; |
||
939 | for (int a = 0; a < MaxParameter; a++) |
||
940 | { |
||
941 | ParameterSet[Settings_ID][a] = RX.Decode[a + 2]; |
||
942 | } |
||
943 | //show_ParameterSet(Settings_ID); |
||
944 | f_Settings->show_ParameterSet(Settings_ID, ParameterSet); |
||
945 | } |
||
946 | else |
||
947 | { |
||
948 | f_Settings->pb_Read->setDisabled(true); |
||
949 | f_Settings->pb_Write->setDisabled(true); |
||
950 | |||
951 | QMessageBox::warning(this, QA_NAME, |
||
952 | "Versionen inkompatibel. \nParameterbearbeitung nicht moeglich.", QMessageBox::Ok); |
||
953 | } |
||
954 | } |
||
955 | break; |
||
956 | // Settings geschrieben |
||
957 | case 'S' : // DONE 0.71g |
||
958 | TickerEvent[0] = false; |
||
959 | break; |
||
960 | } |
||
961 | |||
962 | case ADDRESS_NC : |
||
963 | switch(RX.Input[2]) |
||
964 | { |
||
965 | // Navigationsdaten |
||
966 | case 'O' : // NOT DONE 0.12h |
||
967 | if (ToolBox::Decode64(RX)) |
||
968 | { |
||
969 | } |
||
970 | break; |
||
971 | } |
||
972 | // case ADDRESS_MK3MAG : |
||
973 | |||
974 | default : |
||
975 | switch(RX.Input[2]) |
||
976 | { |
||
977 | // LCD-Anzeige |
||
978 | case 'L' : // DONE 0.71g |
||
979 | if (ToolBox::Decode64(RX)) |
||
980 | { |
||
159 | KeyOz | 981 | int LCD[150]; |
982 | memcpy(LCD,RX.Decode, sizeof(RX.Decode)); |
||
983 | |||
984 | LCD_Page = RX.Decode[0]; |
||
985 | LCD_MAX_Page = RX.Decode[1]; |
||
986 | |||
987 | le_LCD0->setText(ToolBox::Data2QString(LCD,2,22)); |
||
988 | le_LCD1->setText(ToolBox::Data2QString(LCD,22,42)); |
||
989 | le_LCD2->setText(ToolBox::Data2QString(LCD,42,62)); |
||
990 | le_LCD3->setText(ToolBox::Data2QString(LCD,62,82)); |
||
991 | |||
992 | TickerEvent[0] = false; |
||
158 | KeyOz | 993 | } |
994 | break; |
||
167 | KeyOz | 995 | // Analoglabels |
996 | case 'A' : // DONE 0.71g |
||
997 | if (ToolBox::Decode64(RX)) |
||
158 | KeyOz | 998 | { |
159 | KeyOz | 999 | int Position = RX.Decode[0]; |
163 | KeyOz | 1000 | if (Position != 31) |
158 | KeyOz | 1001 | { |
162 | KeyOz | 1002 | Settings->Analog1.Label[Position] = ToolBox::Data2QString(RX.Decode,1,17).trimmed(); |
167 | KeyOz | 1003 | if (Settings->Analog1.Label[Position] == "") |
1004 | { |
||
1005 | Settings->Analog1.Label[Position] = "A-" + QString("%1").arg(Position); |
||
1006 | } |
||
158 | KeyOz | 1007 | Position ++; |
1008 | TX_Data[0] = Position; |
||
167 | KeyOz | 1009 | send_Data('a', ADDRESS_ALL, TX_Data, 1, true); |
158 | KeyOz | 1010 | } |
166 | KeyOz | 1011 | if (Position == 31) |
158 | KeyOz | 1012 | { |
1013 | for (int a = 0; a < MaxAnalog; a++) |
||
1014 | { |
||
162 | KeyOz | 1015 | lb_Analog[a]->setText(Settings->Analog1.Label[a]); |
158 | KeyOz | 1016 | } |
163 | KeyOz | 1017 | Settings->Analog1.Version = Mode.Version; |
162 | KeyOz | 1018 | Settings->write_Settings_AnalogLabels(HardwareID); |
158 | KeyOz | 1019 | config_Plot(); |
1020 | } |
||
1021 | } |
||
1022 | break; |
||
167 | KeyOz | 1023 | // Debug-Daten |
1024 | case 'D' : // DONE 0.71g |
||
1025 | if (ToolBox::Decode64(RX)) |
||
158 | KeyOz | 1026 | { |
1027 | for (int i = 0; i < MaxAnalog; i++) |
||
1028 | { |
||
1029 | AnalogData[i] = ToolBox::Data2Int(RX.Decode, (i * 2) + 2); |
||
1030 | } |
||
1031 | show_DebugData(); |
||
1032 | } |
||
1033 | break; |
||
167 | KeyOz | 1034 | // Version |
1035 | case 'V' : // DONE 0.71h |
||
1036 | if (ToolBox::Decode64(RX)) |
||
159 | KeyOz | 1037 | { |
167 | KeyOz | 1038 | TickerEvent[0] = false; |
159 | KeyOz | 1039 | |
167 | KeyOz | 1040 | Mode.ID = HardwareID; |
1041 | Mode.VERSION_MAJOR = RX.Decode[0]; |
||
1042 | Mode.VERSION_MINOR = RX.Decode[1]; |
||
1043 | Mode.VERSION_PATCH = RX.Decode[4]; |
||
1044 | Mode.VERSION_SERIAL_MAJOR = RX.Decode[2]; |
||
1045 | Mode.VERSION_SERIAL_MINOR = RX.Decode[3]; |
||
159 | KeyOz | 1046 | |
167 | KeyOz | 1047 | Mode.Hardware = HardwareType[Mode.ID]; |
1048 | Mode.Version = QString("%1").arg(RX.Decode[0]) + "." + QString("%1").arg(RX.Decode[1]) + QString(RX.Decode[4] + 'a'); |
||
158 | KeyOz | 1049 | |
167 | KeyOz | 1050 | setWindowTitle(QA_NAME + " v" + QA_VERSION + " - " + Mode.Hardware + " " + Mode.Version); |
158 | KeyOz | 1051 | |
167 | KeyOz | 1052 | if (Mode.VERSION_SERIAL_MAJOR != VERSION_SERIAL_MAJOR) |
1053 | { |
||
1054 | AllowSend = false; |
||
1055 | QMessageBox::warning(this, QA_NAME, |
||
1056 | "Serielles Protokoll Inkompatibel. \nBitte neue Programmversion installieren,", QMessageBox::Ok); |
||
1057 | } |
||
159 | KeyOz | 1058 | |
167 | KeyOz | 1059 | // Wenn MK3MAG dann andauernd Daten neu anfragen. |
1060 | if (Mode.ID == ADDRESS_MK3MAG) |
||
1061 | { |
||
1062 | TickerEvent[3] = true; |
||
1063 | } |
||
158 | KeyOz | 1064 | |
167 | KeyOz | 1065 | TX_Data[0] = Settings->Data.Debug_Slow / 10; |
1066 | send_Data('d', ADDRESS_ALL, TX_Data, 1, false); |
||
158 | KeyOz | 1067 | |
167 | KeyOz | 1068 | // Wenn FlightCtrl dann Settings abfragen. |
1069 | if (Mode.ID == ADDRESS_FC) |
||
1070 | { |
||
1071 | { |
||
1072 | TX_Data[0] = 0xff; |
||
1073 | TX_Data[1] = 0; |
||
1074 | send_Data('q', ADDRESS_FC, TX_Data, 1); |
||
1075 | } |
||
1076 | } |
||
1077 | // Wenn nicht Lesen und Schreiben der Settings deaktivieren. |
||
1078 | else |
||
1079 | { |
||
1080 | f_Settings->pb_Read->setDisabled(true); |
||
1081 | f_Settings->pb_Write->setDisabled(true); |
||
1082 | } |
||
158 | KeyOz | 1083 | |
167 | KeyOz | 1084 | Settings->read_Settings_Analog(HardwareID); |
1085 | Settings->read_Settings_AnalogLabels(HardwareID); |
||
159 | KeyOz | 1086 | |
167 | KeyOz | 1087 | if (Settings->Analog1.Version != Mode.Version) |
158 | KeyOz | 1088 | { |
167 | KeyOz | 1089 | lb_Status->setText("Analoglabel-Version unterschiedlich. Lese Analoglabels neu aus."); |
1090 | slot_ac_GetLabels(); |
||
158 | KeyOz | 1091 | } |
167 | KeyOz | 1092 | else |
1093 | for (int a = 0; a < MaxAnalog; a++) |
||
1094 | { |
||
1095 | lb_Analog[a]->setText(Settings->Analog1.Label[a]); |
||
1096 | } |
||
1097 | config_Plot(); |
||
158 | KeyOz | 1098 | } |
1099 | break; |
||
167 | KeyOz | 1100 | } |
158 | KeyOz | 1101 | } |
1102 | } |
||
1103 | |||
1104 | // Neue Daten an der Schnittstelle |
||
159 | KeyOz | 1105 | void MKTool::slot_newDataReceived(const QByteArray &dataReceived) // DONE 0.71g |
158 | KeyOz | 1106 | { |
1107 | const char *RXt; |
||
1108 | RXt = dataReceived.data(); |
||
1109 | int a = 0; |
||
1110 | |||
1111 | while (RXt[a] != '\0') |
||
1112 | { |
||
1113 | if (RXt[a] == '\r') |
||
1114 | { |
||
1115 | while ((RxData.String.length() > 1) && (RxData.String.at(1) == '#')) |
||
1116 | { |
||
1117 | RxData.String.remove(0,1); |
||
1118 | } |
||
1119 | |||
1120 | if (ToolBox::check_CRC(RxData.String)) |
||
1121 | { |
||
1122 | RxData.Input = RxData.String.toLatin1().data(); |
||
1123 | new_RXData(RxData); |
||
1124 | |||
162 | KeyOz | 1125 | if ((cb_ShowData->isChecked()) && ((tab_Main->currentWidget()->objectName() == QString("Tab_3")) || (cb_ShowAlways->isChecked()))) |
158 | KeyOz | 1126 | { |
1127 | te_RX->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); |
||
166 | KeyOz | 1128 | // te_RX->insertPlainText(" > " + RxData.String + '\r'); |
1129 | te_RX->insertHtml("<span style=\"color:#00008b;\">" + RxData.String + "<br /></span>"); |
||
158 | KeyOz | 1130 | } |
1131 | } |
||
1132 | else |
||
1133 | { |
||
162 | KeyOz | 1134 | if ((cb_ShowMSG->isChecked()) && ((tab_Main->currentWidget()->objectName() == QString("Tab_3")) || (cb_ShowAlways->isChecked()))) |
158 | KeyOz | 1135 | { |
1136 | te_RX->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); |
||
166 | KeyOz | 1137 | // te_RX->insertPlainText(" > " + RxData.String + '\r'); |
1138 | te_RX->insertHtml("<span style=\"color:#008b00;\">" + RxData.String + "<br /></span>"); |
||
158 | KeyOz | 1139 | } |
1140 | } |
||
1141 | RxData.String = QString(""); |
||
1142 | } |
||
1143 | else |
||
1144 | { |
||
1145 | { |
||
1146 | RxData.String = RxData.String + QString(RXt[a]); |
||
1147 | } |
||
1148 | } |
||
1149 | a++; |
||
1150 | } |
||
1151 | } |
||
1152 | |||
1153 | // Seriellen Port öffnen |
||
1154 | void MKTool::slot_OpenPort() |
||
1155 | { |
||
1156 | if (serialPort->isOpen()) |
||
1157 | { |
||
1158 | TX_Data[0] = 0; |
||
1159 | TX_Data[1] = 0; |
||
1160 | TX_Data[2] = 0; |
||
1161 | TX_Data[3] = 0; |
||
159 | KeyOz | 1162 | send_Data('t', ADDRESS_FC, TX_Data, 4, false); |
158 | KeyOz | 1163 | |
1164 | serialPort->close(); |
||
1165 | pb_Open->setText("Verbinden"); |
||
1166 | ac_ConnectTTY->setText("Verbinden"); |
||
1167 | pb_Open->setIcon(Icons[9]); |
||
1168 | ac_ConnectTTY->setIcon(Icons[9]); |
||
167 | KeyOz | 1169 | |
1170 | Ticker->stop(); |
||
158 | KeyOz | 1171 | } |
1172 | else |
||
1173 | { |
||
1174 | serialPort->setPort(le_Port->text()); //Port |
||
1175 | |||
1176 | serialPort->setBaudRate(BAUD57600); //BaudRate |
||
1177 | serialPort->setDataBits(DATA_8); //DataBits |
||
1178 | serialPort->setParity(PAR_NONE); //Parity |
||
1179 | serialPort->setStopBits(STOP_1); //StopBits |
||
1180 | serialPort->setFlowControl(FLOW_OFF); //FlowControl |
||
1181 | |||
1182 | serialPort->setTimeout(0, 10); |
||
1183 | serialPort->enableSending(); |
||
1184 | serialPort->enableReceiving(); |
||
1185 | |||
1186 | serialPort->open(); |
||
1187 | if (serialPort->isOpen()) |
||
1188 | { |
||
1189 | serialPort->receiveData(); |
||
1190 | |||
159 | KeyOz | 1191 | send_Data('v', ADDRESS_ALL, TX_Data, 0, true); |
1192 | |||
158 | KeyOz | 1193 | pb_Open->setText("Trennen"); |
1194 | ac_ConnectTTY->setText("Trennen"); |
||
1195 | pb_Open->setIcon(Icons[8]); |
||
1196 | ac_ConnectTTY->setIcon(Icons[8]); |
||
167 | KeyOz | 1197 | |
1198 | Ticker->start(2000); |
||
158 | KeyOz | 1199 | } |
1200 | } |
||
1201 | } |
||
1202 | |||
1203 | // Daten senden |
||
159 | KeyOz | 1204 | void MKTool::send_Data(char CMD, int Address, char Data[150],unsigned int Length, bool Resend) // DONE 0.71g |
158 | KeyOz | 1205 | { |
159 | KeyOz | 1206 | if (serialPort->isOpen() && AllowSend) |
158 | KeyOz | 1207 | { |
1208 | QString TX_Data = ToolBox::Encode64(Data, Length); |
||
1209 | |||
159 | KeyOz | 1210 | TX_Data = QString("#") + (QString('a' + Address)) + QString(CMD) + TX_Data; |
158 | KeyOz | 1211 | |
1212 | // qDebug(TX_Data.toLatin1().data()); |
||
1213 | |||
1214 | TX_Data = ToolBox::add_CRC(TX_Data) + '\r'; |
||
1215 | |||
1216 | // qDebug(TX_Data.toLatin1().data()); |
||
1217 | |||
1218 | if (Resend) |
||
1219 | { |
||
1220 | LastSend = TX_Data; |
||
1221 | TickerEvent[0] = true; |
||
1222 | } |
||
1223 | |||
1224 | QByteArray Temp(TX_Data.toUtf8()); |
||
1225 | serialPort->sendData(Temp); |
||
166 | KeyOz | 1226 | |
1227 | if (cb_ShowSend->isChecked()) |
||
1228 | { |
||
1229 | te_RX->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); |
||
1230 | te_RX->insertHtml("<span style='color:#8b0000;'>" + TX_Data + "<br /></span>"); |
||
1231 | } |
||
158 | KeyOz | 1232 | } |
1233 | } |
||
1234 | |||
1235 | |||
1236 | // Programm beenden |
||
1237 | /////////////////// |
||
162 | KeyOz | 1238 | |
1239 | MKTool::~MKTool() |
||
158 | KeyOz | 1240 | { |
166 | KeyOz | 1241 | // qDebug(" Programm Ende ..!! "); |
158 | KeyOz | 1242 | if (serialPort->isOpen()) |
1243 | { |
||
1244 | serialPort->close(); |
||
1245 | } |
||
1246 | |||
167 | KeyOz | 1247 | set_Preferences(); |
162 | KeyOz | 1248 | Settings->write_Settings(); |
158 | KeyOz | 1249 | |
1250 | if (CSVFile->isOpen()) |
||
1251 | { |
||
1252 | CSVFile->close(); |
||
1253 | } |
||
1254 | } |