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