Rev 2408 | Rev 2418 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2408 | Rev 2416 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + www.MikroKopter.com |
2 | // + www.MikroKopter.com |
3 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // + Software Nutzungsbedingungen (english version: see below) |
4 | // + Software Nutzungsbedingungen (english version: see below) |
5 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
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 |
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 |
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. |
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. |
9 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
11 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
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. |
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 |
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. |
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 |
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. |
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 |
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 |
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. |
19 | // + des Mitverschuldens offen. |
20 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
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. |
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. |
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 |
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. |
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. |
25 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
26 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
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. |
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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // + Software LICENSING TERMS |
29 | // + Software LICENSING TERMS |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
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 |
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*. |
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. |
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 |
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 |
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. |
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 |
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. |
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 |
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 |
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 |
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 |
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. |
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 |
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. |
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 |
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. |
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. |
49 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
50 | // + #### END OF LICENSING TERMS #### |
50 | // + #### END OF LICENSING TERMS #### |
51 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
51 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
52 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
53 | #include <stdarg.h> |
53 | #include <stdarg.h> |
54 | #include <string.h> |
54 | #include <string.h> |
55 | #include <avr/pgmspace.h> |
55 | #include <avr/pgmspace.h> |
56 | #include "main.h" |
56 | #include "main.h" |
57 | #include "uart.h" |
57 | #include "uart.h" |
58 | #include "libfc.h" |
58 | #include "libfc.h" |
59 | #include "eeprom.h" |
59 | #include "eeprom.h" |
60 | 60 | ||
61 | #define FC_ADDRESS 1 |
61 | #define FC_ADDRESS 1 |
62 | #define NC_ADDRESS 2 |
62 | #define NC_ADDRESS 2 |
63 | #define MK3MAG_ADDRESS 3 |
63 | #define MK3MAG_ADDRESS 3 |
64 | #define BL_CTRL_ADDRESS 5 |
64 | #define BL_CTRL_ADDRESS 5 |
65 | 65 | ||
66 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
66 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
67 | #define MAX_SENDE_BUFF 220 |
67 | #define MAX_SENDE_BUFF 220 |
68 | #define MAX_EMPFANGS_BUFF 220 |
68 | #define MAX_EMPFANGS_BUFF 220 |
69 | 69 | ||
70 | #define BLPARAM_REVISION 1 |
70 | #define BLPARAM_REVISION 1 |
71 | #define MASK_SET_PWM_SCALING 0x01 |
71 | #define MASK_SET_PWM_SCALING 0x01 |
72 | #define MASK_SET_CURRENT_LIMIT 0x02 |
72 | #define MASK_SET_CURRENT_LIMIT 0x02 |
73 | #define MASK_SET_TEMP_LIMIT 0x04 |
73 | #define MASK_SET_TEMP_LIMIT 0x04 |
74 | #define MASK_SET_CURRENT_SCALING 0x08 |
74 | #define MASK_SET_CURRENT_SCALING 0x08 |
75 | #define MASK_SET_BITCONFIG 0x10 |
75 | #define MASK_SET_BITCONFIG 0x10 |
76 | #define MASK_RESET_CAPCOUNTER 0x20 |
76 | #define MASK_RESET_CAPCOUNTER 0x20 |
77 | #define MASK_SET_DEFAULT_PARAMS 0x40 |
77 | #define MASK_SET_DEFAULT_PARAMS 0x40 |
78 | #define MASK_SET_SAVE_EEPROM 0x80 |
78 | #define MASK_SET_SAVE_EEPROM 0x80 |
79 | 79 | ||
80 | unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0; |
80 | unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0; |
81 | unsigned char DisplayLine = 0; |
81 | unsigned char DisplayLine = 0; |
82 | unsigned volatile char SioTmp = 0; |
82 | unsigned volatile char SioTmp = 0; |
83 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
83 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
84 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
84 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
85 | unsigned volatile char UebertragungAbgeschlossen = 1; |
85 | unsigned volatile char UebertragungAbgeschlossen = 1; |
86 | unsigned volatile char CntCrcError = 0; |
86 | unsigned volatile char CntCrcError = 0; |
87 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
87 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
88 | unsigned volatile char TxdBuffer[MAX_SENDE_BUFF]; |
88 | unsigned volatile char TxdBuffer[MAX_SENDE_BUFF]; |
89 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
89 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
90 | 90 | ||
91 | unsigned char *pRxData = 0; |
91 | unsigned char *pRxData = 0; |
92 | unsigned char RxDataLen = 0; |
92 | unsigned char RxDataLen = 0; |
93 | unsigned volatile char PC_DebugTimeout = 0; |
93 | unsigned volatile char PC_DebugTimeout = 0; |
94 | unsigned volatile char PC_MotortestActive = 0; |
94 | unsigned volatile char PC_MotortestActive = 0; |
95 | unsigned char DebugTextAnforderung = 255; |
95 | unsigned char DebugTextAnforderung = 255; |
96 | 96 | ||
97 | unsigned char PcZugriff = 100; |
97 | unsigned char PcZugriff = 100; |
98 | unsigned char MotorTest[16]; |
98 | unsigned char MotorTest[16]; |
99 | unsigned char MeineSlaveAdresse = 1; // Flight-Ctrl |
99 | unsigned char MeineSlaveAdresse = 1; // Flight-Ctrl |
100 | unsigned char ConfirmFrame; |
100 | unsigned char ConfirmFrame; |
101 | struct str_DebugOut DebugOut; |
101 | struct str_DebugOut DebugOut; |
102 | struct str_ExternControl ExternControl; |
102 | struct str_ExternControl ExternControl; |
103 | struct str_VersionInfo VersionInfo; |
103 | struct str_VersionInfo VersionInfo; |
104 | struct str_WinkelOut WinkelOut; |
104 | struct str_WinkelOut WinkelOut; |
105 | struct str_Data3D Data3D; |
105 | struct str_Data3D Data3D; |
106 | 106 | ||
107 | int Display_Timer, Debug_Timer,Kompass_Timer,Timer3D; |
107 | int Display_Timer, Debug_Timer,Kompass_Timer,Timer3D; |
108 | unsigned int DebugDataIntervall = 0, Intervall3D = 0, Display_Interval = 0; |
108 | unsigned int DebugDataIntervall = 0, Intervall3D = 0, Display_Interval = 0; |
109 | unsigned int AboTimeOut = 0; |
109 | unsigned int AboTimeOut = 0; |
110 | unsigned volatile char ReceiverUpdateModeActive = 0; // 1 = Update 2 = JetiBox-Simulation |
110 | unsigned volatile char ReceiverUpdateModeActive = 0; // 1 = Update 2 = JetiBox-Simulation |
111 | 111 | ||
112 | const unsigned char ANALOG_TEXT[32][16] PROGMEM = |
112 | const unsigned char ANALOG_TEXT[32][16] PROGMEM = |
113 | { |
113 | { |
114 | //1234567890123456 |
114 | //1234567890123456 |
115 | "AngleNick ", //0 |
115 | "AngleNick ", //0 |
116 | "AngleRoll ", |
116 | "AngleRoll ", |
117 | "AccNick ", |
117 | "AccNick ", |
118 | "AccRoll ", |
118 | "AccRoll ", |
119 | "YawGyro ", |
119 | "YawGyro ", |
120 | "Altitude [0.1m] ", //5 |
120 | "Altitude [0.1m] ", //5 |
121 | "AccZ ", |
121 | "AccZ ", |
122 | "Gas ", |
122 | "Gas ", |
123 | "Compass Value ", |
123 | "Compass Value ", |
124 | "Voltage [0.1V] ", |
124 | "Voltage [0.1V] ", |
125 | "Receiver Level ", //10 |
125 | "Receiver Level ", //10 |
126 | "Gyro Compass ", |
126 | "Gyro Compass ", |
127 | "Motor 1 ", |
127 | "Motor 1 ", |
128 | "Motor 2 ", |
128 | "Motor 2 ", |
129 | "Motor 3 ", |
129 | "Motor 3 ", |
130 | "Motor 4 ", //15 |
130 | "Motor 4 ", //15 |
131 | "16 ", |
131 | "16 ", |
132 | "17 ", |
132 | "17 ", |
133 | "18 ", |
133 | "18 ", |
134 | "19 ", |
134 | "19 ", |
135 | "Servo ", //20 |
135 | "Servo ", //20 |
136 | "Hovergas ", |
136 | "Hovergas ", |
137 | "Current [0.1A] ", |
137 | "Current [0.1A] ", |
138 | "Capacity [mAh] ", |
138 | "Capacity [mAh] ", |
139 | "Height Setpoint ", |
139 | "Height Setpoint ", |
140 | "25 ", //25 |
140 | "25 ", //25 |
141 | "26 ", //"26 CPU OverLoad ", |
141 | "26 ", //"26 CPU OverLoad ", |
142 | "Compass Setpoint", |
142 | "Compass Setpoint", |
143 | "I2C-Error ", |
143 | "I2C-Error ", |
144 | "BL Limit ", |
144 | "BL Limit ", |
145 | "GPS_Nick ", //30 |
145 | "GPS_Nick ", //30 |
146 | "GPS_Roll " |
146 | "GPS_Roll " |
147 | }; |
147 | }; |
148 | 148 | ||
149 | 149 | ||
150 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
150 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
151 | //++ Sende-Part der Datenübertragung |
151 | //++ Sende-Part der Datenübertragung |
152 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
152 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
153 | ISR(USART0_TX_vect) |
153 | ISR(USART0_TX_vect) |
154 | { |
154 | { |
155 | static unsigned int ptr = 0; |
155 | static unsigned int ptr = 0; |
156 | unsigned char tmp_tx; |
156 | unsigned char tmp_tx; |
157 | 157 | ||
158 | if(!UebertragungAbgeschlossen) |
158 | if(!UebertragungAbgeschlossen) |
159 | { |
159 | { |
160 | ptr++; // die [0] wurde schon gesendet |
160 | ptr++; // die [0] wurde schon gesendet |
161 | tmp_tx = TxdBuffer[ptr]; |
161 | tmp_tx = TxdBuffer[ptr]; |
162 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
162 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
163 | { |
163 | { |
164 | ptr = 0; |
164 | ptr = 0; |
165 | UebertragungAbgeschlossen = 1; |
165 | UebertragungAbgeschlossen = 1; |
166 | } |
166 | } |
167 | UDR0 = tmp_tx; |
167 | UDR0 = tmp_tx; |
168 | } |
168 | } |
169 | else ptr = 0; |
169 | else ptr = 0; |
170 | } |
170 | } |
171 | 171 | ||
172 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
172 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
173 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
173 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
174 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
174 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
175 | ISR(USART0_RX_vect) |
175 | ISR(USART0_RX_vect) |
176 | { |
176 | { |
177 | static unsigned int crc; |
177 | static unsigned int crc; |
178 | static unsigned char crc1,crc2,buf_ptr; |
178 | static unsigned char crc1,crc2,buf_ptr; |
179 | static unsigned char UartState = 0; |
179 | static unsigned char UartState = 0; |
180 | unsigned char CrcOkay = 0; |
180 | unsigned char CrcOkay = 0; |
181 | 181 | ||
182 | if (ReceiverUpdateModeActive == 1) { UDR1 = UDR0; return; } // 1 = Update |
182 | if (ReceiverUpdateModeActive == 1) { UDR1 = UDR0; return; } // 1 = Update |
183 | if (ReceiverUpdateModeActive == 2) { RxdBuffer[0] = UDR0; return; } // 2 = JetiBox-Simulation |
183 | if (ReceiverUpdateModeActive == 2) { RxdBuffer[0] = UDR0; return; } // 2 = JetiBox-Simulation |
184 | 184 | ||
185 | SioTmp = UDR0; |
185 | SioTmp = UDR0; |
186 | 186 | ||
187 | if(buf_ptr >= MAX_SENDE_BUFF) UartState = 0; |
187 | if(buf_ptr >= MAX_SENDE_BUFF) UartState = 0; |
188 | if(SioTmp == '\r' && UartState == 2) |
188 | if(SioTmp == '\r' && UartState == 2) |
189 | { |
189 | { |
190 | UartState = 0; |
190 | UartState = 0; |
191 | crc -= RxdBuffer[buf_ptr-2]; |
191 | crc -= RxdBuffer[buf_ptr-2]; |
192 | crc -= RxdBuffer[buf_ptr-1]; |
192 | crc -= RxdBuffer[buf_ptr-1]; |
193 | crc %= 4096; |
193 | crc %= 4096; |
194 | crc1 = '=' + crc / 64; |
194 | crc1 = '=' + crc / 64; |
195 | crc2 = '=' + crc % 64; |
195 | crc2 = '=' + crc % 64; |
196 | CrcOkay = 0; |
196 | CrcOkay = 0; |
197 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
197 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
198 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
198 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
199 | { |
199 | { |
200 | NeuerDatensatzEmpfangen = 1; |
200 | NeuerDatensatzEmpfangen = 1; |
201 | AnzahlEmpfangsBytes = buf_ptr + 1; |
201 | AnzahlEmpfangsBytes = buf_ptr + 1; |
202 | RxdBuffer[buf_ptr] = '\r'; |
202 | RxdBuffer[buf_ptr] = '\r'; |
203 | if(RxdBuffer[2] == 'R' && !MotorenEin) |
203 | if(RxdBuffer[2] == 'R' && !MotorenEin) |
204 | { |
204 | { |
205 | LcdClear(); |
205 | LcdClear(); |
206 | wdt_enable(WDTO_250MS); // Reset-Commando |
206 | wdt_enable(WDTO_250MS); // Reset-Commando |
207 | ServoActive = 0; |
207 | ServoActive = 0; |
208 | } |
208 | } |
209 | } |
209 | } |
210 | } |
210 | } |
211 | else |
211 | else |
212 | switch(UartState) |
212 | switch(UartState) |
213 | { |
213 | { |
214 | case 0: |
214 | case 0: |
215 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
215 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
216 | buf_ptr = 0; |
216 | buf_ptr = 0; |
217 | RxdBuffer[buf_ptr++] = SioTmp; |
217 | RxdBuffer[buf_ptr++] = SioTmp; |
218 | crc = SioTmp; |
218 | crc = SioTmp; |
219 | break; |
219 | break; |
220 | case 1: // Adresse auswerten |
220 | case 1: // Adresse auswerten |
221 | UartState++; |
221 | UartState++; |
222 | RxdBuffer[buf_ptr++] = SioTmp; |
222 | RxdBuffer[buf_ptr++] = SioTmp; |
223 | crc += SioTmp; |
223 | crc += SioTmp; |
224 | break; |
224 | break; |
225 | case 2: // Eingangsdaten sammeln |
225 | case 2: // Eingangsdaten sammeln |
226 | RxdBuffer[buf_ptr] = SioTmp; |
226 | RxdBuffer[buf_ptr] = SioTmp; |
227 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
227 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
228 | else UartState = 0; |
228 | else UartState = 0; |
229 | crc += SioTmp; |
229 | crc += SioTmp; |
230 | break; |
230 | break; |
231 | default: |
231 | default: |
232 | UartState = 0; |
232 | UartState = 0; |
233 | break; |
233 | break; |
234 | } |
234 | } |
235 | } |
235 | } |
236 | 236 | ||
237 | 237 | ||
238 | // -------------------------------------------------------------------------- |
238 | // -------------------------------------------------------------------------- |
239 | void AddCRC(unsigned int wieviele) |
239 | void AddCRC(unsigned int wieviele) |
240 | { |
240 | { |
241 | unsigned int tmpCRC = 0,i; |
241 | unsigned int tmpCRC = 0,i; |
242 | for(i = 0; i < wieviele;i++) |
242 | for(i = 0; i < wieviele;i++) |
243 | { |
243 | { |
244 | tmpCRC += TxdBuffer[i]; |
244 | tmpCRC += TxdBuffer[i]; |
245 | } |
245 | } |
246 | // if(i > MAX_SENDE_BUFF - 3) tmpCRC += 11; |
246 | // if(i > MAX_SENDE_BUFF - 3) tmpCRC += 11; |
247 | tmpCRC %= 4096; |
247 | tmpCRC %= 4096; |
248 | TxdBuffer[i++] = '=' + tmpCRC / 64; |
248 | TxdBuffer[i++] = '=' + tmpCRC / 64; |
249 | TxdBuffer[i++] = '=' + tmpCRC % 64; |
249 | TxdBuffer[i++] = '=' + tmpCRC % 64; |
250 | TxdBuffer[i++] = '\r'; |
250 | TxdBuffer[i++] = '\r'; |
251 | UebertragungAbgeschlossen = 0; |
251 | UebertragungAbgeschlossen = 0; |
252 | UDR0 = TxdBuffer[0]; |
252 | UDR0 = TxdBuffer[0]; |
253 | //if(DebugOut.Analog[] < i) DebugOut.Analog[] = i; |
253 | //if(DebugOut.Analog[] < i) DebugOut.Analog[] = i; |
254 | } |
254 | } |
255 | 255 | ||
256 | 256 | ||
257 | // -------------------------------------------------------------------------- |
257 | // -------------------------------------------------------------------------- |
258 | void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len) |
258 | void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len) |
259 | { |
259 | { |
260 | va_list ap; |
260 | va_list ap; |
261 | unsigned int pt = 0; |
261 | unsigned int pt = 0; |
262 | unsigned char a,b,c; |
262 | unsigned char a,b,c; |
263 | unsigned char ptr = 0; |
263 | unsigned char ptr = 0; |
264 | 264 | ||
265 | unsigned char *snd = 0; |
265 | unsigned char *snd = 0; |
266 | int len = 0; |
266 | int len = 0; |
267 | 267 | ||
268 | TxdBuffer[pt++] = '#'; // Startzeichen |
268 | TxdBuffer[pt++] = '#'; // Startzeichen |
269 | TxdBuffer[pt++] = 'a' + address; // Adresse (a=0; b=1,...) |
269 | TxdBuffer[pt++] = 'a' + address; // Adresse (a=0; b=1,...) |
270 | TxdBuffer[pt++] = cmd; // Commando |
270 | TxdBuffer[pt++] = cmd; // Commando |
271 | 271 | ||
272 | va_start(ap, BufferAnzahl); |
272 | va_start(ap, BufferAnzahl); |
273 | if(BufferAnzahl) |
273 | if(BufferAnzahl) |
274 | { |
274 | { |
275 | snd = va_arg(ap, unsigned char*); |
275 | snd = va_arg(ap, unsigned char*); |
276 | len = va_arg(ap, int); |
276 | len = va_arg(ap, int); |
277 | ptr = 0; |
277 | ptr = 0; |
278 | BufferAnzahl--; |
278 | BufferAnzahl--; |
279 | } |
279 | } |
280 | while(len) |
280 | while(len) |
281 | { |
281 | { |
282 | if(len) |
282 | if(len) |
283 | { |
283 | { |
284 | a = snd[ptr++]; |
284 | a = snd[ptr++]; |
285 | len--; |
285 | len--; |
286 | if((!len) && BufferAnzahl) |
286 | if((!len) && BufferAnzahl) |
287 | { |
287 | { |
288 | snd = va_arg(ap, unsigned char*); |
288 | snd = va_arg(ap, unsigned char*); |
289 | len = va_arg(ap, int); |
289 | len = va_arg(ap, int); |
290 | ptr = 0; |
290 | ptr = 0; |
291 | BufferAnzahl--; |
291 | BufferAnzahl--; |
292 | } |
292 | } |
293 | } |
293 | } |
294 | else a = 0; |
294 | else a = 0; |
295 | if(len) |
295 | if(len) |
296 | { |
296 | { |
297 | b = snd[ptr++]; |
297 | b = snd[ptr++]; |
298 | len--; |
298 | len--; |
299 | if((!len) && BufferAnzahl) |
299 | if((!len) && BufferAnzahl) |
300 | { |
300 | { |
301 | snd = va_arg(ap, unsigned char*); |
301 | snd = va_arg(ap, unsigned char*); |
302 | len = va_arg(ap, int); |
302 | len = va_arg(ap, int); |
303 | ptr = 0; |
303 | ptr = 0; |
304 | BufferAnzahl--; |
304 | BufferAnzahl--; |
305 | } |
305 | } |
306 | } |
306 | } |
307 | else b = 0; |
307 | else b = 0; |
308 | if(len) |
308 | if(len) |
309 | { |
309 | { |
310 | c = snd[ptr++]; |
310 | c = snd[ptr++]; |
311 | len--; |
311 | len--; |
312 | if((!len) && BufferAnzahl) |
312 | if((!len) && BufferAnzahl) |
313 | { |
313 | { |
314 | snd = va_arg(ap, unsigned char*); |
314 | snd = va_arg(ap, unsigned char*); |
315 | len = va_arg(ap, int); |
315 | len = va_arg(ap, int); |
316 | ptr = 0; |
316 | ptr = 0; |
317 | BufferAnzahl--; |
317 | BufferAnzahl--; |
318 | } |
318 | } |
319 | } |
319 | } |
320 | else c = 0; |
320 | else c = 0; |
321 | TxdBuffer[pt++] = '=' + (a >> 2); |
321 | TxdBuffer[pt++] = '=' + (a >> 2); |
322 | TxdBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
322 | TxdBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
323 | TxdBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
323 | TxdBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
324 | TxdBuffer[pt++] = '=' + ( c & 0x3f); |
324 | TxdBuffer[pt++] = '=' + ( c & 0x3f); |
325 | } |
325 | } |
326 | va_end(ap); |
326 | va_end(ap); |
327 | AddCRC(pt); |
327 | AddCRC(pt); |
328 | } |
328 | } |
329 | 329 | ||
330 | // -------------------------------------------------------------------------- |
330 | // -------------------------------------------------------------------------- |
331 | void Decode64(void) // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden. |
331 | void Decode64(void) // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden. |
332 | { |
332 | { |
333 | unsigned char a,b,c,d; |
333 | unsigned char a,b,c,d; |
334 | unsigned char x,y,z; |
334 | unsigned char x,y,z; |
335 | unsigned char ptrIn = 3; // start at begin of data block |
335 | unsigned char ptrIn = 3; // start at begin of data block |
336 | unsigned char ptrOut = 3; |
336 | unsigned char ptrOut = 3; |
337 | 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. |
337 | 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. |
338 | 338 | ||
339 | while(len) |
339 | while(len) |
340 | { |
340 | { |
341 | a = RxdBuffer[ptrIn++] - '='; |
341 | a = RxdBuffer[ptrIn++] - '='; |
342 | b = RxdBuffer[ptrIn++] - '='; |
342 | b = RxdBuffer[ptrIn++] - '='; |
343 | c = RxdBuffer[ptrIn++] - '='; |
343 | c = RxdBuffer[ptrIn++] - '='; |
344 | d = RxdBuffer[ptrIn++] - '='; |
344 | d = RxdBuffer[ptrIn++] - '='; |
345 | 345 | ||
346 | x = (a << 2) | (b >> 4); |
346 | x = (a << 2) | (b >> 4); |
347 | y = ((b & 0x0f) << 4) | (c >> 2); |
347 | y = ((b & 0x0f) << 4) | (c >> 2); |
348 | z = ((c & 0x03) << 6) | d; |
348 | z = ((c & 0x03) << 6) | d; |
349 | 349 | ||
350 | if(len--) RxdBuffer[ptrOut++] = x; else break; |
350 | if(len--) RxdBuffer[ptrOut++] = x; else break; |
351 | if(len--) RxdBuffer[ptrOut++] = y; else break; |
351 | if(len--) RxdBuffer[ptrOut++] = y; else break; |
352 | if(len--) RxdBuffer[ptrOut++] = z; else break; |
352 | if(len--) RxdBuffer[ptrOut++] = z; else break; |
353 | } |
353 | } |
354 | pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte |
354 | pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte |
355 | RxDataLen = ptrOut - 3; // wie viele Bytes wurden dekodiert? |
355 | RxDataLen = ptrOut - 3; // wie viele Bytes wurden dekodiert? |
356 | 356 | ||
357 | } |
357 | } |
358 | 358 | ||
359 | // -------------------------------------------------------------------------- |
359 | // -------------------------------------------------------------------------- |
360 | void BearbeiteRxDaten(void) |
360 | void BearbeiteRxDaten(void) |
361 | { |
361 | { |
362 | if(!NeuerDatensatzEmpfangen) return; |
362 | if(!NeuerDatensatzEmpfangen) return; |
363 | 363 | ||
364 | unsigned char tempchar1, tempchar2; |
364 | unsigned char tempchar1, tempchar2; |
365 | Decode64(); // dekodiere datenblock im Empfangsbuffer |
365 | Decode64(); // dekodiere datenblock im Empfangsbuffer |
366 | switch(RxdBuffer[1]-'a') // check for Slave Address |
366 | switch(RxdBuffer[1]-'a') // check for Slave Address |
367 | { |
367 | { |
368 | case FC_ADDRESS: // FC special commands |
368 | case FC_ADDRESS: // FC special commands |
369 | switch(RxdBuffer[2]) |
369 | switch(RxdBuffer[2]) |
370 | { |
370 | { |
371 | case 'K':// Kompasswert |
371 | case 'K':// Kompasswert |
372 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
372 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
373 | // KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180; |
373 | // KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180; |
374 | break; |
374 | break; |
375 | case 't':// Motortest |
375 | case 't':// Motortest |
376 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
376 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
377 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
377 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
378 | PC_MotortestActive = 240; |
378 | PC_MotortestActive = 240; |
379 | //while(!UebertragungAbgeschlossen); |
379 | //while(!UebertragungAbgeschlossen); |
380 | //SendOutData('T', MeineSlaveAdresse, 0); |
380 | //SendOutData('T', MeineSlaveAdresse, 0); |
381 | PcZugriff = 255; |
381 | PcZugriff = 255; |
382 | break; |
382 | break; |
383 | 383 | ||
384 | case 'n':// "Get Mixer |
384 | case 'n':// "Get Mixer |
385 | while(!UebertragungAbgeschlossen); |
385 | while(!UebertragungAbgeschlossen); |
386 | SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer, sizeof(Mixer) - 1); |
386 | SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer, sizeof(Mixer) - 1); |
387 | Debug("Mixer lesen"); |
387 | Debug("Mixer lesen"); |
388 | break; |
388 | break; |
389 | 389 | ||
390 | case 'm':// "Write Mixer |
390 | case 'm':// "Write Mixer |
391 | if(pRxData[0] == EEMIXER_REVISION) |
391 | if(pRxData[0] == EEMIXER_REVISION) |
392 | { |
392 | { |
393 | memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer) - 1); |
393 | memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer) - 1); |
394 | MixerTable_WriteToEEProm(); |
394 | MixerTable_WriteToEEProm(); |
395 | tempchar1 = 1; |
395 | tempchar1 = 1; |
396 | VersionInfo.HardwareError[1] &= ~FC_ERROR1_MIXER; |
396 | VersionInfo.HardwareError[1] &= ~FC_ERROR1_MIXER; |
397 | } |
397 | } |
398 | else |
398 | else |
399 | { |
399 | { |
400 | tempchar1 = 0; |
400 | tempchar1 = 0; |
401 | } |
401 | } |
402 | while(!UebertragungAbgeschlossen); |
402 | while(!UebertragungAbgeschlossen); |
403 | SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
403 | SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
404 | break; |
404 | break; |
405 | 405 | ||
406 | case 'p': // get PPM Channels |
406 | case 'p': // get PPM Channels |
407 | GetPPMChannelAnforderung = 1; |
407 | GetPPMChannelAnforderung = 1; |
408 | PcZugriff = 255; |
408 | PcZugriff = 255; |
409 | break; |
409 | break; |
410 | 410 | ||
411 | case 'q':// "Get"-Anforderung für Settings |
411 | case 'q':// "Get"-Anforderung für Settings |
412 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
412 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
413 | if(MotorenEin) break; |
413 | if(!MotorenEin) |
- | 414 | { |
|
414 | if((10 <= pRxData[0]) && (pRxData[0] < 20)) |
415 | if((10 <= pRxData[0]) && (pRxData[0] < 20)) |
415 | { |
416 | { |
416 | tempchar1 = pRxData[0] - 10; |
417 | tempchar1 = pRxData[0] - 10; |
417 | if(tempchar1< 1) tempchar1 = 1; // limit to 1 |
418 | if(tempchar1< 1) tempchar1 = 1; // limit to 1 |
418 | else if(tempchar1 > 5) tempchar1 = 5; // limit to 5 |
419 | else if(tempchar1 > 5) tempchar1 = 5; // limit to 5 |
419 | SetDefaultParameter(tempchar1, 1); |
420 | SetDefaultParameter(tempchar1, 1); |
420 | } |
421 | } |
421 | else if((20 <= pRxData[0]) && (pRxData[0] < 30)) |
422 | else if((20 <= pRxData[0]) && (pRxData[0] < 30)) |
422 | { |
423 | { |
423 | tempchar1 = pRxData[0] - 20; |
424 | tempchar1 = pRxData[0] - 20; |
424 | if(tempchar1< 1) tempchar1 = 1; // limit to 1 |
425 | if(tempchar1< 1) tempchar1 = 1; // limit to 1 |
425 | else if(tempchar1 > 5) tempchar1 = 5; // limit to 5 |
426 | else if(tempchar1 > 5) tempchar1 = 5; // limit to 5 |
426 | SetDefaultParameter(tempchar1, 0); |
427 | SetDefaultParameter(tempchar1, 0); |
427 | } |
428 | } |
428 | else |
429 | else |
429 | { |
430 | { |
430 | tempchar1 = pRxData[0]; |
431 | tempchar1 = pRxData[0]; |
431 | if(tempchar1 == 0xFF) |
432 | if(tempchar1 == 0xFF) |
432 | { |
433 | { |
433 | tempchar1 = GetActiveParamSet(); |
434 | tempchar1 = GetActiveParamSet(); |
434 | } |
435 | } |
435 | if(tempchar1< 1) tempchar1 = 1; // limit to 1 |
436 | if(tempchar1< 1) tempchar1 = 1; // limit to 1 |
436 | else if(tempchar1 > 5) tempchar1 = 5; // limit to 5 |
437 | else if(tempchar1 > 5) tempchar1 = 5; // limit to 5 |
437 | // load requested parameter set |
438 | // load requested parameter set |
438 | ParamSet_ReadFromEEProm(tempchar1); |
439 | ParamSet_ReadFromEEProm(tempchar1); |
439 | } |
440 | } |
- | 441 | LipoDetection(0); |
|
- | 442 | } else tempchar1 = GetActiveParamSet(); |
|
440 | while(!UebertragungAbgeschlossen); |
443 | while(!UebertragungAbgeschlossen); |
441 | SendOutData('Q', FC_ADDRESS, 2, &tempchar1, sizeof(tempchar1), (unsigned char *) &EE_Parameter, sizeof(EE_Parameter) - 1); |
444 | SendOutData('Q', FC_ADDRESS, 2, &tempchar1, sizeof(tempchar1), (unsigned char *) &EE_Parameter, sizeof(EE_Parameter) - 1); |
442 | Debug("Lese Setting %d", tempchar1); |
445 | Debug("Lese Setting %d", tempchar1); |
443 | LipoDetection(0); |
- | |
444 | break; |
446 | break; |
445 | 447 | ||
446 | case 's': // Parametersatz speichern |
448 | case 's': // Parametersatz speichern |
447 | if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EEPARAM_REVISION) && MotorenEin == 0) // check for setting to be in range |
449 | if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EEPARAM_REVISION) && MotorenEin == 0) // check for setting to be in range |
448 | { |
450 | { |
449 | memcpy(&EE_Parameter, (uint8_t*)&pRxData[1], sizeof(EE_Parameter) - 1); |
451 | memcpy(&EE_Parameter, (uint8_t*)&pRxData[1], sizeof(EE_Parameter) - 1); |
450 | ParamSet_WriteToEEProm(pRxData[0]); |
452 | ParamSet_WriteToEEProm(pRxData[0]); |
451 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
453 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
452 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
454 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
453 | tempchar1 = GetActiveParamSet(); |
455 | tempchar1 = GetActiveParamSet(); |
454 | } |
456 | } |
455 | else |
457 | else |
456 | { |
458 | { |
457 | tempchar1 = 0; // mark in response an invlid setting |
459 | tempchar1 = 0; // mark in response an invlid setting |
458 | } |
460 | } |
459 | while(!UebertragungAbgeschlossen); |
461 | while(!UebertragungAbgeschlossen); |
460 | SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
462 | SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
461 | if(!MotorenEin) |
463 | if(!MotorenEin) |
462 | { |
464 | { |
463 | Piep(tempchar1,110); |
465 | Piep(tempchar1,110); |
464 | LipoDetection(0); |
466 | LipoDetection(0); |
465 | } |
467 | } |
466 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
468 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
467 | break; |
469 | break; |
468 | case 'f': // auf anderen Parametersatz umschalten |
470 | case 'f': // auf anderen Parametersatz umschalten |
469 | if(MotorenEin) break; |
471 | if(MotorenEin) break; |
470 | if((1 <= pRxData[0]) && (pRxData[0] <= 5)) ParamSet_ReadFromEEProm(pRxData[0]); |
472 | if((1 <= pRxData[0]) && (pRxData[0] <= 5)) ParamSet_ReadFromEEProm(pRxData[0]); |
471 | tempchar1 = GetActiveParamSet(); |
473 | tempchar1 = GetActiveParamSet(); |
472 | while(!UebertragungAbgeschlossen); |
474 | while(!UebertragungAbgeschlossen); |
473 | SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
475 | SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
474 | if(!MotorenEin) |
476 | if(!MotorenEin) |
475 | { |
477 | { |
476 | Piep(tempchar1,110); |
478 | Piep(tempchar1,110); |
477 | LipoDetection(0); |
479 | LipoDetection(0); |
478 | } |
480 | } |
479 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
481 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
480 | break; |
482 | break; |
481 | case 'y':// serial Potis |
483 | case 'y':// serial Potis |
482 | for(tempchar1 = 0; tempchar1 < 12; tempchar1++) PPM_in[SERIAL_POTI_START + tempchar1] = (signed char) pRxData[tempchar1]; |
484 | for(tempchar1 = 0; tempchar1 < 12; tempchar1++) PPM_in[SERIAL_POTI_START + tempchar1] = (signed char) pRxData[tempchar1]; |
483 | break; |
485 | break; |
484 | case 'u': // request BL parameter |
486 | case 'u': // request BL parameter |
485 | Debug("Reading BL %d", pRxData[0]); |
487 | Debug("Reading BL %d", pRxData[0]); |
486 | // try to read BL configuration |
488 | // try to read BL configuration |
487 | tempchar2 = I2C_ReadBLConfig(pRxData[0]); |
489 | tempchar2 = I2C_ReadBLConfig(pRxData[0]); |
488 | if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1; |
490 | if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1; |
489 | else tempchar1 = 0; |
491 | else tempchar1 = 0; |
490 | while(!UebertragungAbgeschlossen); // wait for previous frame to be sent |
492 | while(!UebertragungAbgeschlossen); // wait for previous frame to be sent |
491 | SendOutData('U', FC_ADDRESS, 4, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), &pRxData[0], 1, &BLConfig, sizeof(BLConfig_t)); |
493 | SendOutData('U', FC_ADDRESS, 4, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), &pRxData[0], 1, &BLConfig, sizeof(BLConfig_t)); |
492 | break; |
494 | break; |
493 | case 'w': // write BL parameter |
495 | case 'w': // write BL parameter |
494 | Debug("Writing BL %d", pRxData[0]); |
496 | Debug("Writing BL %d", pRxData[0]); |
495 | if(RxDataLen >= 1+sizeof(BLConfig_t)) |
497 | if(RxDataLen >= 1+sizeof(BLConfig_t)) |
496 | { |
498 | { |
497 | memcpy(&BLConfig, (uint8_t*)(&pRxData[1]), sizeof(BLConfig_t)); |
499 | memcpy(&BLConfig, (uint8_t*)(&pRxData[1]), sizeof(BLConfig_t)); |
498 | tempchar2 = I2C_WriteBLConfig(pRxData[0]); |
500 | tempchar2 = I2C_WriteBLConfig(pRxData[0]); |
499 | if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1; |
501 | if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1; |
500 | else tempchar1 = 0; // indicate error |
502 | else tempchar1 = 0; // indicate error |
501 | while(!UebertragungAbgeschlossen); // wait for previous frame to be sent |
503 | while(!UebertragungAbgeschlossen); // wait for previous frame to be sent |
502 | SendOutData('W', FC_ADDRESS,2, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2)); |
504 | SendOutData('W', FC_ADDRESS,2, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2)); |
503 | } |
505 | } |
504 | break; |
506 | break; |
505 | case 'j': |
507 | case 'j': |
506 | if(MotorenEin) break; |
508 | if(MotorenEin) break; |
507 | tempchar1 = LIBFC_GetCPUType(); |
509 | tempchar1 = LIBFC_GetCPUType(); |
508 | if((tempchar1 == CPU_ATMEGA644P) || (tempchar1 == CPU_ATMEGA1284P)) |
510 | if((tempchar1 == CPU_ATMEGA644P) || (tempchar1 == CPU_ATMEGA1284P)) |
509 | { |
511 | { |
510 | uint16_t ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 38400L) - 1); |
512 | uint16_t ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 38400L) - 1); |
511 | 513 | ||
512 | cli(); |
514 | cli(); |
513 | 515 | ||
514 | // UART0 & UART1 disable RX and TX-Interrupt |
516 | // UART0 & UART1 disable RX and TX-Interrupt |
515 | UCSR0B &= ~((1 << RXCIE0)|(1 << TXCIE0)); |
517 | UCSR0B &= ~((1 << RXCIE0)|(1 << TXCIE0)); |
516 | UCSR1B &= ~((1 << RXCIE1)|(1 << TXCIE1)); |
518 | UCSR1B &= ~((1 << RXCIE1)|(1 << TXCIE1)); |
517 | 519 | ||
518 | // UART0 & UART1 disable receiver and transmitter |
520 | // UART0 & UART1 disable receiver and transmitter |
519 | UCSR0B &= ~((1 << TXEN0) | (1 << RXEN0)); |
521 | UCSR0B &= ~((1 << TXEN0) | (1 << RXEN0)); |
520 | UCSR1B &= ~((1 << TXEN1) | (1 << RXEN1)); |
522 | UCSR1B &= ~((1 << TXEN1) | (1 << RXEN1)); |
521 | 523 | ||
522 | // UART0 & UART1 flush receive buffer explicit |
524 | // UART0 & UART1 flush receive buffer explicit |
523 | while ( UCSR1A & (1<<RXC1) ) UDR1; |
525 | while ( UCSR1A & (1<<RXC1) ) UDR1; |
524 | while ( UCSR0A & (1<<RXC0) ) UDR0; |
526 | while ( UCSR0A & (1<<RXC0) ) UDR0; |
525 | 527 | ||
526 | 528 | ||
527 | if(pRxData[0] == 1) ReceiverUpdateModeActive = 2; |
529 | if(pRxData[0] == 1) ReceiverUpdateModeActive = 2; |
528 | else |
530 | else |
529 | { // Jeti or HoTT update |
531 | { // Jeti or HoTT update |
530 | //#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
532 | //#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
531 | if(pRxData[0] == 100) ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 19200L) - 1); // HoTT |
533 | if(pRxData[0] == 100) ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 19200L) - 1); // HoTT |
532 | //#endif |
534 | //#endif |
533 | ReceiverUpdateModeActive = 1; |
535 | ReceiverUpdateModeActive = 1; |
534 | // UART0 & UART1 set baudrate |
536 | // UART0 & UART1 set baudrate |
535 | UBRR1H = (uint8_t)(ubrr>>8); |
537 | UBRR1H = (uint8_t)(ubrr>>8); |
536 | UBRR1L = (uint8_t)ubrr; |
538 | UBRR1L = (uint8_t)ubrr; |
537 | UBRR0H = UBRR1H; |
539 | UBRR0H = UBRR1H; |
538 | UBRR0L = UBRR1L; |
540 | UBRR0L = UBRR1L; |
539 | // UART1 no parity |
541 | // UART1 no parity |
540 | UCSR1C &= ~(1 << UPM11); |
542 | UCSR1C &= ~(1 << UPM11); |
541 | UCSR1C &= ~(1 << UPM10); |
543 | UCSR1C &= ~(1 << UPM10); |
542 | // UART1 8-bit |
544 | // UART1 8-bit |
543 | UCSR1B &= ~(1 << UCSZ12); |
545 | UCSR1B &= ~(1 << UCSZ12); |
544 | UCSR1C |= (1 << UCSZ11); |
546 | UCSR1C |= (1 << UCSZ11); |
545 | UCSR1C |= (1 << UCSZ10); |
547 | UCSR1C |= (1 << UCSZ10); |
546 | } |
548 | } |
547 | // UART0 & UART1 1 stop bit |
549 | // UART0 & UART1 1 stop bit |
548 | UCSR1C &= ~(1 << USBS1); |
550 | UCSR1C &= ~(1 << USBS1); |
549 | UCSR0C &= ~(1 << USBS0); |
551 | UCSR0C &= ~(1 << USBS0); |
550 | // UART1 clear 9th bit |
552 | // UART1 clear 9th bit |
551 | UCSR1B &= ~(1<<TXB81); |
553 | UCSR1B &= ~(1<<TXB81); |
552 | // enable receiver and transmitter for UART0 and UART1 |
554 | // enable receiver and transmitter for UART0 and UART1 |
553 | UCSR0B |= (1 << TXEN0) | (1 << RXEN0); |
555 | UCSR0B |= (1 << TXEN0) | (1 << RXEN0); |
554 | UCSR1B |= (1 << TXEN1) | (1 << RXEN1); |
556 | UCSR1B |= (1 << TXEN1) | (1 << RXEN1); |
555 | // enable RX-Interrupt for UART0 and UART1 |
557 | // enable RX-Interrupt for UART0 and UART1 |
556 | UCSR0B |= (1 << RXCIE0); |
558 | UCSR0B |= (1 << RXCIE0); |
557 | UCSR1B |= (1 << RXCIE1); |
559 | UCSR1B |= (1 << RXCIE1); |
558 | // disable other Interrupts |
560 | // disable other Interrupts |
559 | TIMSK0 = 0; |
561 | TIMSK0 = 0; |
560 | TIMSK1 = 0; |
562 | TIMSK1 = 0; |
561 | TIMSK2 = 0; |
563 | TIMSK2 = 0; |
562 | 564 | ||
563 | sei(); |
565 | sei(); |
564 | } |
566 | } |
565 | break; |
567 | break; |
566 | 568 | ||
567 | } // case FC_ADDRESS: |
569 | } // case FC_ADDRESS: |
568 | 570 | ||
569 | default: // any Slave Address |
571 | default: // any Slave Address |
570 | 572 | ||
571 | switch(RxdBuffer[2]) |
573 | switch(RxdBuffer[2]) |
572 | { |
574 | { |
573 | // 't' comand placed here only for compatibility to BL |
575 | // 't' comand placed here only for compatibility to BL |
574 | case 't':// Motortest |
576 | case 't':// Motortest |
575 | if(AnzahlEmpfangsBytes >= sizeof(MotorTest)) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
577 | if(AnzahlEmpfangsBytes >= sizeof(MotorTest)) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
576 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
578 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
577 | while(!UebertragungAbgeschlossen); |
579 | while(!UebertragungAbgeschlossen); |
578 | SendOutData('T', MeineSlaveAdresse, 0); |
580 | SendOutData('T', MeineSlaveAdresse, 0); |
579 | PC_MotortestActive = 250; |
581 | PC_MotortestActive = 250; |
580 | PcZugriff = 255; |
582 | PcZugriff = 255; |
581 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
583 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
582 | break; |
584 | break; |
583 | // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address |
585 | // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address |
584 | case 'K':// Kompasswert |
586 | case 'K':// Kompasswert |
585 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
587 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
586 | // KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180; |
588 | // KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180; |
587 | break; |
589 | break; |
588 | case 'a':// Texte der Analogwerte |
590 | case 'a':// Texte der Analogwerte |
589 | DebugTextAnforderung = pRxData[0]; |
591 | DebugTextAnforderung = pRxData[0]; |
590 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
592 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
591 | PcZugriff = 255; |
593 | PcZugriff = 255; |
592 | break; |
594 | break; |
593 | case 'b': |
595 | case 'b': |
594 | memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl)); |
596 | memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl)); |
595 | ConfirmFrame = ExternControl.Frame; |
597 | ConfirmFrame = ExternControl.Frame; |
596 | PcZugriff = 255; |
598 | PcZugriff = 255; |
597 | break; |
599 | break; |
598 | case 'c': // Poll the 3D-Data |
600 | case 'c': // Poll the 3D-Data |
599 | if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);} |
601 | if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);} |
600 | Intervall3D = pRxData[0] * 10; |
602 | Intervall3D = pRxData[0] * 10; |
601 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
603 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
602 | break; |
604 | break; |
603 | case 'd': // Poll the debug data |
605 | case 'd': // Poll the debug data |
604 | PcZugriff = 255; |
606 | PcZugriff = 255; |
605 | DebugDataIntervall = (unsigned int)pRxData[0] * 10; |
607 | DebugDataIntervall = (unsigned int)pRxData[0] * 10; |
606 | if(DebugDataIntervall > 0) DebugDataAnforderung = 1; |
608 | if(DebugDataIntervall > 0) DebugDataAnforderung = 1; |
607 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
609 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
608 | break; |
610 | break; |
609 | 611 | ||
610 | case 'h':// x-1 Displayzeilen |
612 | case 'h':// x-1 Displayzeilen |
611 | PcZugriff = 255; |
613 | PcZugriff = 255; |
612 | if((pRxData[0] & 0x80) == 0x00) // old format |
614 | if((pRxData[0] & 0x80) == 0x00) // old format |
613 | { |
615 | { |
614 | DisplayLine = 2; |
616 | DisplayLine = 2; |
615 | Display_Interval = 0; |
617 | Display_Interval = 0; |
616 | } |
618 | } |
617 | else // new format |
619 | else // new format |
618 | { |
620 | { |
619 | RemoteKeys |= ~pRxData[0]; |
621 | RemoteKeys |= ~pRxData[0]; |
620 | Display_Interval = (unsigned int)pRxData[1] * 10; |
622 | Display_Interval = (unsigned int)pRxData[1] * 10; |
621 | DisplayLine = 4; |
623 | DisplayLine = 4; |
622 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
624 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
623 | } |
625 | } |
624 | DebugDisplayAnforderung = 1; |
626 | DebugDisplayAnforderung = 1; |
625 | break; |
627 | break; |
626 | 628 | ||
627 | case 'l':// x-1 Displayzeilen |
629 | case 'l':// x-1 Displayzeilen |
628 | PcZugriff = 255; |
630 | PcZugriff = 255; |
629 | MenuePunkt = pRxData[0]; |
631 | MenuePunkt = pRxData[0]; |
630 | DebugDisplayAnforderung1 = 1; |
632 | DebugDisplayAnforderung1 = 1; |
631 | break; |
633 | break; |
632 | case 'v': // Version-Anforderung und Ausbaustufe |
634 | case 'v': // Version-Anforderung und Ausbaustufe |
633 | GetVersionAnforderung = 1; |
635 | GetVersionAnforderung = 1; |
634 | break; |
636 | break; |
635 | 637 | ||
636 | case 'g':// |
638 | case 'g':// |
637 | GetExternalControl = 1; |
639 | GetExternalControl = 1; |
638 | break; |
640 | break; |
639 | 641 | ||
640 | default: |
642 | default: |
641 | //unsupported command received |
643 | //unsupported command received |
642 | break; |
644 | break; |
643 | } |
645 | } |
644 | break; // default: |
646 | break; // default: |
645 | } |
647 | } |
646 | NeuerDatensatzEmpfangen = 0; |
648 | NeuerDatensatzEmpfangen = 0; |
647 | pRxData = 0; |
649 | pRxData = 0; |
648 | RxDataLen = 0; |
650 | RxDataLen = 0; |
649 | } |
651 | } |
650 | 652 | ||
651 | //############################################################################ |
653 | //############################################################################ |
652 | //Routine für die Serielle Ausgabe |
654 | //Routine für die Serielle Ausgabe |
653 | void uart_putchar (char c) |
655 | void uart_putchar (char c) |
654 | //############################################################################ |
656 | //############################################################################ |
655 | { |
657 | { |
656 | //Warten solange bis Zeichen gesendet wurde |
658 | //Warten solange bis Zeichen gesendet wurde |
657 | loop_until_bit_is_set(UCSR0A, UDRE0); |
659 | loop_until_bit_is_set(UCSR0A, UDRE0); |
658 | //Ausgabe des Zeichens |
660 | //Ausgabe des Zeichens |
659 | UDR0 = c; |
661 | UDR0 = c; |
660 | } |
662 | } |
661 | 663 | ||
662 | 664 | ||
663 | //############################################################################ |
665 | //############################################################################ |
664 | //INstallation der Seriellen Schnittstelle |
666 | //INstallation der Seriellen Schnittstelle |
665 | void UART_Init (void) |
667 | void UART_Init (void) |
666 | //############################################################################ |
668 | //############################################################################ |
667 | { |
669 | { |
668 | unsigned int ubrr = (unsigned int) ((unsigned long) F_CPU/(8 * USART0_BAUD) - 1); |
670 | unsigned int ubrr = (unsigned int) ((unsigned long) F_CPU/(8 * USART0_BAUD) - 1); |
669 | 671 | ||
670 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
672 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
671 | UCSR0B = (1 << TXEN0) | (1 << RXEN0); |
673 | UCSR0B = (1 << TXEN0) | (1 << RXEN0); |
672 | // UART Double Speed (U2X) |
674 | // UART Double Speed (U2X) |
673 | UCSR0A |= (1 << U2X0); |
675 | UCSR0A |= (1 << U2X0); |
674 | // RX-Interrupt Freigabe |
676 | // RX-Interrupt Freigabe |
675 | UCSR0B |= (1 << RXCIE0); |
677 | UCSR0B |= (1 << RXCIE0); |
676 | // TX-Interrupt Freigabe |
678 | // TX-Interrupt Freigabe |
677 | UCSR0B |= (1 << TXCIE0); |
679 | UCSR0B |= (1 << TXCIE0); |
678 | // USART0 Baud Rate Register |
680 | // USART0 Baud Rate Register |
679 | // set clock divider |
681 | // set clock divider |
680 | UBRR0H = (uint8_t)(ubrr >> 8); |
682 | UBRR0H = (uint8_t)(ubrr >> 8); |
681 | UBRR0L = (uint8_t)ubrr; |
683 | UBRR0L = (uint8_t)ubrr; |
682 | 684 | ||
683 | Debug_Timer = SetDelay(DebugDataIntervall); |
685 | Debug_Timer = SetDelay(DebugDataIntervall); |
684 | Kompass_Timer = SetDelay(220); |
686 | Kompass_Timer = SetDelay(220); |
685 | 687 | ||
686 | VersionInfo.SWMajor = VERSION_MAJOR; |
688 | VersionInfo.SWMajor = VERSION_MAJOR; |
687 | VersionInfo.SWMinor = VERSION_MINOR; |
689 | VersionInfo.SWMinor = VERSION_MINOR; |
688 | VersionInfo.SWPatch = VERSION_PATCH; |
690 | VersionInfo.SWPatch = VERSION_PATCH; |
689 | VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
691 | VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
690 | VersionInfo.reserved1 = 0; |
692 | VersionInfo.reserved1 = 0; |
691 | VersionInfo.reserved2 = 0; |
693 | VersionInfo.reserved2 = 0; |
692 | VersionInfo.HWMajor = PlatinenVersion; |
694 | VersionInfo.HWMajor = PlatinenVersion; |
693 | pRxData = 0; |
695 | pRxData = 0; |
694 | RxDataLen = 0; |
696 | RxDataLen = 0; |
695 | } |
697 | } |
696 | 698 | ||
697 | //--------------------------------------------------------------------------------------------- |
699 | //--------------------------------------------------------------------------------------------- |
698 | void DatenUebertragung(void) |
700 | void DatenUebertragung(void) |
699 | { |
701 | { |
700 | if(!UebertragungAbgeschlossen) return; |
702 | if(!UebertragungAbgeschlossen) return; |
701 | 703 | ||
702 | if(CheckDelay(AboTimeOut)) |
704 | if(CheckDelay(AboTimeOut)) |
703 | { |
705 | { |
704 | Display_Interval = 0; |
706 | Display_Interval = 0; |
705 | DebugDataIntervall = 0; |
707 | DebugDataIntervall = 0; |
706 | Intervall3D = 0; |
708 | Intervall3D = 0; |
707 | } |
709 | } |
708 | 710 | ||
709 | if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen) |
711 | if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen) |
710 | { |
712 | { |
711 | if(DisplayLine > 3)// new format |
713 | if(DisplayLine > 3)// new format |
712 | { |
714 | { |
713 | Menu(); |
715 | Menu(); |
714 | SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80); |
716 | SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80); |
715 | } |
717 | } |
716 | else // old format |
718 | else // old format |
717 | { |
719 | { |
718 | LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!"); |
720 | LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!"); |
719 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20); |
721 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20); |
720 | if(DisplayLine++ > 3) DisplayLine = 0; |
722 | if(DisplayLine++ > 3) DisplayLine = 0; |
721 | } |
723 | } |
722 | Display_Timer = SetDelay(Display_Interval); |
724 | Display_Timer = SetDelay(Display_Interval); |
723 | DebugDisplayAnforderung = 0; |
725 | DebugDisplayAnforderung = 0; |
724 | } |
726 | } |
725 | if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen) |
727 | if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen) |
726 | { |
728 | { |
727 | Menu(); |
729 | Menu(); |
728 | SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
730 | SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
729 | DebugDisplayAnforderung1 = 0; |
731 | DebugDisplayAnforderung1 = 0; |
730 | } |
732 | } |
731 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
733 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
732 | { |
734 | { |
733 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
735 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
734 | GetVersionAnforderung = 0; |
736 | GetVersionAnforderung = 0; |
735 | Debug_OK("Version gesendet"); |
737 | Debug_OK("Version gesendet"); |
736 | } |
738 | } |
737 | 739 | ||
738 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
740 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
739 | { |
741 | { |
740 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl)); |
742 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl)); |
741 | GetExternalControl = 0; |
743 | GetExternalControl = 0; |
742 | } |
744 | } |
743 | if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
745 | if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
744 | { |
746 | { |
745 | CopyDebugValues(); |
747 | CopyDebugValues(); |
746 | SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
748 | SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
747 | DebugDataAnforderung = 0; |
749 | DebugDataAnforderung = 0; |
748 | if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall); |
750 | if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall); |
749 | } |
751 | } |
750 | if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen) |
752 | if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen) |
751 | { |
753 | { |
752 | Data3D.Winkel[0] = ToNaviCtrl.IntegralNick;//(int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
754 | Data3D.Winkel[0] = ToNaviCtrl.IntegralNick;//(int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
753 | Data3D.Winkel[1] = ToNaviCtrl.IntegralRoll;//(int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
755 | Data3D.Winkel[1] = ToNaviCtrl.IntegralRoll;//(int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
754 | Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR); |
756 | Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR); |
755 | Data3D.Centroid[0] = SummeNick >> 9; |
757 | Data3D.Centroid[0] = SummeNick >> 9; |
756 | Data3D.Centroid[1] = SummeRoll >> 9; |
758 | Data3D.Centroid[1] = SummeRoll >> 9; |
757 | Data3D.Centroid[2] = Mess_Integral_Gier >> 9; |
759 | Data3D.Centroid[2] = Mess_Integral_Gier >> 9; |
758 | SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D)); |
760 | SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D)); |
759 | Timer3D = SetDelay(Intervall3D); |
761 | Timer3D = SetDelay(Intervall3D); |
760 | } |
762 | } |
761 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
763 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
762 | { |
764 | { |
763 | unsigned char label[16]; // local sram buffer |
765 | unsigned char label[16]; // local sram buffer |
764 | memcpy_P(label, ANALOG_TEXT[DebugTextAnforderung], 16); // read lable from flash to sra |
766 | memcpy_P(label, ANALOG_TEXT[DebugTextAnforderung], 16); // read lable from flash to sra |
765 | SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),label, 16); |
767 | SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),label, 16); |
766 | DebugTextAnforderung = 255; |
768 | DebugTextAnforderung = 255; |
767 | } |
769 | } |
768 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
770 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
769 | { |
771 | { |
770 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
772 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
771 | ConfirmFrame = 0; |
773 | ConfirmFrame = 0; |
772 | } |
774 | } |
773 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
775 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
774 | { |
776 | { |
775 | SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |
777 | SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |
776 | GetPPMChannelAnforderung = 0; |
778 | GetPPMChannelAnforderung = 0; |
777 | } |
779 | } |
778 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
780 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
779 | { |
781 | { |
780 | WinkelOut.Winkel[0] = ToNaviCtrl.IntegralNick;//(int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
782 | WinkelOut.Winkel[0] = ToNaviCtrl.IntegralNick;//(int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
781 | WinkelOut.Winkel[1] = ToNaviCtrl.IntegralRoll;//(int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
783 | WinkelOut.Winkel[1] = ToNaviCtrl.IntegralRoll;//(int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
782 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
784 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
783 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
785 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
784 | SendOutData('k', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
786 | SendOutData('k', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
785 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
787 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
786 | if(!NaviDataOkay) Kompass_Timer = SetDelay(99); |
788 | if(JustMK3MagConnected) Kompass_Timer = SetDelay(99); |
787 | else Kompass_Timer = SetDelay(999); |
789 | else Kompass_Timer = SetDelay(999); |
788 | } |
790 | } |
789 | #ifdef DEBUG // only include functions if DEBUG is defined |
791 | #ifdef DEBUG // only include functions if DEBUG is defined |
790 | if(SendDebugOutput && UebertragungAbgeschlossen) |
792 | if(SendDebugOutput && UebertragungAbgeschlossen) |
791 | { |
793 | { |
792 | SendOutData('0', FC_ADDRESS, 1, (unsigned char *) &tDebug, sizeof(tDebug)); |
794 | SendOutData('0', FC_ADDRESS, 1, (unsigned char *) &tDebug, sizeof(tDebug)); |
793 | SendDebugOutput = 0; |
795 | SendDebugOutput = 0; |
794 | } |
796 | } |
795 | #endif |
797 | #endif |
796 | } |
798 | } |
797 | 799 | ||
798 | 800 | ||
799 | 801 |