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