Rev 2516 | Rev 2526 | Go to most recent revision | Details | Compare with Previous | 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; |
||
2516 | 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; |
2516 | holgerb | 101 | unsigned char ExternalControlTimeout = 0; |
1 | ingob | 102 | struct str_DebugOut DebugOut; |
2516 | 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 | |
2518 | holgerb | 150 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
151 | //++ Calculate checksum |
||
152 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
153 | unsigned char CalculateDebugLableCrc(void) |
||
154 | { |
||
155 | unsigned int i; |
||
156 | unsigned char crc = 0; |
||
157 | for(i=0;i<sizeof(ANALOG_TEXT);i++) crc += pgm_read_word(&ANALOG_TEXT[0][i]); |
||
158 | return(crc); |
||
159 | } |
||
2230 | holgerb | 160 | |
1 | ingob | 161 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
162 | //++ Sende-Part der Datenübertragung |
||
163 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1561 | killagreg | 164 | ISR(USART0_TX_vect) |
1 | ingob | 165 | { |
166 | static unsigned int ptr = 0; |
||
167 | unsigned char tmp_tx; |
||
1783 | killagreg | 168 | |
169 | if(!UebertragungAbgeschlossen) |
||
1 | ingob | 170 | { |
171 | ptr++; // die [0] wurde schon gesendet |
||
1438 | ingob | 172 | tmp_tx = TxdBuffer[ptr]; |
1 | ingob | 173 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
174 | { |
||
175 | ptr = 0; |
||
176 | UebertragungAbgeschlossen = 1; |
||
177 | } |
||
1561 | killagreg | 178 | UDR0 = tmp_tx; |
1051 | killagreg | 179 | } |
2518 | holgerb | 180 | else ptr = 0; |
1 | ingob | 181 | } |
182 | |||
183 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
184 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
||
185 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1561 | killagreg | 186 | ISR(USART0_RX_vect) |
1 | ingob | 187 | { |
188 | static unsigned int crc; |
||
189 | static unsigned char crc1,crc2,buf_ptr; |
||
190 | static unsigned char UartState = 0; |
||
191 | unsigned char CrcOkay = 0; |
||
192 | |||
2230 | holgerb | 193 | if (ReceiverUpdateModeActive == 1) { UDR1 = UDR0; return; } // 1 = Update |
194 | if (ReceiverUpdateModeActive == 2) { RxdBuffer[0] = UDR0; return; } // 2 = JetiBox-Simulation |
||
1783 | killagreg | 195 | |
1561 | killagreg | 196 | SioTmp = UDR0; |
1783 | killagreg | 197 | |
1438 | ingob | 198 | if(buf_ptr >= MAX_SENDE_BUFF) UartState = 0; |
1051 | killagreg | 199 | if(SioTmp == '\r' && UartState == 2) |
1 | ingob | 200 | { |
201 | UartState = 0; |
||
202 | crc -= RxdBuffer[buf_ptr-2]; |
||
203 | crc -= RxdBuffer[buf_ptr-1]; |
||
204 | crc %= 4096; |
||
205 | crc1 = '=' + crc / 64; |
||
206 | crc2 = '=' + crc % 64; |
||
207 | CrcOkay = 0; |
||
208 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
||
209 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
||
210 | { |
||
1051 | killagreg | 211 | NeuerDatensatzEmpfangen = 1; |
212 | AnzahlEmpfangsBytes = buf_ptr + 1; |
||
1 | ingob | 213 | RxdBuffer[buf_ptr] = '\r'; |
2380 | holgerb | 214 | if(RxdBuffer[2] == 'R' && !MotorenEin) |
1232 | hbuss | 215 | { |
1435 | killagreg | 216 | LcdClear(); |
1232 | hbuss | 217 | wdt_enable(WDTO_250MS); // Reset-Commando |
218 | ServoActive = 0; |
||
1253 | killagreg | 219 | } |
1051 | killagreg | 220 | } |
1 | ingob | 221 | } |
222 | else |
||
223 | switch(UartState) |
||
224 | { |
||
225 | case 0: |
||
226 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
||
227 | buf_ptr = 0; |
||
228 | RxdBuffer[buf_ptr++] = SioTmp; |
||
229 | crc = SioTmp; |
||
230 | break; |
||
231 | case 1: // Adresse auswerten |
||
232 | UartState++; |
||
233 | RxdBuffer[buf_ptr++] = SioTmp; |
||
234 | crc += SioTmp; |
||
235 | break; |
||
236 | case 2: // Eingangsdaten sammeln |
||
237 | RxdBuffer[buf_ptr] = SioTmp; |
||
1490 | killagreg | 238 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
1 | ingob | 239 | else UartState = 0; |
2443 | holgerb | 240 | //if(DebugOut.Analog[] < buf_ptr) DebugOut.Analog[] = buf_ptr; |
1 | ingob | 241 | crc += SioTmp; |
242 | break; |
||
1051 | killagreg | 243 | default: |
244 | UartState = 0; |
||
1 | ingob | 245 | break; |
246 | } |
||
247 | } |
||
248 | |||
249 | |||
250 | // -------------------------------------------------------------------------- |
||
251 | void AddCRC(unsigned int wieviele) |
||
252 | { |
||
1051 | killagreg | 253 | unsigned int tmpCRC = 0,i; |
1 | ingob | 254 | for(i = 0; i < wieviele;i++) |
255 | { |
||
1438 | ingob | 256 | tmpCRC += TxdBuffer[i]; |
1 | ingob | 257 | } |
2340 | holgerb | 258 | // if(i > MAX_SENDE_BUFF - 3) tmpCRC += 11; |
1 | ingob | 259 | tmpCRC %= 4096; |
1438 | ingob | 260 | TxdBuffer[i++] = '=' + tmpCRC / 64; |
261 | TxdBuffer[i++] = '=' + tmpCRC % 64; |
||
262 | TxdBuffer[i++] = '\r'; |
||
1 | ingob | 263 | UebertragungAbgeschlossen = 0; |
1561 | killagreg | 264 | UDR0 = TxdBuffer[0]; |
2340 | holgerb | 265 | //if(DebugOut.Analog[] < i) DebugOut.Analog[] = i; |
1 | ingob | 266 | } |
267 | |||
268 | |||
269 | // -------------------------------------------------------------------------- |
||
1056 | killagreg | 270 | void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len) |
1 | ingob | 271 | { |
1051 | killagreg | 272 | va_list ap; |
1 | ingob | 273 | unsigned int pt = 0; |
274 | unsigned char a,b,c; |
||
275 | unsigned char ptr = 0; |
||
276 | |||
1051 | killagreg | 277 | unsigned char *snd = 0; |
278 | int len = 0; |
||
279 | |||
1438 | ingob | 280 | TxdBuffer[pt++] = '#'; // Startzeichen |
281 | TxdBuffer[pt++] = 'a' + address; // Adresse (a=0; b=1,...) |
||
282 | TxdBuffer[pt++] = cmd; // Commando |
||
1 | ingob | 283 | |
1051 | killagreg | 284 | va_start(ap, BufferAnzahl); |
285 | if(BufferAnzahl) |
||
286 | { |
||
287 | snd = va_arg(ap, unsigned char*); |
||
288 | len = va_arg(ap, int); |
||
289 | ptr = 0; |
||
290 | BufferAnzahl--; |
||
291 | } |
||
1 | ingob | 292 | while(len) |
293 | { |
||
1051 | killagreg | 294 | if(len) |
295 | { |
||
296 | a = snd[ptr++]; |
||
297 | len--; |
||
298 | if((!len) && BufferAnzahl) |
||
299 | { |
||
300 | snd = va_arg(ap, unsigned char*); |
||
301 | len = va_arg(ap, int); |
||
302 | ptr = 0; |
||
303 | BufferAnzahl--; |
||
304 | } |
||
305 | } |
||
306 | else a = 0; |
||
307 | if(len) |
||
308 | { |
||
309 | b = snd[ptr++]; |
||
310 | len--; |
||
311 | if((!len) && BufferAnzahl) |
||
312 | { |
||
313 | snd = va_arg(ap, unsigned char*); |
||
314 | len = va_arg(ap, int); |
||
315 | ptr = 0; |
||
316 | BufferAnzahl--; |
||
317 | } |
||
318 | } |
||
319 | else b = 0; |
||
320 | if(len) |
||
321 | { |
||
322 | c = snd[ptr++]; |
||
323 | len--; |
||
324 | if((!len) && BufferAnzahl) |
||
325 | { |
||
326 | snd = va_arg(ap, unsigned char*); |
||
327 | len = va_arg(ap, int); |
||
328 | ptr = 0; |
||
329 | BufferAnzahl--; |
||
330 | } |
||
331 | } |
||
332 | else c = 0; |
||
1438 | ingob | 333 | TxdBuffer[pt++] = '=' + (a >> 2); |
334 | TxdBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
||
335 | TxdBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
||
336 | TxdBuffer[pt++] = '=' + ( c & 0x3f); |
||
1 | ingob | 337 | } |
1051 | killagreg | 338 | va_end(ap); |
1 | ingob | 339 | AddCRC(pt); |
340 | } |
||
341 | |||
342 | // -------------------------------------------------------------------------- |
||
1051 | killagreg | 343 | void Decode64(void) // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden. |
1 | ingob | 344 | { |
345 | unsigned char a,b,c,d; |
||
2230 | holgerb | 346 | unsigned char x,y,z; |
1051 | killagreg | 347 | unsigned char ptrIn = 3; // start at begin of data block |
348 | unsigned char ptrOut = 3; |
||
349 | 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. |
||
350 | |||
2230 | holgerb | 351 | while(len) |
1 | ingob | 352 | { |
353 | a = RxdBuffer[ptrIn++] - '='; |
||
354 | b = RxdBuffer[ptrIn++] - '='; |
||
355 | c = RxdBuffer[ptrIn++] - '='; |
||
356 | d = RxdBuffer[ptrIn++] - '='; |
||
357 | |||
2230 | holgerb | 358 | x = (a << 2) | (b >> 4); |
359 | y = ((b & 0x0f) << 4) | (c >> 2); |
||
360 | z = ((c & 0x03) << 6) | d; |
||
361 | |||
362 | if(len--) RxdBuffer[ptrOut++] = x; else break; |
||
363 | if(len--) RxdBuffer[ptrOut++] = y; else break; |
||
364 | if(len--) RxdBuffer[ptrOut++] = z; else break; |
||
1 | ingob | 365 | } |
1051 | killagreg | 366 | pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte |
367 | RxDataLen = ptrOut - 3; // wie viele Bytes wurden dekodiert? |
||
1 | ingob | 368 | |
369 | } |
||
370 | |||
371 | // -------------------------------------------------------------------------- |
||
372 | void BearbeiteRxDaten(void) |
||
373 | { |
||
374 | if(!NeuerDatensatzEmpfangen) return; |
||
375 | |||
1665 | killagreg | 376 | unsigned char tempchar1, tempchar2; |
1056 | killagreg | 377 | Decode64(); // dekodiere datenblock im Empfangsbuffer |
1055 | ingob | 378 | switch(RxdBuffer[1]-'a') // check for Slave Address |
1054 | killagreg | 379 | { |
380 | case FC_ADDRESS: // FC special commands |
||
381 | switch(RxdBuffer[2]) |
||
382 | { |
||
383 | case 'K':// Kompasswert |
||
384 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
||
385 | break; |
||
386 | case 't':// Motortest |
||
1212 | hbuss | 387 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
388 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
||
389 | PC_MotortestActive = 240; |
||
1065 | killagreg | 390 | //while(!UebertragungAbgeschlossen); |
391 | //SendOutData('T', MeineSlaveAdresse, 0); |
||
1054 | killagreg | 392 | PcZugriff = 255; |
393 | break; |
||
1053 | killagreg | 394 | |
1209 | hbuss | 395 | case 'n':// "Get Mixer |
396 | while(!UebertragungAbgeschlossen); |
||
1622 | killagreg | 397 | SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer, sizeof(Mixer) - 1); |
1636 | ingob | 398 | Debug("Mixer lesen"); |
1209 | hbuss | 399 | break; |
400 | |||
401 | case 'm':// "Write Mixer |
||
1622 | killagreg | 402 | if(pRxData[0] == EEMIXER_REVISION) |
1521 | killagreg | 403 | { |
1622 | killagreg | 404 | memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer) - 1); |
405 | MixerTable_WriteToEEProm(); |
||
1211 | hbuss | 406 | tempchar1 = 1; |
1765 | killagreg | 407 | VersionInfo.HardwareError[1] &= ~FC_ERROR1_MIXER; |
1521 | killagreg | 408 | } |
1622 | killagreg | 409 | else |
410 | { |
||
411 | tempchar1 = 0; |
||
412 | } |
||
413 | while(!UebertragungAbgeschlossen); |
||
1211 | hbuss | 414 | SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
1209 | hbuss | 415 | break; |
416 | |||
1054 | killagreg | 417 | case 'p': // get PPM Channels |
418 | GetPPMChannelAnforderung = 1; |
||
1377 | hbuss | 419 | PcZugriff = 255; |
1054 | killagreg | 420 | break; |
1053 | killagreg | 421 | |
1054 | killagreg | 422 | case 'q':// "Get"-Anforderung für Settings |
423 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
2416 | holgerb | 424 | if(!MotorenEin) |
425 | { |
||
1761 | killagreg | 426 | if((10 <= pRxData[0]) && (pRxData[0] < 20)) |
1054 | killagreg | 427 | { |
1761 | killagreg | 428 | tempchar1 = pRxData[0] - 10; |
429 | if(tempchar1< 1) tempchar1 = 1; // limit to 1 |
||
430 | else if(tempchar1 > 5) tempchar1 = 5; // limit to 5 |
||
431 | SetDefaultParameter(tempchar1, 1); |
||
1054 | killagreg | 432 | } |
1761 | killagreg | 433 | else if((20 <= pRxData[0]) && (pRxData[0] < 30)) |
434 | { |
||
435 | tempchar1 = pRxData[0] - 20; |
||
436 | if(tempchar1< 1) tempchar1 = 1; // limit to 1 |
||
437 | else if(tempchar1 > 5) tempchar1 = 5; // limit to 5 |
||
438 | SetDefaultParameter(tempchar1, 0); |
||
439 | } |
||
440 | else |
||
441 | { |
||
442 | tempchar1 = pRxData[0]; |
||
443 | if(tempchar1 == 0xFF) |
||
444 | { |
||
445 | tempchar1 = GetActiveParamSet(); |
||
446 | } |
||
447 | if(tempchar1< 1) tempchar1 = 1; // limit to 1 |
||
448 | else if(tempchar1 > 5) tempchar1 = 5; // limit to 5 |
||
449 | // load requested parameter set |
||
450 | ParamSet_ReadFromEEProm(tempchar1); |
||
451 | } |
||
2416 | holgerb | 452 | LipoDetection(0); |
453 | } else tempchar1 = GetActiveParamSet(); |
||
1054 | killagreg | 454 | while(!UebertragungAbgeschlossen); |
1622 | killagreg | 455 | SendOutData('Q', FC_ADDRESS, 2, &tempchar1, sizeof(tempchar1), (unsigned char *) &EE_Parameter, sizeof(EE_Parameter) - 1); |
1636 | ingob | 456 | Debug("Lese Setting %d", tempchar1); |
1054 | killagreg | 457 | break; |
1051 | killagreg | 458 | |
1054 | killagreg | 459 | case 's': // Parametersatz speichern |
1862 | holgerb | 460 | if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EEPARAM_REVISION) && MotorenEin == 0) // check for setting to be in range |
1054 | killagreg | 461 | { |
1622 | killagreg | 462 | memcpy(&EE_Parameter, (uint8_t*)&pRxData[1], sizeof(EE_Parameter) - 1); |
463 | ParamSet_WriteToEEProm(pRxData[0]); |
||
1054 | killagreg | 464 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
465 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
||
1622 | killagreg | 466 | tempchar1 = GetActiveParamSet(); |
1054 | killagreg | 467 | } |
1058 | killagreg | 468 | else |
469 | { |
||
470 | tempchar1 = 0; // mark in response an invlid setting |
||
471 | } |
||
472 | while(!UebertragungAbgeschlossen); |
||
473 | SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
||
2390 | holgerb | 474 | if(!MotorenEin) |
475 | { |
||
476 | Piep(tempchar1,110); |
||
477 | LipoDetection(0); |
||
478 | } |
||
1626 | killagreg | 479 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
1054 | killagreg | 480 | break; |
1405 | hbuss | 481 | case 'f': // auf anderen Parametersatz umschalten |
2340 | holgerb | 482 | if(MotorenEin) break; |
1622 | killagreg | 483 | if((1 <= pRxData[0]) && (pRxData[0] <= 5)) ParamSet_ReadFromEEProm(pRxData[0]); |
484 | tempchar1 = GetActiveParamSet(); |
||
1405 | hbuss | 485 | while(!UebertragungAbgeschlossen); |
486 | SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
||
2390 | holgerb | 487 | if(!MotorenEin) |
488 | { |
||
489 | Piep(tempchar1,110); |
||
490 | LipoDetection(0); |
||
491 | } |
||
1626 | killagreg | 492 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
1405 | hbuss | 493 | break; |
1391 | killagreg | 494 | case 'y':// serial Potis |
2340 | holgerb | 495 | for(tempchar1 = 0; tempchar1 < 12; tempchar1++) PPM_in[SERIAL_POTI_START + tempchar1] = (signed char) pRxData[tempchar1]; |
1391 | killagreg | 496 | break; |
1662 | killagreg | 497 | case 'u': // request BL parameter |
498 | Debug("Reading BL %d", pRxData[0]); |
||
499 | // try to read BL configuration |
||
1665 | killagreg | 500 | tempchar2 = I2C_ReadBLConfig(pRxData[0]); |
1673 | killagreg | 501 | if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1; |
502 | else tempchar1 = 0; |
||
503 | while(!UebertragungAbgeschlossen); // wait for previous frame to be sent |
||
1674 | ingob | 504 | SendOutData('U', FC_ADDRESS, 4, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), &pRxData[0], 1, &BLConfig, sizeof(BLConfig_t)); |
1662 | killagreg | 505 | break; |
506 | case 'w': // write BL parameter |
||
507 | Debug("Writing BL %d", pRxData[0]); |
||
508 | if(RxDataLen >= 1+sizeof(BLConfig_t)) |
||
509 | { |
||
510 | memcpy(&BLConfig, (uint8_t*)(&pRxData[1]), sizeof(BLConfig_t)); |
||
1665 | killagreg | 511 | tempchar2 = I2C_WriteBLConfig(pRxData[0]); |
512 | if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1; |
||
513 | else tempchar1 = 0; // indicate error |
||
1662 | killagreg | 514 | while(!UebertragungAbgeschlossen); // wait for previous frame to be sent |
1665 | killagreg | 515 | SendOutData('W', FC_ADDRESS,2, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2)); |
1662 | killagreg | 516 | } |
517 | break; |
||
1783 | killagreg | 518 | case 'j': |
1942 | holgerb | 519 | if(MotorenEin) break; |
1783 | killagreg | 520 | tempchar1 = LIBFC_GetCPUType(); |
521 | if((tempchar1 == CPU_ATMEGA644P) || (tempchar1 == CPU_ATMEGA1284P)) |
||
1782 | ingob | 522 | { |
1783 | killagreg | 523 | uint16_t ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 38400L) - 1); |
1782 | ingob | 524 | |
1783 | killagreg | 525 | cli(); |
1782 | ingob | 526 | |
1783 | killagreg | 527 | // UART0 & UART1 disable RX and TX-Interrupt |
528 | UCSR0B &= ~((1 << RXCIE0)|(1 << TXCIE0)); |
||
529 | UCSR1B &= ~((1 << RXCIE1)|(1 << TXCIE1)); |
||
530 | |||
531 | // UART0 & UART1 disable receiver and transmitter |
||
532 | UCSR0B &= ~((1 << TXEN0) | (1 << RXEN0)); |
||
533 | UCSR1B &= ~((1 << TXEN1) | (1 << RXEN1)); |
||
534 | |||
535 | // UART0 & UART1 flush receive buffer explicit |
||
536 | while ( UCSR1A & (1<<RXC1) ) UDR1; |
||
537 | while ( UCSR0A & (1<<RXC0) ) UDR0; |
||
538 | |||
539 | |||
1942 | holgerb | 540 | if(pRxData[0] == 1) ReceiverUpdateModeActive = 2; |
541 | else |
||
542 | { // Jeti or HoTT update |
||
543 | //#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
544 | if(pRxData[0] == 100) ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 19200L) - 1); // HoTT |
||
545 | //#endif |
||
546 | ReceiverUpdateModeActive = 1; |
||
1783 | killagreg | 547 | // UART0 & UART1 set baudrate |
548 | UBRR1H = (uint8_t)(ubrr>>8); |
||
549 | UBRR1L = (uint8_t)ubrr; |
||
550 | UBRR0H = UBRR1H; |
||
551 | UBRR0L = UBRR1L; |
||
552 | // UART1 no parity |
||
553 | UCSR1C &= ~(1 << UPM11); |
||
554 | UCSR1C &= ~(1 << UPM10); |
||
555 | // UART1 8-bit |
||
556 | UCSR1B &= ~(1 << UCSZ12); |
||
557 | UCSR1C |= (1 << UCSZ11); |
||
558 | UCSR1C |= (1 << UCSZ10); |
||
559 | } |
||
560 | // UART0 & UART1 1 stop bit |
||
561 | UCSR1C &= ~(1 << USBS1); |
||
562 | UCSR0C &= ~(1 << USBS0); |
||
563 | // UART1 clear 9th bit |
||
564 | UCSR1B &= ~(1<<TXB81); |
||
565 | // enable receiver and transmitter for UART0 and UART1 |
||
566 | UCSR0B |= (1 << TXEN0) | (1 << RXEN0); |
||
567 | UCSR1B |= (1 << TXEN1) | (1 << RXEN1); |
||
568 | // enable RX-Interrupt for UART0 and UART1 |
||
569 | UCSR0B |= (1 << RXCIE0); |
||
570 | UCSR1B |= (1 << RXCIE1); |
||
571 | // disable other Interrupts |
||
572 | TIMSK0 = 0; |
||
573 | TIMSK1 = 0; |
||
574 | TIMSK2 = 0; |
||
575 | |||
576 | sei(); |
||
1777 | ingob | 577 | } |
578 | break; |
||
579 | |||
1056 | killagreg | 580 | } // case FC_ADDRESS: |
1054 | killagreg | 581 | |
582 | default: // any Slave Address |
||
1056 | killagreg | 583 | |
1054 | killagreg | 584 | switch(RxdBuffer[2]) |
585 | { |
||
2437 | holgerb | 586 | #ifdef REDUNDANT_FC_SLAVE |
2418 | holgerb | 587 | static unsigned int clear_I; |
588 | case '?':// Serielle Antwort eines BL-Reglers |
||
589 | tempchar1 = RxdBuffer[1] - ('a'+11); |
||
590 | if(tempchar1 >= MAX_MOTORS) break; |
||
591 | memcpy((unsigned char *)&RedundantMotor[tempchar1], (unsigned char *)pRxData, sizeof(RedundantBl_t)); |
||
592 | if(RedundantMotor[tempchar1].BitSate & BL_BIT_STATE_I2C_OK && clear_I) clear_I--; |
||
2437 | holgerb | 593 | if(!(RedundantMotor[tempchar1].BitSate & BL_BIT_STATE_I2C_OK)) ROT_FLASH; |
594 | GRN_FLASH; |
||
2418 | holgerb | 595 | if(RedundantMotor[tempchar1].BitSate & BL_BIT_STATE_I2C_BAD) |
596 | { |
||
2437 | holgerb | 597 | ROT_ON; |
2418 | holgerb | 598 | if(clear_I == 0) |
599 | { |
||
600 | SummeNick = 0; |
||
601 | SummeRoll = 0; |
||
602 | Mess_Integral_Gier = 0; |
||
603 | } |
||
604 | clear_I = 500; |
||
605 | } |
||
606 | //DebugOut.Analog[16] = RedundantMotor[tempchar1].BitSate; |
||
607 | //DebugOut.Analog[17]++; |
||
608 | //DebugOut.Analog[18] = tempchar1; |
||
609 | break; |
||
2437 | holgerb | 610 | #endif |
1054 | killagreg | 611 | // 't' comand placed here only for compatibility to BL |
612 | case 't':// Motortest |
||
1662 | killagreg | 613 | if(AnzahlEmpfangsBytes >= sizeof(MotorTest)) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
1212 | hbuss | 614 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
1054 | killagreg | 615 | while(!UebertragungAbgeschlossen); |
616 | SendOutData('T', MeineSlaveAdresse, 0); |
||
1212 | hbuss | 617 | PC_MotortestActive = 250; |
1054 | killagreg | 618 | PcZugriff = 255; |
1638 | holgerb | 619 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
1054 | killagreg | 620 | break; |
621 | // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address |
||
622 | case 'K':// Kompasswert |
||
623 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
||
624 | break; |
||
625 | case 'a':// Texte der Analogwerte |
||
626 | DebugTextAnforderung = pRxData[0]; |
||
627 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
||
628 | PcZugriff = 255; |
||
629 | break; |
||
630 | case 'b': |
||
2516 | holgerb | 631 | if(AnzahlEmpfangsBytes < 20) // prevents that the old frame is guilty |
632 | { |
||
633 | memcpy((unsigned char *)&ExternalControl, (unsigned char *)pRxData, sizeof(ExternalControl)); |
||
634 | ConfirmFrame = ExternalControl.Frame; |
||
635 | ExternalControlTimeout = 100; // 2 seconds timeout |
||
636 | } |
||
1054 | killagreg | 637 | break; |
1171 | hbuss | 638 | case 'c': // Poll the 3D-Data |
639 | if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);} |
||
640 | Intervall3D = pRxData[0] * 10; |
||
1417 | killagreg | 641 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
1171 | hbuss | 642 | break; |
1054 | killagreg | 643 | case 'd': // Poll the debug data |
1438 | ingob | 644 | PcZugriff = 255; |
1399 | killagreg | 645 | DebugDataIntervall = (unsigned int)pRxData[0] * 10; |
1171 | hbuss | 646 | if(DebugDataIntervall > 0) DebugDataAnforderung = 1; |
1415 | killagreg | 647 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
1054 | killagreg | 648 | break; |
649 | |||
650 | case 'h':// x-1 Displayzeilen |
||
1059 | hbuss | 651 | PcZugriff = 255; |
1399 | killagreg | 652 | if((pRxData[0] & 0x80) == 0x00) // old format |
653 | { |
||
654 | DisplayLine = 2; |
||
655 | Display_Interval = 0; |
||
656 | } |
||
657 | else // new format |
||
658 | { |
||
659 | RemoteKeys |= ~pRxData[0]; |
||
660 | Display_Interval = (unsigned int)pRxData[1] * 10; |
||
661 | DisplayLine = 4; |
||
1415 | killagreg | 662 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
1399 | killagreg | 663 | } |
1054 | killagreg | 664 | DebugDisplayAnforderung = 1; |
665 | break; |
||
666 | |||
667 | case 'l':// x-1 Displayzeilen |
||
1059 | hbuss | 668 | PcZugriff = 255; |
1054 | killagreg | 669 | MenuePunkt = pRxData[0]; |
670 | DebugDisplayAnforderung1 = 1; |
||
671 | break; |
||
672 | case 'v': // Version-Anforderung und Ausbaustufe |
||
2466 | holgerb | 673 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
674 | if(RxDataLen > 0 && pRxData[0] == 2) GetVersionAnforderung = 2; |
||
675 | else |
||
676 | #endif |
||
1054 | killagreg | 677 | GetVersionAnforderung = 1; |
678 | break; |
||
679 | case 'g':// |
||
680 | GetExternalControl = 1; |
||
681 | break; |
||
1657 | killagreg | 682 | |
683 | default: |
||
684 | //unsupported command received |
||
685 | break; |
||
1054 | killagreg | 686 | } |
687 | break; // default: |
||
688 | } |
||
1051 | killagreg | 689 | NeuerDatensatzEmpfangen = 0; |
690 | pRxData = 0; |
||
691 | RxDataLen = 0; |
||
1 | ingob | 692 | } |
693 | |||
694 | //############################################################################ |
||
695 | //Routine für die Serielle Ausgabe |
||
1444 | ingob | 696 | void uart_putchar (char c) |
1 | ingob | 697 | //############################################################################ |
698 | { |
||
699 | //Warten solange bis Zeichen gesendet wurde |
||
1561 | killagreg | 700 | loop_until_bit_is_set(UCSR0A, UDRE0); |
1 | ingob | 701 | //Ausgabe des Zeichens |
1561 | killagreg | 702 | UDR0 = c; |
1 | ingob | 703 | } |
704 | |||
705 | //############################################################################ |
||
706 | //INstallation der Seriellen Schnittstelle |
||
707 | void UART_Init (void) |
||
708 | //############################################################################ |
||
709 | { |
||
1561 | killagreg | 710 | unsigned int ubrr = (unsigned int) ((unsigned long) F_CPU/(8 * USART0_BAUD) - 1); |
711 | |||
1 | ingob | 712 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
1561 | killagreg | 713 | UCSR0B = (1 << TXEN0) | (1 << RXEN0); |
1 | ingob | 714 | // UART Double Speed (U2X) |
1561 | killagreg | 715 | UCSR0A |= (1 << U2X0); |
1 | ingob | 716 | // RX-Interrupt Freigabe |
1561 | killagreg | 717 | UCSR0B |= (1 << RXCIE0); |
1 | ingob | 718 | // TX-Interrupt Freigabe |
1561 | killagreg | 719 | UCSR0B |= (1 << TXCIE0); |
720 | // USART0 Baud Rate Register |
||
721 | // set clock divider |
||
722 | UBRR0H = (uint8_t)(ubrr >> 8); |
||
723 | UBRR0L = (uint8_t)ubrr; |
||
1 | ingob | 724 | |
1051 | killagreg | 725 | Debug_Timer = SetDelay(DebugDataIntervall); |
726 | Kompass_Timer = SetDelay(220); |
||
727 | |||
1058 | killagreg | 728 | VersionInfo.SWMajor = VERSION_MAJOR; |
729 | VersionInfo.SWMinor = VERSION_MINOR; |
||
730 | VersionInfo.SWPatch = VERSION_PATCH; |
||
731 | VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
||
2466 | holgerb | 732 | VersionInfo.BL_Firmware = 255; |
2342 | holgerb | 733 | VersionInfo.HWMajor = PlatinenVersion; |
2518 | holgerb | 734 | VersionInfo.LabelTextCRC = CalculateDebugLableCrc(); |
1051 | killagreg | 735 | pRxData = 0; |
736 | RxDataLen = 0; |
||
1 | ingob | 737 | } |
738 | |||
739 | //--------------------------------------------------------------------------------------------- |
||
1051 | killagreg | 740 | void DatenUebertragung(void) |
1 | ingob | 741 | { |
2418 | holgerb | 742 | |
1415 | killagreg | 743 | if(!UebertragungAbgeschlossen) return; |
1 | ingob | 744 | |
1415 | killagreg | 745 | if(CheckDelay(AboTimeOut)) |
746 | { |
||
747 | Display_Interval = 0; |
||
748 | DebugDataIntervall = 0; |
||
1417 | killagreg | 749 | Intervall3D = 0; |
1415 | killagreg | 750 | } |
751 | |||
1399 | killagreg | 752 | if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen) |
1065 | killagreg | 753 | { |
1399 | killagreg | 754 | if(DisplayLine > 3)// new format |
755 | { |
||
1423 | hbuss | 756 | Menu(); |
1399 | killagreg | 757 | SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80); |
758 | } |
||
759 | else // old format |
||
760 | { |
||
761 | LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!"); |
||
762 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20); |
||
763 | if(DisplayLine++ > 3) DisplayLine = 0; |
||
764 | } |
||
765 | Display_Timer = SetDelay(Display_Interval); |
||
1065 | killagreg | 766 | DebugDisplayAnforderung = 0; |
767 | } |
||
768 | if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen) |
||
769 | { |
||
770 | Menu(); |
||
771 | SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
||
772 | DebugDisplayAnforderung1 = 0; |
||
773 | } |
||
774 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
||
775 | { |
||
2466 | holgerb | 776 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
777 | if(GetVersionAnforderung == 2) // poll version of NC |
||
778 | { |
||
779 | struct str_VersionInfo nc; |
||
780 | nc.SWMajor = NC_Version.Major; |
||
781 | nc.SWMinor = NC_Version.Minor; |
||
782 | nc.SWPatch = NC_Version.Patch; |
||
783 | nc.HWMajor = NC_Version.Hardware; |
||
784 | nc.HardwareError[0] = 0xff; |
||
785 | nc.HardwareError[1] = 0xff; |
||
786 | nc.ProtoMajor = VersionInfo.ProtoMajor; |
||
787 | nc.BL_Firmware = VersionInfo.BL_Firmware; |
||
788 | nc.Flags = VersionInfo.Flags; |
||
2518 | holgerb | 789 | //nc.reserved1 = 0; |
2466 | holgerb | 790 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &nc, sizeof(nc)); |
791 | } |
||
792 | else |
||
793 | #endif |
||
794 | { |
||
795 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
||
796 | } |
||
1065 | killagreg | 797 | GetVersionAnforderung = 0; |
1636 | ingob | 798 | Debug_OK("Version gesendet"); |
1065 | killagreg | 799 | } |
1 | ingob | 800 | |
1065 | killagreg | 801 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
802 | { |
||
2516 | holgerb | 803 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternalControl, sizeof(ExternalControl)); |
1065 | killagreg | 804 | GetExternalControl = 0; |
805 | } |
||
1171 | hbuss | 806 | if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
1 | ingob | 807 | { |
1639 | holgerb | 808 | CopyDebugValues(); |
1276 | hbuss | 809 | SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
1 | ingob | 810 | DebugDataAnforderung = 0; |
1055 | ingob | 811 | if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall); |
1051 | killagreg | 812 | } |
1171 | hbuss | 813 | if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen) |
814 | { |
||
2373 | holgerb | 815 | Data3D.Winkel[0] = ToNaviCtrl.IntegralNick;//(int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
816 | Data3D.Winkel[1] = ToNaviCtrl.IntegralRoll;//(int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
1171 | hbuss | 817 | Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR); |
1685 | holgerb | 818 | Data3D.Centroid[0] = SummeNick >> 9; |
819 | Data3D.Centroid[1] = SummeRoll >> 9; |
||
820 | Data3D.Centroid[2] = Mess_Integral_Gier >> 9; |
||
2518 | holgerb | 821 | Data3D.AccZ = Aktuell_az; |
1171 | hbuss | 822 | SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D)); |
823 | Timer3D = SetDelay(Intervall3D); |
||
824 | } |
||
499 | hbuss | 825 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
826 | { |
||
1490 | killagreg | 827 | unsigned char label[16]; // local sram buffer |
828 | memcpy_P(label, ANALOG_TEXT[DebugTextAnforderung], 16); // read lable from flash to sra |
||
829 | SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),label, 16); |
||
499 | hbuss | 830 | DebugTextAnforderung = 255; |
831 | } |
||
1051 | killagreg | 832 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
595 | hbuss | 833 | { |
1054 | killagreg | 834 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
1051 | killagreg | 835 | ConfirmFrame = 0; |
595 | hbuss | 836 | } |
1051 | killagreg | 837 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
838 | { |
||
1054 | killagreg | 839 | SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |
1051 | killagreg | 840 | GetPPMChannelAnforderung = 0; |
841 | } |
||
2427 | holgerb | 842 | #ifndef REDUNDANT_FC_SLAVE |
2346 | holgerb | 843 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
844 | { |
||
2425 | holgerb | 845 | if(!NaviDataOkay) // no external compass needed |
846 | { |
||
847 | WinkelOut.Winkel[0] = ToNaviCtrl.IntegralNick;//(int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
848 | WinkelOut.Winkel[1] = ToNaviCtrl.IntegralRoll;//(int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
||
849 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
||
850 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
||
851 | SendOutData('k', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
||
852 | } |
||
2346 | holgerb | 853 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
2416 | holgerb | 854 | if(JustMK3MagConnected) Kompass_Timer = SetDelay(99); |
2346 | holgerb | 855 | else Kompass_Timer = SetDelay(999); |
856 | } |
||
2418 | holgerb | 857 | #endif |
858 | |||
2427 | holgerb | 859 | #ifdef REDUNDANT_FC_SLAVE |
2514 | holgerb | 860 | //if(UebertragungAbgeschlossen || MotorenEin) |
861 | if(UebertragungAbgeschlossen && (CheckDelay(Kompass_Timer) || MotorenEin)) |
||
2418 | holgerb | 862 | { |
2452 | holgerb | 863 | static unsigned char who, request; |
2418 | holgerb | 864 | unsigned char SendRedundantMotor[MAX_MOTORS], i; |
2452 | holgerb | 865 | if(!request) { who = (who+1) % RequiredMotors; request = 1;} // nur in jedem 2. Zykus abfragen, weil die Antwort zu lang ist |
866 | else request = 0; |
||
2418 | holgerb | 867 | for(i=0; i<RequiredMotors; i++) |
868 | { |
||
2452 | holgerb | 869 | if(request) SendRedundantMotor[0] = who+1; |
870 | else SendRedundantMotor[0] = 0; |
||
2418 | holgerb | 871 | if(PC_MotortestActive) SendRedundantMotor[0] |= 0x80; |
872 | SendRedundantMotor[i+1] = Motor[i].SetPoint; |
||
873 | } |
||
874 | SendOutData('!', FC_ADDRESS, 1, (unsigned char *) &SendRedundantMotor, RequiredMotors+1); |
||
2516 | holgerb | 875 | Kompass_Timer = SetDelay(25); |
2418 | holgerb | 876 | } |
877 | #endif |
||
878 | |||
1636 | ingob | 879 | #ifdef DEBUG // only include functions if DEBUG is defined |
880 | if(SendDebugOutput && UebertragungAbgeschlossen) |
||
881 | { |
||
882 | SendOutData('0', FC_ADDRESS, 1, (unsigned char *) &tDebug, sizeof(tDebug)); |
||
883 | SendDebugOutput = 0; |
||
884 | } |
||
1654 | killagreg | 885 | #endif |
1 | ingob | 886 | } |
887 | |||
1636 | ingob | 888 |