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