Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1234 | ligi | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
||
3 | // + only for non-profit use |
||
4 | // + www.MikroKopter.com |
||
5 | // + see the File "License.txt" for further Informations |
||
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
7 | #include <stdarg.h> |
||
8 | #include <string.h> |
||
9 | #include "main.h" |
||
10 | #include "uart.h" |
||
11 | |||
12 | |||
13 | #define FC_ADDRESS 1 |
||
14 | #define NC_ADDRESS 2 |
||
15 | #define MK3MAG_ADDRESS 3 |
||
16 | |||
17 | unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0; |
||
18 | unsigned char DisplayLine = 0; |
||
19 | unsigned volatile char SioTmp = 0; |
||
20 | unsigned volatile char SendeBuffer[MAX_SENDE_BUFF]; |
||
21 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
||
22 | unsigned volatile char NMEABuffer[MAX_EMPFANGS_BUFF]; |
||
23 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
||
24 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
||
25 | unsigned volatile char UebertragungAbgeschlossen = 1; |
||
26 | unsigned volatile char CntCrcError = 0; |
||
27 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
||
28 | unsigned char *pRxData = 0; |
||
29 | unsigned char RxDataLen = 0; |
||
30 | unsigned volatile char PC_DebugTimeout = 0; |
||
31 | unsigned volatile char PC_MotortestActive = 0; |
||
32 | |||
33 | unsigned char DebugTextAnforderung = 255; |
||
34 | unsigned char PcZugriff = 100; |
||
35 | unsigned char MotorTest[16]; |
||
36 | unsigned char MeineSlaveAdresse = 1; // Flight-Ctrl |
||
37 | unsigned char ConfirmFrame; |
||
38 | struct str_DebugOut DebugOut; |
||
39 | struct str_ExternControl ExternControl; |
||
40 | struct str_ExternEvent ExternEvent; |
||
41 | struct str_VersionInfo VersionInfo; |
||
42 | struct str_WinkelOut WinkelOut; |
||
43 | struct str_Data3D Data3D; |
||
44 | |||
45 | int Debug_Timer,Kompass_Timer,Timer3D; |
||
46 | unsigned int DebugDataIntervall = 200, Intervall3D = 0; |
||
47 | |||
48 | const unsigned char ANALOG_TEXT[32][16] = |
||
49 | { |
||
50 | //1234567890123456 |
||
51 | "AngleNick ", //0 |
||
52 | "AngleRoll ", |
||
53 | "AccNick ", |
||
54 | "AccRoll ", |
||
55 | "GyroGier ", |
||
56 | "Hight Value ", //5 |
||
57 | "AccZ ", |
||
58 | "Gas ", |
||
59 | "Compass Value ", |
||
60 | "Voltage ", |
||
61 | "Empfang ", //10 |
||
62 | "Gyro Kompass ", |
||
63 | "Motor Front ", |
||
64 | "Motor Rear ", |
||
65 | "Motor Left ", |
||
66 | "Motor Right ", //15 |
||
67 | "ligi ", |
||
68 | " ", |
||
69 | " ", |
||
70 | "MK3Mag CalState ", |
||
71 | "Servo ", //20 |
||
72 | " ", |
||
73 | " ", |
||
74 | " ", |
||
75 | " ", |
||
76 | " ", //25 |
||
77 | " ", |
||
78 | "Kalman_MaxDrift ", |
||
79 | " ", |
||
80 | "Navi Serial Data", |
||
81 | "GPS_Nick ", //30 |
||
82 | "GPS_Roll " |
||
83 | }; |
||
84 | |||
85 | |||
86 | |||
87 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
88 | //++ Sende-Part der Datenübertragung |
||
89 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
90 | SIGNAL(INT_VEC_TX) |
||
91 | { |
||
92 | static unsigned int ptr = 0; |
||
93 | unsigned char tmp_tx; |
||
94 | if(!UebertragungAbgeschlossen) |
||
95 | { |
||
96 | ptr++; // die [0] wurde schon gesendet |
||
97 | tmp_tx = SendeBuffer[ptr]; |
||
98 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
||
99 | { |
||
100 | ptr = 0; |
||
101 | UebertragungAbgeschlossen = 1; |
||
102 | } |
||
103 | UDR = tmp_tx; |
||
104 | } |
||
105 | else ptr = 0; |
||
106 | } |
||
107 | |||
108 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
109 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
||
110 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
111 | SIGNAL(INT_VEC_RX) |
||
112 | { |
||
113 | static unsigned int crc; |
||
114 | static unsigned char crc1,crc2,buf_ptr; |
||
115 | static unsigned char UartState = 0; |
||
116 | unsigned char CrcOkay = 0; |
||
117 | |||
118 | SioTmp = UDR; |
||
119 | if(buf_ptr >= MAX_EMPFANGS_BUFF) UartState = 0; |
||
120 | if(SioTmp == '\r' && UartState == 2) |
||
121 | { |
||
122 | UartState = 0; |
||
123 | crc -= RxdBuffer[buf_ptr-2]; |
||
124 | crc -= RxdBuffer[buf_ptr-1]; |
||
125 | crc %= 4096; |
||
126 | crc1 = '=' + crc / 64; |
||
127 | crc2 = '=' + crc % 64; |
||
128 | CrcOkay = 0; |
||
129 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
||
130 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
||
131 | { |
||
132 | NeuerDatensatzEmpfangen = 1; |
||
133 | AnzahlEmpfangsBytes = buf_ptr + 1; |
||
134 | RxdBuffer[buf_ptr] = '\r'; |
||
135 | if(RxdBuffer[2] == 'R') |
||
136 | { |
||
137 | wdt_enable(WDTO_250MS); // Reset-Commando |
||
138 | ServoActive = 0; |
||
139 | } |
||
140 | } |
||
141 | } |
||
142 | else |
||
143 | switch(UartState) |
||
144 | { |
||
145 | case 0: |
||
146 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
||
147 | buf_ptr = 0; |
||
148 | RxdBuffer[buf_ptr++] = SioTmp; |
||
149 | crc = SioTmp; |
||
150 | break; |
||
151 | case 1: // Adresse auswerten |
||
152 | UartState++; |
||
153 | RxdBuffer[buf_ptr++] = SioTmp; |
||
154 | crc += SioTmp; |
||
155 | break; |
||
156 | case 2: // Eingangsdaten sammeln |
||
157 | RxdBuffer[buf_ptr] = SioTmp; |
||
158 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
||
159 | else UartState = 0; |
||
160 | crc += SioTmp; |
||
161 | break; |
||
162 | default: |
||
163 | UartState = 0; |
||
164 | break; |
||
165 | } |
||
166 | } |
||
167 | |||
168 | |||
169 | // -------------------------------------------------------------------------- |
||
170 | void AddCRC(unsigned int wieviele) |
||
171 | { |
||
172 | unsigned int tmpCRC = 0,i; |
||
173 | for(i = 0; i < wieviele;i++) |
||
174 | { |
||
175 | tmpCRC += SendeBuffer[i]; |
||
176 | } |
||
177 | tmpCRC %= 4096; |
||
178 | SendeBuffer[i++] = '=' + tmpCRC / 64; |
||
179 | SendeBuffer[i++] = '=' + tmpCRC % 64; |
||
180 | SendeBuffer[i++] = '\r'; |
||
181 | UebertragungAbgeschlossen = 0; |
||
182 | UDR = SendeBuffer[0]; |
||
183 | } |
||
184 | |||
185 | |||
186 | |||
187 | // -------------------------------------------------------------------------- |
||
188 | void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len) |
||
189 | { |
||
190 | va_list ap; |
||
191 | unsigned int pt = 0; |
||
192 | unsigned char a,b,c; |
||
193 | unsigned char ptr = 0; |
||
194 | |||
195 | unsigned char *snd = 0; |
||
196 | int len = 0; |
||
197 | |||
198 | SendeBuffer[pt++] = '#'; // Startzeichen |
||
199 | SendeBuffer[pt++] = 'a' + address; // Adresse (a=0; b=1,...) |
||
200 | SendeBuffer[pt++] = cmd; // Commando |
||
201 | |||
202 | va_start(ap, BufferAnzahl); |
||
203 | if(BufferAnzahl) |
||
204 | { |
||
205 | snd = va_arg(ap, unsigned char*); |
||
206 | len = va_arg(ap, int); |
||
207 | ptr = 0; |
||
208 | BufferAnzahl--; |
||
209 | } |
||
210 | while(len) |
||
211 | { |
||
212 | if(len) |
||
213 | { |
||
214 | a = snd[ptr++]; |
||
215 | len--; |
||
216 | if((!len) && BufferAnzahl) |
||
217 | { |
||
218 | snd = va_arg(ap, unsigned char*); |
||
219 | len = va_arg(ap, int); |
||
220 | ptr = 0; |
||
221 | BufferAnzahl--; |
||
222 | } |
||
223 | } |
||
224 | else a = 0; |
||
225 | if(len) |
||
226 | { |
||
227 | b = snd[ptr++]; |
||
228 | len--; |
||
229 | if((!len) && BufferAnzahl) |
||
230 | { |
||
231 | snd = va_arg(ap, unsigned char*); |
||
232 | len = va_arg(ap, int); |
||
233 | ptr = 0; |
||
234 | BufferAnzahl--; |
||
235 | } |
||
236 | } |
||
237 | else b = 0; |
||
238 | if(len) |
||
239 | { |
||
240 | c = snd[ptr++]; |
||
241 | len--; |
||
242 | if((!len) && BufferAnzahl) |
||
243 | { |
||
244 | snd = va_arg(ap, unsigned char*); |
||
245 | len = va_arg(ap, int); |
||
246 | ptr = 0; |
||
247 | BufferAnzahl--; |
||
248 | } |
||
249 | } |
||
250 | else c = 0; |
||
251 | SendeBuffer[pt++] = '=' + (a >> 2); |
||
252 | SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
||
253 | SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
||
254 | SendeBuffer[pt++] = '=' + ( c & 0x3f); |
||
255 | } |
||
256 | va_end(ap); |
||
257 | AddCRC(pt); |
||
258 | } |
||
259 | |||
260 | |||
261 | // -------------------------------------------------------------------------- |
||
262 | void Decode64(void) // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden. |
||
263 | { |
||
264 | unsigned char a,b,c,d; |
||
265 | unsigned char x,y,z; |
||
266 | unsigned char ptrIn = 3; // start at begin of data block |
||
267 | unsigned char ptrOut = 3; |
||
268 | unsigned char len = AnzahlEmpfangsBytes - 6; // von der Gesamtbytezahl eines Frames gehen 3 Bytes des Headers ('#',Addr, Cmd) und 3 Bytes des Footers (CRC1, CRC2, '\r') ab. |
||
269 | |||
270 | while(len) |
||
271 | { |
||
272 | a = RxdBuffer[ptrIn++] - '='; |
||
273 | b = RxdBuffer[ptrIn++] - '='; |
||
274 | c = RxdBuffer[ptrIn++] - '='; |
||
275 | d = RxdBuffer[ptrIn++] - '='; |
||
276 | |||
277 | x = (a << 2) | (b >> 4); |
||
278 | y = ((b & 0x0f) << 4) | (c >> 2); |
||
279 | z = ((c & 0x03) << 6) | d; |
||
280 | |||
281 | if(len--) RxdBuffer[ptrOut++] = x; else break; |
||
282 | if(len--) RxdBuffer[ptrOut++] = y; else break; |
||
283 | if(len--) RxdBuffer[ptrOut++] = z; else break; |
||
284 | } |
||
285 | pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte |
||
286 | RxDataLen = ptrOut - 3; // wie viele Bytes wurden dekodiert? |
||
287 | |||
288 | } |
||
289 | |||
290 | // -------------------------------------------------------------------------- |
||
291 | void BearbeiteRxDaten(void) |
||
292 | { |
||
293 | if(!NeuerDatensatzEmpfangen) return; |
||
294 | |||
295 | unsigned char tempchar1, tempchar2; |
||
296 | Decode64(); // dekodiere datenblock im Empfangsbuffer |
||
297 | switch(RxdBuffer[1]-'a') // check for Slave Address |
||
298 | { |
||
299 | case FC_ADDRESS: // FC special commands |
||
300 | |||
301 | switch(RxdBuffer[2]) |
||
302 | { |
||
303 | case 'K':// Kompasswert |
||
304 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
||
305 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
||
306 | break; |
||
307 | case 't':// Motortest |
||
308 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
||
309 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
||
310 | PC_MotortestActive = 240; |
||
311 | //while(!UebertragungAbgeschlossen); |
||
312 | //SendOutData('T', MeineSlaveAdresse, 0); |
||
313 | PcZugriff = 255; |
||
314 | break; |
||
315 | |||
316 | case 'n':// "Get Mixer |
||
317 | while(!UebertragungAbgeschlossen); |
||
318 | SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer,sizeof(Mixer)); |
||
319 | break; |
||
320 | |||
321 | case 'm':// "Write Mixer |
||
322 | while(!UebertragungAbgeschlossen); |
||
323 | if(pRxData[0] == MIXER_REVISION) |
||
324 | { |
||
325 | memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer)); |
||
326 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
||
327 | tempchar1 = 1; |
||
328 | } |
||
329 | else tempchar1 = 0; |
||
330 | SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
||
331 | break; |
||
332 | |||
333 | case 'p': // get PPM Channels |
||
334 | GetPPMChannelAnforderung = 1; |
||
335 | break; |
||
336 | |||
337 | case 'q':// "Get"-Anforderung für Settings |
||
338 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
339 | if(pRxData[0] == 0xFF) |
||
340 | { |
||
341 | pRxData[0] = GetActiveParamSetNumber(); |
||
342 | } |
||
343 | // limit settings range |
||
344 | if(pRxData[0] < 1) pRxData[0] = 1; // limit to 5 |
||
345 | else if(pRxData[0] > 5) pRxData[0] = 5; // limit to 5 |
||
346 | // load requested parameter set |
||
347 | ReadParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
348 | |||
349 | while(!UebertragungAbgeschlossen); |
||
350 | tempchar1 = pRxData[0]; |
||
351 | tempchar2 = EE_DATENREVISION; |
||
352 | SendOutData('Q', FC_ADDRESS, 3, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
353 | break; |
||
354 | |||
355 | case 's': // Parametersatz speichern |
||
356 | if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EE_DATENREVISION)) // check for setting to be in range |
||
357 | { |
||
358 | memcpy((unsigned char *) &EE_Parameter.Kanalbelegung[0], (unsigned char *)&pRxData[2], STRUCT_PARAM_LAENGE); |
||
359 | WriteParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
360 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
||
361 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
||
362 | SetActiveParamSetNumber(pRxData[0]); |
||
363 | tempchar1 = GetActiveParamSetNumber(); |
||
364 | Piep(tempchar1,110); |
||
365 | } |
||
366 | else |
||
367 | { |
||
368 | tempchar1 = 0; // mark in response an invlid setting |
||
369 | } |
||
370 | while(!UebertragungAbgeschlossen); |
||
371 | SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
||
372 | break; |
||
373 | |||
374 | } // case FC_ADDRESS: |
||
375 | |||
376 | default: // any Slave Address |
||
377 | |||
378 | switch(RxdBuffer[2]) |
||
379 | { |
||
380 | // 't' comand placed here only for compatibility to BL |
||
381 | case 't':// Motortest |
||
382 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
||
383 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
||
384 | while(!UebertragungAbgeschlossen); |
||
385 | SendOutData('T', MeineSlaveAdresse, 0); |
||
386 | PC_MotortestActive = 250; |
||
387 | PcZugriff = 255; |
||
388 | break; |
||
389 | // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address |
||
390 | case 'K':// Kompasswert |
||
391 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
||
392 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
||
393 | break; |
||
394 | case 'a':// Texte der Analogwerte |
||
395 | DebugTextAnforderung = pRxData[0]; |
||
396 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
||
397 | PcZugriff = 255; |
||
398 | break; |
||
399 | case 'b': |
||
400 | memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl)); |
||
401 | ConfirmFrame = ExternControl.Frame; |
||
402 | PcZugriff = 255; |
||
403 | break; |
||
404 | case 'c': // Poll the 3D-Data |
||
405 | if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);} |
||
406 | Intervall3D = pRxData[0] * 10; |
||
407 | break; |
||
408 | case 'd': // Poll the debug data |
||
409 | DebugDataIntervall = pRxData[0] * 10; |
||
410 | if(DebugDataIntervall > 0) DebugDataAnforderung = 1; |
||
411 | break; |
||
412 | |||
413 | case 'h':// x-1 Displayzeilen |
||
414 | PcZugriff = 255; |
||
415 | RemoteKeys |= pRxData[0]; |
||
416 | if(RemoteKeys) DisplayLine = 0; |
||
417 | DebugDisplayAnforderung = 1; |
||
418 | break; |
||
419 | |||
420 | case 'l':// x-1 Displayzeilen |
||
421 | PcZugriff = 255; |
||
422 | MenuePunkt = pRxData[0]; |
||
423 | DebugDisplayAnforderung1 = 1; |
||
424 | break; |
||
425 | case 'v': // Version-Anforderung und Ausbaustufe |
||
426 | GetVersionAnforderung = 1; |
||
427 | break; |
||
428 | |||
429 | case 'g':// |
||
430 | GetExternalControl = 1; |
||
431 | break; |
||
432 | case 'e': |
||
433 | while(!UebertragungAbgeschlossen); |
||
434 | |||
435 | memcpy(&ExternEvent, (unsigned char *)pRxData, sizeof(ExternEvent)); |
||
436 | |||
437 | tempchar1=pRxData[0]; |
||
438 | SendOutData('E', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
||
439 | break; |
||
440 | } |
||
441 | break; // default: |
||
442 | } |
||
443 | NeuerDatensatzEmpfangen = 0; |
||
444 | pRxData = 0; |
||
445 | RxDataLen = 0; |
||
446 | } |
||
447 | |||
448 | //############################################################################ |
||
449 | //Routine für die Serielle Ausgabe |
||
450 | int uart_putchar (char c) |
||
451 | //############################################################################ |
||
452 | { |
||
453 | if (c == '\n') |
||
454 | uart_putchar('\r'); |
||
455 | //Warten solange bis Zeichen gesendet wurde |
||
456 | loop_until_bit_is_set(USR, UDRE); |
||
457 | //Ausgabe des Zeichens |
||
458 | UDR = c; |
||
459 | |||
460 | return (0); |
||
461 | } |
||
462 | |||
463 | // -------------------------------------------------------------------------- |
||
464 | void WriteProgramData(unsigned int pos, unsigned char wert) |
||
465 | { |
||
466 | //if (ProgramLocation == IN_RAM) Buffer[pos] = wert; |
||
467 | // else eeprom_write_byte(&EE_Buffer[pos], wert); |
||
468 | // Buffer[pos] = wert; |
||
469 | } |
||
470 | |||
471 | //############################################################################ |
||
472 | //INstallation der Seriellen Schnittstelle |
||
473 | void UART_Init (void) |
||
474 | //############################################################################ |
||
475 | { |
||
476 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
||
477 | |||
478 | UCR=(1 << TXEN) | (1 << RXEN); |
||
479 | // UART Double Speed (U2X) |
||
480 | USR |= (1<<U2X); |
||
481 | // RX-Interrupt Freigabe |
||
482 | UCSRB |= (1<<RXCIE); |
||
483 | // TX-Interrupt Freigabe |
||
484 | UCSRB |= (1<<TXCIE); |
||
485 | |||
486 | //Teiler wird gesetzt |
||
487 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
||
488 | //UBRR = 33; |
||
489 | //öffnet einen Kanal für printf (STDOUT) |
||
490 | //fdevopen (uart_putchar, 0); |
||
491 | //sbi(PORTD,4); |
||
492 | Debug_Timer = SetDelay(DebugDataIntervall); |
||
493 | Kompass_Timer = SetDelay(220); |
||
494 | |||
495 | VersionInfo.SWMajor = VERSION_MAJOR; |
||
496 | VersionInfo.SWMinor = VERSION_MINOR; |
||
497 | VersionInfo.SWPatch = VERSION_PATCH; |
||
498 | VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
||
499 | VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
||
500 | |||
501 | pRxData = 0; |
||
502 | RxDataLen = 0; |
||
503 | } |
||
504 | |||
505 | //--------------------------------------------------------------------------------------------- |
||
506 | void DatenUebertragung(void) |
||
507 | { |
||
508 | if(!UebertragungAbgeschlossen) return; |
||
509 | |||
510 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
||
511 | { |
||
512 | Menu(); |
||
513 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), &DisplayBuff[DisplayLine * 20], 20); |
||
514 | DisplayLine++; |
||
515 | if(DisplayLine >= 4) DisplayLine = 0; |
||
516 | DebugDisplayAnforderung = 0; |
||
517 | } |
||
518 | if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen) |
||
519 | { |
||
520 | Menu(); |
||
521 | SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
||
522 | DebugDisplayAnforderung1 = 0; |
||
523 | } |
||
524 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
||
525 | { |
||
526 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
||
527 | GetVersionAnforderung = 0; |
||
528 | } |
||
529 | |||
530 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
531 | { |
||
532 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl)); |
||
533 | GetExternalControl = 0; |
||
534 | } |
||
535 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
||
536 | { |
||
537 | WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
538 | WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
539 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
||
540 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
||
541 | SendOutData('w', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
||
542 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
||
543 | Kompass_Timer = SetDelay(99); |
||
544 | } |
||
545 | if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
||
546 | { |
||
547 | SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
||
548 | DebugDataAnforderung = 0; |
||
549 | if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall); |
||
550 | } |
||
551 | if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen) |
||
552 | { |
||
553 | Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
554 | Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
555 | Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR); |
||
556 | SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D)); |
||
557 | Timer3D = SetDelay(Intervall3D); |
||
558 | } |
||
559 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
||
560 | { |
||
561 | SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),(unsigned char *) ANALOG_TEXT[DebugTextAnforderung], 16); |
||
562 | DebugTextAnforderung = 255; |
||
563 | } |
||
564 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
||
565 | { |
||
566 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
||
567 | ConfirmFrame = 0; |
||
568 | } |
||
569 | |||
570 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
||
571 | { |
||
572 | SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |
||
573 | GetPPMChannelAnforderung = 0; |
||
574 | } |
||
575 | |||
576 | } |
||
577 |