Rev 741 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 741 | Rev 745 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
2 | // + Copyright (c) 04.2007 Holger Buss |
3 | // + only for non-profit use |
3 | // + only for non-profit use |
4 | // + www.MikroKopter.com |
4 | // + www.MikroKopter.com |
5 | // + see the File "License.txt" for further Informations |
5 | // + see the File "License.txt" for further Informations |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 19... | Line 19... | ||
19 | #include "rc.h" |
19 | #include "rc.h" |
Line 20... | Line 20... | ||
20 | 20 | ||
21 | #define FALSE 0 |
21 | #define FALSE 0 |
Line -... | Line 22... | ||
- | 22 | #define TRUE 1 |
|
- | 23 | ||
22 | #define TRUE 1 |
24 | //int8_t test __attribute__ ((section (".noinit"))); |
Line 23... | Line 25... | ||
23 | 25 | ||
24 | uint8_t DebugGetAnforderung = 0, DebugDisplayAnforderung = 0, DebugDataAnforderung = 0, GetVersionAnforderung = 0; |
26 | uint8_t DebugGetRequest = 0, DebugDisplayRequest = 0, DebugDataRequest = 0, GetVersionRequest = 0; |
25 | 27 | ||
26 | volatile uint8_t txd_buffer[TXD_BUFFER_LEN]; |
28 | volatile uint8_t txd_buffer[TXD_BUFFER_LEN]; |
Line 33... | Line 35... | ||
33 | uint8_t NurKanalAnforderung = 0; |
35 | uint8_t NurKanalAnforderung = 0; |
34 | uint8_t DebugTextAnforderung = 255; |
36 | uint8_t DebugTextAnforderung = 255; |
35 | uint8_t PcAccess = 100; |
37 | uint8_t PcAccess = 100; |
36 | uint8_t MotorTest[4] = {0,0,0,0}; |
38 | uint8_t MotorTest[4] = {0,0,0,0}; |
37 | uint8_t DubWiseKeys[4] = {0,0,0,0}; |
39 | uint8_t DubWiseKeys[4] = {0,0,0,0}; |
38 | uint8_t MySlaveAddr; |
40 | uint8_t MySlaveAddr = 0; |
39 | uint8_t ConfirmFrame; |
41 | uint8_t ConfirmFrame; |
Line 40... | Line 42... | ||
40 | 42 | ||
41 | DebugOut_t DebugOut; |
43 | DebugOut_t DebugOut; |
42 | ExternControl_t ExternControl; |
44 | ExternControl_t ExternControl; |
Line 216... | Line 218... | ||
216 | { // checksum valid |
218 | { // checksum valid |
217 | rxd_buffer_locked = TRUE; // lock the rxd buffer |
219 | rxd_buffer_locked = TRUE; // lock the rxd buffer |
218 | ReceivedBytes = ptr_rxd_buffer; // store number of received bytes |
220 | ReceivedBytes = ptr_rxd_buffer; // store number of received bytes |
219 | rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character |
221 | rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character |
220 | // if 2nd byte is an 'R' enable watchdog that will result in an reset |
222 | // if 2nd byte is an 'R' enable watchdog that will result in an reset |
221 | if(rxd_buffer[2] == 'R') wdt_enable(WDTO_250MS); // Reset-Commando |
223 | if(rxd_buffer[2] == 'R') {wdt_enable(WDTO_250MS);} // Reset-Commando |
222 | } |
224 | } |
223 | else |
225 | else |
224 | { // checksum invalid |
226 | { // checksum invalid |
225 | rxd_buffer_locked = FALSE; // unlock rxd buffer |
227 | rxd_buffer_locked = FALSE; // unlock rxd buffer |
226 | } |
228 | } |
Line 253... | Line 255... | ||
253 | } |
255 | } |
Line 254... | Line 256... | ||
254 | 256 | ||
255 | 257 | ||
256 | 258 | ||
257 | // -------------------------------------------------------------------------- |
259 | // -------------------------------------------------------------------------- |
258 | void SendOutData(uint8_t cmd,uint8_t modul, uint8_t *snd, uint8_t len) |
260 | void SendOutData(uint8_t cmd,uint8_t module, uint8_t *snd, uint8_t len) |
259 | { |
261 | { |
Line 260... | Line 262... | ||
260 | uint16_t pt = 0; |
262 | uint16_t pt = 0; |
261 | uint8_t a,b,c; |
263 | uint8_t a,b,c; |
262 | uint8_t ptr = 0; |
264 | uint8_t ptr = 0; |
Line 263... | Line 265... | ||
263 | 265 | ||
264 | txd_buffer[pt++] = '#'; // Start character |
266 | txd_buffer[pt++] = '#'; // Start character |
265 | txd_buffer[pt++] = modul; // Address (a=0; b=1,...) |
267 | txd_buffer[pt++] = module; // Address (a=0; b=1,...) |
Line 278... | Line 280... | ||
278 | AddCRC(pt); // add checksum after data block and initates the transmission |
280 | AddCRC(pt); // add checksum after data block and initates the transmission |
279 | } |
281 | } |
Line 280... | Line 282... | ||
280 | 282 | ||
281 | 283 | ||
282 | // -------------------------------------------------------------------------- |
284 | // -------------------------------------------------------------------------- |
283 | void Decode64(uint8_t *ptrOut, uint8_t len, uint8_t ptrIn, uint8_t max) // Wohin mit den Daten; Wie lang; Wo im rxd_buffer |
285 | void Decode64(uint8_t *ptrOut, uint8_t len, uint8_t ptrIn, uint8_t max) |
284 | { |
286 | { |
285 | uint8_t a,b,c,d; |
287 | uint8_t a,b,c,d; |
286 | uint8_t ptr = 0; |
288 | uint8_t ptr = 0; |
287 | uint8_t x,y,z; |
289 | uint8_t x,y,z; |
288 | while(len) |
290 | while(len) |
289 | { |
291 | { |
290 | a = rxd_buffer[ptrIn++] - '='; |
292 | a = rxd_buffer[ptrIn++] - '='; |
291 | b = rxd_buffer[ptrIn++] - '='; |
293 | b = rxd_buffer[ptrIn++] - '='; |
292 | c = rxd_buffer[ptrIn++] - '='; |
294 | c = rxd_buffer[ptrIn++] - '='; |
Line 293... | Line 295... | ||
293 | d = rxd_buffer[ptrIn++] - '='; |
295 | d = rxd_buffer[ptrIn++] - '='; |
294 | if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
296 | if(ptrIn > max - 2) break; |
295 | 297 | ||
Line 326... | Line 328... | ||
326 | break; |
328 | break; |
327 | case 'c': // extern control with debug request |
329 | case 'c': // extern control with debug request |
328 | Decode64((uint8_t *) &ExternControl,sizeof(ExternControl),3,ReceivedBytes); |
330 | Decode64((uint8_t *) &ExternControl,sizeof(ExternControl),3,ReceivedBytes); |
329 | RemoteButtons |= ExternControl.RemoteButtons; |
331 | RemoteButtons |= ExternControl.RemoteButtons; |
330 | ConfirmFrame = ExternControl.Frame; |
332 | ConfirmFrame = ExternControl.Frame; |
331 | DebugDataAnforderung = 1; |
333 | DebugDataRequest = 1; |
332 | break; |
334 | break; |
333 | case 'h':// x-1 display columns |
335 | case 'h':// x-1 display columns |
334 | Decode64((uint8_t *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,ReceivedBytes); |
336 | Decode64((uint8_t *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,ReceivedBytes); |
335 | RemoteButtons |= tmp_char_arr2[0]; |
337 | RemoteButtons |= tmp_char_arr2[0]; |
336 | if(tmp_char_arr2[1] == 255) NurKanalAnforderung = 1; |
338 | if(tmp_char_arr2[1] == 255) NurKanalAnforderung = 1; |
337 | else NurKanalAnforderung = 0; // keine Displaydaten |
339 | else NurKanalAnforderung = 0; // keine Displaydaten |
338 | DebugDisplayAnforderung = 1; |
340 | DebugDisplayRequest = 1; |
339 | break; |
341 | break; |
340 | case 't':// motor test |
342 | case 't':// motor test |
341 | Decode64((uint8_t *) &MotorTest[0],sizeof(MotorTest),3,ReceivedBytes); |
343 | Decode64((uint8_t *) &MotorTest[0],sizeof(MotorTest),3,ReceivedBytes); |
342 | break; |
344 | break; |
343 | case 'k':// keys from DubWise |
345 | case 'k':// keys from DubWise |
344 | Decode64((uint8_t *) &DubWiseKeys[0],sizeof(DubWiseKeys),3,ReceivedBytes); |
346 | Decode64((uint8_t *) &DubWiseKeys[0],sizeof(DubWiseKeys),3,ReceivedBytes); |
345 | ConfirmFrame = DubWiseKeys[3]; |
347 | ConfirmFrame = DubWiseKeys[3]; |
346 | break; |
348 | break; |
347 | case 'v': // get version and board release |
349 | case 'v': // get version and board release |
348 | GetVersionAnforderung = 1; |
350 | GetVersionRequest = 1; |
349 | break; |
351 | break; |
350 | case 'g':// get debug data |
352 | case 'g':// get debug data |
351 | DebugGetAnforderung = 1; |
353 | DebugGetRequest = 1; |
352 | break; |
354 | break; |
353 | case 'q':// get settings |
355 | case 'q':// get settings |
354 | Decode64((uint8_t *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,ReceivedBytes); |
356 | Decode64((uint8_t *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,ReceivedBytes); |
355 | if(tmp_char_arr2[0] != 0xff) |
357 | if(tmp_char_arr2[0] != 0xff) |
356 | { |
358 | { |
Line 402... | Line 404... | ||
402 | void TransmitTxData(void) |
404 | void TransmitTxData(void) |
403 | { |
405 | { |
404 | static int16_t Debug_Timer = 0; |
406 | static int16_t Debug_Timer = 0; |
405 | if(!txd_complete) return; |
407 | if(!txd_complete) return; |
Line 406... | Line 408... | ||
406 | 408 | ||
407 | if(DebugGetAnforderung && txd_complete) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
409 | if(DebugGetRequest && txd_complete) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
408 | { |
410 | { |
409 | SendOutData('G',MySlaveAddr,(uint8_t *) &ExternControl,sizeof(ExternControl)); |
411 | SendOutData('G',MySlaveAddr,(uint8_t *) &ExternControl,sizeof(ExternControl)); |
410 | DebugGetAnforderung = 0; |
412 | DebugGetRequest = 0; |
Line 411... | Line 413... | ||
411 | } |
413 | } |
412 | 414 | ||
413 | if((CheckDelay(Debug_Timer) || DebugDataAnforderung) && txd_complete) |
415 | if((CheckDelay(Debug_Timer) || DebugDataRequest) && txd_complete) |
414 | { |
416 | { |
415 | SendOutData('D',MySlaveAddr,(uint8_t *) &DebugOut,sizeof(DebugOut)); |
417 | SendOutData('D',MySlaveAddr,(uint8_t *) &DebugOut,sizeof(DebugOut)); |
416 | DebugDataAnforderung = 0; |
418 | DebugDataRequest = 0; |
417 | Debug_Timer = SetDelay(MIN_DEBUG_INTERVALL); |
419 | Debug_Timer = SetDelay(MIN_DEBUG_INTERVALL); |
418 | } |
420 | } |
419 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
421 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
Line 428... | Line 430... | ||
428 | txd_buffer[2] = '\r'; |
430 | txd_buffer[2] = '\r'; |
429 | txd_complete = 0; |
431 | txd_complete = 0; |
430 | ConfirmFrame = 0; |
432 | ConfirmFrame = 0; |
431 | UDR0 = txd_buffer[0]; |
433 | UDR0 = txd_buffer[0]; |
432 | } |
434 | } |
433 | if(DebugDisplayAnforderung && txd_complete) |
435 | if(DebugDisplayRequest && txd_complete) |
434 | { |
436 | { |
435 | LCD_PrintMenu(); |
437 | LCD_PrintMenu(); |
436 | DebugDisplayAnforderung = 0; |
438 | DebugDisplayRequest = 0; |
437 | if(++RemotePollDisplayLine == 4 || NurKanalAnforderung) |
439 | if(++RemotePollDisplayLine == 4 || NurKanalAnforderung) |
438 | { |
440 | { |
439 | SendOutData('4',0,(uint8_t *)&PPM_in,sizeof(PPM_in)); // DisplayZeile übertragen |
441 | SendOutData('4',0,(uint8_t *)&PPM_in,sizeof(PPM_in)); // DisplayZeile übertragen |
440 | RemotePollDisplayLine = -1; |
442 | RemotePollDisplayLine = -1; |
441 | } |
443 | } |
442 | else SendOutData('0' + RemotePollDisplayLine,0,(uint8_t *)&DisplayBuff[20 * RemotePollDisplayLine],20); // DisplayZeile übertragen |
444 | else SendOutData('0' + RemotePollDisplayLine,0,(uint8_t *)&DisplayBuff[20 * RemotePollDisplayLine],20); // DisplayZeile übertragen |
443 | } |
445 | } |
444 | if(GetVersionAnforderung && txd_complete) |
446 | if(GetVersionRequest && txd_complete) |
445 | { |
447 | { |
446 | SendOutData('V',MySlaveAddr,(uint8_t *) &VersionInfo,sizeof(VersionInfo)); |
448 | SendOutData('V',MySlaveAddr,(uint8_t *) &VersionInfo,sizeof(VersionInfo)); |
447 | GetVersionAnforderung = 0; |
449 | GetVersionRequest = 0; |
448 | } |
450 | } |
Line 449... | Line 451... | ||
449 | 451 |