Rev 1209 | Rev 1212 | 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; |
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 |
1175 | hbuss | 49 | "AngleNick ", //0 |
50 | "AngleRoll ", |
||
1051 | killagreg | 51 | "AccNick ", |
499 | hbuss | 52 | "AccRoll ", |
53 | "GyroGier ", |
||
1175 | hbuss | 54 | "Hight Value ", //5 |
499 | hbuss | 55 | "AccZ ", |
56 | "Gas ", |
||
1175 | hbuss | 57 | "Compass Value ", |
58 | "Voltage ", |
||
513 | hbuss | 59 | "Empfang ", //10 |
1175 | hbuss | 60 | "Gyro Kompass ", |
61 | "Motor Front ", |
||
62 | "Motor Rear ", |
||
63 | "Motor Left ", |
||
64 | "Motor Right ", //15 |
||
929 | hbuss | 65 | " ", |
1175 | hbuss | 66 | " ", |
67 | " ", |
||
819 | hbuss | 68 | "MK3Mag CalState ", |
854 | hbuss | 69 | "Servo ", //20 |
720 | ingob | 70 | " ", |
71 | " ", |
||
1175 | hbuss | 72 | " ", |
73 | " ", |
||
720 | ingob | 74 | " ", //25 |
75 | " ", |
||
992 | hbuss | 76 | "Kalman_MaxDrift ", |
720 | ingob | 77 | " ", |
1175 | hbuss | 78 | " ", |
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 | |
1209 | hbuss | 309 | case 'n':// "Get Mixer |
310 | while(!UebertragungAbgeschlossen); |
||
311 | SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer,sizeof(Mixer)); |
||
312 | break; |
||
313 | |||
314 | case 'm':// "Write Mixer |
||
315 | while(!UebertragungAbgeschlossen); |
||
1211 | hbuss | 316 | if(pRxData[0] == MIXER_REVISION) |
317 | { |
||
318 | memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer)); |
||
319 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
||
320 | tempchar1 = 1; |
||
321 | } |
||
322 | else tempchar1 = 0; |
||
323 | SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
||
1209 | hbuss | 324 | break; |
325 | |||
1054 | killagreg | 326 | case 'p': // get PPM Channels |
327 | GetPPMChannelAnforderung = 1; |
||
328 | break; |
||
1053 | killagreg | 329 | |
1054 | killagreg | 330 | case 'q':// "Get"-Anforderung für Settings |
331 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
332 | if(pRxData[0] == 0xFF) |
||
333 | { |
||
334 | pRxData[0] = GetActiveParamSetNumber(); |
||
335 | } |
||
1063 | killagreg | 336 | // limit settings range |
337 | if(pRxData[0] < 1) pRxData[0] = 1; // limit to 5 |
||
338 | else if(pRxData[0] > 5) pRxData[0] = 5; // limit to 5 |
||
339 | // load requested parameter set |
||
340 | ReadParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
341 | |||
1054 | killagreg | 342 | while(!UebertragungAbgeschlossen); |
1058 | killagreg | 343 | tempchar1 = pRxData[0]; |
344 | tempchar2 = EE_DATENREVISION; |
||
345 | SendOutData('Q', FC_ADDRESS, 3, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
1054 | killagreg | 346 | break; |
1051 | killagreg | 347 | |
1054 | killagreg | 348 | case 's': // Parametersatz speichern |
1058 | killagreg | 349 | if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EE_DATENREVISION)) // check for setting to be in range |
1054 | killagreg | 350 | { |
1058 | killagreg | 351 | memcpy((unsigned char *) &EE_Parameter.Kanalbelegung[0], (unsigned char *)&pRxData[2], STRUCT_PARAM_LAENGE); |
1054 | killagreg | 352 | WriteParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
353 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
||
354 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
||
1063 | killagreg | 355 | SetActiveParamSetNumber(pRxData[0]); |
356 | tempchar1 = GetActiveParamSetNumber(); |
||
357 | Piep(tempchar1); |
||
1054 | killagreg | 358 | } |
1058 | killagreg | 359 | else |
360 | { |
||
361 | tempchar1 = 0; // mark in response an invlid setting |
||
362 | } |
||
363 | while(!UebertragungAbgeschlossen); |
||
364 | SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
||
1054 | killagreg | 365 | break; |
366 | |||
1056 | killagreg | 367 | } // case FC_ADDRESS: |
1054 | killagreg | 368 | |
369 | default: // any Slave Address |
||
1056 | killagreg | 370 | |
1054 | killagreg | 371 | switch(RxdBuffer[2]) |
372 | { |
||
373 | // 't' comand placed here only for compatibility to BL |
||
374 | case 't':// Motortest |
||
375 | memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
||
376 | while(!UebertragungAbgeschlossen); |
||
377 | SendOutData('T', MeineSlaveAdresse, 0); |
||
378 | PcZugriff = 255; |
||
379 | break; |
||
380 | // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address |
||
381 | case 'K':// Kompasswert |
||
382 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
||
383 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
||
384 | break; |
||
385 | case 'a':// Texte der Analogwerte |
||
386 | DebugTextAnforderung = pRxData[0]; |
||
387 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
||
388 | PcZugriff = 255; |
||
389 | break; |
||
390 | case 'b': |
||
391 | memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl)); |
||
392 | ConfirmFrame = ExternControl.Frame; |
||
393 | PcZugriff = 255; |
||
394 | break; |
||
1171 | hbuss | 395 | case 'c': // Poll the 3D-Data |
396 | if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);} |
||
397 | Intervall3D = pRxData[0] * 10; |
||
398 | break; |
||
1054 | killagreg | 399 | case 'd': // Poll the debug data |
400 | DebugDataIntervall = pRxData[0] * 10; |
||
1171 | hbuss | 401 | if(DebugDataIntervall > 0) DebugDataAnforderung = 1; |
1054 | killagreg | 402 | break; |
403 | |||
404 | case 'h':// x-1 Displayzeilen |
||
1059 | hbuss | 405 | PcZugriff = 255; |
1054 | killagreg | 406 | RemoteKeys |= pRxData[0]; |
407 | if(RemoteKeys) DisplayLine = 0; |
||
408 | DebugDisplayAnforderung = 1; |
||
409 | break; |
||
410 | |||
411 | case 'l':// x-1 Displayzeilen |
||
1059 | hbuss | 412 | PcZugriff = 255; |
1054 | killagreg | 413 | MenuePunkt = pRxData[0]; |
414 | DebugDisplayAnforderung1 = 1; |
||
415 | break; |
||
416 | case 'v': // Version-Anforderung und Ausbaustufe |
||
417 | GetVersionAnforderung = 1; |
||
418 | break; |
||
419 | |||
420 | case 'g':// |
||
421 | GetExternalControl = 1; |
||
422 | break; |
||
423 | } |
||
424 | break; // default: |
||
425 | } |
||
1051 | killagreg | 426 | NeuerDatensatzEmpfangen = 0; |
427 | pRxData = 0; |
||
428 | RxDataLen = 0; |
||
1 | ingob | 429 | } |
430 | |||
431 | //############################################################################ |
||
432 | //Routine für die Serielle Ausgabe |
||
433 | int uart_putchar (char c) |
||
434 | //############################################################################ |
||
435 | { |
||
436 | if (c == '\n') |
||
437 | uart_putchar('\r'); |
||
438 | //Warten solange bis Zeichen gesendet wurde |
||
439 | loop_until_bit_is_set(USR, UDRE); |
||
440 | //Ausgabe des Zeichens |
||
441 | UDR = c; |
||
1051 | killagreg | 442 | |
1 | ingob | 443 | return (0); |
444 | } |
||
445 | |||
446 | // -------------------------------------------------------------------------- |
||
447 | void WriteProgramData(unsigned int pos, unsigned char wert) |
||
448 | { |
||
449 | //if (ProgramLocation == IN_RAM) Buffer[pos] = wert; |
||
450 | // else eeprom_write_byte(&EE_Buffer[pos], wert); |
||
451 | // Buffer[pos] = wert; |
||
452 | } |
||
453 | |||
454 | //############################################################################ |
||
455 | //INstallation der Seriellen Schnittstelle |
||
456 | void UART_Init (void) |
||
457 | //############################################################################ |
||
458 | { |
||
459 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
||
460 | |||
461 | UCR=(1 << TXEN) | (1 << RXEN); |
||
462 | // UART Double Speed (U2X) |
||
1051 | killagreg | 463 | USR |= (1<<U2X); |
1 | ingob | 464 | // RX-Interrupt Freigabe |
1051 | killagreg | 465 | UCSRB |= (1<<RXCIE); |
1 | ingob | 466 | // TX-Interrupt Freigabe |
1051 | killagreg | 467 | UCSRB |= (1<<TXCIE); |
1 | ingob | 468 | |
1051 | killagreg | 469 | //Teiler wird gesetzt |
1 | ingob | 470 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
471 | //UBRR = 33; |
||
472 | //öffnet einen Kanal für printf (STDOUT) |
||
473 | //fdevopen (uart_putchar, 0); |
||
474 | //sbi(PORTD,4); |
||
1051 | killagreg | 475 | Debug_Timer = SetDelay(DebugDataIntervall); |
476 | Kompass_Timer = SetDelay(220); |
||
477 | |||
1058 | killagreg | 478 | VersionInfo.SWMajor = VERSION_MAJOR; |
479 | VersionInfo.SWMinor = VERSION_MINOR; |
||
480 | VersionInfo.SWPatch = VERSION_PATCH; |
||
481 | VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
||
482 | VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
||
1051 | killagreg | 483 | |
484 | pRxData = 0; |
||
485 | RxDataLen = 0; |
||
1 | ingob | 486 | } |
487 | |||
488 | //--------------------------------------------------------------------------------------------- |
||
1051 | killagreg | 489 | void DatenUebertragung(void) |
1 | ingob | 490 | { |
491 | if(!UebertragungAbgeschlossen) return; |
||
492 | |||
1065 | killagreg | 493 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
494 | { |
||
495 | Menu(); |
||
496 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), &DisplayBuff[DisplayLine * 20], 20); |
||
497 | DisplayLine++; |
||
498 | if(DisplayLine >= 4) DisplayLine = 0; |
||
499 | DebugDisplayAnforderung = 0; |
||
500 | } |
||
501 | if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen) |
||
502 | { |
||
503 | Menu(); |
||
504 | SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
||
505 | DebugDisplayAnforderung1 = 0; |
||
506 | } |
||
507 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
||
508 | { |
||
509 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
||
510 | GetVersionAnforderung = 0; |
||
511 | } |
||
1 | ingob | 512 | |
1065 | killagreg | 513 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
514 | { |
||
515 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl)); |
||
516 | GetExternalControl = 0; |
||
517 | } |
||
1051 | killagreg | 518 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
693 | hbuss | 519 | { |
1171 | hbuss | 520 | WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
521 | WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
717 | hbuss | 522 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
523 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
||
1054 | killagreg | 524 | SendOutData('w', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
855 | hbuss | 525 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
1051 | killagreg | 526 | Kompass_Timer = SetDelay(99); |
527 | } |
||
1171 | hbuss | 528 | if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
1 | ingob | 529 | { |
1054 | killagreg | 530 | SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
1 | ingob | 531 | DebugDataAnforderung = 0; |
1055 | ingob | 532 | if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall); |
1051 | killagreg | 533 | } |
1171 | hbuss | 534 | if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen) |
535 | { |
||
536 | Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
537 | Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
538 | Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR); |
||
539 | SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D)); |
||
540 | Timer3D = SetDelay(Intervall3D); |
||
541 | } |
||
499 | hbuss | 542 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
543 | { |
||
1054 | killagreg | 544 | SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),(unsigned char *) ANALOG_TEXT[DebugTextAnforderung], 16); |
499 | hbuss | 545 | DebugTextAnforderung = 255; |
546 | } |
||
1051 | killagreg | 547 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
595 | hbuss | 548 | { |
1054 | killagreg | 549 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
1051 | killagreg | 550 | ConfirmFrame = 0; |
595 | hbuss | 551 | } |
1053 | killagreg | 552 | |
1051 | killagreg | 553 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
554 | { |
||
1054 | killagreg | 555 | SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |
1051 | killagreg | 556 | GetPPMChannelAnforderung = 0; |
557 | } |
||
1 | ingob | 558 | |
559 | } |
||
560 |