Go to most recent revision | Details | 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 | { |
1435 | killagreg | 138 | LcdClear(); |
1232 | hbuss | 139 | wdt_enable(WDTO_250MS); // Reset-Commando |
140 | ServoActive = 0; |
||
1435 | killagreg | 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); |
||
1435 | killagreg | 376 | LIBFC_ReceiverInit(); |
1054 | killagreg | 377 | break; |
1405 | hbuss | 378 | case 'f': // auf anderen Parametersatz umschalten |
379 | if((1 <= pRxData[0]) && (pRxData[0] <= 5)) SetActiveParamSetNumber(pRxData[0]); |
||
380 | tempchar1 = pRxData[0]; |
||
381 | while(!UebertragungAbgeschlossen); |
||
382 | SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
||
383 | if(!MotorenEin) Piep(tempchar1,110); |
||
384 | LipoDetection(0); |
||
1435 | killagreg | 385 | LIBFC_ReceiverInit(); |
1405 | hbuss | 386 | break; |
1391 | killagreg | 387 | case 'y':// serial Potis |
388 | 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]; |
||
389 | 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]; |
||
390 | 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]; |
||
391 | break; |
||
392 | |||
1056 | killagreg | 393 | } // case FC_ADDRESS: |
1054 | killagreg | 394 | |
395 | default: // any Slave Address |
||
1056 | killagreg | 396 | |
1054 | killagreg | 397 | switch(RxdBuffer[2]) |
398 | { |
||
399 | // 't' comand placed here only for compatibility to BL |
||
400 | case 't':// Motortest |
||
1212 | hbuss | 401 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
402 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
||
1054 | killagreg | 403 | while(!UebertragungAbgeschlossen); |
404 | SendOutData('T', MeineSlaveAdresse, 0); |
||
1212 | hbuss | 405 | PC_MotortestActive = 250; |
1054 | killagreg | 406 | PcZugriff = 255; |
407 | break; |
||
408 | // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address |
||
409 | case 'K':// Kompasswert |
||
410 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
||
411 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
||
412 | break; |
||
413 | case 'a':// Texte der Analogwerte |
||
414 | DebugTextAnforderung = pRxData[0]; |
||
415 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
||
416 | PcZugriff = 255; |
||
417 | break; |
||
418 | case 'b': |
||
419 | memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl)); |
||
420 | ConfirmFrame = ExternControl.Frame; |
||
421 | PcZugriff = 255; |
||
422 | break; |
||
1171 | hbuss | 423 | case 'c': // Poll the 3D-Data |
424 | if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);} |
||
425 | Intervall3D = pRxData[0] * 10; |
||
1417 | killagreg | 426 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
1171 | hbuss | 427 | break; |
1054 | killagreg | 428 | case 'd': // Poll the debug data |
1399 | killagreg | 429 | DebugDataIntervall = (unsigned int)pRxData[0] * 10; |
1171 | hbuss | 430 | if(DebugDataIntervall > 0) DebugDataAnforderung = 1; |
1415 | killagreg | 431 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
1054 | killagreg | 432 | break; |
433 | |||
434 | case 'h':// x-1 Displayzeilen |
||
1059 | hbuss | 435 | PcZugriff = 255; |
1399 | killagreg | 436 | if((pRxData[0] & 0x80) == 0x00) // old format |
437 | { |
||
438 | DisplayLine = 2; |
||
439 | Display_Interval = 0; |
||
440 | } |
||
441 | else // new format |
||
442 | { |
||
443 | RemoteKeys |= ~pRxData[0]; |
||
444 | Display_Interval = (unsigned int)pRxData[1] * 10; |
||
445 | DisplayLine = 4; |
||
1415 | killagreg | 446 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
1399 | killagreg | 447 | } |
1054 | killagreg | 448 | DebugDisplayAnforderung = 1; |
449 | break; |
||
450 | |||
451 | case 'l':// x-1 Displayzeilen |
||
1059 | hbuss | 452 | PcZugriff = 255; |
1054 | killagreg | 453 | MenuePunkt = pRxData[0]; |
454 | DebugDisplayAnforderung1 = 1; |
||
455 | break; |
||
456 | case 'v': // Version-Anforderung und Ausbaustufe |
||
457 | GetVersionAnforderung = 1; |
||
458 | break; |
||
459 | |||
460 | case 'g':// |
||
461 | GetExternalControl = 1; |
||
462 | break; |
||
463 | } |
||
464 | break; // default: |
||
465 | } |
||
1051 | killagreg | 466 | NeuerDatensatzEmpfangen = 0; |
467 | pRxData = 0; |
||
468 | RxDataLen = 0; |
||
1 | ingob | 469 | } |
470 | |||
471 | //############################################################################ |
||
472 | //Routine für die Serielle Ausgabe |
||
473 | int uart_putchar (char c) |
||
474 | //############################################################################ |
||
475 | { |
||
476 | if (c == '\n') |
||
477 | uart_putchar('\r'); |
||
478 | //Warten solange bis Zeichen gesendet wurde |
||
479 | loop_until_bit_is_set(USR, UDRE); |
||
480 | //Ausgabe des Zeichens |
||
481 | UDR = c; |
||
1051 | killagreg | 482 | |
1 | ingob | 483 | return (0); |
484 | } |
||
485 | |||
486 | // -------------------------------------------------------------------------- |
||
487 | void WriteProgramData(unsigned int pos, unsigned char wert) |
||
488 | { |
||
489 | //if (ProgramLocation == IN_RAM) Buffer[pos] = wert; |
||
490 | // else eeprom_write_byte(&EE_Buffer[pos], wert); |
||
491 | // Buffer[pos] = wert; |
||
492 | } |
||
493 | |||
494 | //############################################################################ |
||
495 | //INstallation der Seriellen Schnittstelle |
||
496 | void UART_Init (void) |
||
497 | //############################################################################ |
||
498 | { |
||
499 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
||
500 | |||
501 | UCR=(1 << TXEN) | (1 << RXEN); |
||
502 | // UART Double Speed (U2X) |
||
1051 | killagreg | 503 | USR |= (1<<U2X); |
1 | ingob | 504 | // RX-Interrupt Freigabe |
1051 | killagreg | 505 | UCSRB |= (1<<RXCIE); |
1 | ingob | 506 | // TX-Interrupt Freigabe |
1051 | killagreg | 507 | UCSRB |= (1<<TXCIE); |
1 | ingob | 508 | |
1051 | killagreg | 509 | //Teiler wird gesetzt |
1 | ingob | 510 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
511 | //UBRR = 33; |
||
512 | //öffnet einen Kanal für printf (STDOUT) |
||
513 | //fdevopen (uart_putchar, 0); |
||
514 | //sbi(PORTD,4); |
||
1051 | killagreg | 515 | Debug_Timer = SetDelay(DebugDataIntervall); |
516 | Kompass_Timer = SetDelay(220); |
||
517 | |||
1058 | killagreg | 518 | VersionInfo.SWMajor = VERSION_MAJOR; |
519 | VersionInfo.SWMinor = VERSION_MINOR; |
||
520 | VersionInfo.SWPatch = VERSION_PATCH; |
||
521 | VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
||
522 | VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
||
1051 | killagreg | 523 | |
524 | pRxData = 0; |
||
525 | RxDataLen = 0; |
||
1 | ingob | 526 | } |
527 | |||
528 | //--------------------------------------------------------------------------------------------- |
||
1051 | killagreg | 529 | void DatenUebertragung(void) |
1 | ingob | 530 | { |
1415 | killagreg | 531 | if(!UebertragungAbgeschlossen) return; |
1 | ingob | 532 | |
1415 | killagreg | 533 | if(CheckDelay(AboTimeOut)) |
534 | { |
||
535 | Display_Interval = 0; |
||
536 | DebugDataIntervall = 0; |
||
1417 | killagreg | 537 | Intervall3D = 0; |
1415 | killagreg | 538 | } |
539 | |||
1399 | killagreg | 540 | if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen) |
1065 | killagreg | 541 | { |
1399 | killagreg | 542 | if(DisplayLine > 3)// new format |
543 | { |
||
1423 | hbuss | 544 | Menu(); |
1399 | killagreg | 545 | SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80); |
546 | } |
||
547 | else // old format |
||
548 | { |
||
549 | LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!"); |
||
550 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20); |
||
551 | if(DisplayLine++ > 3) DisplayLine = 0; |
||
552 | } |
||
553 | Display_Timer = SetDelay(Display_Interval); |
||
1065 | killagreg | 554 | DebugDisplayAnforderung = 0; |
555 | } |
||
556 | if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen) |
||
557 | { |
||
558 | Menu(); |
||
559 | SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
||
560 | DebugDisplayAnforderung1 = 0; |
||
561 | } |
||
562 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
||
563 | { |
||
564 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
||
565 | GetVersionAnforderung = 0; |
||
566 | } |
||
1 | ingob | 567 | |
1065 | killagreg | 568 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
569 | { |
||
570 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl)); |
||
571 | GetExternalControl = 0; |
||
572 | } |
||
1051 | killagreg | 573 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
693 | hbuss | 574 | { |
1171 | hbuss | 575 | WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
576 | WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
717 | hbuss | 577 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
578 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
||
1054 | killagreg | 579 | SendOutData('w', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
855 | hbuss | 580 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
1051 | killagreg | 581 | Kompass_Timer = SetDelay(99); |
582 | } |
||
1171 | hbuss | 583 | if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
1 | ingob | 584 | { |
1391 | killagreg | 585 | //if(Poti3 > 64) |
1276 | hbuss | 586 | SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
1 | ingob | 587 | DebugDataAnforderung = 0; |
1055 | ingob | 588 | if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall); |
1051 | killagreg | 589 | } |
1171 | hbuss | 590 | if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen) |
591 | { |
||
592 | Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
593 | Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
594 | Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR); |
||
595 | SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D)); |
||
596 | Timer3D = SetDelay(Intervall3D); |
||
597 | } |
||
499 | hbuss | 598 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
599 | { |
||
1054 | killagreg | 600 | SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),(unsigned char *) ANALOG_TEXT[DebugTextAnforderung], 16); |
499 | hbuss | 601 | DebugTextAnforderung = 255; |
602 | } |
||
1051 | killagreg | 603 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
595 | hbuss | 604 | { |
1054 | killagreg | 605 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
1051 | killagreg | 606 | ConfirmFrame = 0; |
595 | hbuss | 607 | } |
1053 | killagreg | 608 | |
1051 | killagreg | 609 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
610 | { |
||
1054 | killagreg | 611 | SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |
1051 | killagreg | 612 | GetPPMChannelAnforderung = 0; |
613 | } |
||
1 | ingob | 614 | |
615 | } |
||
616 |