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