Rev 462 | Rev 513 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 462 | Rev 500 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include "Handler.h" |
1 | #include "Handler.h" |
2 | #include <iostream> |
2 | #include "FlightLog.h" |
Line 3... | Line 3... | ||
3 | 3 | ||
4 | /** |
4 | /** |
5 | * Constructor that gets a communication instance |
5 | * Constructor that gets a communication instance |
6 | */ |
6 | */ |
Line 188... | Line 188... | ||
188 | } |
188 | } |
Line 189... | Line 189... | ||
189 | 189 | ||
190 | /** |
190 | /** |
191 | * receive data |
191 | * receive data |
- | 192 | */ |
|
- | 193 | void Handler::receive_data(char * incomming, int length) { |
|
- | 194 | if (incomming[0] != '#') |
|
- | 195 | FlightLog::error("this frame is not correct"); |
|
- | 196 | FlightLog::info(incomming); |
|
- | 197 | return; |
|
- | 198 | int hardwareID = incomming[1] - 'a'; |
|
- | 199 | ||
- | 200 | //The cmd is also known as ID-Byte (or ID for short) in the wiki-dokumentation |
|
192 | */ |
201 | char cmd = incomming[2]; |
- | 202 | //decode data |
|
- | 203 | unsigned char data[150]; |
|
193 | //Parser::decode64(data); |
204 | |
- | 205 | Parser::decode64(incomming, length, data, 3); |
|
194 | void Handler::receive_data(int hardwareID, int cmd, char * data) { |
206 | |
195 | switch(hardwareID) |
207 | switch(hardwareID) |
196 | { |
208 | { |
197 | case ADDRESS_FC : |
209 | case ADDRESS_FC : |
198 | switch(cmd) |
210 | switch(cmd) |
Line 201... | Line 213... | ||
201 | case 'N' : |
213 | case 'N' : |
202 | //if (Parser::decode64(RX)) |
214 | //if (Parser::decode64(RX)) |
203 | //{ |
215 | //{ |
204 | com->stop_resend(); |
216 | com->stop_resend(); |
205 | //decoded data |
217 | //decoded data |
- | 218 | FlightLog::info("received motortest values from FlightCtrl"); |
|
206 | if (data[0] == VERSION_MIXER) |
219 | if (data[0] == VERSION_MIXER) |
207 | { |
220 | { |
208 | //f_MotorMixer->set_MotorConfig(RX); |
221 | //f_MotorMixer->set_MotorConfig(RX); |
209 | } |
222 | } |
210 | //} |
223 | //} |
Line 213... | Line 226... | ||
213 | case 'M' : |
226 | case 'M' : |
214 | com->stop_resend(); |
227 | com->stop_resend(); |
Line 215... | Line 228... | ||
215 | 228 | ||
216 | if (data[0] == 1) |
229 | if (data[0] == 1) |
- | 230 | { |
|
217 | { |
231 | FlightLog::info("motor values written to FlightCtrl."); |
- | 232 | //lb_Status->setText(tr("MotorMixer-Daten in FC geschrieben.")); |
|
- | 233 | } else { |
|
218 | //lb_Status->setText(tr("MotorMixer-Daten in FC geschrieben.")); |
234 | FlightLog::warning("could not write motor values to FlightCtrl!"); |
219 | } |
235 | } |
Line 220... | Line 236... | ||
220 | break; |
236 | break; |
221 | 237 | ||
- | 238 | // Stick-Belegung der Fernsteuerung |
|
222 | // Stick-Belegung der Fernsteuerung |
239 | case 'P' : // DONE 0.71g |
223 | case 'P' : // DONE 0.71g |
240 | FlightLog::info("received stick-settings from FlightCtrl:"); |
224 | /*f_Settings->pb_K1->setValue(Parser::dataToInt(RX.decode, 2,true)); |
241 | /*f_Settings->pb_K1->setValue(Parser::dataToInt(RX.decode, 2,true)); |
225 | f_Settings->pb_K2->setValue(Parser::dataToInt(RX.decode, 4,true)); |
242 | f_Settings->pb_K2->setValue(Parser::dataToInt(RX.decode, 4,true)); |
226 | f_Settings->pb_K3->setValue(Parser::dataToInt(RX.decode, 6,true)); |
243 | f_Settings->pb_K3->setValue(Parser::dataToInt(RX.decode, 6,true)); |
Line 231... | Line 248... | ||
231 | f_Settings->pb_K8->setValue(Parser::dataToInt(RX.decode, 16,true));*/ |
248 | f_Settings->pb_K8->setValue(Parser::dataToInt(RX.decode, 16,true));*/ |
232 | break; |
249 | break; |
233 | // Settings lesen |
250 | // Settings lesen |
234 | case 'Q' : // DONE 0.71g |
251 | case 'Q' : // DONE 0.71g |
235 | com->stop_resend(); |
252 | com->stop_resend(); |
236 | - | ||
- | 253 | FlightLog::info("received settings from FlightCtrl"); |
|
237 | if (data[1] == VERSION_SETTINGS) |
254 | if (data[1] == VERSION_SETTINGS) |
238 | { |
255 | { |
239 | int Settings_ID = data[0]; |
256 | int Settings_ID = data[0]; |
240 | /*for (int a = 0; a < MaxParameter; a++) |
257 | /*for (int a = 0; a < MaxParameter; a++) |
241 | { |
258 | { |
Line 245... | Line 262... | ||
245 | f_Settings->pb_Read->setEnabled(true); |
262 | f_Settings->pb_Read->setEnabled(true); |
246 | f_Settings->pb_Write->setEnabled(true);*/ |
263 | f_Settings->pb_Write->setEnabled(true);*/ |
247 | } |
264 | } |
248 | else |
265 | else |
249 | { |
266 | { |
- | 267 | FlightLog::error("wrong FlightCtrl version"); |
|
250 | /*f_Settings->pb_Read->setDisabled(true); |
268 | /*f_Settings->pb_Read->setDisabled(true); |
251 | f_Settings->pb_Write->setDisabled(true); |
269 | f_Settings->pb_Write->setDisabled(true); |
Line 252... | Line 270... | ||
252 | 270 | ||
253 | QString name = QString("Versionen inkompatibel.\n") + |
271 | QString name = QString("Versionen inkompatibel.\n") + |
Line 261... | Line 279... | ||
261 | } |
279 | } |
262 | break; |
280 | break; |
263 | // Settings written |
281 | // Settings written |
264 | case 'S' : // DONE 0.71g |
282 | case 'S' : // DONE 0.71g |
265 | com->stop_resend(); |
283 | com->stop_resend(); |
- | 284 | FlightLog::info("settings written successfully to FlightCtrl"); |
|
266 | //TODO: QMessagebox("settings written successful") ? |
285 | //TODO: QMessagebox("settings written successful") ? |
267 | break; |
286 | break; |
268 | } |
287 | } |
Line 269... | Line 288... | ||
269 | 288 | ||
270 | case ADDRESS_NC : |
289 | case ADDRESS_NC : |
271 | switch(cmd) |
290 | switch(cmd) |
272 | { |
291 | { |
273 | // Navigationsdaten |
292 | // Navigationsdaten |
274 | case 'O' : // NOT DONE 0.12h |
293 | case 'O' : // NOT DONE 0.12h |
- | 294 | //new_NaviData(RX); |
|
275 | //new_NaviData(RX); |
295 | FlightLog::info("received navigation data from NaviCtrl"); |
276 | break; |
296 | break; |
277 | } |
297 | } |
Line 278... | Line 298... | ||
278 | // case ADDRESS_MK3MAG : |
298 | // case ADDRESS_MK3MAG : |
279 | 299 | ||
280 | default : |
300 | default : |
281 | switch(cmd) |
301 | switch(cmd) |
282 | { |
302 | { |
283 | // LCD-Anzeige |
303 | // LCD-Anzeige |
284 | case 'L' : // DONE 0.71g |
- | |
- | 304 | case 'L' : // DONE 0.71g |
|
285 | com->stop_resend(); |
305 | com->stop_resend(); |
286 | 306 | FlightLog::info("received LCD page."); |
|
Line 287... | Line 307... | ||
287 | /*int LCD[150]; |
307 | /*int LCD[150]; |
Line 294... | Line 314... | ||
294 | */ |
314 | */ |
295 | break; |
315 | break; |
296 | // Analoglabels |
316 | // Analoglabels |
297 | case 'A' : // DONE 0.71g |
317 | case 'A' : // DONE 0.71g |
298 | com->stop_resend(); |
318 | com->stop_resend(); |
299 | - | ||
- | 319 | FlightLog::info("received analog labels"); |
|
300 | //check position |
320 | //check position |
301 | if (data[0] != 31) { |
321 | if (data[0] != 31) { |
302 | /* |
322 | /* |
303 | Settings->Analog1.Label[Position] = ToolBox::dataToQString(RX.decode,1,17).trimmed(); |
323 | Settings->Analog1.Label[Position] = ToolBox::dataToQString(RX.decode,1,17).trimmed(); |
304 | if (Settings->Analog1.Label[Position] == "") |
324 | if (Settings->Analog1.Label[Position] == "") |
Line 319... | Line 339... | ||
319 | config_Plot();*/ |
339 | config_Plot();*/ |
320 | } |
340 | } |
321 | break; |
341 | break; |
322 | // Debug-Daten |
342 | // Debug-Daten |
323 | case 'D' : // DONE 0.71g |
343 | case 'D' : // DONE 0.71g |
- | 344 | FlightLog::info("received debug data:"); |
|
324 | for (int i = 0; i < MaxAnalog; i++) { |
345 | for (int i = 0; i < MaxAnalog; i++) { |
- | 346 | /* |
|
325 | std::cout << Parser::dataToInt(data, (i * 2) + 2) << std::endl; |
347 | Parser::dataToInt((char *)data, (i * 2) + 2, false); |
- | 348 | */ |
|
326 | } |
349 | } |
327 | //show_DebugData(); |
350 | //show_DebugData(); |
328 | break; |
351 | break; |
329 | // Version |
352 | // Version |
330 | case 'V' : // DONE 0.71h |
353 | case 'V' : // DONE 0.71h |
331 | com->stop_resend(); |
354 | com->stop_resend(); |
- | 355 | FlightLog::info("received version"); |
|
332 | /* |
356 | /* |
333 | Mode.ID = HardwareID; |
357 | Mode.ID = HardwareID; |
334 | Mode.VERSION_MAJOR = RX.decode[0]; |
358 | Mode.VERSION_MAJOR = RX.decode[0]; |
335 | Mode.VERSION_MINOR = RX.decode[1]; |
359 | Mode.VERSION_MINOR = RX.decode[1]; |
336 | Mode.VERSION_PATCH = RX.decode[4]; |
360 | Mode.VERSION_PATCH = RX.decode[4]; |