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