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