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