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