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 | { |
138 | wdt_enable(WDTO_250MS); // Reset-Commando |
||
139 | ServoActive = 0; |
||
1253 | killagreg | 140 | } |
1051 | killagreg | 141 | } |
1 | ingob | 142 | } |
143 | else |
||
144 | switch(UartState) |
||
145 | { |
||
146 | case 0: |
||
147 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
||
148 | buf_ptr = 0; |
||
149 | RxdBuffer[buf_ptr++] = SioTmp; |
||
150 | crc = SioTmp; |
||
151 | break; |
||
152 | case 1: // Adresse auswerten |
||
153 | UartState++; |
||
154 | RxdBuffer[buf_ptr++] = SioTmp; |
||
155 | crc += SioTmp; |
||
156 | break; |
||
157 | case 2: // Eingangsdaten sammeln |
||
158 | RxdBuffer[buf_ptr] = SioTmp; |
||
1051 | killagreg | 159 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
1 | ingob | 160 | else UartState = 0; |
161 | crc += SioTmp; |
||
162 | break; |
||
1051 | killagreg | 163 | default: |
164 | UartState = 0; |
||
1 | ingob | 165 | break; |
166 | } |
||
167 | } |
||
168 | |||
169 | |||
170 | // -------------------------------------------------------------------------- |
||
171 | void AddCRC(unsigned int wieviele) |
||
172 | { |
||
1051 | killagreg | 173 | unsigned int tmpCRC = 0,i; |
1 | ingob | 174 | for(i = 0; i < wieviele;i++) |
175 | { |
||
176 | tmpCRC += SendeBuffer[i]; |
||
177 | } |
||
178 | tmpCRC %= 4096; |
||
179 | SendeBuffer[i++] = '=' + tmpCRC / 64; |
||
180 | SendeBuffer[i++] = '=' + tmpCRC % 64; |
||
181 | SendeBuffer[i++] = '\r'; |
||
182 | UebertragungAbgeschlossen = 0; |
||
183 | UDR = SendeBuffer[0]; |
||
184 | } |
||
185 | |||
186 | |||
187 | |||
188 | // -------------------------------------------------------------------------- |
||
1056 | killagreg | 189 | void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len) |
1 | ingob | 190 | { |
1051 | killagreg | 191 | va_list ap; |
1 | ingob | 192 | unsigned int pt = 0; |
193 | unsigned char a,b,c; |
||
194 | unsigned char ptr = 0; |
||
195 | |||
1051 | killagreg | 196 | unsigned char *snd = 0; |
197 | int len = 0; |
||
198 | |||
1056 | killagreg | 199 | SendeBuffer[pt++] = '#'; // Startzeichen |
200 | SendeBuffer[pt++] = 'a' + address; // Adresse (a=0; b=1,...) |
||
201 | SendeBuffer[pt++] = cmd; // Commando |
||
1 | ingob | 202 | |
1051 | killagreg | 203 | va_start(ap, BufferAnzahl); |
204 | if(BufferAnzahl) |
||
205 | { |
||
206 | snd = va_arg(ap, unsigned char*); |
||
207 | len = va_arg(ap, int); |
||
208 | ptr = 0; |
||
209 | BufferAnzahl--; |
||
210 | } |
||
1 | ingob | 211 | while(len) |
212 | { |
||
1051 | killagreg | 213 | if(len) |
214 | { |
||
215 | a = snd[ptr++]; |
||
216 | len--; |
||
217 | if((!len) && BufferAnzahl) |
||
218 | { |
||
219 | snd = va_arg(ap, unsigned char*); |
||
220 | len = va_arg(ap, int); |
||
221 | ptr = 0; |
||
222 | BufferAnzahl--; |
||
223 | } |
||
224 | } |
||
225 | else a = 0; |
||
226 | if(len) |
||
227 | { |
||
228 | b = snd[ptr++]; |
||
229 | len--; |
||
230 | if((!len) && BufferAnzahl) |
||
231 | { |
||
232 | snd = va_arg(ap, unsigned char*); |
||
233 | len = va_arg(ap, int); |
||
234 | ptr = 0; |
||
235 | BufferAnzahl--; |
||
236 | } |
||
237 | } |
||
238 | else b = 0; |
||
239 | if(len) |
||
240 | { |
||
241 | c = snd[ptr++]; |
||
242 | len--; |
||
243 | if((!len) && BufferAnzahl) |
||
244 | { |
||
245 | snd = va_arg(ap, unsigned char*); |
||
246 | len = va_arg(ap, int); |
||
247 | ptr = 0; |
||
248 | BufferAnzahl--; |
||
249 | } |
||
250 | } |
||
251 | else c = 0; |
||
1 | ingob | 252 | SendeBuffer[pt++] = '=' + (a >> 2); |
253 | SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
||
254 | SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
||
255 | SendeBuffer[pt++] = '=' + ( c & 0x3f); |
||
256 | } |
||
1051 | killagreg | 257 | va_end(ap); |
1 | ingob | 258 | AddCRC(pt); |
259 | } |
||
260 | |||
261 | |||
262 | // -------------------------------------------------------------------------- |
||
1051 | killagreg | 263 | void Decode64(void) // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden. |
1 | ingob | 264 | { |
265 | unsigned char a,b,c,d; |
||
266 | unsigned char x,y,z; |
||
1051 | killagreg | 267 | unsigned char ptrIn = 3; // start at begin of data block |
268 | unsigned char ptrOut = 3; |
||
269 | 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. |
||
270 | |||
1 | ingob | 271 | while(len) |
272 | { |
||
273 | a = RxdBuffer[ptrIn++] - '='; |
||
274 | b = RxdBuffer[ptrIn++] - '='; |
||
275 | c = RxdBuffer[ptrIn++] - '='; |
||
276 | d = RxdBuffer[ptrIn++] - '='; |
||
277 | |||
278 | x = (a << 2) | (b >> 4); |
||
279 | y = ((b & 0x0f) << 4) | (c >> 2); |
||
280 | z = ((c & 0x03) << 6) | d; |
||
281 | |||
1051 | killagreg | 282 | if(len--) RxdBuffer[ptrOut++] = x; else break; |
283 | if(len--) RxdBuffer[ptrOut++] = y; else break; |
||
284 | if(len--) RxdBuffer[ptrOut++] = z; else break; |
||
1 | ingob | 285 | } |
1051 | killagreg | 286 | pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte |
287 | RxDataLen = ptrOut - 3; // wie viele Bytes wurden dekodiert? |
||
1 | ingob | 288 | |
289 | } |
||
290 | |||
291 | // -------------------------------------------------------------------------- |
||
292 | void BearbeiteRxDaten(void) |
||
293 | { |
||
294 | if(!NeuerDatensatzEmpfangen) return; |
||
295 | |||
1058 | killagreg | 296 | unsigned char tempchar1, tempchar2; |
1056 | killagreg | 297 | Decode64(); // dekodiere datenblock im Empfangsbuffer |
1055 | ingob | 298 | switch(RxdBuffer[1]-'a') // check for Slave Address |
1054 | killagreg | 299 | { |
300 | case FC_ADDRESS: // FC special commands |
||
301 | switch(RxdBuffer[2]) |
||
302 | { |
||
303 | case 'K':// Kompasswert |
||
304 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
||
305 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
||
306 | break; |
||
307 | case 't':// Motortest |
||
1212 | hbuss | 308 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
309 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
||
310 | PC_MotortestActive = 240; |
||
1065 | killagreg | 311 | //while(!UebertragungAbgeschlossen); |
312 | //SendOutData('T', MeineSlaveAdresse, 0); |
||
1054 | killagreg | 313 | PcZugriff = 255; |
314 | break; |
||
1053 | killagreg | 315 | |
1209 | hbuss | 316 | case 'n':// "Get Mixer |
317 | while(!UebertragungAbgeschlossen); |
||
318 | SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer,sizeof(Mixer)); |
||
319 | break; |
||
320 | |||
321 | case 'm':// "Write Mixer |
||
322 | while(!UebertragungAbgeschlossen); |
||
1211 | hbuss | 323 | if(pRxData[0] == MIXER_REVISION) |
324 | { |
||
325 | memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer)); |
||
326 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
||
327 | tempchar1 = 1; |
||
328 | } |
||
329 | else tempchar1 = 0; |
||
330 | SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
||
1209 | hbuss | 331 | break; |
332 | |||
1054 | killagreg | 333 | case 'p': // get PPM Channels |
334 | GetPPMChannelAnforderung = 1; |
||
1377 | hbuss | 335 | PcZugriff = 255; |
1054 | killagreg | 336 | break; |
1053 | killagreg | 337 | |
1054 | killagreg | 338 | case 'q':// "Get"-Anforderung für Settings |
339 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
340 | if(pRxData[0] == 0xFF) |
||
341 | { |
||
342 | pRxData[0] = GetActiveParamSetNumber(); |
||
343 | } |
||
1063 | killagreg | 344 | // limit settings range |
345 | if(pRxData[0] < 1) pRxData[0] = 1; // limit to 5 |
||
346 | else if(pRxData[0] > 5) pRxData[0] = 5; // limit to 5 |
||
347 | // load requested parameter set |
||
348 | ReadParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
349 | |||
1054 | killagreg | 350 | while(!UebertragungAbgeschlossen); |
1058 | killagreg | 351 | tempchar1 = pRxData[0]; |
352 | tempchar2 = EE_DATENREVISION; |
||
353 | SendOutData('Q', FC_ADDRESS, 3, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
1054 | killagreg | 354 | break; |
1051 | killagreg | 355 | |
1054 | killagreg | 356 | case 's': // Parametersatz speichern |
1058 | killagreg | 357 | if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EE_DATENREVISION)) // check for setting to be in range |
1054 | killagreg | 358 | { |
1058 | killagreg | 359 | memcpy((unsigned char *) &EE_Parameter.Kanalbelegung[0], (unsigned char *)&pRxData[2], STRUCT_PARAM_LAENGE); |
1054 | killagreg | 360 | WriteParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
361 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
||
362 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
||
1063 | killagreg | 363 | SetActiveParamSetNumber(pRxData[0]); |
364 | tempchar1 = GetActiveParamSetNumber(); |
||
1054 | killagreg | 365 | } |
1058 | killagreg | 366 | else |
367 | { |
||
368 | tempchar1 = 0; // mark in response an invlid setting |
||
369 | } |
||
370 | while(!UebertragungAbgeschlossen); |
||
371 | SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
||
1405 | hbuss | 372 | if(!MotorenEin) Piep(tempchar1,110); |
373 | LipoDetection(0); |
||
1054 | killagreg | 374 | break; |
1405 | hbuss | 375 | case 'f': // auf anderen Parametersatz umschalten |
376 | if((1 <= pRxData[0]) && (pRxData[0] <= 5)) SetActiveParamSetNumber(pRxData[0]); |
||
377 | tempchar1 = pRxData[0]; |
||
378 | while(!UebertragungAbgeschlossen); |
||
379 | SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
||
380 | if(!MotorenEin) Piep(tempchar1,110); |
||
381 | LipoDetection(0); |
||
382 | break; |
||
1391 | killagreg | 383 | case 'y':// serial Potis |
384 | 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]; |
||
385 | 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]; |
||
386 | 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]; |
||
387 | break; |
||
388 | |||
1056 | killagreg | 389 | } // case FC_ADDRESS: |
1054 | killagreg | 390 | |
391 | default: // any Slave Address |
||
1056 | killagreg | 392 | |
1054 | killagreg | 393 | switch(RxdBuffer[2]) |
394 | { |
||
395 | // 't' comand placed here only for compatibility to BL |
||
396 | case 't':// Motortest |
||
1212 | hbuss | 397 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
398 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
||
1054 | killagreg | 399 | while(!UebertragungAbgeschlossen); |
400 | SendOutData('T', MeineSlaveAdresse, 0); |
||
1212 | hbuss | 401 | PC_MotortestActive = 250; |
1054 | killagreg | 402 | PcZugriff = 255; |
403 | break; |
||
404 | // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address |
||
405 | case 'K':// Kompasswert |
||
406 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
||
407 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
||
408 | break; |
||
409 | case 'a':// Texte der Analogwerte |
||
410 | DebugTextAnforderung = pRxData[0]; |
||
411 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
||
412 | PcZugriff = 255; |
||
413 | break; |
||
414 | case 'b': |
||
415 | memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl)); |
||
416 | ConfirmFrame = ExternControl.Frame; |
||
417 | PcZugriff = 255; |
||
418 | break; |
||
1171 | hbuss | 419 | case 'c': // Poll the 3D-Data |
420 | if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);} |
||
421 | Intervall3D = pRxData[0] * 10; |
||
1417 | killagreg | 422 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
1171 | hbuss | 423 | break; |
1054 | killagreg | 424 | case 'd': // Poll the debug data |
1399 | killagreg | 425 | DebugDataIntervall = (unsigned int)pRxData[0] * 10; |
1171 | hbuss | 426 | if(DebugDataIntervall > 0) DebugDataAnforderung = 1; |
1415 | killagreg | 427 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
1054 | killagreg | 428 | break; |
429 | |||
430 | case 'h':// x-1 Displayzeilen |
||
1059 | hbuss | 431 | PcZugriff = 255; |
1399 | killagreg | 432 | if((pRxData[0] & 0x80) == 0x00) // old format |
433 | { |
||
434 | DisplayLine = 2; |
||
435 | Display_Interval = 0; |
||
436 | } |
||
437 | else // new format |
||
438 | { |
||
439 | RemoteKeys |= ~pRxData[0]; |
||
440 | Display_Interval = (unsigned int)pRxData[1] * 10; |
||
441 | DisplayLine = 4; |
||
1415 | killagreg | 442 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
1399 | killagreg | 443 | } |
1054 | killagreg | 444 | DebugDisplayAnforderung = 1; |
445 | break; |
||
446 | |||
447 | case 'l':// x-1 Displayzeilen |
||
1059 | hbuss | 448 | PcZugriff = 255; |
1054 | killagreg | 449 | MenuePunkt = pRxData[0]; |
450 | DebugDisplayAnforderung1 = 1; |
||
451 | break; |
||
452 | case 'v': // Version-Anforderung und Ausbaustufe |
||
453 | GetVersionAnforderung = 1; |
||
454 | break; |
||
455 | |||
456 | case 'g':// |
||
457 | GetExternalControl = 1; |
||
458 | break; |
||
459 | } |
||
460 | break; // default: |
||
461 | } |
||
1051 | killagreg | 462 | NeuerDatensatzEmpfangen = 0; |
463 | pRxData = 0; |
||
464 | RxDataLen = 0; |
||
1 | ingob | 465 | } |
466 | |||
467 | //############################################################################ |
||
468 | //Routine für die Serielle Ausgabe |
||
469 | int uart_putchar (char c) |
||
470 | //############################################################################ |
||
471 | { |
||
472 | if (c == '\n') |
||
473 | uart_putchar('\r'); |
||
474 | //Warten solange bis Zeichen gesendet wurde |
||
475 | loop_until_bit_is_set(USR, UDRE); |
||
476 | //Ausgabe des Zeichens |
||
477 | UDR = c; |
||
1051 | killagreg | 478 | |
1 | ingob | 479 | return (0); |
480 | } |
||
481 | |||
482 | // -------------------------------------------------------------------------- |
||
483 | void WriteProgramData(unsigned int pos, unsigned char wert) |
||
484 | { |
||
485 | //if (ProgramLocation == IN_RAM) Buffer[pos] = wert; |
||
486 | // else eeprom_write_byte(&EE_Buffer[pos], wert); |
||
487 | // Buffer[pos] = wert; |
||
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 | { |
||
540 | Menu(); |
||
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 |