Rev 1054 | Rev 1056 | Go to most recent revision | Details | Compare with Previous | 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 | // -------------------------------------------------------------------------- |
||
1051 | killagreg | 181 | void SendOutData(unsigned char cmd,unsigned char modul, 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 | |||
1 | ingob | 191 | SendeBuffer[pt++] = '#'; // Startzeichen |
192 | SendeBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
||
193 | SendeBuffer[pt++] = cmd; // Commando |
||
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 | |||
1055 | ingob | 288 | switch(RxdBuffer[1]-'a') // check for Slave Address |
1054 | killagreg | 289 | { |
290 | case FC_ADDRESS: // FC special commands |
||
291 | Decode64(); // dekodiere datenblock im Empfangsbuffer |
||
292 | switch(RxdBuffer[2]) |
||
293 | { |
||
294 | case 'K':// Kompasswert |
||
295 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
||
296 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
||
297 | break; |
||
1051 | killagreg | 298 | |
1054 | killagreg | 299 | case 't':// Motortest |
300 | memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
||
301 | while(!UebertragungAbgeschlossen); |
||
302 | SendOutData('T', MeineSlaveAdresse, 0); |
||
303 | PcZugriff = 255; |
||
304 | break; |
||
1053 | killagreg | 305 | |
1054 | killagreg | 306 | case 'p': // get PPM Channels |
307 | GetPPMChannelAnforderung = 1; |
||
308 | break; |
||
1053 | killagreg | 309 | |
1054 | killagreg | 310 | case 'q':// "Get"-Anforderung für Settings |
311 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
312 | if(pRxData[0] == 0xFF) |
||
313 | { |
||
314 | pRxData[0] = GetActiveParamSetNumber(); |
||
315 | } |
||
316 | else // request active parameter set |
||
317 | { |
||
318 | if(pRxData[0] < 1) pRxData[0] = 1; // limit to 5 |
||
319 | else if(pRxData[0] > 5) pRxData[0] = 5; // limit to 5 |
||
320 | // load requested parameter set |
||
321 | ReadParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
322 | } |
||
323 | while(!UebertragungAbgeschlossen); |
||
324 | SendOutData('Q', FC_ADDRESS, 2, &pRxData[0], sizeof(unsigned char), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
325 | break; |
||
1051 | killagreg | 326 | |
1054 | killagreg | 327 | case 's': // Parametersatz speichern |
328 | if((1 <= pRxData[0]) && (pRxData[0] <= 5)) // check for setting to be in range |
||
329 | { |
||
330 | memcpy((unsigned char *) &EE_Parameter.Kanalbelegung[0], (unsigned char *)&pRxData[1], STRUCT_PARAM_LAENGE); |
||
331 | WriteParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
332 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], RxdBuffer[2] - 'l' + 1); // aktiven Datensatz merken |
||
333 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
||
334 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
||
335 | Piep(GetActiveParamSetNumber()); |
||
336 | while(!UebertragungAbgeschlossen); |
||
337 | SendOutData('S', FC_ADDRESS, 1, &pRxData[0], sizeof(unsigned char)); |
||
338 | } |
||
339 | break; |
||
340 | |||
341 | } |
||
342 | break; // case FC_ADDRESS: |
||
343 | |||
344 | default: // any Slave Address |
||
345 | Decode64(); |
||
346 | switch(RxdBuffer[2]) |
||
347 | { |
||
348 | // 't' comand placed here only for compatibility to BL |
||
349 | case 't':// Motortest |
||
350 | memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
||
351 | while(!UebertragungAbgeschlossen); |
||
352 | SendOutData('T', MeineSlaveAdresse, 0); |
||
353 | PcZugriff = 255; |
||
354 | break; |
||
355 | // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address |
||
356 | case 'K':// Kompasswert |
||
357 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
||
358 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
||
359 | break; |
||
360 | |||
361 | case 'a':// Texte der Analogwerte |
||
362 | DebugTextAnforderung = pRxData[0]; |
||
363 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
||
364 | PcZugriff = 255; |
||
365 | break; |
||
366 | |||
367 | case 'b': |
||
368 | memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl)); |
||
369 | ConfirmFrame = ExternControl.Frame; |
||
370 | PcZugriff = 255; |
||
371 | break; |
||
372 | case 'd': // Poll the debug data |
||
373 | DebugDataIntervall = pRxData[0] * 10; |
||
1055 | ingob | 374 | if (DebugDataIntervall>0) DebugDataAnforderung = 1; |
1054 | killagreg | 375 | break; |
376 | |||
377 | case 'h':// x-1 Displayzeilen |
||
378 | RemoteKeys |= pRxData[0]; |
||
379 | if(RemoteKeys) DisplayLine = 0; |
||
380 | DebugDisplayAnforderung = 1; |
||
381 | break; |
||
382 | |||
383 | case 'l':// x-1 Displayzeilen |
||
384 | MenuePunkt = pRxData[0]; |
||
385 | DebugDisplayAnforderung1 = 1; |
||
386 | break; |
||
387 | case 'v': // Version-Anforderung und Ausbaustufe |
||
388 | GetVersionAnforderung = 1; |
||
389 | break; |
||
390 | |||
391 | case 'g':// |
||
392 | GetExternalControl = 1; |
||
393 | break; |
||
394 | } |
||
395 | break; // default: |
||
396 | } |
||
1051 | killagreg | 397 | NeuerDatensatzEmpfangen = 0; |
398 | pRxData = 0; |
||
399 | RxDataLen = 0; |
||
1 | ingob | 400 | } |
401 | |||
402 | //############################################################################ |
||
403 | //Routine für die Serielle Ausgabe |
||
404 | int uart_putchar (char c) |
||
405 | //############################################################################ |
||
406 | { |
||
407 | if (c == '\n') |
||
408 | uart_putchar('\r'); |
||
409 | //Warten solange bis Zeichen gesendet wurde |
||
410 | loop_until_bit_is_set(USR, UDRE); |
||
411 | //Ausgabe des Zeichens |
||
412 | UDR = c; |
||
1051 | killagreg | 413 | |
1 | ingob | 414 | return (0); |
415 | } |
||
416 | |||
417 | // -------------------------------------------------------------------------- |
||
418 | void WriteProgramData(unsigned int pos, unsigned char wert) |
||
419 | { |
||
420 | //if (ProgramLocation == IN_RAM) Buffer[pos] = wert; |
||
421 | // else eeprom_write_byte(&EE_Buffer[pos], wert); |
||
422 | // Buffer[pos] = wert; |
||
423 | } |
||
424 | |||
425 | //############################################################################ |
||
426 | //INstallation der Seriellen Schnittstelle |
||
427 | void UART_Init (void) |
||
428 | //############################################################################ |
||
429 | { |
||
430 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
||
431 | |||
432 | UCR=(1 << TXEN) | (1 << RXEN); |
||
433 | // UART Double Speed (U2X) |
||
1051 | killagreg | 434 | USR |= (1<<U2X); |
1 | ingob | 435 | // RX-Interrupt Freigabe |
1051 | killagreg | 436 | UCSRB |= (1<<RXCIE); |
1 | ingob | 437 | // TX-Interrupt Freigabe |
1051 | killagreg | 438 | UCSRB |= (1<<TXCIE); |
1 | ingob | 439 | |
1051 | killagreg | 440 | //Teiler wird gesetzt |
1 | ingob | 441 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
442 | //UBRR = 33; |
||
443 | //öffnet einen Kanal für printf (STDOUT) |
||
444 | //fdevopen (uart_putchar, 0); |
||
445 | //sbi(PORTD,4); |
||
1051 | killagreg | 446 | Debug_Timer = SetDelay(DebugDataIntervall); |
447 | Kompass_Timer = SetDelay(220); |
||
448 | |||
449 | VersionInfo.Major = VERSION_MAJOR; |
||
450 | VersionInfo.Minor = VERSION_MINOR; |
||
451 | VersionInfo.Patch = VERSION_PATCH; |
||
452 | VersionInfo.Compatible = VERSION_SERIAL_COMPATIBLE; |
||
453 | |||
454 | pRxData = 0; |
||
455 | RxDataLen = 0; |
||
1 | ingob | 456 | } |
457 | |||
458 | //--------------------------------------------------------------------------------------------- |
||
1051 | killagreg | 459 | void DatenUebertragung(void) |
1 | ingob | 460 | { |
461 | if(!UebertragungAbgeschlossen) return; |
||
462 | |||
1038 | hbuss | 463 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
1051 | killagreg | 464 | { |
465 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl)); |
||
1038 | hbuss | 466 | GetExternalControl = 0; |
1 | ingob | 467 | } |
468 | |||
1051 | killagreg | 469 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
693 | hbuss | 470 | { |
846 | hbuss | 471 | WinkelOut.Winkel[0] = (int) (IntegralNick / 108); // etwa in 0,1 Grad |
472 | WinkelOut.Winkel[1] = (int) (IntegralRoll / 108); // etwa in 0,1 Grad |
||
717 | hbuss | 473 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
474 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
||
1054 | killagreg | 475 | SendOutData('w', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
855 | hbuss | 476 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
1051 | killagreg | 477 | Kompass_Timer = SetDelay(99); |
478 | } |
||
1055 | ingob | 479 | if((( DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
1 | ingob | 480 | { |
1054 | killagreg | 481 | SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
1 | ingob | 482 | DebugDataAnforderung = 0; |
1055 | ingob | 483 | if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall); |
1051 | killagreg | 484 | } |
499 | hbuss | 485 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
486 | { |
||
1054 | killagreg | 487 | SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),(unsigned char *) ANALOG_TEXT[DebugTextAnforderung], 16); |
499 | hbuss | 488 | DebugTextAnforderung = 255; |
489 | } |
||
1051 | killagreg | 490 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
595 | hbuss | 491 | { |
1054 | killagreg | 492 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
1051 | killagreg | 493 | ConfirmFrame = 0; |
595 | hbuss | 494 | } |
1053 | killagreg | 495 | |
1 | ingob | 496 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
497 | { |
||
1053 | killagreg | 498 | Menu(); |
1054 | killagreg | 499 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), &DisplayBuff[DisplayLine * 20], 20); |
1053 | killagreg | 500 | DisplayLine++; |
501 | if(DisplayLine >= 4) DisplayLine = 0; |
||
502 | DebugDisplayAnforderung = 0; |
||
1051 | killagreg | 503 | } |
1053 | killagreg | 504 | if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen) |
505 | { |
||
506 | Menu(); |
||
1054 | killagreg | 507 | SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
1053 | killagreg | 508 | DebugDisplayAnforderung1 = 0; |
509 | } |
||
1051 | killagreg | 510 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
511 | { |
||
1054 | killagreg | 512 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
1 | ingob | 513 | GetVersionAnforderung = 0; |
514 | } |
||
1051 | killagreg | 515 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
516 | { |
||
1054 | killagreg | 517 | SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |
1051 | killagreg | 518 | GetPPMChannelAnforderung = 0; |
519 | } |
||
1 | ingob | 520 | |
521 | } |
||
522 |