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