Rev 1438 | Rev 1444 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1338 | ingob | 2 | // + Copyright (c) Holger Buss, Ingo Busker |
1 | ingob | 3 | // + only for non-profit use |
4 | // + www.MikroKopter.com |
||
5 | // + see the File "License.txt" for further Informations |
||
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 7 | #include <stdarg.h> |
8 | #include <string.h> |
||
1 | ingob | 9 | #include "main.h" |
10 | #include "uart.h" |
||
1438 | ingob | 11 | #include "libfc.h" |
1 | ingob | 12 | |
1054 | killagreg | 13 | |
14 | #define FC_ADDRESS 1 |
||
15 | #define NC_ADDRESS 2 |
||
16 | #define MK3MAG_ADDRESS 3 |
||
17 | |||
1415 | killagreg | 18 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
1441 | ingob | 19 | #define MAX_SENDE_BUFF 160 |
20 | #define MAX_EMPFANGS_BUFF 160 |
||
1053 | killagreg | 21 | unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0; |
22 | unsigned char DisplayLine = 0; |
||
1 | ingob | 23 | unsigned volatile char SioTmp = 0; |
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; |
||
1441 | ingob | 29 | unsigned volatile char TxdBuffer[MAX_SENDE_BUFF]; |
30 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
||
31 | |||
1051 | killagreg | 32 | unsigned char *pRxData = 0; |
33 | unsigned char RxDataLen = 0; |
||
1 | ingob | 34 | unsigned volatile char PC_DebugTimeout = 0; |
1212 | hbuss | 35 | unsigned volatile char PC_MotortestActive = 0; |
1051 | killagreg | 36 | |
499 | hbuss | 37 | unsigned char DebugTextAnforderung = 255; |
1 | ingob | 38 | unsigned char PcZugriff = 100; |
1212 | hbuss | 39 | unsigned char MotorTest[16]; |
1036 | hbuss | 40 | unsigned char MeineSlaveAdresse = 1; // Flight-Ctrl |
595 | hbuss | 41 | unsigned char ConfirmFrame; |
1 | ingob | 42 | struct str_DebugOut DebugOut; |
595 | hbuss | 43 | struct str_ExternControl ExternControl; |
1 | ingob | 44 | struct str_VersionInfo VersionInfo; |
693 | hbuss | 45 | struct str_WinkelOut WinkelOut; |
1171 | hbuss | 46 | struct str_Data3D Data3D; |
1 | ingob | 47 | |
1399 | killagreg | 48 | int Display_Timer, Debug_Timer,Kompass_Timer,Timer3D; |
1415 | killagreg | 49 | unsigned int DebugDataIntervall = 0, Intervall3D = 0, Display_Interval = 0; |
50 | unsigned int AboTimeOut = 0; |
||
693 | hbuss | 51 | |
499 | hbuss | 52 | const unsigned char ANALOG_TEXT[32][16] = |
53 | { |
||
1051 | killagreg | 54 | //1234567890123456 |
1175 | hbuss | 55 | "AngleNick ", //0 |
56 | "AngleRoll ", |
||
1051 | killagreg | 57 | "AccNick ", |
499 | hbuss | 58 | "AccRoll ", |
59 | "GyroGier ", |
||
1175 | hbuss | 60 | "Hight Value ", //5 |
499 | hbuss | 61 | "AccZ ", |
62 | "Gas ", |
||
1175 | hbuss | 63 | "Compass Value ", |
64 | "Voltage ", |
||
513 | hbuss | 65 | "Empfang ", //10 |
1175 | hbuss | 66 | "Gyro Kompass ", |
67 | "Motor Front ", |
||
68 | "Motor Rear ", |
||
69 | "Motor Left ", |
||
70 | "Motor Right ", //15 |
||
929 | hbuss | 71 | " ", |
1175 | hbuss | 72 | " ", |
1253 | killagreg | 73 | "VarioMeter ", |
819 | hbuss | 74 | "MK3Mag CalState ", |
854 | hbuss | 75 | "Servo ", //20 |
1322 | hbuss | 76 | "Hoovergas ", |
720 | ingob | 77 | " ", |
1322 | hbuss | 78 | " ", |
79 | " ", |
||
80 | " ", //25 |
||
81 | " ", |
||
82 | " ", |
||
83 | "I2C-Error ", |
||
1352 | hbuss | 84 | " ",// "Navi Serial Data", |
720 | ingob | 85 | "GPS_Nick ", //30 |
86 | "GPS_Roll " |
||
499 | hbuss | 87 | }; |
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; |
||
1438 | ingob | 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 |
||
476 | int uart_putchar (char c) |
||
477 | //############################################################################ |
||
478 | { |
||
479 | if (c == '\n') |
||
480 | uart_putchar('\r'); |
||
481 | //Warten solange bis Zeichen gesendet wurde |
||
482 | loop_until_bit_is_set(USR, UDRE); |
||
483 | //Ausgabe des Zeichens |
||
484 | UDR = c; |
||
1051 | killagreg | 485 | |
1 | ingob | 486 | return (0); |
487 | } |
||
488 | |||
489 | |||
490 | //############################################################################ |
||
491 | //INstallation der Seriellen Schnittstelle |
||
492 | void UART_Init (void) |
||
493 | //############################################################################ |
||
494 | { |
||
495 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
||
496 | |||
497 | UCR=(1 << TXEN) | (1 << RXEN); |
||
498 | // UART Double Speed (U2X) |
||
1051 | killagreg | 499 | USR |= (1<<U2X); |
1 | ingob | 500 | // RX-Interrupt Freigabe |
1051 | killagreg | 501 | UCSRB |= (1<<RXCIE); |
1 | ingob | 502 | // TX-Interrupt Freigabe |
1051 | killagreg | 503 | UCSRB |= (1<<TXCIE); |
1 | ingob | 504 | |
1051 | killagreg | 505 | //Teiler wird gesetzt |
1 | ingob | 506 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
507 | //UBRR = 33; |
||
508 | //öffnet einen Kanal für printf (STDOUT) |
||
509 | //fdevopen (uart_putchar, 0); |
||
510 | //sbi(PORTD,4); |
||
1051 | killagreg | 511 | Debug_Timer = SetDelay(DebugDataIntervall); |
512 | Kompass_Timer = SetDelay(220); |
||
513 | |||
1058 | killagreg | 514 | VersionInfo.SWMajor = VERSION_MAJOR; |
515 | VersionInfo.SWMinor = VERSION_MINOR; |
||
516 | VersionInfo.SWPatch = VERSION_PATCH; |
||
517 | VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
||
518 | VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
||
1051 | killagreg | 519 | |
520 | pRxData = 0; |
||
521 | RxDataLen = 0; |
||
1 | ingob | 522 | } |
523 | |||
524 | //--------------------------------------------------------------------------------------------- |
||
1051 | killagreg | 525 | void DatenUebertragung(void) |
1 | ingob | 526 | { |
1415 | killagreg | 527 | if(!UebertragungAbgeschlossen) return; |
1 | ingob | 528 | |
1415 | killagreg | 529 | if(CheckDelay(AboTimeOut)) |
530 | { |
||
531 | Display_Interval = 0; |
||
532 | DebugDataIntervall = 0; |
||
1417 | killagreg | 533 | Intervall3D = 0; |
1415 | killagreg | 534 | } |
535 | |||
1399 | killagreg | 536 | if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen) |
1065 | killagreg | 537 | { |
1399 | killagreg | 538 | if(DisplayLine > 3)// new format |
539 | { |
||
1423 | hbuss | 540 | Menu(); |
1399 | killagreg | 541 | SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80); |
542 | } |
||
543 | else // old format |
||
544 | { |
||
545 | LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!"); |
||
546 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20); |
||
547 | if(DisplayLine++ > 3) DisplayLine = 0; |
||
548 | } |
||
549 | Display_Timer = SetDelay(Display_Interval); |
||
1065 | killagreg | 550 | DebugDisplayAnforderung = 0; |
551 | } |
||
552 | if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen) |
||
553 | { |
||
554 | Menu(); |
||
555 | SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
||
556 | DebugDisplayAnforderung1 = 0; |
||
557 | } |
||
558 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
||
559 | { |
||
560 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
||
561 | GetVersionAnforderung = 0; |
||
562 | } |
||
1 | ingob | 563 | |
1065 | killagreg | 564 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
565 | { |
||
566 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl)); |
||
567 | GetExternalControl = 0; |
||
568 | } |
||
1051 | killagreg | 569 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
693 | hbuss | 570 | { |
1171 | hbuss | 571 | WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
572 | WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
717 | hbuss | 573 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
574 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
||
1054 | killagreg | 575 | SendOutData('w', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
855 | hbuss | 576 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
1051 | killagreg | 577 | Kompass_Timer = SetDelay(99); |
578 | } |
||
1171 | hbuss | 579 | if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
1 | ingob | 580 | { |
1391 | killagreg | 581 | //if(Poti3 > 64) |
1276 | hbuss | 582 | SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
1 | ingob | 583 | DebugDataAnforderung = 0; |
1055 | ingob | 584 | if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall); |
1051 | killagreg | 585 | } |
1171 | hbuss | 586 | if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen) |
587 | { |
||
588 | Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
589 | Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
590 | Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR); |
||
591 | SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D)); |
||
592 | Timer3D = SetDelay(Intervall3D); |
||
593 | } |
||
499 | hbuss | 594 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
595 | { |
||
1054 | killagreg | 596 | SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),(unsigned char *) ANALOG_TEXT[DebugTextAnforderung], 16); |
499 | hbuss | 597 | DebugTextAnforderung = 255; |
598 | } |
||
1051 | killagreg | 599 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
595 | hbuss | 600 | { |
1054 | killagreg | 601 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
1051 | killagreg | 602 | ConfirmFrame = 0; |
595 | hbuss | 603 | } |
1053 | killagreg | 604 | |
1051 | killagreg | 605 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
606 | { |
||
1054 | killagreg | 607 | SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |
1051 | killagreg | 608 | GetPPMChannelAnforderung = 0; |
609 | } |
||
1 | ingob | 610 | |
611 | } |
||
612 |