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