Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
279 | 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 | // TODO: Wiederholungssenden wieder einbauen |
||
21 | |||
22 | #include <QtGui> |
||
23 | |||
24 | #include <QLineEdit> |
||
25 | #include <QString> |
||
26 | #include <QTimer> |
||
27 | #include <QIcon> |
||
28 | #include <QToolButton> |
||
29 | #include <QSpinBox> |
||
30 | #include <QAction> |
||
31 | #include <QPalette> |
||
32 | |||
33 | #include "mktool.h" |
||
34 | #include "dlg_Config.h" |
||
35 | #include "dlg_Motortest.h" |
||
36 | #include "dlg_Preferences.h" |
||
37 | #include "../global.h" |
||
38 | #include "../Classes/ToolBox.h" |
||
39 | |||
40 | #include <stdlib.h> |
||
41 | |||
42 | MKTool::MKTool() |
||
43 | { |
||
44 | setupUi(this); |
||
45 | |||
46 | Settings = new cSettings; |
||
47 | |||
48 | init_Arrays(); |
||
49 | init_GUI(); |
||
50 | |||
51 | init_Objects(); |
||
52 | init_Connections(); |
||
53 | |||
54 | init_Plot(); |
||
55 | } |
||
56 | |||
57 | void MKTool::init_GUI() |
||
58 | { |
||
59 | setWindowTitle(QA_NAME + " v" + QA_VERSION); |
||
60 | |||
61 | // Tab mit Debug-Elementen verbergen |
||
62 | tab_Main->removeTab(6); |
||
63 | // Develop - Nicht gebrauchte sachen abschalten. |
||
64 | pb_SettingsReset->hide(); |
||
65 | pb_Flash->hide(); |
||
66 | rb_NC->hide(); |
||
67 | |||
68 | // Beta-Sachen einschalten. |
||
69 | #ifdef _BETA_ |
||
70 | ac_QMKServer->setEnabled(true); |
||
71 | #endif |
||
72 | |||
73 | // Settings-Tab hinzufügen. |
||
74 | f_Settings = new wdg_Settings( this ); |
||
75 | f_Settings->set_Config(Settings); |
||
76 | tab_Main->insertTab ( 2, f_Settings, ac_View2->icon(), "FC-Settings"); |
||
77 | tab_Main->widget(2)->setObjectName("Tab_2"); |
||
78 | |||
79 | // Zusätzliche Widgets in die Toolbar. |
||
80 | tb_TTY->addWidget(lb_Port); |
||
81 | tb_TTY->addWidget(le_Port); |
||
82 | |||
83 | tb_Hardware->addWidget(rb_SelFC); |
||
84 | tb_Hardware->addWidget(rb_SelNC); |
||
85 | tb_Hardware->addWidget(rb_SelMag); |
||
86 | |||
87 | tb_Allgemein->setVisible(Settings->GUI.ToolViews[0]); |
||
88 | tb_Werkzeuge->setVisible(Settings->GUI.ToolViews[1]); |
||
89 | tb_Debug->setVisible(Settings->GUI.ToolViews[2]); |
||
90 | tb_TTY->setVisible(Settings->GUI.ToolViews[3]); |
||
91 | tb_Hardware->setVisible(Settings->GUI.ToolViews[4]); |
||
92 | |||
93 | #ifdef _EEEPC_ |
||
94 | lb_Status->hide(); |
||
95 | #endif |
||
96 | |||
97 | lb_Status->setText(tr("Hallo bei QMK-Groundstation...!!!")); |
||
98 | |||
99 | // Cockpit-Elemente |
||
100 | QPalette newPalette; |
||
101 | |||
102 | newPalette.setColor(QPalette::Base, Qt::darkBlue); |
||
103 | newPalette.setColor(QPalette::Foreground, QColor(Qt::darkBlue).dark(120)); |
||
104 | newPalette.setColor(QPalette::Text, Qt::white); |
||
105 | |||
106 | Compass->setScaleOptions(QwtDial::ScaleTicks | QwtDial::ScaleLabel); |
||
107 | Compass->setScaleTicks(0, 0, 3); |
||
108 | Compass->setScale(36, 5, 0); |
||
109 | |||
110 | Compass->setNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow, true, Qt::red, QColor(Qt::gray).light(130))); |
||
111 | Compass->setPalette(newPalette); |
||
112 | Compass->setMaximumSize(QSize(MeterSize, MeterSize)); |
||
113 | Compass->setMinimumSize(QSize(MeterSize, MeterSize)); |
||
114 | |||
115 | QPalette newPalette1; |
||
116 | |||
117 | newPalette1.setColor(QPalette::Base, Qt::darkBlue); |
||
118 | newPalette1.setColor(QPalette::Foreground, QColor(255,128,0).dark(120)); |
||
119 | newPalette1.setColor(QPalette::Text, Qt::white); |
||
120 | |||
121 | Attitude = new AttitudeIndicator(this); |
||
122 | Attitude->setMaximumSize(QSize(MeterSize, MeterSize)); |
||
123 | Attitude->setMinimumSize(QSize(MeterSize, MeterSize)); |
||
124 | Attitude->setPalette(newPalette1); |
||
125 | |||
126 | verticalLayout->addWidget(Attitude); |
||
127 | |||
128 | qwt_Rate->setRange(-10.0, 10.0, 0.1, 0); |
||
129 | |||
130 | newPalette1.setColor(QPalette::Foreground, QColor(Qt::darkBlue).dark(120)); |
||
131 | |||
132 | SpeedMeter = new cSpeedMeter(this); |
||
133 | SpeedMeter->setMaximumSize(QSize(MeterSize, MeterSize)); |
||
134 | SpeedMeter->setMinimumSize(QSize(MeterSize, MeterSize)); |
||
135 | SpeedMeter->setPalette(newPalette1); |
||
136 | SpeedMeter->setRange(0.0, 5.0); |
||
137 | SpeedMeter->setScale(1, 2, 0.5); |
||
138 | SpeedMeter->setProperty("END", 5); |
||
139 | |||
140 | LayOut_Speed->addWidget(SpeedMeter); |
||
141 | |||
142 | resize(Settings->GUI.Size); |
||
143 | move(Settings->GUI.Point); |
||
144 | |||
145 | if (Settings->GUI.isMax) |
||
146 | { |
||
147 | showMaximized(); |
||
148 | } |
||
149 | |||
150 | // Analoglabels anzeigen |
||
151 | for (int a = 0; a < MaxAnalog; a++) |
||
152 | { |
||
153 | lb_Analog[a]->setText(Settings->Analog1.Label[a]); |
||
154 | } |
||
155 | |||
156 | // Kopie der Tabs anlegen |
||
157 | for (int b = 0; b < 7; b++) |
||
158 | { |
||
159 | TabWidgets[b] = tab_Main->widget(b); |
||
160 | } |
||
161 | |||
162 | // Ausgeblendete Tabs ausblenden |
||
163 | for (int c = 0; c < 7; c++) |
||
164 | { |
||
165 | if (Settings->GUI.TabViews[c] == false) |
||
166 | { |
||
167 | QString TabName = QString("Tab_%1").arg(c); |
||
168 | |||
169 | for (int d = 0; d < tab_Main->count(); d++) |
||
170 | { |
||
171 | if (tab_Main->widget(d)->objectName() == TabName) |
||
172 | { |
||
173 | tab_Main->removeTab(d); |
||
174 | } |
||
175 | } |
||
176 | } |
||
177 | } |
||
178 | |||
179 | ac_View0->setChecked(Settings->GUI.TabViews[0]); |
||
180 | ac_View1->setChecked(Settings->GUI.TabViews[1]); |
||
181 | ac_View2->setChecked(Settings->GUI.TabViews[2]); |
||
182 | ac_View3->setChecked(Settings->GUI.TabViews[3]); |
||
183 | ac_View4->setChecked(Settings->GUI.TabViews[4]); |
||
184 | ac_View5->setChecked(Settings->GUI.TabViews[5]); |
||
185 | ac_View6->setChecked(Settings->GUI.TabViews[6]); |
||
186 | |||
187 | le_Port->setText(Settings->TTY.Port); |
||
188 | |||
189 | cb_ShowMSG->setChecked(Settings->GUI.Term_Info); |
||
190 | cb_ShowData->setChecked(Settings->GUI.Term_Data); |
||
191 | cb_ShowAlways->setChecked(Settings->GUI.Term_Always); |
||
192 | } |
||
193 | |||
194 | void MKTool::init_Objects() |
||
195 | { |
||
196 | // QTimer-Instanzen |
||
197 | Ticker = new QTimer(this); |
||
198 | |||
199 | Conn = new cConnection(); |
||
200 | |||
201 | // neuer Logger |
||
202 | logger = new Logger(Settings, &Mode); |
||
203 | |||
204 | // LCD-Dialog |
||
205 | f_LCD = new dlg_LCD(this); |
||
206 | |||
207 | GE_Server = new cServer(); |
||
208 | |||
209 | QMK_Server = new cQMK_Server(); |
||
210 | QMK_Server->setProperty("Connect", false); |
||
211 | |||
212 | if (Settings->Server.StartServer) |
||
213 | { |
||
214 | ac_StartServer->setChecked(true); |
||
215 | GE_Server->start_Server(Settings->Server.Port.toInt(), Settings); |
||
216 | } |
||
217 | } |
||
218 | |||
219 | void MKTool::init_Connections() |
||
220 | { |
||
221 | connect(Dec, SIGNAL(clicked()), this, SLOT(slot_Test())); |
||
222 | |||
223 | // Daten Senden / Empfangen |
||
224 | connect(Conn, SIGNAL(newData(sRxData)), this, SLOT(slot_newData(sRxData))); |
||
225 | connect(Conn, SIGNAL(showTerminal(int, QString)), this, SLOT(slot_showTerminal(int, QString))); |
||
226 | |||
227 | // Serielle Verbundung öffnen / schließen |
||
228 | connect(ac_ConnectTTY, SIGNAL(triggered()), this, SLOT(slot_OpenPort())); |
||
229 | |||
230 | // TCP-Connection verbinden / trennen |
||
231 | connect(ac_QMKServer, SIGNAL(triggered()), this, SLOT(slot_QMKS_Connect())); |
||
232 | |||
233 | // Buttons Settings lesen / schreiben |
||
234 | connect(f_Settings->pb_Read, SIGNAL(clicked()), this, SLOT(slot_GetFCSettings())); |
||
235 | connect(f_Settings->pb_Write, SIGNAL(clicked()), this, SLOT(slot_SetFCSettings())); |
||
236 | |||
237 | // Actions |
||
238 | connect(ac_Config, SIGNAL(triggered()), this, SLOT(slot_ac_Config())); |
||
239 | connect(ac_Preferences, SIGNAL(triggered()), this, SLOT(slot_ac_Preferences())); |
||
240 | connect(ac_Motortest, SIGNAL(triggered()), this, SLOT(slot_ac_Motortest())); |
||
241 | connect(ac_LCD, SIGNAL(triggered()), this, SLOT(slot_ac_LCD())); |
||
242 | connect(ac_FastDebug, SIGNAL(triggered()), this, SLOT(slot_ac_FastDebug())); |
||
243 | connect(ac_NoDebug, SIGNAL(triggered()), this, SLOT(slot_ac_NoDebug())); |
||
244 | connect(ac_FastNavi, SIGNAL(triggered()), this, SLOT(slot_ac_FastNavi())); |
||
245 | connect(ac_NoNavi, SIGNAL(triggered()), this, SLOT(slot_ac_NoNavi())); |
||
246 | connect(ac_GetLabels, SIGNAL(triggered()), this, SLOT(slot_ac_GetLabels())); |
||
247 | |||
248 | // Plotter starten / scrollen |
||
249 | connect(scroll_plot, SIGNAL(valueChanged(int)), this, SLOT(slot_ScrollPlot(int))); |
||
250 | connect(ac_StartPlotter, SIGNAL(triggered()), this, SLOT(slot_ac_StartPlotter())); |
||
251 | connect(ac_StartServer, SIGNAL(triggered()), this, SLOT(slot_ac_StartServer())); |
||
252 | |||
253 | // Tabs ein & ausblenden |
||
254 | connect(ac_View0, SIGNAL(triggered()), this, SLOT(slot_ac_View())); |
||
255 | connect(ac_View1, SIGNAL(triggered()), this, SLOT(slot_ac_View())); |
||
256 | connect(ac_View2, SIGNAL(triggered()), this, SLOT(slot_ac_View())); |
||
257 | connect(ac_View3, SIGNAL(triggered()), this, SLOT(slot_ac_View())); |
||
258 | connect(ac_View4, SIGNAL(triggered()), this, SLOT(slot_ac_View())); |
||
259 | connect(ac_View5, SIGNAL(triggered()), this, SLOT(slot_ac_View())); |
||
260 | connect(ac_View6, SIGNAL(triggered()), this, SLOT(slot_ac_View())); |
||
261 | |||
262 | connect(ac_SelNC, SIGNAL(triggered()), this, SLOT(slot_ac_Hardware())); |
||
263 | connect(ac_SelFC, SIGNAL(triggered()), this, SLOT(slot_ac_Hardware())); |
||
264 | connect(ac_SelMag, SIGNAL(triggered()), this, SLOT(slot_ac_Hardware())); |
||
265 | |||
266 | connect(rb_SelNC, SIGNAL(clicked()), this, SLOT(slot_rb_Hardware())); |
||
267 | connect(rb_SelFC, SIGNAL(clicked()), this, SLOT(slot_rb_Hardware())); |
||
268 | connect(rb_SelMag, SIGNAL(clicked()), this, SLOT(slot_rb_Hardware())); |
||
269 | |||
270 | // firmeware Updateen / flashen |
||
271 | connect(pb_Update, SIGNAL(clicked()), this, SLOT(slot_pb_Update())); |
||
272 | connect(pb_HexFile, SIGNAL(clicked()), this, SLOT(slot_pb_HexFile())); |
||
273 | |||
274 | // Wegpunkt-Befehl |
||
275 | connect(pb_FlyTo, SIGNAL(clicked()), this, SLOT(slot_pb_SendWaypoint())); |
||
276 | |||
277 | // CVS-Record starten / stoppen |
||
278 | connect(ac_RecordCSV, SIGNAL(triggered()), this, SLOT(slot_RecordLog())); |
||
279 | |||
280 | // Timer-Events |
||
281 | connect(Ticker, SIGNAL(timeout()), SLOT(slot_Ticker())); |
||
282 | |||
283 | // Seitenwechsel |
||
284 | connect(tab_Main, SIGNAL(currentChanged(int)), this, SLOT(slot_TabChanged(int))); |
||
285 | connect(f_Settings->tab_Par, SIGNAL(currentChanged(int)), this, SLOT(slot_TabChanged(int))); |
||
286 | |||
287 | // About QMK & About-QT Dialog einfügen |
||
288 | connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About())); |
||
289 | menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt())); |
||
290 | } |
||
291 | |||
292 | void MKTool::init_Arrays() |
||
293 | { |
||
294 | lb_Analog[0] = lb_A_0; |
||
295 | lb_Analog[1] = lb_A_1; |
||
296 | lb_Analog[2] = lb_A_2; |
||
297 | lb_Analog[3] = lb_A_3; |
||
298 | lb_Analog[4] = lb_A_4; |
||
299 | lb_Analog[5] = lb_A_5; |
||
300 | lb_Analog[6] = lb_A_6; |
||
301 | lb_Analog[7] = lb_A_7; |
||
302 | lb_Analog[8] = lb_A_8; |
||
303 | lb_Analog[9] = lb_A_9; |
||
304 | lb_Analog[10] = lb_A_10; |
||
305 | lb_Analog[11] = lb_A_11; |
||
306 | lb_Analog[12] = lb_A_12; |
||
307 | lb_Analog[13] = lb_A_13; |
||
308 | lb_Analog[14] = lb_A_14; |
||
309 | lb_Analog[15] = lb_A_15; |
||
310 | lb_Analog[16] = lb_A_16; |
||
311 | lb_Analog[17] = lb_A_17; |
||
312 | lb_Analog[18] = lb_A_18; |
||
313 | lb_Analog[19] = lb_A_19; |
||
314 | lb_Analog[20] = lb_A_20; |
||
315 | lb_Analog[21] = lb_A_21; |
||
316 | lb_Analog[22] = lb_A_22; |
||
317 | lb_Analog[23] = lb_A_23; |
||
318 | lb_Analog[24] = lb_A_24; |
||
319 | lb_Analog[25] = lb_A_25; |
||
320 | lb_Analog[26] = lb_A_26; |
||
321 | lb_Analog[27] = lb_A_27; |
||
322 | lb_Analog[28] = lb_A_28; |
||
323 | lb_Analog[29] = lb_A_29; |
||
324 | lb_Analog[30] = lb_A_30; |
||
325 | lb_Analog[31] = lb_A_31; |
||
326 | } |
||
327 | |||
328 | void MKTool::init_Plot() |
||
329 | { |
||
330 | NextPlot = 0; |
||
331 | |||
332 | qwtPlot->setCanvasBackground(QColor(QRgb(0x00000000))); |
||
333 | |||
334 | qwtPlot->insertLegend(new QwtLegend(), QwtPlot::RightLegend); |
||
335 | |||
336 | QwtPlotGrid *Grid = new QwtPlotGrid(); |
||
337 | Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine)); |
||
338 | |||
339 | Grid->attach(qwtPlot); |
||
340 | |||
341 | qwtPlot->setAxisScale(QwtPlot::xBottom,0,Settings->Data.Plotter_Count,0); |
||
342 | |||
343 | for (int a = 0; a < MaxAnalog; a++) |
||
344 | { |
||
345 | Plot[a] = new QwtPlotCurve(Settings->Analog1.Label[a]); |
||
346 | Plot[a]->setPen(QPen(QColor(Def_Colors[a]))); |
||
347 | // Plot[a]->setRenderHint(QwtPlotItem::RenderAntialiased); |
||
348 | |||
349 | if (Settings->Analog1.PlotView[a]) |
||
350 | Plot[a]->attach(qwtPlot); |
||
351 | } |
||
352 | qwtPlot->replot(); |
||
353 | } |
||
354 | |||
355 | void MKTool::slot_Test() |
||
356 | { |
||
357 | // qDebug("Decode Data"); |
||
358 | sRxData RX; |
||
359 | |||
360 | RX.String = IN->text(); |
||
361 | |||
362 | // qDebug(RX.String.toLatin1().data()); |
||
363 | |||
364 | // if (ToolBox::check_CRC(RX.String)) |
||
365 | { |
||
366 | qDebug("Decode Data CRC OK"); |
||
367 | RX.Input = RX.String.toLatin1().data(); |
||
368 | |||
369 | // qDebug(RX.Input); |
||
370 | |||
371 | slot_newData(RX); |
||
372 | } |
||
373 | } |
||
374 | |||
375 | // KML-Datei nach Wegpunkt parsen |
||
376 | // TODO: Richtigen KML-Parser bauen |
||
377 | void MKTool::parse_TargetKML() |
||
378 | { |
||
379 | QString Tmp = te_KML->toPlainText().simplified(); |
||
380 | QStringList List; |
||
381 | |||
382 | if ((Tmp.contains("<kml xmlns=\"http://earth.google.com/kml/2.2\">")) && (Tmp.contains("<coordinates>"))) |
||
383 | { |
||
384 | List = Tmp.split("<coordinates>"); |
||
385 | List = List[1].split(","); |
||
386 | |||
387 | le_TarLong->setText(ToolBox::get_Float((List[0].toDouble() * 10000000), 10000000)); |
||
388 | le_TarLat->setText(ToolBox::get_Float((List[1].toDouble() * 10000000), 10000000)); |
||
389 | } |
||
390 | } |
||
391 | |||
392 | // Waypoint zur NC Senden. |
||
393 | void MKTool::slot_pb_SendWaypoint() |
||
394 | { |
||
395 | if ((Navi.Current.Longitude == 0) && (Navi.Current.Latitude == 0)) |
||
396 | { |
||
397 | QMessageBox msgB; |
||
398 | QString msg; |
||
399 | msgB.setText("Fehler: Es konnten keine GPS-Daten vom Mikrokopter empfangen werden"); |
||
400 | msgB.exec(); |
||
401 | return; |
||
402 | } |
||
403 | |||
404 | //erstelle einen Wegpunkt, den die NaviCtrl auswerten kann |
||
405 | Waypoint_t desired_pos; |
||
406 | bool ok_lat, ok_lon; |
||
407 | |||
408 | //eingegebene Daten holen |
||
409 | double desired_long, desired_lat; |
||
410 | |||
411 | desired_long = le_TarLong->text().toDouble(&ok_lon); |
||
412 | desired_lat = le_TarLat->text().toDouble(&ok_lat); |
||
413 | |||
414 | if (ok_lon && desired_long < 100) |
||
415 | desired_long *= 10000000+0.5; |
||
416 | |||
417 | if (ok_lat && desired_lat < 100) |
||
418 | desired_lat *= 10000000+0.5; |
||
419 | |||
420 | //fülle Wegpunkt-Daten |
||
421 | desired_pos.Position.Altitude = 0; |
||
422 | desired_pos.Position.Longitude = int32_t(desired_long); |
||
423 | desired_pos.Position.Latitude = int32_t(desired_lat); |
||
424 | desired_pos.Position.Status = NEWDATA; |
||
425 | desired_pos.Heading = -1; |
||
426 | desired_pos.ToleranceRadius = 1; |
||
427 | desired_pos.HoldTime = 60; |
||
428 | desired_pos.Event_Flag = 0; |
||
429 | desired_pos.reserve[0] = 0; // reserve |
||
430 | desired_pos.reserve[1] = 0; // reserve |
||
431 | desired_pos.reserve[2] = 0; // reserve |
||
432 | desired_pos.reserve[3] = 0; // reserve |
||
433 | |||
434 | //...und sende ihn an die NaviCtrl |
||
435 | int max_radius = 10000; |
||
436 | if (ok_lat && ok_lon && |
||
437 | abs(Navi.Current.Longitude - desired_pos.Position.Longitude) < max_radius && |
||
438 | abs(Navi.Current.Latitude - desired_pos.Position.Latitude) < max_radius) |
||
439 | { |
||
440 | Conn->send_Cmd('s', ADDRESS_NC, (char *)&desired_pos, sizeof(desired_pos), false); |
||
441 | } |
||
442 | else |
||
443 | { |
||
444 | QMessageBox msgB; |
||
445 | QString msg; |
||
446 | msg += "Bitte die Eingabe ueberpruefen!\n"; |
||
447 | msg += "Die Werte muessen sich in der Naehe der aktuellen Koordinaten befinden\n"; |
||
448 | msg += "(Lon: "; |
||
449 | msg += ToolBox::get_Float(Navi.Current.Longitude,10000000); |
||
450 | msg += ", "; |
||
451 | msg += "Lat: "; |
||
452 | msg += ToolBox::get_Float(Navi.Current.Latitude,10000000); |
||
453 | msg += ")"; |
||
454 | msgB.setText(msg); |
||
455 | msgB.exec(); |
||
456 | } |
||
457 | } |
||
458 | |||
459 | void MKTool::slot_ac_Hardware() |
||
460 | { |
||
461 | QAction *Action = (QAction*)sender(); |
||
462 | |||
463 | if (Action->isChecked() == false) |
||
464 | { |
||
465 | Action->setChecked(true); |
||
466 | } |
||
467 | |||
468 | slot_rb_Hardware(); |
||
469 | } |
||
470 | |||
471 | void MKTool::slot_rb_Hardware() |
||
472 | { |
||
473 | if ((rb_SelNC->isChecked() == false) && (Mode.ID != ADDRESS_NC)) |
||
474 | { |
||
475 | lb_Status->setText(tr("Schalte um auf NaviCtrl.")); |
||
476 | TX_Data[0] = 0x1B; |
||
477 | TX_Data[1] = 0x1B; |
||
478 | TX_Data[2] = 0x55; |
||
479 | TX_Data[3] = 0xAA; |
||
480 | TX_Data[4] = 0x00; |
||
481 | TX_Data[5] = '\r'; |
||
482 | Conn->send_Cmd('#', ADDRESS_NC, TX_Data, 6, false); |
||
483 | ToolBox::Wait(SLEEP); |
||
484 | } |
||
485 | |||
486 | if (rb_SelFC->isChecked()) |
||
487 | { |
||
488 | lb_Status->setText(tr("Schalte um auf FlightCtrl.")); |
||
489 | TX_Data[0] = 0; |
||
490 | Conn->send_Cmd('u', ADDRESS_NC, TX_Data, 1, false); |
||
491 | } |
||
492 | else |
||
493 | if (rb_SelMag->isChecked()) |
||
494 | { |
||
495 | lb_Status->setText(tr("Schalte um auf MK3MAG.")); |
||
496 | TX_Data[0] = 1; |
||
497 | Conn->send_Cmd('u', ADDRESS_NC, TX_Data, 1, false); |
||
498 | } |
||
499 | else |
||
500 | if (rb_SelNC->isChecked()) |
||
501 | { |
||
502 | lb_Status->setText(tr("Schalte um auf NaviCtrl.")); |
||
503 | TX_Data[0] = 0x1B; |
||
504 | TX_Data[1] = 0x1B; |
||
505 | TX_Data[2] = 0x55; |
||
506 | TX_Data[3] = 0xAA; |
||
507 | TX_Data[4] = 0x00; |
||
508 | TX_Data[5] = '\r'; |
||
509 | Conn->send_Cmd('#', ADDRESS_NC, TX_Data, 6, false); |
||
510 | } |
||
511 | ToolBox::Wait(SLEEP); |
||
512 | |||
513 | // qDebug("Select RB Hardware"); |
||
514 | Conn->send_Cmd('v', ADDRESS_ALL, TX_Data, 0, true); |
||
515 | } |
||
516 | |||
517 | // Ticker-Event |
||
518 | /////////////// |
||
519 | void MKTool::slot_Ticker() |
||
520 | { |
||
521 | if (TickerDiv) |
||
522 | TickerDiv = false; |
||
523 | else |
||
524 | TickerDiv = true; |
||
525 | |||
526 | if (cb_ClipBoard->isChecked()) |
||
527 | { |
||
528 | QString s_OLD = te_KML->toPlainText(); |
||
529 | te_KML->clear(); |
||
530 | te_KML->paste(); |
||
531 | if (s_OLD != te_KML->toPlainText()) |
||
532 | { |
||
533 | parse_TargetKML(); |
||
534 | } |
||
535 | } |
||
536 | |||
537 | for (int a = 0; a < MaxTickerEvents; a++) |
||
538 | { |
||
539 | if (TickerEvent[a] == true) |
||
540 | { |
||
541 | switch(a) |
||
542 | { |
||
543 | case 0 : |
||
544 | if (TickerDiv) |
||
545 | { |
||
546 | QByteArray Temp(LastSend.toUtf8()); |
||
547 | // serialPort->sendData(Temp); |
||
548 | } |
||
549 | break; |
||
550 | case 1 : |
||
551 | TX_Data[0] = 0; |
||
552 | Conn->send_Cmd('p', ADDRESS_FC, TX_Data, 0, false); |
||
553 | break; |
||
554 | case 2 : |
||
555 | if (f_LCD->cb_LCD->isChecked()) |
||
556 | { |
||
557 | if (!f_LCD->isVisible()) |
||
558 | { |
||
559 | Ticker->setInterval(2000); |
||
560 | TickerEvent[2] = false; |
||
561 | } |
||
562 | TX_Data[0] = LCD_Page; |
||
563 | TX_Data[1] = 0; |
||
564 | Conn->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true); |
||
565 | } |
||
566 | break; |
||
567 | case 3 : |
||
568 | if (ac_FastDebug->isChecked()) |
||
569 | { |
||
570 | TX_Data[0] = Settings->Data.Debug_Fast / 10; |
||
571 | Conn->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false); |
||
572 | } |
||
573 | else |
||
574 | { |
||
575 | TX_Data[0] = Settings->Data.Debug_Slow / 10; |
||
576 | Conn->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false); |
||
577 | } |
||
578 | break; |
||
579 | } |
||
580 | } |
||
581 | } |
||
582 | } |
||
583 | |||
584 | void MKTool::slot_QMKS_Connect() |
||
585 | { |
||
586 | if (ac_QMKServer->isChecked()) |
||
587 | { |
||
588 | lb_Status->setText(tr("Verbinde zum QMK-Datenserver.")); |
||
589 | |||
590 | QMK_Server->Connect(Settings->Server.QMKS_Host, Settings->Server.QMKS_Port.toInt(), Settings->Server.QMKS_Login, Settings->Server.QMKS_Password); |
||
591 | |||
592 | connect(QMK_Server, SIGNAL(sig_Connected()), this, SLOT(slot_QMKS_Connected())); |
||
593 | connect(QMK_Server, SIGNAL(sig_Disconnected(int)), this, SLOT(slot_QMKS_Disconnected(int))); |
||
594 | } |
||
595 | else |
||
596 | { |
||
597 | if ((QMK_Server->property("Connect")) == true) |
||
598 | { |
||
599 | disconnect(QMK_Server, SIGNAL(sig_Disconnected(int)), 0, 0); |
||
600 | lb_Status->setText(tr("Trenne vom QMK-Datenserver.")); |
||
601 | |||
602 | QMK_Server->Disconnect(); |
||
603 | QMK_Server->setProperty("Connect", false); |
||
604 | ac_QMKServer->setText("QMK-Server Verbinden"); |
||
605 | } |
||
606 | } |
||
607 | } |
||
608 | |||
609 | void MKTool::slot_QMKS_Connected() |
||
610 | { |
||
611 | QMK_Server->setProperty("Connect", true); |
||
612 | ac_QMKServer->setText("QMK-Server Trennnen"); |
||
613 | lb_Status->setText(tr("Verbunden mit QMK-Datenserver.")); |
||
614 | } |
||
615 | |||
616 | void MKTool::slot_QMKS_Disconnected(int Error) |
||
617 | { |
||
618 | QMK_Server->setProperty("Connect", false); |
||
619 | ac_QMKServer->setText("QMK-Server Verbinden"); |
||
620 | ac_QMKServer->setChecked(false); |
||
621 | |||
622 | disconnect(QMK_Server, SIGNAL(sig_Disconnected(int)), 0, 0); |
||
623 | |||
624 | switch (Error) |
||
625 | { |
||
626 | case 1 : |
||
627 | { |
||
628 | lb_Status->setText(tr("Verbindung vom Server beendet.")); |
||
629 | QMessageBox::warning(this, QA_NAME,"QMK-Datenserver: Verbindung wurde vom Server beendet.", QMessageBox::Ok); |
||
630 | } |
||
631 | break; |
||
632 | case 2 : |
||
633 | { |
||
634 | lb_Status->setText(tr("Server nicht gefunden.")); |
||
635 | QMessageBox::warning(this, QA_NAME,"QMK-Datenserver: Kann nicht zum Server verbinden.", QMessageBox::Ok); |
||
636 | } |
||
637 | break; |
||
638 | case 3 : |
||
639 | { |
||
640 | lb_Status->setText(tr("Serververbindung getrennt. Logindaten falsch.")); |
||
641 | QMessageBox::warning(this, QA_NAME,"QMK-Datenserver: Loginname oder Password falsch.", QMessageBox::Ok); |
||
642 | } |
||
643 | break; |
||
644 | default : |
||
645 | { |
||
646 | lb_Status->setText(tr("Getrennt vom QMK-Datenserver.")); |
||
647 | } |
||
648 | break; |
||
649 | } |
||
650 | } |
||
651 | |||
652 | // Slots der Actions (Menüpunkte, Buttons) |
||
653 | ////////////////////////////////////////// |
||
654 | void MKTool::slot_ac_Motortest() |
||
655 | { |
||
656 | dlg_Motortest *f_Motortest = new dlg_Motortest(this); |
||
657 | |||
658 | connect(f_Motortest, SIGNAL(updateMotor(int, int, int, int)), this, SLOT(slot_Motortest(int, int, int, int))); |
||
659 | |||
660 | if (f_Motortest->exec()==QDialog::Accepted) |
||
661 | { |
||
662 | } |
||
663 | |||
664 | disconnect(f_Motortest, 0,0,0); |
||
665 | slot_Motortest(0,0,0,0); |
||
666 | } |
||
667 | |||
668 | void MKTool::slot_ac_LCD() |
||
669 | { |
||
670 | if (!f_LCD->isVisible()) |
||
671 | { |
||
672 | f_LCD = new dlg_LCD(this); |
||
673 | |||
674 | // LCD auf / ab |
||
675 | connect(f_LCD->pb_LCDup, SIGNAL(clicked()), this, SLOT(slot_LCD_UP())); |
||
676 | connect(f_LCD->pb_LCDdown, SIGNAL(clicked()), this, SLOT(slot_LCD_DOWN())); |
||
677 | |||
678 | f_LCD->show(); |
||
679 | TX_Data[0] = 0; |
||
680 | TX_Data[1] = 0; |
||
681 | Conn->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true); |
||
682 | |||
683 | Ticker->setInterval(500); |
||
684 | TickerEvent[2] = true; |
||
685 | } |
||
686 | } |
||
687 | |||
688 | void MKTool::slot_Motortest(int Motor1, int Motor2, int Motor3, int Motor4) |
||
689 | { |
||
690 | TX_Data[0] = Motor1; |
||
691 | TX_Data[1] = Motor2; |
||
692 | TX_Data[2] = Motor3; |
||
693 | TX_Data[3] = Motor4; |
||
694 | Conn->send_Cmd('t', ADDRESS_FC, TX_Data, 4, false); |
||
695 | } |
||
696 | |||
697 | void MKTool::slot_ac_Config() |
||
698 | { |
||
699 | set_Analog Old_Analog1; |
||
700 | |||
701 | Old_Analog1 = Settings->Analog1; |
||
702 | |||
703 | dlg_Config *f_Config = new dlg_Config(this); |
||
704 | f_Config->set_Settings(Settings, Mode.ID); |
||
705 | |||
706 | if (f_Config->exec()==QDialog::Accepted) |
||
707 | { |
||
708 | Settings = f_Config->get_Settings(); |
||
709 | Settings->write_Settings_Analog(Mode.ID); |
||
710 | |||
711 | // Plotter neu einrichten |
||
712 | if (Old_Analog1.PlotView != Settings->Analog1.PlotView) |
||
713 | { |
||
714 | config_Plot(); |
||
715 | } |
||
716 | |||
717 | // CVS-Datei neu anlegen. |
||
718 | if ((logger->is_active()) && (Old_Analog1.LogView != Settings->Analog1.LogView)) |
||
719 | { |
||
720 | logger->close(); |
||
721 | logger->start_Log(); |
||
722 | } |
||
723 | |||
724 | } |
||
725 | } |
||
726 | |||
727 | //aktualisiere Logging-Status |
||
728 | void MKTool::update_Log() |
||
729 | { |
||
730 | if (logger->is_active()) |
||
731 | { |
||
732 | |||
733 | ac_RecordCSV->setText("Log Stop"); |
||
734 | lb_Status->setText(tr("Log-Record gestartet.")); |
||
735 | } |
||
736 | else |
||
737 | { |
||
738 | ac_RecordCSV->setText("Log Aufzeichnen"); |
||
739 | lb_Status->setText(tr("Log-Record gestopt.")); |
||
740 | } |
||
741 | } |
||
742 | |||
743 | //starte/stoppe Logging, wenn auf den entsprechenden Button gedrückt wurde |
||
744 | void MKTool::slot_RecordLog() |
||
745 | { |
||
746 | if (!logger->is_active()) |
||
747 | logger->start_Log(); |
||
748 | else |
||
749 | logger->close(); |
||
750 | |||
751 | update_Log(); |
||
752 | } |
||
753 | |||
754 | void MKTool::slot_ac_Preferences() |
||
755 | { |
||
756 | dlg_Preferences *f_Preferences = new dlg_Preferences(this); |
||
757 | |||
758 | Settings->TTY.Port = le_Port->text(); |
||
759 | f_Preferences->set_Settings(Settings); |
||
760 | |||
761 | if (f_Preferences->exec()==QDialog::Accepted) |
||
762 | { |
||
763 | Settings = f_Preferences->get_Settings(); |
||
764 | Settings->write_Settings(); |
||
765 | le_Port->setText(Settings->TTY.Port); |
||
766 | config_Plot(); |
||
767 | } |
||
768 | } |
||
769 | |||
770 | void MKTool::slot_ac_StartPlotter() |
||
771 | { |
||
772 | if (ac_StartPlotter->isChecked()) |
||
773 | { |
||
774 | lb_Status->setText(tr("Datenplotter gestartet.")); |
||
775 | ac_StartPlotter->setText("Stop Plotter"); |
||
776 | pb_StartPlotter->setText("Stop Plotter"); |
||
777 | } |
||
778 | else |
||
779 | { |
||
780 | lb_Status->setText(tr("Datenplotter gestopt.")); |
||
781 | ac_StartPlotter->setText("Start Plotter"); |
||
782 | pb_StartPlotter->setText("Start Plotter"); |
||
783 | } |
||
784 | } |
||
785 | |||
786 | void MKTool::slot_ac_View() |
||
787 | { |
||
788 | int Aktive = -1; |
||
789 | |||
790 | QAction *Action = (QAction*)sender(); |
||
791 | |||
792 | if (Action->objectName() == QString("ac_View0")) |
||
793 | Aktive = 0; |
||
794 | if (Action->objectName() == QString("ac_View1")) |
||
795 | Aktive = 1; |
||
796 | if (Action->objectName() == QString("ac_View2")) |
||
797 | Aktive = 2; |
||
798 | if (Action->objectName() == QString("ac_View3")) |
||
799 | Aktive = 3; |
||
800 | if (Action->objectName() == QString("ac_View4")) |
||
801 | Aktive = 4; |
||
802 | if (Action->objectName() == QString("ac_View5")) |
||
803 | Aktive = 5; |
||
804 | if (Action->objectName() == QString("ac_View6")) |
||
805 | Aktive = 6; |
||
806 | |||
807 | QString TabName = QString("Tab_%1").arg(Aktive); |
||
808 | |||
809 | if (!Action->isChecked()) |
||
810 | { |
||
811 | for (int a = 0; a < tab_Main->count(); a++) |
||
812 | { |
||
813 | if (tab_Main->widget(a)->objectName() == TabName) |
||
814 | { |
||
815 | tab_Main->removeTab(a); |
||
816 | } |
||
817 | } |
||
818 | } |
||
819 | else |
||
820 | { |
||
821 | tab_Main->insertTab(Aktive, TabWidgets[Aktive], Action->icon(), Action->text()); |
||
822 | } |
||
823 | } |
||
824 | |||
825 | void MKTool::slot_ac_FastNavi() // DONE NC 0.12i |
||
826 | { |
||
827 | if (!ac_NoNavi->isChecked()) |
||
828 | { |
||
829 | if (ac_FastNavi->isChecked()) |
||
830 | { |
||
831 | lb_Status->setText(tr("Fordere schnelle NaviDaten an.")); |
||
832 | TX_Data[0] = Settings->Data.Navi_Fast / 10; |
||
833 | } |
||
834 | else |
||
835 | { |
||
836 | lb_Status->setText(tr("Fordere langsame NaviDaten an.")); |
||
837 | TX_Data[0] = Settings->Data.Navi_Slow / 10; |
||
838 | } |
||
839 | Conn->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false); |
||
840 | } |
||
841 | } |
||
842 | |||
843 | void MKTool::slot_ac_NoNavi() // DONE NC 0.12i |
||
844 | { |
||
845 | if (ac_NoNavi->isChecked()) |
||
846 | { |
||
847 | lb_Status->setText(tr("NaviDaten abstellen.")); |
||
848 | TX_Data[0] = 0; |
||
849 | } |
||
850 | else |
||
851 | { |
||
852 | if (ac_FastNavi->isChecked()) |
||
853 | { |
||
854 | lb_Status->setText(tr("Fordere schnelle NaviDaten an.")); |
||
855 | TX_Data[0] = Settings->Data.Navi_Fast / 10; |
||
856 | } |
||
857 | else |
||
858 | { |
||
859 | lb_Status->setText(tr("Fordere langsame NaviDaten an.")); |
||
860 | TX_Data[0] = Settings->Data.Navi_Slow / 10; |
||
861 | } |
||
862 | } |
||
863 | Conn->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false); |
||
864 | } |
||
865 | |||
866 | void MKTool::slot_ac_FastDebug() // DONE 0.71g |
||
867 | { |
||
868 | if (!ac_NoDebug->isChecked()) |
||
869 | { |
||
870 | if (ac_FastDebug->isChecked()) |
||
871 | { |
||
872 | lb_Status->setText(tr("Fordere schnelle DebugDaten an.")); |
||
873 | TX_Data[0] = Settings->Data.Debug_Fast / 10; |
||
874 | } |
||
875 | else |
||
876 | { |
||
877 | lb_Status->setText(tr("Fordere langsame DebugDaten an.")); |
||
878 | TX_Data[0] = Settings->Data.Debug_Slow / 10; |
||
879 | } |
||
880 | Conn->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false); |
||
881 | } |
||
882 | } |
||
883 | |||
884 | void MKTool::slot_ac_NoDebug() // DONE 0.71g |
||
885 | { |
||
886 | if (ac_NoDebug->isChecked()) |
||
887 | { |
||
888 | lb_Status->setText(tr("DebugDaten abstellen.")); |
||
889 | TickerEvent[3] = false; |
||
890 | TX_Data[0] = 0; |
||
891 | } |
||
892 | else |
||
893 | { |
||
894 | // Wenn MK3MAG dann andauernd Daten neu anfragen. |
||
895 | if (Mode.ID == ADDRESS_MK3MAG) |
||
896 | TickerEvent[3] = true; |
||
897 | |||
898 | if (ac_FastDebug->isChecked()) |
||
899 | { |
||
900 | lb_Status->setText(tr("Fordere schnelle DebugDaten an.")); |
||
901 | TX_Data[0] = Settings->Data.Debug_Fast / 10; |
||
902 | } |
||
903 | else |
||
904 | { |
||
905 | lb_Status->setText(tr("Fordere langsame DebugDaten an.")); |
||
906 | TX_Data[0] = Settings->Data.Debug_Slow / 10; |
||
907 | } |
||
908 | } |
||
909 | Conn->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false); |
||
910 | } |
||
911 | |||
912 | void MKTool::slot_ac_About() |
||
913 | { |
||
914 | QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT); |
||
915 | } |
||
916 | |||
917 | void MKTool::slot_ac_GetLabels() // DONE 0.71g |
||
918 | { |
||
919 | lb_Status->setText(tr("Analoglabels auslesen.")); |
||
920 | TX_Data[0] = 0; |
||
921 | Conn->send_Cmd('a', ADDRESS_ALL, TX_Data, 1, true); |
||
922 | } |
||
923 | |||
924 | void MKTool::slot_ac_StartServer() |
||
925 | { |
||
926 | if (ac_StartServer->isChecked()) |
||
927 | { |
||
928 | lb_Status->setText(tr("GoogleEarth-Server gestartet.")); |
||
929 | GE_Server->start_Server(Settings->Server.Port.toInt(), Settings); |
||
930 | } |
||
931 | else |
||
932 | { |
||
933 | lb_Status->setText(tr("GoogleEarth-Server gestopt.")); |
||
934 | GE_Server->stop_Server(); |
||
935 | } |
||
936 | } |
||
937 | |||
938 | |||
939 | // Daten-Plotter |
||
940 | ///////////////// |
||
941 | void MKTool::update_Plot() |
||
942 | { |
||
943 | for (int a = 0; a < MaxAnalog; a++) |
||
944 | { |
||
945 | Plot[a]->setData(aID,aData[a],NextPlot - 1); |
||
946 | } |
||
947 | |||
948 | if ((NextPlot > Settings->Data.Plotter_Count)) |
||
949 | { |
||
950 | scroll_plot->setMaximum(NextPlot - Settings->Data.Plotter_Count); |
||
951 | } |
||
952 | |||
953 | if ((scroll_plot->value() == NextPlot - (Settings->Data.Plotter_Count + 1))) |
||
954 | { |
||
955 | qwtPlot->setAxisScale(QwtPlot::xBottom,NextPlot - Settings->Data.Plotter_Count,NextPlot,0); |
||
956 | scroll_plot->setValue(NextPlot - Settings->Data.Plotter_Count); |
||
957 | } |
||
958 | |||
959 | qwtPlot->replot(); |
||
960 | } |
||
961 | |||
962 | void MKTool::config_Plot() |
||
963 | { |
||
964 | // qDebug("Plotter rekonfiguriert..!!"); |
||
965 | qwtPlot->setAxisScale(QwtPlot::xBottom,0,Settings->Data.Plotter_Count,0); |
||
966 | |||
967 | for (int a = 0; a < MaxAnalog; a++) |
||
968 | { |
||
969 | Plot[a]->detach(); |
||
970 | Plot[a]->setPen(QPen(QColor(Def_Colors[a]))); |
||
971 | |||
972 | if (Settings->Analog1.PlotView[a]) |
||
973 | { |
||
974 | Plot[a]->setTitle(Settings->Analog1.Label[a]); |
||
975 | Plot[a]->attach(qwtPlot); |
||
976 | } |
||
977 | } |
||
978 | qwtPlot->replot(); |
||
979 | } |
||
980 | |||
981 | void MKTool::slot_ScrollPlot(int Pos) |
||
982 | { |
||
983 | qwtPlot->setAxisScale(QwtPlot::xBottom,Pos,Pos + Settings->Data.Plotter_Count,0); |
||
984 | qwtPlot->replot(); |
||
985 | } |
||
986 | |||
987 | |||
988 | // Firmeware-Update |
||
989 | /////////////////// |
||
990 | void MKTool::slot_pb_Update() |
||
991 | { |
||
992 | QString Device; |
||
993 | QString Hardware; |
||
994 | |||
995 | if (rb_FC->isChecked()) |
||
996 | { |
||
997 | Device = "m644"; |
||
998 | Hardware = "FlightCtrl"; |
||
999 | } |
||
1000 | else if (rb_MK3MAG->isChecked()) |
||
1001 | { |
||
1002 | Device = "m168"; |
||
1003 | Hardware = "MK3MAG"; |
||
1004 | } |
||
1005 | else if (rb_BL->isChecked()) |
||
1006 | { |
||
1007 | Device = "m8"; |
||
1008 | Hardware = "BL-Ctrl"; |
||
1009 | } |
||
1010 | |||
1011 | QString Message = "Firmeware-Datei \n\n"; |
||
1012 | Message = Message + le_HexFile->text() + "\n\n"; |
||
1013 | Message = Message + "an " + Hardware + trUtf8(" mit AVRDUDE - Seriel & Bootloader über ") + le_Port->text() + trUtf8(" übertragen?\n"); |
||
1014 | |||
1015 | if (le_HexFile->text() == "") |
||
1016 | { |
||
1017 | QMessageBox::warning(this, QA_NAME, trUtf8("Bitte Firmeware-Datei wählen."), QMessageBox::Ok); |
||
1018 | } |
||
1019 | else if (QMessageBox::warning(this, QA_NAME, Message, QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) |
||
1020 | { |
||
1021 | QString Programm = "avrdude" ; |
||
1022 | |||
1023 | QStringList Argumente; |
||
1024 | |||
1025 | Update = new QProcess(); |
||
1026 | |||
1027 | if (Conn->isOpen()) |
||
1028 | { |
||
1029 | slot_OpenPort(); |
||
1030 | } |
||
1031 | |||
1032 | Argumente << "-P"; |
||
1033 | Argumente << le_Port->text(); |
||
1034 | Argumente << "-p"; |
||
1035 | Argumente << Device; |
||
1036 | Argumente << "-c"; |
||
1037 | Argumente << "butterfly"; |
||
1038 | Argumente << "-b"; |
||
1039 | Argumente << "57600"; |
||
1040 | Argumente << "-U"; |
||
1041 | Argumente << "flash:w:" + le_HexFile->text(); |
||
1042 | |||
1043 | // 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"; |
||
1044 | |||
1045 | te_Shell->setText(""); // Ausgabefenster säubern |
||
1046 | |||
1047 | connect(Update, SIGNAL(readyReadStandardOutput()), this, SLOT(slot_UpdateShell()) ); |
||
1048 | connect(Update, SIGNAL(readyReadStandardError()), this, SLOT(slot_UpdateShell()) ); |
||
1049 | |||
1050 | Update->start(Programm, Argumente); // Programmaufruf |
||
1051 | } |
||
1052 | } |
||
1053 | |||
1054 | void MKTool::slot_UpdateShell() |
||
1055 | { |
||
1056 | QByteArray Output; |
||
1057 | |||
1058 | Output = Update->readAllStandardError(); // Shellausgabe an Variable |
||
1059 | te_Shell->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); |
||
1060 | te_Shell->insertPlainText(QString::fromUtf8(Output)); |
||
1061 | |||
1062 | Output = Update->readAll(); |
||
1063 | te_Shell->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); |
||
1064 | te_Shell->insertPlainText(QString::fromUtf8(Output)); |
||
1065 | } |
||
1066 | |||
1067 | void MKTool::slot_pb_HexFile() |
||
1068 | { |
||
1069 | QString FileName = QFileDialog::getOpenFileName(this,trUtf8(("Firmeware-Datei wählen")),"", |
||
1070 | tr("Intel Hex(*.hex);;Alle Dateien (*)")); |
||
1071 | if (!FileName.isEmpty()) |
||
1072 | { |
||
1073 | le_HexFile->setText(FileName); |
||
1074 | } |
||
1075 | } |
||
1076 | |||
1077 | |||
1078 | // Wechsel der Tabs erkennen |
||
1079 | void MKTool::slot_TabChanged(int Tab) // DONE 0.71g |
||
1080 | { |
||
1081 | Tab = Tab; |
||
1082 | if (tab_Main->count() != 0) |
||
1083 | { |
||
1084 | if ((tab_Main->currentWidget()->objectName() == QString("Tab_2")) && (f_Settings->tab_Par->currentIndex() == 1)) |
||
1085 | { |
||
1086 | TX_Data[0] = 0; |
||
1087 | Conn->send_Cmd('p', ADDRESS_FC, TX_Data, 0, true); |
||
1088 | |||
1089 | Ticker->setInterval(500); |
||
1090 | TickerEvent[1] = true; |
||
1091 | } |
||
1092 | else |
||
1093 | { |
||
1094 | Ticker->setInterval(2000); |
||
1095 | TickerEvent[1] = false; |
||
1096 | } |
||
1097 | /* |
||
1098 | if ((tab_Main->currentWidget()->objectName() == QString("Tab_4"))) |
||
1099 | { |
||
1100 | TX_Data[0] = 0; |
||
1101 | TX_Data[1] = 0; |
||
1102 | send_Data('l', ADDRESS_ALL, TX_Data, 1, true); |
||
1103 | |||
1104 | Ticker->setInterval(500); |
||
1105 | TickerEvent[2] = true; |
||
1106 | } |
||
1107 | else |
||
1108 | { |
||
1109 | Ticker->setInterval(2000); |
||
1110 | TickerEvent[2] = false; |
||
1111 | } |
||
1112 | */ |
||
1113 | } |
||
1114 | } |
||
1115 | |||
1116 | // LCD-Seiten weiterschalten |
||
1117 | void MKTool::slot_LCD_UP() // DONE 0.71g |
||
1118 | { |
||
1119 | if (LCD_Page == LCD_MAX_Page) |
||
1120 | TX_Data[0] = 0; |
||
1121 | else |
||
1122 | TX_Data[0] = LCD_Page + 1; |
||
1123 | |||
1124 | TX_Data[1] = 0; |
||
1125 | Conn->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true); |
||
1126 | } |
||
1127 | |||
1128 | void MKTool::slot_LCD_DOWN() // DONE 0.71g |
||
1129 | { |
||
1130 | if (LCD_Page == 0) |
||
1131 | TX_Data[0] = LCD_MAX_Page; |
||
1132 | else |
||
1133 | TX_Data[0] = LCD_Page - 1; |
||
1134 | |||
1135 | TX_Data[1] = 0; |
||
1136 | Conn->send_Cmd('l', ADDRESS_ALL, TX_Data, 1, true); |
||
1137 | } |
||
1138 | |||
1139 | // Settings aus MK lesen / in MK schreiben |
||
1140 | void MKTool::slot_GetFCSettings() // DONE 0.71g |
||
1141 | { |
||
1142 | lb_Status->setText(tr("Lese FlightCtrl-Settings aus.")); |
||
1143 | TX_Data[0] = f_Settings->sb_Set->value(); |
||
1144 | TX_Data[1] = 0; |
||
1145 | Conn->send_Cmd('q', ADDRESS_FC, TX_Data, 1); |
||
1146 | } |
||
1147 | |||
1148 | void MKTool::slot_SetFCSettings() // DONE 0.71g |
||
1149 | { |
||
1150 | char *TX_Data2 = f_Settings->GetFCSettings(); |
||
1151 | |||
1152 | lb_Status->setText(tr("Schreibe FlightCtrl-Settings.")); |
||
1153 | |||
1154 | Conn->send_Cmd('s', ADDRESS_FC, TX_Data2, MaxParameter + 2, false); |
||
1155 | } |
||
1156 | |||
1157 | |||
1158 | // Save GUI-Preferences |
||
1159 | /////////////////////// |
||
1160 | void MKTool::set_Preferences() |
||
1161 | { |
||
1162 | Settings->GUI.TabViews.setBit(0, ac_View0->isChecked()); |
||
1163 | Settings->GUI.TabViews.setBit(1, ac_View1->isChecked()); |
||
1164 | Settings->GUI.TabViews.setBit(2, ac_View2->isChecked()); |
||
1165 | Settings->GUI.TabViews.setBit(3, ac_View3->isChecked()); |
||
1166 | Settings->GUI.TabViews.setBit(4, ac_View4->isChecked()); |
||
1167 | Settings->GUI.TabViews.setBit(5, ac_View5->isChecked()); |
||
1168 | Settings->GUI.TabViews.setBit(6, ac_View6->isChecked()); |
||
1169 | |||
1170 | Settings->GUI.ToolViews.setBit(0, tb_Allgemein->isVisibleTo(this)); |
||
1171 | Settings->GUI.ToolViews.setBit(1, tb_Werkzeuge->isVisibleTo(this)); |
||
1172 | Settings->GUI.ToolViews.setBit(2, tb_Debug->isVisibleTo(this)); |
||
1173 | Settings->GUI.ToolViews.setBit(3, tb_TTY->isVisibleTo(this)); |
||
1174 | Settings->GUI.ToolViews.setBit(4, tb_Hardware->isVisibleTo(this)); |
||
1175 | |||
1176 | Settings->GUI.Term_Info = cb_ShowMSG->isChecked(); |
||
1177 | Settings->GUI.Term_Data = cb_ShowData->isChecked(); |
||
1178 | Settings->GUI.Term_Always = cb_ShowAlways->isChecked(); |
||
1179 | Settings->GUI.Term_Send = cb_ShowSend->isChecked(); |
||
1180 | Settings->GUI.isMax = isMaximized(); |
||
1181 | Settings->GUI.Size = size(); |
||
1182 | Settings->GUI.Point = pos(); |
||
1183 | |||
1184 | Settings->TTY.Port = le_Port->text(); |
||
1185 | } |
||
1186 | |||
1187 | void MKTool::show_DebugData() |
||
1188 | { |
||
1189 | if (logger->is_active()) |
||
1190 | logger->write(AnalogData); |
||
1191 | |||
1192 | if (ac_StartPlotter->isChecked()) |
||
1193 | { |
||
1194 | aID[NextPlot] = NextPlot; |
||
1195 | |||
1196 | for (int a = 0; a < MaxAnalog; a++) |
||
1197 | { |
||
1198 | aData[a][NextPlot] = AnalogData[a]; |
||
1199 | } |
||
1200 | NextPlot++; |
||
1201 | |||
1202 | if ((tab_Main->currentWidget()->objectName() == QString("Tab_1"))) |
||
1203 | update_Plot(); |
||
1204 | } |
||
1205 | |||
1206 | le_A_0->setText(QString("%1").arg(AnalogData[0])); |
||
1207 | le_A_1->setText(QString("%1").arg(AnalogData[1])); |
||
1208 | le_A_2->setText(QString("%1").arg(AnalogData[2])); |
||
1209 | le_A_3->setText(QString("%1").arg(AnalogData[3])); |
||
1210 | le_A_4->setText(QString("%1").arg(AnalogData[4])); |
||
1211 | le_A_5->setText(QString("%1").arg(AnalogData[5])); |
||
1212 | le_A_6->setText(QString("%1").arg(AnalogData[6])); |
||
1213 | le_A_7->setText(QString("%1").arg(AnalogData[7])); |
||
1214 | le_A_8->setText(QString("%1").arg(AnalogData[8])); |
||
1215 | le_A_9->setText(QString("%1").arg(AnalogData[9])); |
||
1216 | le_A_10->setText(QString("%1").arg(AnalogData[10])); |
||
1217 | le_A_11->setText(QString("%1").arg(AnalogData[11])); |
||
1218 | le_A_12->setText(QString("%1").arg(AnalogData[12])); |
||
1219 | le_A_13->setText(QString("%1").arg(AnalogData[13])); |
||
1220 | le_A_14->setText(QString("%1").arg(AnalogData[14])); |
||
1221 | le_A_15->setText(QString("%1").arg(AnalogData[15])); |
||
1222 | le_A_16->setText(QString("%1").arg(AnalogData[16])); |
||
1223 | le_A_17->setText(QString("%1").arg(AnalogData[17])); |
||
1224 | le_A_18->setText(QString("%1").arg(AnalogData[18])); |
||
1225 | le_A_19->setText(QString("%1").arg(AnalogData[19])); |
||
1226 | le_A_20->setText(QString("%1").arg(AnalogData[20])); |
||
1227 | le_A_21->setText(QString("%1").arg(AnalogData[21])); |
||
1228 | le_A_22->setText(QString("%1").arg(AnalogData[22])); |
||
1229 | le_A_23->setText(QString("%1").arg(AnalogData[23])); |
||
1230 | le_A_24->setText(QString("%1").arg(AnalogData[24])); |
||
1231 | le_A_25->setText(QString("%1").arg(AnalogData[25])); |
||
1232 | le_A_26->setText(QString("%1").arg(AnalogData[26])); |
||
1233 | le_A_27->setText(QString("%1").arg(AnalogData[27])); |
||
1234 | le_A_28->setText(QString("%1").arg(AnalogData[28])); |
||
1235 | le_A_29->setText(QString("%1").arg(AnalogData[29])); |
||
1236 | le_A_30->setText(QString("%1").arg(AnalogData[30])); |
||
1237 | le_A_31->setText(QString("%1").arg(AnalogData[31])); |
||
1238 | |||
1239 | if ((Mode.ID == ADDRESS_FC) && (FCSettings[P_GYRO_ACC_FAKTOR] > 0)) |
||
1240 | { |
||
1241 | bar_UBAT->setValue(AnalogData[9]); |
||
1242 | bar_RX->setValue(AnalogData[10]); |
||
1243 | |||
1244 | Compass->setValue(AnalogData[8]); |
||
1245 | |||
1246 | int Roll = (AnalogData[1] * FCSettings[P_GYRO_ACC_FAKTOR]) / 1024; |
||
1247 | int Nick = (AnalogData[0] * FCSettings[P_GYRO_ACC_FAKTOR]) / 1024; |
||
1248 | |||
1249 | if (Roll > 128) |
||
1250 | Roll = Roll - 255; |
||
1251 | |||
1252 | if (Nick > 128) |
||
1253 | Nick = Nick - 255; |
||
1254 | |||
1255 | Attitude->setAngle(Roll); |
||
1256 | Attitude->setGradient(double(double(Nick) / 100.0)); |
||
1257 | } |
||
1258 | } |
||
1259 | |||
1260 | void MKTool::new_NaviData(sRxData RX) |
||
1261 | { |
||
1262 | Navi.Current.Longitude = ToolBox::Data2Long(RX.Decode, N_CUR_LONGITUDE, true); |
||
1263 | Navi.Current.Latitude = ToolBox::Data2Long(RX.Decode, N_CUR_LATITUDE, true); |
||
1264 | Navi.Current.Altitude = ToolBox::Data2Long(RX.Decode, N_CUR_ALTITUDE, true); |
||
1265 | Navi.Target.Longitude = ToolBox::Data2Long(RX.Decode, N_TAR_LONGITUDE, true); |
||
1266 | Navi.Target.Latitude = ToolBox::Data2Long(RX.Decode, N_TAR_LATITUDE, true); |
||
1267 | Navi.Target.Altitude = ToolBox::Data2Long(RX.Decode, N_TAR_ALTITUDE, true); |
||
1268 | |||
1269 | le_CDistance->setText(QString("%1 cm").arg(ToolBox::Data2Int(RX.Decode, N_HOME_DISTANCE))); |
||
1270 | le_CWPA->setText(QString("%1").arg(RX.Decode[N_WP_INDEX])); |
||
1271 | le_CWPT->setText(QString("%1").arg(RX.Decode[N_WP_NUMBER])); |
||
1272 | le_CSats->setText(QString("%1").arg(RX.Decode[N_SATS_IN_USER])); |
||
1273 | |||
1274 | qwt_Rate->setValue(double(ToolBox::Data2Int(RX.Decode, N_VARIOMETER, true))); |
||
1275 | |||
1276 | le_CTime->setText(QString("%1 sec.").arg(ToolBox::Data2Int(RX.Decode, N_FLYING_TIME))); |
||
1277 | |||
1278 | bar_UBAT->setValue(RX.Decode[N_UBAT]); |
||
1279 | |||
1280 | double Speed = double((ToolBox::Data2Int(RX.Decode, N_GROUND_SPEED)) / 10.0); |
||
1281 | |||
1282 | if ((Speed > 4.5) && SpeedMeter->property("END") == 5) |
||
1283 | { |
||
1284 | SpeedMeter->setRange(0.0, 10.0); |
||
1285 | SpeedMeter->setScale(1, 2, 1); |
||
1286 | SpeedMeter->setProperty("END", 10); |
||
1287 | } |
||
1288 | |||
1289 | if ((Speed > 9) && SpeedMeter->property("END") == 10) |
||
1290 | { |
||
1291 | SpeedMeter->setRange(0.0, 20.0); |
||
1292 | SpeedMeter->setScale(1, 2, 2); |
||
1293 | SpeedMeter->setProperty("END", 20); |
||
1294 | } |
||
1295 | |||
1296 | SpeedMeter->setValue(Speed); |
||
1297 | |||
1298 | Compass->setValue(ToolBox::Data2Int(RX.Decode, N_COMAPSS_HEADING)); //(68) |
||
1299 | |||
1300 | bar_RX->setValue(RX.Decode[N_RC_QUALITY]); |
||
1301 | |||
1302 | int Nick = RX.Decode[N_ANGLE_NICK]; |
||
1303 | int Roll = RX.Decode[N_ANGLE_ROLL]; |
||
1304 | |||
1305 | if (Roll > 128) |
||
1306 | Roll = Roll - 255; |
||
1307 | |||
1308 | if (Nick > 128) |
||
1309 | Nick = Nick - 255; |
||
1310 | |||
1311 | Attitude->setAngle(Roll); |
||
1312 | Attitude->setGradient(double(0.0 - (double(Nick) / 100.0))); |
||
1313 | |||
1314 | sNaviString NaviString; |
||
1315 | |||
1316 | NaviString.Longitude = ToolBox::get_Float(Navi.Current.Longitude,10000000); |
||
1317 | NaviString.Latitude = ToolBox::get_Float(Navi.Current.Latitude,10000000); |
||
1318 | NaviString.Altitude = ToolBox::get_Float(Navi.Current.Altitude,1000); |
||
1319 | |||
1320 | GE_Server->store_NaviString(NaviString); |
||
1321 | |||
1322 | if ((QMK_Server->property("Connect")) == true) |
||
1323 | { |
||
1324 | // qDebug("Send Data to Server..!!"); |
||
1325 | QMK_Server->NewPosition(NaviString); |
||
1326 | } |
||
1327 | } |
||
1328 | |||
1329 | // Kopter-Kommunikations-Bereich, Befehle senden und Daten empfangen |
||
1330 | //////////////////////////////////////////////////////////////////// |
||
1331 | |||
1332 | // Neues Datenpacket empfangen -> Verarbeiten |
||
1333 | void MKTool::slot_newData(sRxData RX) // DONE 0.71g |
||
1334 | { |
||
1335 | if (LastSend.length() > 2) |
||
1336 | { |
||
1337 | } |
||
1338 | int HardwareID = RX.Input[1] - 'a'; |
||
1339 | |||
1340 | switch(HardwareID) |
||
1341 | { |
||
1342 | case ADDRESS_FC : |
||
1343 | switch(RX.Input[2]) |
||
1344 | { |
||
1345 | // Stick-Belegung der Fernsteuerung |
||
1346 | case 'P' : // DONE 0.71g |
||
1347 | if (ToolBox::Decode64(RX)) |
||
1348 | { |
||
1349 | f_Settings->pb_K1->setValue(ToolBox::Data2Int(RX.Decode, 2,true)); |
||
1350 | f_Settings->pb_K2->setValue(ToolBox::Data2Int(RX.Decode, 4,true)); |
||
1351 | f_Settings->pb_K3->setValue(ToolBox::Data2Int(RX.Decode, 6,true)); |
||
1352 | f_Settings->pb_K4->setValue(ToolBox::Data2Int(RX.Decode, 8,true)); |
||
1353 | f_Settings->pb_K5->setValue(ToolBox::Data2Int(RX.Decode, 10 ,true)); |
||
1354 | f_Settings->pb_K6->setValue(ToolBox::Data2Int(RX.Decode, 12,true)); |
||
1355 | f_Settings->pb_K7->setValue(ToolBox::Data2Int(RX.Decode, 14,true)); |
||
1356 | f_Settings->pb_K8->setValue(ToolBox::Data2Int(RX.Decode, 16,true)); |
||
1357 | } |
||
1358 | break; |
||
1359 | // Settings lesen |
||
1360 | case 'Q' : // DONE 0.71g |
||
1361 | if (ToolBox::Decode64(RX)) |
||
1362 | { |
||
1363 | TickerEvent[0] = false; |
||
1364 | |||
1365 | if (RX.Decode[1] == VERSION_SETTINGS) |
||
1366 | { |
||
1367 | int Settings_ID = RX.Decode[0]; |
||
1368 | for (int a = 0; a < MaxParameter; a++) |
||
1369 | { |
||
1370 | FCSettings[a] = RX.Decode[a + 2]; |
||
1371 | } |
||
1372 | //show_ParameterSet(Settings_ID); |
||
1373 | f_Settings->show_FCSettings(Settings_ID, FCSettings); |
||
1374 | f_Settings->pb_Read->setEnabled(true); |
||
1375 | f_Settings->pb_Write->setEnabled(true); |
||
1376 | } |
||
1377 | else |
||
1378 | { |
||
1379 | f_Settings->pb_Read->setDisabled(true); |
||
1380 | f_Settings->pb_Write->setDisabled(true); |
||
1381 | |||
1382 | QMessageBox::warning(this, QA_NAME, |
||
1383 | "Versionen inkompatibel. \nParameterbearbeitung nicht moeglich.", QMessageBox::Ok); |
||
1384 | } |
||
1385 | } |
||
1386 | break; |
||
1387 | // Settings geschrieben |
||
1388 | case 'S' : // DONE 0.71g |
||
1389 | TickerEvent[0] = false; |
||
1390 | break; |
||
1391 | } |
||
1392 | |||
1393 | case ADDRESS_NC : |
||
1394 | switch(RX.Input[2]) |
||
1395 | { |
||
1396 | // Navigationsdaten |
||
1397 | case 'O' : // NOT DONE 0.12h |
||
1398 | if (ToolBox::Decode64(RX)) |
||
1399 | { |
||
1400 | new_NaviData(RX); |
||
1401 | } |
||
1402 | break; |
||
1403 | } |
||
1404 | // case ADDRESS_MK3MAG : |
||
1405 | |||
1406 | default : |
||
1407 | switch(RX.Input[2]) |
||
1408 | { |
||
1409 | // LCD-Anzeige |
||
1410 | case 'L' : // DONE 0.71g |
||
1411 | if (ToolBox::Decode64(RX)) |
||
1412 | { |
||
1413 | int LCD[150]; |
||
1414 | memcpy(LCD,RX.Decode, sizeof(RX.Decode)); |
||
1415 | |||
1416 | f_LCD->show_Data(LCD); |
||
1417 | |||
1418 | LCD_Page = RX.Decode[0]; |
||
1419 | LCD_MAX_Page = RX.Decode[1]; |
||
1420 | |||
1421 | TickerEvent[0] = false; |
||
1422 | } |
||
1423 | break; |
||
1424 | // Analoglabels |
||
1425 | case 'A' : // DONE 0.71g |
||
1426 | if (ToolBox::Decode64(RX)) |
||
1427 | { |
||
1428 | int Position = RX.Decode[0]; |
||
1429 | if (Position != 31) |
||
1430 | { |
||
1431 | Settings->Analog1.Label[Position] = ToolBox::Data2QString(RX.Decode,1,17).trimmed(); |
||
1432 | if (Settings->Analog1.Label[Position] == "") |
||
1433 | { |
||
1434 | Settings->Analog1.Label[Position] = "A-" + QString("%1").arg(Position); |
||
1435 | } |
||
1436 | Position ++; |
||
1437 | TX_Data[0] = Position; |
||
1438 | Conn->send_Cmd('a', ADDRESS_ALL, TX_Data, 1, true); |
||
1439 | } |
||
1440 | if (Position == 31) |
||
1441 | { |
||
1442 | for (int a = 0; a < MaxAnalog; a++) |
||
1443 | { |
||
1444 | lb_Analog[a]->setText(Settings->Analog1.Label[a]); |
||
1445 | } |
||
1446 | Settings->Analog1.Version = Mode.Version; |
||
1447 | Settings->write_Settings_AnalogLabels(HardwareID); |
||
1448 | config_Plot(); |
||
1449 | } |
||
1450 | } |
||
1451 | break; |
||
1452 | // Debug-Daten |
||
1453 | case 'D' : // DONE 0.71g |
||
1454 | if (ToolBox::Decode64(RX)) |
||
1455 | { |
||
1456 | for (int i = 0; i < MaxAnalog; i++) |
||
1457 | { |
||
1458 | AnalogData[i] = ToolBox::Data2Int(RX.Decode, (i * 2) + 2); |
||
1459 | } |
||
1460 | show_DebugData(); |
||
1461 | } |
||
1462 | break; |
||
1463 | // Version |
||
1464 | case 'V' : // DONE 0.71h |
||
1465 | if (ToolBox::Decode64(RX)) |
||
1466 | { |
||
1467 | TickerEvent[0] = false; |
||
1468 | |||
1469 | Mode.ID = HardwareID; |
||
1470 | Mode.VERSION_MAJOR = RX.Decode[0]; |
||
1471 | Mode.VERSION_MINOR = RX.Decode[1]; |
||
1472 | Mode.VERSION_PATCH = RX.Decode[4]; |
||
1473 | Mode.VERSION_SERIAL_MAJOR = RX.Decode[2]; |
||
1474 | Mode.VERSION_SERIAL_MINOR = RX.Decode[3]; |
||
1475 | |||
1476 | Mode.Hardware = HardwareType[Mode.ID]; |
||
1477 | Mode.Version = QString("%1").arg(RX.Decode[0]) + "." + QString("%1").arg(RX.Decode[1]) + QString(RX.Decode[4] + 'a'); |
||
1478 | |||
1479 | setWindowTitle(QA_NAME + " v" + QA_VERSION + " - " + Mode.Hardware + " " + Mode.Version); |
||
1480 | |||
1481 | if (Mode.VERSION_SERIAL_MAJOR != VERSION_SERIAL_MAJOR) |
||
1482 | { |
||
1483 | // AllowSend = false; |
||
1484 | QMessageBox::warning(this, QA_NAME, |
||
1485 | "Serielles Protokoll Inkompatibel. \nBitte neue Programmversion installieren,", QMessageBox::Ok); |
||
1486 | } |
||
1487 | |||
1488 | if (ac_NoDebug->isChecked()) |
||
1489 | { |
||
1490 | TX_Data[0] = 0; |
||
1491 | } |
||
1492 | else |
||
1493 | if (ac_FastDebug->isChecked()) |
||
1494 | { |
||
1495 | TX_Data[0] = Settings->Data.Debug_Fast / 10; |
||
1496 | } |
||
1497 | else |
||
1498 | { |
||
1499 | TX_Data[0] = Settings->Data.Debug_Slow / 10; |
||
1500 | } |
||
1501 | |||
1502 | Conn->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false); |
||
1503 | |||
1504 | // Wenn MK3MAG dann andauernd Daten neu anfragen. |
||
1505 | if (Mode.ID == ADDRESS_MK3MAG) |
||
1506 | { |
||
1507 | TickerEvent[3] = true; |
||
1508 | rb_SelMag->setChecked(true); |
||
1509 | } |
||
1510 | |||
1511 | // Wenn NaviCtrl dann hier. |
||
1512 | if (Mode.ID == ADDRESS_NC) |
||
1513 | { |
||
1514 | rb_SelNC->setChecked(true); |
||
1515 | |||
1516 | if (ac_NoNavi->isChecked()) |
||
1517 | { |
||
1518 | TX_Data[0] = 0; |
||
1519 | } |
||
1520 | else |
||
1521 | if (ac_FastNavi->isChecked()) |
||
1522 | { |
||
1523 | TX_Data[0] = Settings->Data.Navi_Fast / 10; |
||
1524 | } |
||
1525 | else |
||
1526 | { |
||
1527 | TX_Data[0] = Settings->Data.Navi_Slow / 10; |
||
1528 | } |
||
1529 | |||
1530 | Conn->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false); |
||
1531 | } |
||
1532 | |||
1533 | |||
1534 | // Wenn FlightCtrl dann Settings abfragen. |
||
1535 | if (Mode.ID == ADDRESS_FC) |
||
1536 | { |
||
1537 | rb_SelFC->setChecked(true); |
||
1538 | { |
||
1539 | TX_Data[0] = 0xff; |
||
1540 | TX_Data[1] = 0; |
||
1541 | |||
1542 | // DEP: Raus wenn Resend implementiert. |
||
1543 | ToolBox::Wait(SLEEP); |
||
1544 | Conn->send_Cmd('q', ADDRESS_FC, TX_Data, 1, true); |
||
1545 | qDebug("FC - Get Settings"); |
||
1546 | } |
||
1547 | } |
||
1548 | // Wenn nicht Lesen und Schreiben der Settings deaktivieren. |
||
1549 | else |
||
1550 | { |
||
1551 | f_Settings->pb_Read->setDisabled(true); |
||
1552 | f_Settings->pb_Write->setDisabled(true); |
||
1553 | } |
||
1554 | |||
1555 | Settings->read_Settings_Analog(HardwareID); |
||
1556 | Settings->read_Settings_AnalogLabels(HardwareID); |
||
1557 | |||
1558 | if (Settings->Analog1.Version != Mode.Version) |
||
1559 | { |
||
1560 | lb_Status->setText("Analoglabel-Version unterschiedlich. Lese Analoglabels neu aus."); |
||
1561 | slot_ac_GetLabels(); |
||
1562 | } |
||
1563 | else |
||
1564 | for (int a = 0; a < MaxAnalog; a++) |
||
1565 | { |
||
1566 | lb_Analog[a]->setText(Settings->Analog1.Label[a]); |
||
1567 | } |
||
1568 | config_Plot(); |
||
1569 | } |
||
1570 | break; |
||
1571 | } |
||
1572 | } |
||
1573 | |||
1574 | // TODO: Roh-Daten senden zum QMK-Server dazu Sendebuffer bauen. |
||
1575 | if ((QMK_Server->property("Connect")) == true) |
||
1576 | { |
||
1577 | // QMK_Server->send_RawData(RX.String); |
||
1578 | } |
||
1579 | |||
1580 | slot_showTerminal(1, RX.String); |
||
1581 | } |
||
1582 | |||
1583 | void MKTool::slot_showTerminal(int Typ, QString Text) |
||
1584 | { |
||
1585 | switch(Typ) |
||
1586 | { |
||
1587 | case 1 : |
||
1588 | { |
||
1589 | if ((cb_ShowData->isChecked()) && ((tab_Main->currentWidget()->objectName() == QString("Tab_3")) || (cb_ShowAlways->isChecked()))) |
||
1590 | { |
||
1591 | te_RX->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); |
||
1592 | te_RX->insertHtml("<span style=\"color:#00008b;\">" + Text + "<br /></span>"); |
||
1593 | } |
||
1594 | } |
||
1595 | break; |
||
1596 | case 2 : |
||
1597 | { |
||
1598 | if ((cb_ShowMSG->isChecked()) && ((tab_Main->currentWidget()->objectName() == QString("Tab_3")) || (cb_ShowAlways->isChecked()))) |
||
1599 | { |
||
1600 | te_RX->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); |
||
1601 | te_RX->insertHtml("<span style=\"color:#008b00;\">" + Text + "</span>"); |
||
1602 | } |
||
1603 | } |
||
1604 | break; |
||
1605 | case 3 : |
||
1606 | { |
||
1607 | if (cb_ShowSend->isChecked()) |
||
1608 | { |
||
1609 | te_RX->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); |
||
1610 | te_RX->insertHtml("<span style='color:#8b0000;'>" + Text + "<br /></span>"); |
||
1611 | } |
||
1612 | } |
||
1613 | break; |
||
1614 | } |
||
1615 | } |
||
1616 | |||
1617 | // Verbindung zum Kopter herstellen / Trennen |
||
1618 | void MKTool::slot_OpenPort() |
||
1619 | { |
||
1620 | if (Conn->isOpen()) |
||
1621 | { |
||
1622 | TX_Data[0] = Settings->Data.Debug_Off / 10; |
||
1623 | Conn->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false); |
||
1624 | ToolBox::Wait(SLEEP); |
||
1625 | |||
1626 | if (Mode.ID == ADDRESS_NC) |
||
1627 | { |
||
1628 | TX_Data[0] = Settings->Data.Navi_Off / 10; |
||
1629 | Conn->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false); |
||
1630 | ToolBox::Wait(SLEEP); |
||
1631 | } |
||
1632 | |||
1633 | if (Mode.ID == ADDRESS_FC) |
||
1634 | { |
||
1635 | TX_Data[0] = 0; |
||
1636 | TX_Data[1] = 0; |
||
1637 | TX_Data[2] = 0; |
||
1638 | TX_Data[3] = 0; |
||
1639 | Conn->send_Cmd('t', ADDRESS_FC, TX_Data, 4, false); |
||
1640 | ToolBox::Wait(SLEEP); |
||
1641 | } |
||
1642 | |||
1643 | Conn->Close(); |
||
1644 | |||
1645 | ac_ConnectTTY->setText("Kopter Verbinden"); |
||
1646 | le_Port->setEnabled(true); |
||
1647 | |||
1648 | Ticker->stop(); |
||
1649 | } |
||
1650 | else |
||
1651 | { |
||
1652 | int i_Type; |
||
1653 | if (le_Port->text().contains(QString("IP:"))) |
||
1654 | { |
||
1655 | i_Type = C_IP; |
||
1656 | } |
||
1657 | else |
||
1658 | { |
||
1659 | i_Type = C_TTY; |
||
1660 | } |
||
1661 | |||
1662 | if (Conn->Open(i_Type, le_Port->text())) |
||
1663 | { |
||
1664 | ac_ConnectTTY->setText("Kopter Trennen"); |
||
1665 | le_Port->setEnabled(false); |
||
1666 | |||
1667 | Conn->send_Cmd('v', ADDRESS_ALL, TX_Data, 0, true); |
||
1668 | |||
1669 | Ticker->start(2000); |
||
1670 | } |
||
1671 | } |
||
1672 | } |
||
1673 | |||
1674 | // Programm beenden |
||
1675 | /////////////////// |
||
1676 | |||
1677 | MKTool::~MKTool() |
||
1678 | { |
||
1679 | if (Conn->isOpen()) |
||
1680 | { |
||
1681 | Conn->Close(); |
||
1682 | } |
||
1683 | |||
1684 | set_Preferences(); |
||
1685 | Settings->write_Settings(); |
||
1686 | |||
1687 | logger->close(); |
||
1688 | } |