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