Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + www.MikroKopter.com |
||
3 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
2050 | holgerb | 4 | // + Software Nutzungsbedingungen (english version: see below) |
5 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
||
6 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
||
2230 | holgerb | 7 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
2050 | holgerb | 8 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
9 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
||
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
11 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
||
12 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
||
13 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
||
14 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
||
15 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
||
16 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
17 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
||
2230 | holgerb | 18 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
2050 | holgerb | 19 | // + des Mitverschuldens offen. |
20 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
||
21 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
22 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
||
23 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
||
24 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
||
25 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
||
26 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
||
27 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
||
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
29 | // + Software LICENSING TERMS |
||
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
31 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
||
2230 | holgerb | 32 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
2050 | holgerb | 33 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
34 | // + The Software may only be used with the Licensor's products. |
||
35 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
||
36 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
||
37 | // + agreement shall be the property of the Licensor. |
||
38 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
||
39 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
||
40 | // + The customer shall be responsible for taking reasonable precautions |
||
41 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
||
42 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
||
43 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
||
44 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
||
45 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
||
46 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
||
47 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
||
48 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
||
49 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
||
50 | // + #### END OF LICENSING TERMS #### |
||
51 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
||
52 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 53 | #include <stdarg.h> |
54 | #include <string.h> |
||
1490 | killagreg | 55 | #include <avr/pgmspace.h> |
1 | ingob | 56 | #include "main.h" |
57 | #include "uart.h" |
||
1438 | ingob | 58 | #include "libfc.h" |
1622 | killagreg | 59 | #include "eeprom.h" |
1 | ingob | 60 | |
1054 | killagreg | 61 | #define FC_ADDRESS 1 |
62 | #define NC_ADDRESS 2 |
||
63 | #define MK3MAG_ADDRESS 3 |
||
1622 | killagreg | 64 | #define BL_CTRL_ADDRESS 5 |
1054 | killagreg | 65 | |
1415 | killagreg | 66 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
2340 | holgerb | 67 | #define MAX_SENDE_BUFF 220 |
68 | #define MAX_EMPFANGS_BUFF 220 |
||
1657 | killagreg | 69 | |
70 | #define BLPARAM_REVISION 1 |
||
71 | #define MASK_SET_PWM_SCALING 0x01 |
||
72 | #define MASK_SET_CURRENT_LIMIT 0x02 |
||
73 | #define MASK_SET_TEMP_LIMIT 0x04 |
||
74 | #define MASK_SET_CURRENT_SCALING 0x08 |
||
75 | #define MASK_SET_BITCONFIG 0x10 |
||
76 | #define MASK_RESET_CAPCOUNTER 0x20 |
||
77 | #define MASK_SET_DEFAULT_PARAMS 0x40 |
||
78 | #define MASK_SET_SAVE_EEPROM 0x80 |
||
79 | |||
1053 | killagreg | 80 | unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0; |
81 | unsigned char DisplayLine = 0; |
||
1 | ingob | 82 | unsigned volatile char SioTmp = 0; |
83 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
||
84 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
||
85 | unsigned volatile char UebertragungAbgeschlossen = 1; |
||
86 | unsigned volatile char CntCrcError = 0; |
||
2496 | holgerb | 87 | unsigned volatile char AnzahlEmpfangsBytes = 0; // achtung: das ist die AscII-Buffer länge, nicht die Nettodatenlänge |
1441 | ingob | 88 | unsigned volatile char TxdBuffer[MAX_SENDE_BUFF]; |
89 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
||
90 | |||
1051 | killagreg | 91 | unsigned char *pRxData = 0; |
92 | unsigned char RxDataLen = 0; |
||
1 | ingob | 93 | unsigned volatile char PC_DebugTimeout = 0; |
1212 | hbuss | 94 | unsigned volatile char PC_MotortestActive = 0; |
1636 | ingob | 95 | unsigned char DebugTextAnforderung = 255; |
1051 | killagreg | 96 | |
1 | ingob | 97 | unsigned char PcZugriff = 100; |
1212 | hbuss | 98 | unsigned char MotorTest[16]; |
1036 | hbuss | 99 | unsigned char MeineSlaveAdresse = 1; // Flight-Ctrl |
595 | hbuss | 100 | unsigned char ConfirmFrame; |
2496 | holgerb | 101 | unsigned char ExternalControlTimeout = 0; |
1 | ingob | 102 | struct str_DebugOut DebugOut; |
2496 | holgerb | 103 | struct str_ExternControl ExternalControl; |
1 | ingob | 104 | struct str_VersionInfo VersionInfo; |
693 | hbuss | 105 | struct str_WinkelOut WinkelOut; |
1171 | hbuss | 106 | struct str_Data3D Data3D; |
1 | ingob | 107 | |
1399 | killagreg | 108 | int Display_Timer, Debug_Timer,Kompass_Timer,Timer3D; |
1415 | killagreg | 109 | unsigned int DebugDataIntervall = 0, Intervall3D = 0, Display_Interval = 0; |
110 | unsigned int AboTimeOut = 0; |
||
1942 | holgerb | 111 | unsigned volatile char ReceiverUpdateModeActive = 0; // 1 = Update 2 = JetiBox-Simulation |
693 | hbuss | 112 | |
1490 | killagreg | 113 | const unsigned char ANALOG_TEXT[32][16] PROGMEM = |
499 | hbuss | 114 | { |
1051 | killagreg | 115 | //1234567890123456 |
1175 | hbuss | 116 | "AngleNick ", //0 |
117 | "AngleRoll ", |
||
1051 | killagreg | 118 | "AccNick ", |
499 | hbuss | 119 | "AccRoll ", |
1523 | holgerb | 120 | "YawGyro ", |
2316 | holgerb | 121 | "Altitude [0.1m] ", //5 |
499 | hbuss | 122 | "AccZ ", |
123 | "Gas ", |
||
1175 | hbuss | 124 | "Compass Value ", |
1528 | holgerb | 125 | "Voltage [0.1V] ", |
1521 | killagreg | 126 | "Receiver Level ", //10 |
127 | "Gyro Compass ", |
||
128 | "Motor 1 ", |
||
129 | "Motor 2 ", |
||
130 | "Motor 3 ", |
||
131 | "Motor 4 ", //15 |
||
2316 | holgerb | 132 | "16 ", |
133 | "17 ", |
||
134 | "18 ", |
||
135 | "19 ", |
||
2230 | holgerb | 136 | "Servo ", //20 |
1521 | killagreg | 137 | "Hovergas ", |
2230 | holgerb | 138 | "Current [0.1A] ", |
1501 | holgerb | 139 | "Capacity [mAh] ", |
1913 | holgerb | 140 | "Height Setpoint ", |
2316 | holgerb | 141 | "25 ", //25 |
142 | "26 ", //"26 CPU OverLoad ", |
||
2437 | holgerb | 143 | "27 ", |
1322 | hbuss | 144 | "I2C-Error ", |
2230 | holgerb | 145 | "BL Limit ", |
720 | ingob | 146 | "GPS_Nick ", //30 |
147 | "GPS_Roll " |
||
499 | hbuss | 148 | }; |
2230 | holgerb | 149 | |
150 | |||
1 | ingob | 151 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
152 | //++ Sende-Part der Datenübertragung |
||
153 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1561 | killagreg | 154 | ISR(USART0_TX_vect) |
1 | ingob | 155 | { |
156 | static unsigned int ptr = 0; |
||
157 | unsigned char tmp_tx; |
||
1783 | killagreg | 158 | |
159 | if(!UebertragungAbgeschlossen) |
||
1 | ingob | 160 | { |
161 | ptr++; // die [0] wurde schon gesendet |
||
1438 | ingob | 162 | tmp_tx = TxdBuffer[ptr]; |
1 | ingob | 163 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
164 | { |
||
165 | ptr = 0; |
||
166 | UebertragungAbgeschlossen = 1; |
||
167 | } |
||
1561 | killagreg | 168 | UDR0 = tmp_tx; |
1051 | killagreg | 169 | } |
1 | ingob | 170 | else ptr = 0; |
171 | } |
||
172 | |||
173 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
174 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
||
175 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1561 | killagreg | 176 | ISR(USART0_RX_vect) |
1 | ingob | 177 | { |
178 | static unsigned int crc; |
||
179 | static unsigned char crc1,crc2,buf_ptr; |
||
180 | static unsigned char UartState = 0; |
||
181 | unsigned char CrcOkay = 0; |
||
182 | |||
2230 | holgerb | 183 | if (ReceiverUpdateModeActive == 1) { UDR1 = UDR0; return; } // 1 = Update |
184 | if (ReceiverUpdateModeActive == 2) { RxdBuffer[0] = UDR0; return; } // 2 = JetiBox-Simulation |
||
1783 | killagreg | 185 | |
1561 | killagreg | 186 | SioTmp = UDR0; |
1783 | killagreg | 187 | |
1438 | ingob | 188 | if(buf_ptr >= MAX_SENDE_BUFF) UartState = 0; |
1051 | killagreg | 189 | if(SioTmp == '\r' && UartState == 2) |
1 | ingob | 190 | { |
191 | UartState = 0; |
||
192 | crc -= RxdBuffer[buf_ptr-2]; |
||
193 | crc -= RxdBuffer[buf_ptr-1]; |
||
194 | crc %= 4096; |
||
195 | crc1 = '=' + crc / 64; |
||
196 | crc2 = '=' + crc % 64; |
||
197 | CrcOkay = 0; |
||
198 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
||
199 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
||
200 | { |
||
1051 | killagreg | 201 | NeuerDatensatzEmpfangen = 1; |
202 | AnzahlEmpfangsBytes = buf_ptr + 1; |
||
1 | ingob | 203 | RxdBuffer[buf_ptr] = '\r'; |
2380 | holgerb | 204 | if(RxdBuffer[2] == 'R' && !MotorenEin) |
1232 | hbuss | 205 | { |
1435 | killagreg | 206 | LcdClear(); |
1232 | hbuss | 207 | wdt_enable(WDTO_250MS); // Reset-Commando |
208 | ServoActive = 0; |
||
1253 | killagreg | 209 | } |
1051 | killagreg | 210 | } |
1 | ingob | 211 | } |
212 | else |
||
213 | switch(UartState) |
||
214 | { |
||
215 | case 0: |
||
216 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
||
217 | buf_ptr = 0; |
||
218 | RxdBuffer[buf_ptr++] = SioTmp; |
||
219 | crc = SioTmp; |
||
220 | break; |
||
221 | case 1: // Adresse auswerten |
||
222 | UartState++; |
||
223 | RxdBuffer[buf_ptr++] = SioTmp; |
||
224 | crc += SioTmp; |
||
225 | break; |
||
226 | case 2: // Eingangsdaten sammeln |
||
227 | RxdBuffer[buf_ptr] = SioTmp; |
||
1490 | killagreg | 228 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
1 | ingob | 229 | else UartState = 0; |
2443 | holgerb | 230 | //if(DebugOut.Analog[] < buf_ptr) DebugOut.Analog[] = buf_ptr; |
1 | ingob | 231 | crc += SioTmp; |
232 | break; |
||
1051 | killagreg | 233 | default: |
234 | UartState = 0; |
||
1 | ingob | 235 | break; |
236 | } |
||
237 | } |
||
238 | |||
239 | |||
240 | // -------------------------------------------------------------------------- |
||
241 | void AddCRC(unsigned int wieviele) |
||
242 | { |
||
1051 | killagreg | 243 | unsigned int tmpCRC = 0,i; |
1 | ingob | 244 | for(i = 0; i < wieviele;i++) |
245 | { |
||
1438 | ingob | 246 | tmpCRC += TxdBuffer[i]; |
1 | ingob | 247 | } |
2340 | holgerb | 248 | // if(i > MAX_SENDE_BUFF - 3) tmpCRC += 11; |
1 | ingob | 249 | tmpCRC %= 4096; |
1438 | ingob | 250 | TxdBuffer[i++] = '=' + tmpCRC / 64; |
251 | TxdBuffer[i++] = '=' + tmpCRC % 64; |
||
252 | TxdBuffer[i++] = '\r'; |
||
1 | ingob | 253 | UebertragungAbgeschlossen = 0; |
1561 | killagreg | 254 | UDR0 = TxdBuffer[0]; |
2340 | holgerb | 255 | //if(DebugOut.Analog[] < i) DebugOut.Analog[] = i; |
1 | ingob | 256 | } |
257 | |||
258 | |||
259 | // -------------------------------------------------------------------------- |
||
1056 | killagreg | 260 | void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len) |
1 | ingob | 261 | { |
1051 | killagreg | 262 | va_list ap; |
1 | ingob | 263 | unsigned int pt = 0; |
264 | unsigned char a,b,c; |
||
265 | unsigned char ptr = 0; |
||
266 | |||
1051 | killagreg | 267 | unsigned char *snd = 0; |
268 | int len = 0; |
||
269 | |||
1438 | ingob | 270 | TxdBuffer[pt++] = '#'; // Startzeichen |
271 | TxdBuffer[pt++] = 'a' + address; // Adresse (a=0; b=1,...) |
||
272 | TxdBuffer[pt++] = cmd; // Commando |
||
1 | ingob | 273 | |
1051 | killagreg | 274 | va_start(ap, BufferAnzahl); |
275 | if(BufferAnzahl) |
||
276 | { |
||
277 | snd = va_arg(ap, unsigned char*); |
||
278 | len = va_arg(ap, int); |
||
279 | ptr = 0; |
||
280 | BufferAnzahl--; |
||
281 | } |
||
1 | ingob | 282 | while(len) |
283 | { |
||
1051 | killagreg | 284 | if(len) |
285 | { |
||
286 | a = snd[ptr++]; |
||
287 | len--; |
||
288 | if((!len) && BufferAnzahl) |
||
289 | { |
||
290 | snd = va_arg(ap, unsigned char*); |
||
291 | len = va_arg(ap, int); |
||
292 | ptr = 0; |
||
293 | BufferAnzahl--; |
||
294 | } |
||
295 | } |
||
296 | else a = 0; |
||
297 | if(len) |
||
298 | { |
||
299 | b = snd[ptr++]; |
||
300 | len--; |
||
301 | if((!len) && BufferAnzahl) |
||
302 | { |
||
303 | snd = va_arg(ap, unsigned char*); |
||
304 | len = va_arg(ap, int); |
||
305 | ptr = 0; |
||
306 | BufferAnzahl--; |
||
307 | } |
||
308 | } |
||
309 | else b = 0; |
||
310 | if(len) |
||
311 | { |
||
312 | c = snd[ptr++]; |
||
313 | len--; |
||
314 | if((!len) && BufferAnzahl) |
||
315 | { |
||
316 | snd = va_arg(ap, unsigned char*); |
||
317 | len = va_arg(ap, int); |
||
318 | ptr = 0; |
||
319 | BufferAnzahl--; |
||
320 | } |
||
321 | } |
||
322 | else c = 0; |
||
1438 | ingob | 323 | TxdBuffer[pt++] = '=' + (a >> 2); |
324 | TxdBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
||
325 | TxdBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
||
326 | TxdBuffer[pt++] = '=' + ( c & 0x3f); |
||
1 | ingob | 327 | } |
1051 | killagreg | 328 | va_end(ap); |
1 | ingob | 329 | AddCRC(pt); |
330 | } |
||
331 | |||
332 | // -------------------------------------------------------------------------- |
||
1051 | killagreg | 333 | void Decode64(void) // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden. |
1 | ingob | 334 | { |
335 | unsigned char a,b,c,d; |
||
2230 | holgerb | 336 | unsigned char x,y,z; |
1051 | killagreg | 337 | unsigned char ptrIn = 3; // start at begin of data block |
338 | unsigned char ptrOut = 3; |
||
339 | 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. |
||
340 | |||
2230 | holgerb | 341 | while(len) |
1 | ingob | 342 | { |
343 | a = RxdBuffer[ptrIn++] - '='; |
||
344 | b = RxdBuffer[ptrIn++] - '='; |
||
345 | c = RxdBuffer[ptrIn++] - '='; |
||
346 | d = RxdBuffer[ptrIn++] - '='; |
||
347 | |||
2230 | holgerb | 348 | x = (a << 2) | (b >> 4); |
349 | y = ((b & 0x0f) << 4) | (c >> 2); |
||
350 | z = ((c & 0x03) << 6) | d; |
||
351 | |||
352 | if(len--) RxdBuffer[ptrOut++] = x; else break; |
||
353 | if(len--) RxdBuffer[ptrOut++] = y; else break; |
||
354 | if(len--) RxdBuffer[ptrOut++] = z; else break; |
||
1 | ingob | 355 | } |
1051 | killagreg | 356 | pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte |
357 | RxDataLen = ptrOut - 3; // wie viele Bytes wurden dekodiert? |
||
1 | ingob | 358 | |
359 | } |
||
360 | |||
361 | // -------------------------------------------------------------------------- |
||
362 | void BearbeiteRxDaten(void) |
||
363 | { |
||
364 | if(!NeuerDatensatzEmpfangen) return; |
||
365 | |||
1665 | killagreg | 366 | unsigned char tempchar1, tempchar2; |
1056 | killagreg | 367 | Decode64(); // dekodiere datenblock im Empfangsbuffer |
1055 | ingob | 368 | switch(RxdBuffer[1]-'a') // check for Slave Address |
1054 | killagreg | 369 | { |
370 | case FC_ADDRESS: // FC special commands |
||
371 | switch(RxdBuffer[2]) |
||
372 | { |
||
373 | case 'K':// Kompasswert |
||
374 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
||
375 | break; |
||
376 | case 't':// Motortest |
||
1212 | hbuss | 377 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
378 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
||
379 | PC_MotortestActive = 240; |
||
1065 | killagreg | 380 | //while(!UebertragungAbgeschlossen); |
381 | //SendOutData('T', MeineSlaveAdresse, 0); |
||
1054 | killagreg | 382 | PcZugriff = 255; |
383 | break; |
||
1053 | killagreg | 384 | |
1209 | hbuss | 385 | case 'n':// "Get Mixer |
386 | while(!UebertragungAbgeschlossen); |
||
1622 | killagreg | 387 | SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer, sizeof(Mixer) - 1); |
1636 | ingob | 388 | Debug("Mixer lesen"); |
1209 | hbuss | 389 | break; |
390 | |||
391 | case 'm':// "Write Mixer |
||
1622 | killagreg | 392 | if(pRxData[0] == EEMIXER_REVISION) |
1521 | killagreg | 393 | { |
1622 | killagreg | 394 | memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer) - 1); |
395 | MixerTable_WriteToEEProm(); |
||
1211 | hbuss | 396 | tempchar1 = 1; |
1765 | killagreg | 397 | VersionInfo.HardwareError[1] &= ~FC_ERROR1_MIXER; |
1521 | killagreg | 398 | } |
1622 | killagreg | 399 | else |
400 | { |
||
401 | tempchar1 = 0; |
||
402 | } |
||
403 | while(!UebertragungAbgeschlossen); |
||
1211 | hbuss | 404 | SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
1209 | hbuss | 405 | break; |
406 | |||
1054 | killagreg | 407 | case 'p': // get PPM Channels |
408 | GetPPMChannelAnforderung = 1; |
||
1377 | hbuss | 409 | PcZugriff = 255; |
1054 | killagreg | 410 | break; |
1053 | killagreg | 411 | |
1054 | killagreg | 412 | case 'q':// "Get"-Anforderung für Settings |
413 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
2416 | holgerb | 414 | if(!MotorenEin) |
415 | { |
||
1761 | killagreg | 416 | if((10 <= pRxData[0]) && (pRxData[0] < 20)) |
1054 | killagreg | 417 | { |
1761 | killagreg | 418 | tempchar1 = pRxData[0] - 10; |
419 | if(tempchar1< 1) tempchar1 = 1; // limit to 1 |
||
420 | else if(tempchar1 > 5) tempchar1 = 5; // limit to 5 |
||
421 | SetDefaultParameter(tempchar1, 1); |
||
1054 | killagreg | 422 | } |
1761 | killagreg | 423 | else if((20 <= pRxData[0]) && (pRxData[0] < 30)) |
424 | { |
||
425 | tempchar1 = pRxData[0] - 20; |
||
426 | if(tempchar1< 1) tempchar1 = 1; // limit to 1 |
||
427 | else if(tempchar1 > 5) tempchar1 = 5; // limit to 5 |
||
428 | SetDefaultParameter(tempchar1, 0); |
||
429 | } |
||
430 | else |
||
431 | { |
||
432 | tempchar1 = pRxData[0]; |
||
433 | if(tempchar1 == 0xFF) |
||
434 | { |
||
435 | tempchar1 = GetActiveParamSet(); |
||
436 | } |
||
437 | if(tempchar1< 1) tempchar1 = 1; // limit to 1 |
||
438 | else if(tempchar1 > 5) tempchar1 = 5; // limit to 5 |
||
439 | // load requested parameter set |
||
440 | ParamSet_ReadFromEEProm(tempchar1); |
||
441 | } |
||
2416 | holgerb | 442 | LipoDetection(0); |
443 | } else tempchar1 = GetActiveParamSet(); |
||
1054 | killagreg | 444 | while(!UebertragungAbgeschlossen); |
1622 | killagreg | 445 | SendOutData('Q', FC_ADDRESS, 2, &tempchar1, sizeof(tempchar1), (unsigned char *) &EE_Parameter, sizeof(EE_Parameter) - 1); |
1636 | ingob | 446 | Debug("Lese Setting %d", tempchar1); |
1054 | killagreg | 447 | break; |
1051 | killagreg | 448 | |
1054 | killagreg | 449 | case 's': // Parametersatz speichern |
1862 | holgerb | 450 | if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EEPARAM_REVISION) && MotorenEin == 0) // check for setting to be in range |
1054 | killagreg | 451 | { |
1622 | killagreg | 452 | memcpy(&EE_Parameter, (uint8_t*)&pRxData[1], sizeof(EE_Parameter) - 1); |
453 | ParamSet_WriteToEEProm(pRxData[0]); |
||
1054 | killagreg | 454 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
455 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
||
1622 | killagreg | 456 | tempchar1 = GetActiveParamSet(); |
1054 | killagreg | 457 | } |
1058 | killagreg | 458 | else |
459 | { |
||
460 | tempchar1 = 0; // mark in response an invlid setting |
||
461 | } |
||
462 | while(!UebertragungAbgeschlossen); |
||
463 | SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
||
2390 | holgerb | 464 | if(!MotorenEin) |
465 | { |
||
466 | Piep(tempchar1,110); |
||
467 | LipoDetection(0); |
||
468 | } |
||
1626 | killagreg | 469 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
1054 | killagreg | 470 | break; |
1405 | hbuss | 471 | case 'f': // auf anderen Parametersatz umschalten |
2340 | holgerb | 472 | if(MotorenEin) break; |
1622 | killagreg | 473 | if((1 <= pRxData[0]) && (pRxData[0] <= 5)) ParamSet_ReadFromEEProm(pRxData[0]); |
474 | tempchar1 = GetActiveParamSet(); |
||
1405 | hbuss | 475 | while(!UebertragungAbgeschlossen); |
476 | SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
||
2390 | holgerb | 477 | if(!MotorenEin) |
478 | { |
||
479 | Piep(tempchar1,110); |
||
480 | LipoDetection(0); |
||
481 | } |
||
1626 | killagreg | 482 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
1405 | hbuss | 483 | break; |
1391 | killagreg | 484 | case 'y':// serial Potis |
2340 | holgerb | 485 | for(tempchar1 = 0; tempchar1 < 12; tempchar1++) PPM_in[SERIAL_POTI_START + tempchar1] = (signed char) pRxData[tempchar1]; |
1391 | killagreg | 486 | break; |
1662 | killagreg | 487 | case 'u': // request BL parameter |
488 | Debug("Reading BL %d", pRxData[0]); |
||
489 | // try to read BL configuration |
||
1665 | killagreg | 490 | tempchar2 = I2C_ReadBLConfig(pRxData[0]); |
1673 | killagreg | 491 | if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1; |
492 | else tempchar1 = 0; |
||
493 | while(!UebertragungAbgeschlossen); // wait for previous frame to be sent |
||
1674 | ingob | 494 | SendOutData('U', FC_ADDRESS, 4, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), &pRxData[0], 1, &BLConfig, sizeof(BLConfig_t)); |
1662 | killagreg | 495 | break; |
496 | case 'w': // write BL parameter |
||
497 | Debug("Writing BL %d", pRxData[0]); |
||
498 | if(RxDataLen >= 1+sizeof(BLConfig_t)) |
||
499 | { |
||
500 | memcpy(&BLConfig, (uint8_t*)(&pRxData[1]), sizeof(BLConfig_t)); |
||
1665 | killagreg | 501 | tempchar2 = I2C_WriteBLConfig(pRxData[0]); |
502 | if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1; |
||
503 | else tempchar1 = 0; // indicate error |
||
1662 | killagreg | 504 | while(!UebertragungAbgeschlossen); // wait for previous frame to be sent |
1665 | killagreg | 505 | SendOutData('W', FC_ADDRESS,2, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2)); |
1662 | killagreg | 506 | } |
507 | break; |
||
1783 | killagreg | 508 | case 'j': |
1942 | holgerb | 509 | if(MotorenEin) break; |
1783 | killagreg | 510 | tempchar1 = LIBFC_GetCPUType(); |
511 | if((tempchar1 == CPU_ATMEGA644P) || (tempchar1 == CPU_ATMEGA1284P)) |
||
1782 | ingob | 512 | { |
1783 | killagreg | 513 | uint16_t ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 38400L) - 1); |
1782 | ingob | 514 | |
1783 | killagreg | 515 | cli(); |
1782 | ingob | 516 | |
1783 | killagreg | 517 | // UART0 & UART1 disable RX and TX-Interrupt |
518 | UCSR0B &= ~((1 << RXCIE0)|(1 << TXCIE0)); |
||
519 | UCSR1B &= ~((1 << RXCIE1)|(1 << TXCIE1)); |
||
520 | |||
521 | // UART0 & UART1 disable receiver and transmitter |
||
522 | UCSR0B &= ~((1 << TXEN0) | (1 << RXEN0)); |
||
523 | UCSR1B &= ~((1 << TXEN1) | (1 << RXEN1)); |
||
524 | |||
525 | // UART0 & UART1 flush receive buffer explicit |
||
526 | while ( UCSR1A & (1<<RXC1) ) UDR1; |
||
527 | while ( UCSR0A & (1<<RXC0) ) UDR0; |
||
528 | |||
529 | |||
1942 | holgerb | 530 | if(pRxData[0] == 1) ReceiverUpdateModeActive = 2; |
531 | else |
||
532 | { // Jeti or HoTT update |
||
533 | //#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
534 | if(pRxData[0] == 100) ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 19200L) - 1); // HoTT |
||
535 | //#endif |
||
536 | ReceiverUpdateModeActive = 1; |
||
1783 | killagreg | 537 | // UART0 & UART1 set baudrate |
538 | UBRR1H = (uint8_t)(ubrr>>8); |
||
539 | UBRR1L = (uint8_t)ubrr; |
||
540 | UBRR0H = UBRR1H; |
||
541 | UBRR0L = UBRR1L; |
||
542 | // UART1 no parity |
||
543 | UCSR1C &= ~(1 << UPM11); |
||
544 | UCSR1C &= ~(1 << UPM10); |
||
545 | // UART1 8-bit |
||
546 | UCSR1B &= ~(1 << UCSZ12); |
||
547 | UCSR1C |= (1 << UCSZ11); |
||
548 | UCSR1C |= (1 << UCSZ10); |
||
549 | } |
||
550 | // UART0 & UART1 1 stop bit |
||
551 | UCSR1C &= ~(1 << USBS1); |
||
552 | UCSR0C &= ~(1 << USBS0); |
||
553 | // UART1 clear 9th bit |
||
554 | UCSR1B &= ~(1<<TXB81); |
||
555 | // enable receiver and transmitter for UART0 and UART1 |
||
556 | UCSR0B |= (1 << TXEN0) | (1 << RXEN0); |
||
557 | UCSR1B |= (1 << TXEN1) | (1 << RXEN1); |
||
558 | // enable RX-Interrupt for UART0 and UART1 |
||
559 | UCSR0B |= (1 << RXCIE0); |
||
560 | UCSR1B |= (1 << RXCIE1); |
||
561 | // disable other Interrupts |
||
562 | TIMSK0 = 0; |
||
563 | TIMSK1 = 0; |
||
564 | TIMSK2 = 0; |
||
565 | |||
566 | sei(); |
||
1777 | ingob | 567 | } |
568 | break; |
||
569 | |||
1056 | killagreg | 570 | } // case FC_ADDRESS: |
1054 | killagreg | 571 | |
572 | default: // any Slave Address |
||
1056 | killagreg | 573 | |
1054 | killagreg | 574 | switch(RxdBuffer[2]) |
575 | { |
||
2437 | holgerb | 576 | #ifdef REDUNDANT_FC_SLAVE |
2418 | holgerb | 577 | static unsigned int clear_I; |
578 | case '?':// Serielle Antwort eines BL-Reglers |
||
579 | tempchar1 = RxdBuffer[1] - ('a'+11); |
||
580 | if(tempchar1 >= MAX_MOTORS) break; |
||
581 | memcpy((unsigned char *)&RedundantMotor[tempchar1], (unsigned char *)pRxData, sizeof(RedundantBl_t)); |
||
582 | if(RedundantMotor[tempchar1].BitSate & BL_BIT_STATE_I2C_OK && clear_I) clear_I--; |
||
2437 | holgerb | 583 | if(!(RedundantMotor[tempchar1].BitSate & BL_BIT_STATE_I2C_OK)) ROT_FLASH; |
584 | GRN_FLASH; |
||
2418 | holgerb | 585 | if(RedundantMotor[tempchar1].BitSate & BL_BIT_STATE_I2C_BAD) |
586 | { |
||
2437 | holgerb | 587 | ROT_ON; |
2418 | holgerb | 588 | if(clear_I == 0) |
589 | { |
||
590 | SummeNick = 0; |
||
591 | SummeRoll = 0; |
||
592 | Mess_Integral_Gier = 0; |
||
593 | } |
||
594 | clear_I = 500; |
||
595 | } |
||
596 | //DebugOut.Analog[16] = RedundantMotor[tempchar1].BitSate; |
||
597 | //DebugOut.Analog[17]++; |
||
598 | //DebugOut.Analog[18] = tempchar1; |
||
599 | break; |
||
2437 | holgerb | 600 | #endif |
1054 | killagreg | 601 | // 't' comand placed here only for compatibility to BL |
602 | case 't':// Motortest |
||
1662 | killagreg | 603 | if(AnzahlEmpfangsBytes >= sizeof(MotorTest)) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
1212 | hbuss | 604 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
1054 | killagreg | 605 | while(!UebertragungAbgeschlossen); |
606 | SendOutData('T', MeineSlaveAdresse, 0); |
||
1212 | hbuss | 607 | PC_MotortestActive = 250; |
1054 | killagreg | 608 | PcZugriff = 255; |
1638 | holgerb | 609 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
1054 | killagreg | 610 | break; |
611 | // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address |
||
612 | case 'K':// Kompasswert |
||
613 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
||
614 | break; |
||
615 | case 'a':// Texte der Analogwerte |
||
616 | DebugTextAnforderung = pRxData[0]; |
||
617 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
||
618 | PcZugriff = 255; |
||
619 | break; |
||
620 | case 'b': |
||
2496 | holgerb | 621 | if(AnzahlEmpfangsBytes < 20) // prevents that the old frame is guilty |
622 | { |
||
623 | memcpy((unsigned char *)&ExternalControl, (unsigned char *)pRxData, sizeof(ExternalControl)); |
||
624 | ConfirmFrame = ExternalControl.Frame; |
||
625 | ExternalControlTimeout = 100; // 2 seconds timeout |
||
626 | } |
||
1054 | killagreg | 627 | break; |
1171 | hbuss | 628 | case 'c': // Poll the 3D-Data |
629 | if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);} |
||
630 | Intervall3D = pRxData[0] * 10; |
||
1417 | killagreg | 631 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
1171 | hbuss | 632 | break; |
1054 | killagreg | 633 | case 'd': // Poll the debug data |
1438 | ingob | 634 | PcZugriff = 255; |
1399 | killagreg | 635 | DebugDataIntervall = (unsigned int)pRxData[0] * 10; |
1171 | hbuss | 636 | if(DebugDataIntervall > 0) DebugDataAnforderung = 1; |
1415 | killagreg | 637 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
1054 | killagreg | 638 | break; |
639 | |||
640 | case 'h':// x-1 Displayzeilen |
||
1059 | hbuss | 641 | PcZugriff = 255; |
1399 | killagreg | 642 | if((pRxData[0] & 0x80) == 0x00) // old format |
643 | { |
||
644 | DisplayLine = 2; |
||
645 | Display_Interval = 0; |
||
646 | } |
||
647 | else // new format |
||
648 | { |
||
649 | RemoteKeys |= ~pRxData[0]; |
||
650 | Display_Interval = (unsigned int)pRxData[1] * 10; |
||
651 | DisplayLine = 4; |
||
1415 | killagreg | 652 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
1399 | killagreg | 653 | } |
1054 | killagreg | 654 | DebugDisplayAnforderung = 1; |
655 | break; |
||
656 | |||
657 | case 'l':// x-1 Displayzeilen |
||
1059 | hbuss | 658 | PcZugriff = 255; |
1054 | killagreg | 659 | MenuePunkt = pRxData[0]; |
660 | DebugDisplayAnforderung1 = 1; |
||
661 | break; |
||
662 | case 'v': // Version-Anforderung und Ausbaustufe |
||
2466 | holgerb | 663 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
664 | if(RxDataLen > 0 && pRxData[0] == 2) GetVersionAnforderung = 2; |
||
665 | else |
||
666 | #endif |
||
1054 | killagreg | 667 | GetVersionAnforderung = 1; |
668 | break; |
||
669 | case 'g':// |
||
670 | GetExternalControl = 1; |
||
671 | break; |
||
1657 | killagreg | 672 | |
673 | default: |
||
674 | //unsupported command received |
||
675 | break; |
||
1054 | killagreg | 676 | } |
677 | break; // default: |
||
678 | } |
||
1051 | killagreg | 679 | NeuerDatensatzEmpfangen = 0; |
680 | pRxData = 0; |
||
681 | RxDataLen = 0; |
||
1 | ingob | 682 | } |
683 | |||
684 | //############################################################################ |
||
685 | //Routine für die Serielle Ausgabe |
||
1444 | ingob | 686 | void uart_putchar (char c) |
1 | ingob | 687 | //############################################################################ |
688 | { |
||
689 | //Warten solange bis Zeichen gesendet wurde |
||
1561 | killagreg | 690 | loop_until_bit_is_set(UCSR0A, UDRE0); |
1 | ingob | 691 | //Ausgabe des Zeichens |
1561 | killagreg | 692 | UDR0 = c; |
1 | ingob | 693 | } |
694 | |||
695 | |||
696 | //############################################################################ |
||
697 | //INstallation der Seriellen Schnittstelle |
||
698 | void UART_Init (void) |
||
699 | //############################################################################ |
||
700 | { |
||
1561 | killagreg | 701 | unsigned int ubrr = (unsigned int) ((unsigned long) F_CPU/(8 * USART0_BAUD) - 1); |
702 | |||
1 | ingob | 703 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
1561 | killagreg | 704 | UCSR0B = (1 << TXEN0) | (1 << RXEN0); |
1 | ingob | 705 | // UART Double Speed (U2X) |
1561 | killagreg | 706 | UCSR0A |= (1 << U2X0); |
1 | ingob | 707 | // RX-Interrupt Freigabe |
1561 | killagreg | 708 | UCSR0B |= (1 << RXCIE0); |
1 | ingob | 709 | // TX-Interrupt Freigabe |
1561 | killagreg | 710 | UCSR0B |= (1 << TXCIE0); |
711 | // USART0 Baud Rate Register |
||
712 | // set clock divider |
||
713 | UBRR0H = (uint8_t)(ubrr >> 8); |
||
714 | UBRR0L = (uint8_t)ubrr; |
||
1 | ingob | 715 | |
1051 | killagreg | 716 | Debug_Timer = SetDelay(DebugDataIntervall); |
717 | Kompass_Timer = SetDelay(220); |
||
718 | |||
1058 | killagreg | 719 | VersionInfo.SWMajor = VERSION_MAJOR; |
720 | VersionInfo.SWMinor = VERSION_MINOR; |
||
721 | VersionInfo.SWPatch = VERSION_PATCH; |
||
722 | VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
||
2342 | holgerb | 723 | VersionInfo.reserved1 = 0; |
2466 | holgerb | 724 | VersionInfo.BL_Firmware = 255; |
2342 | holgerb | 725 | VersionInfo.HWMajor = PlatinenVersion; |
1051 | killagreg | 726 | pRxData = 0; |
727 | RxDataLen = 0; |
||
1 | ingob | 728 | } |
729 | |||
730 | //--------------------------------------------------------------------------------------------- |
||
1051 | killagreg | 731 | void DatenUebertragung(void) |
1 | ingob | 732 | { |
2418 | holgerb | 733 | |
1415 | killagreg | 734 | if(!UebertragungAbgeschlossen) return; |
1 | ingob | 735 | |
1415 | killagreg | 736 | if(CheckDelay(AboTimeOut)) |
737 | { |
||
738 | Display_Interval = 0; |
||
739 | DebugDataIntervall = 0; |
||
1417 | killagreg | 740 | Intervall3D = 0; |
1415 | killagreg | 741 | } |
742 | |||
1399 | killagreg | 743 | if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen) |
1065 | killagreg | 744 | { |
1399 | killagreg | 745 | if(DisplayLine > 3)// new format |
746 | { |
||
1423 | hbuss | 747 | Menu(); |
1399 | killagreg | 748 | SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80); |
749 | } |
||
750 | else // old format |
||
751 | { |
||
752 | LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!"); |
||
753 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20); |
||
754 | if(DisplayLine++ > 3) DisplayLine = 0; |
||
755 | } |
||
756 | Display_Timer = SetDelay(Display_Interval); |
||
1065 | killagreg | 757 | DebugDisplayAnforderung = 0; |
758 | } |
||
759 | if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen) |
||
760 | { |
||
761 | Menu(); |
||
762 | SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
||
763 | DebugDisplayAnforderung1 = 0; |
||
764 | } |
||
765 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
||
766 | { |
||
2466 | holgerb | 767 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
768 | if(GetVersionAnforderung == 2) // poll version of NC |
||
769 | { |
||
770 | struct str_VersionInfo nc; |
||
771 | nc.SWMajor = NC_Version.Major; |
||
772 | nc.SWMinor = NC_Version.Minor; |
||
773 | nc.SWPatch = NC_Version.Patch; |
||
774 | nc.HWMajor = NC_Version.Hardware; |
||
775 | nc.HardwareError[0] = 0xff; |
||
776 | nc.HardwareError[1] = 0xff; |
||
777 | nc.ProtoMajor = VersionInfo.ProtoMajor; |
||
778 | nc.BL_Firmware = VersionInfo.BL_Firmware; |
||
779 | nc.Flags = VersionInfo.Flags; |
||
780 | nc.reserved1 = 0; |
||
781 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &nc, sizeof(nc)); |
||
782 | } |
||
783 | else |
||
784 | #endif |
||
785 | { |
||
786 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
||
787 | } |
||
1065 | killagreg | 788 | GetVersionAnforderung = 0; |
1636 | ingob | 789 | Debug_OK("Version gesendet"); |
1065 | killagreg | 790 | } |
1 | ingob | 791 | |
1065 | killagreg | 792 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
793 | { |
||
2496 | holgerb | 794 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternalControl, sizeof(ExternalControl)); |
1065 | killagreg | 795 | GetExternalControl = 0; |
796 | } |
||
1171 | hbuss | 797 | if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
1 | ingob | 798 | { |
1639 | holgerb | 799 | CopyDebugValues(); |
1276 | hbuss | 800 | SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
1 | ingob | 801 | DebugDataAnforderung = 0; |
1055 | ingob | 802 | if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall); |
1051 | killagreg | 803 | } |
1171 | hbuss | 804 | if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen) |
805 | { |
||
2373 | holgerb | 806 | Data3D.Winkel[0] = ToNaviCtrl.IntegralNick;//(int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
807 | Data3D.Winkel[1] = ToNaviCtrl.IntegralRoll;//(int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
1171 | hbuss | 808 | Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR); |
1685 | holgerb | 809 | Data3D.Centroid[0] = SummeNick >> 9; |
810 | Data3D.Centroid[1] = SummeRoll >> 9; |
||
811 | Data3D.Centroid[2] = Mess_Integral_Gier >> 9; |
||
1171 | hbuss | 812 | SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D)); |
813 | Timer3D = SetDelay(Intervall3D); |
||
814 | } |
||
499 | hbuss | 815 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
816 | { |
||
1490 | killagreg | 817 | unsigned char label[16]; // local sram buffer |
818 | memcpy_P(label, ANALOG_TEXT[DebugTextAnforderung], 16); // read lable from flash to sra |
||
819 | SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),label, 16); |
||
499 | hbuss | 820 | DebugTextAnforderung = 255; |
821 | } |
||
1051 | killagreg | 822 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
595 | hbuss | 823 | { |
1054 | killagreg | 824 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
1051 | killagreg | 825 | ConfirmFrame = 0; |
595 | hbuss | 826 | } |
1051 | killagreg | 827 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
828 | { |
||
1054 | killagreg | 829 | SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |
1051 | killagreg | 830 | GetPPMChannelAnforderung = 0; |
831 | } |
||
2427 | holgerb | 832 | #ifndef REDUNDANT_FC_SLAVE |
2346 | holgerb | 833 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
834 | { |
||
2425 | holgerb | 835 | if(!NaviDataOkay) // no external compass needed |
836 | { |
||
837 | WinkelOut.Winkel[0] = ToNaviCtrl.IntegralNick;//(int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
838 | WinkelOut.Winkel[1] = ToNaviCtrl.IntegralRoll;//(int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
839 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
||
840 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
||
841 | SendOutData('k', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
||
842 | } |
||
2346 | holgerb | 843 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
2416 | holgerb | 844 | if(JustMK3MagConnected) Kompass_Timer = SetDelay(99); |
2346 | holgerb | 845 | else Kompass_Timer = SetDelay(999); |
846 | } |
||
2418 | holgerb | 847 | #endif |
848 | |||
2427 | holgerb | 849 | #ifdef REDUNDANT_FC_SLAVE |
2514 | holgerb | 850 | //if(UebertragungAbgeschlossen || MotorenEin) |
851 | if(UebertragungAbgeschlossen && (CheckDelay(Kompass_Timer) || MotorenEin)) |
||
2418 | holgerb | 852 | { |
2452 | holgerb | 853 | static unsigned char who, request; |
2418 | holgerb | 854 | unsigned char SendRedundantMotor[MAX_MOTORS], i; |
2452 | holgerb | 855 | if(!request) { who = (who+1) % RequiredMotors; request = 1;} // nur in jedem 2. Zykus abfragen, weil die Antwort zu lang ist |
856 | else request = 0; |
||
2418 | holgerb | 857 | for(i=0; i<RequiredMotors; i++) |
858 | { |
||
2452 | holgerb | 859 | if(request) SendRedundantMotor[0] = who+1; |
860 | else SendRedundantMotor[0] = 0; |
||
2418 | holgerb | 861 | if(PC_MotortestActive) SendRedundantMotor[0] |= 0x80; |
862 | SendRedundantMotor[i+1] = Motor[i].SetPoint; |
||
863 | } |
||
864 | SendOutData('!', FC_ADDRESS, 1, (unsigned char *) &SendRedundantMotor, RequiredMotors+1); |
||
2514 | holgerb | 865 | Kompass_Timer = SetDelay(25); |
2418 | holgerb | 866 | } |
867 | #endif |
||
868 | |||
1636 | ingob | 869 | #ifdef DEBUG // only include functions if DEBUG is defined |
870 | if(SendDebugOutput && UebertragungAbgeschlossen) |
||
871 | { |
||
872 | SendOutData('0', FC_ADDRESS, 1, (unsigned char *) &tDebug, sizeof(tDebug)); |
||
873 | SendDebugOutput = 0; |
||
874 | } |
||
1654 | killagreg | 875 | #endif |
1 | ingob | 876 | } |
877 | |||
1636 | ingob | 878 |