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