Rev 360 | Rev 378 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 360 | Rev 362 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | // + Software Nutzungsbedingungen (english version: see below) |
7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
22 | // + des Mitverschuldens offen. |
22 | // + des Mitverschuldens offen. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
30 | // + 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. |
30 | // + 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. |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Software LICENSING TERMS |
32 | // + Software LICENSING TERMS |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
35 | // + 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 |
35 | // + 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 |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
37 | // + The Software may only be used with the Licensor's products. |
37 | // + The Software may only be used with the Licensor's products. |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
40 | // + agreement shall be the property of the Licensor. |
40 | // + agreement shall be the property of the Licensor. |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
43 | // + The customer shall be responsible for taking reasonable precautions |
43 | // + The customer shall be responsible for taking reasonable precautions |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
53 | // + #### END OF LICENSING TERMS #### |
53 | // + #### END OF LICENSING TERMS #### |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | #include <stdio.h> |
56 | #include <stdio.h> |
57 | #include <stdarg.h> |
57 | #include <stdarg.h> |
58 | #include <string.h> |
58 | #include <string.h> |
59 | 59 | ||
60 | #include "91x_lib.h" |
60 | #include "91x_lib.h" |
61 | #include "main.h" |
61 | #include "main.h" |
62 | #include "config.h" |
62 | #include "config.h" |
63 | #include "menu.h" |
63 | #include "menu.h" |
64 | #include "GPS.h" |
64 | #include "GPS.h" |
65 | #include "i2c.h" |
65 | #include "i2c.h" |
66 | #include "uart0.h" |
66 | #include "uart0.h" |
67 | #include "uart1.h" |
67 | #include "uart1.h" |
68 | #include "uart2.h" |
68 | #include "uart2.h" |
69 | #include "timer1.h" |
69 | #include "timer1.h" |
70 | #include "timer2.h" |
70 | #include "timer2.h" |
71 | #include "analog.h" |
71 | #include "analog.h" |
72 | #include "compass.h" |
72 | #include "compass.h" |
73 | #include "waypoints.h" |
73 | #include "waypoints.h" |
74 | #include "mkprotocol.h" |
74 | #include "mkprotocol.h" |
75 | #include "params.h" |
75 | #include "params.h" |
76 | #include "fifo.h" |
76 | #include "fifo.h" |
77 | #include "debug.h" |
77 | #include "debug.h" |
78 | #include "spi_slave.h" |
78 | #include "spi_slave.h" |
79 | #include "ftphelper.h" |
79 | #include "ftphelper.h" |
80 | 80 | ||
81 | #define FALSE 0 |
81 | #define FALSE 0 |
82 | #define TRUE 1 |
82 | #define TRUE 1 |
83 | 83 | ||
84 | #define ABO_TIMEOUT 8000 // disable abo after 8 seconds |
84 | #define ABO_TIMEOUT 8000 // disable abo after 8 seconds |
85 | u32 UART1_AboTimeOut = 0; |
85 | u32 UART1_AboTimeOut = 0; |
86 | 86 | ||
87 | u8 UART1_Request_VersionInfo = FALSE; |
87 | u8 UART1_Request_VersionInfo = FALSE; |
88 | u8 UART1_Request_ExternalControl= FALSE; |
88 | u8 UART1_Request_ExternalControl= FALSE; |
89 | u8 UART1_Request_Display = FALSE; |
89 | u8 UART1_Request_Display = FALSE; |
90 | u8 UART1_Request_Display1 = FALSE; |
90 | u8 UART1_Request_Display1 = FALSE; |
91 | u8 UART1_Request_DebugData = FALSE; |
91 | u8 UART1_Request_DebugData = FALSE; |
92 | u8 UART1_Request_DebugLabel = 255; |
92 | u8 UART1_Request_DebugLabel = 255; |
93 | u8 UART1_Request_NaviData = FALSE; |
93 | u8 UART1_Request_NaviData = FALSE; |
94 | u8 UART1_Request_ErrorMessage = FALSE; |
94 | u8 UART1_Request_ErrorMessage = FALSE; |
95 | u8 UART1_Request_WritePoint = 0xFF; |
95 | u8 UART1_Request_WritePoint = 0xFF; |
96 | u8 UART1_Request_ReadPoint = 0; |
96 | u8 UART1_Request_ReadPoint = 0; |
97 | u8 UART1_Request_Data3D = FALSE; |
97 | u8 UART1_Request_Data3D = FALSE; |
98 | u8 UART1_Request_MotorData = FALSE; |
98 | u8 UART1_Request_MotorData = FALSE; |
99 | u8 UART1_Request_Echo = FALSE; |
99 | u8 UART1_Request_Echo = FALSE; |
100 | u8 UART1_Request_ParameterId = 0; |
100 | u8 UART1_Request_ParameterId = 0; |
101 | u8 UART1_Request_Parameter = FALSE; |
101 | u8 UART1_Request_Parameter = FALSE; |
102 | u8 UART1_DisplayKeys = 0; |
102 | u8 UART1_DisplayKeys = 0; |
103 | u8 UART1_DisplayLine = 0; |
103 | u8 UART1_DisplayLine = 0; |
104 | u8 UART1_ConfirmFrame = 0; |
104 | u8 UART1_ConfirmFrame = 0; |
105 | u8 UART1_Request_FTP = FALSE; |
105 | u8 UART1_Request_FTP = FALSE; |
106 | u8 LastTransmittedFCStatusFlags2 = 0; |
106 | u8 LastTransmittedFCStatusFlags2 = 0; |
107 | 107 | ||
108 | UART_TypeDef *DebugUART = UART1; |
108 | UART_TypeDef *DebugUART = UART1; |
109 | 109 | ||
110 | #ifdef FOLLOW_ME |
110 | #ifdef FOLLOW_ME |
111 | #define FOLLOW_ME_INTERVAL 200 // 5 Hz |
111 | #define FOLLOW_ME_INTERVAL 200 // 5 Hz |
112 | u32 UART1_FollowMe_Timer = 0; |
112 | u32 UART1_FollowMe_Timer = 0; |
113 | Point_t FollowMe; |
113 | Point_t FollowMe; |
114 | #endif |
114 | #endif |
115 | 115 | ||
116 | // the primary rx fifo |
116 | // the primary rx fifo |
117 | #define UART1_RX_FIFO_LEN 512 |
117 | #define UART1_RX_FIFO_LEN 512 |
118 | u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN]; |
118 | u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN]; |
119 | fifo_t UART1_rx_fifo; |
119 | fifo_t UART1_rx_fifo; |
120 | 120 | ||
121 | // the rx buffer |
121 | // the rx buffer |
122 | #define UART1_RX_BUFFER_LEN 150 |
122 | #define UART1_RX_BUFFER_LEN 150 |
123 | u8 UART1_rbuffer[UART1_RX_BUFFER_LEN]; |
123 | u8 UART1_rbuffer[UART1_RX_BUFFER_LEN]; |
124 | Buffer_t UART1_rx_buffer; |
124 | Buffer_t UART1_rx_buffer; |
125 | 125 | ||
126 | // the tx buffer |
126 | // the tx buffer |
127 | #define UART1_TX_BUFFER_LEN 1024 |
127 | #define UART1_TX_BUFFER_LEN 1024 |
128 | u8 UART1_tbuffer[UART1_TX_BUFFER_LEN]; |
128 | u8 UART1_tbuffer[UART1_TX_BUFFER_LEN]; |
129 | Buffer_t UART1_tx_buffer; |
129 | Buffer_t UART1_tx_buffer; |
130 | 130 | ||
131 | volatile u8 SerialLinkOkay = 0; |
131 | volatile u8 SerialLinkOkay = 0; |
132 | 132 | ||
133 | u8 text[200]; |
133 | u8 text[200]; |
134 | 134 | ||
135 | const u8 ANALOG_LABEL[32][16] = |
135 | const u8 ANALOG_LABEL[32][16] = |
136 | { |
136 | { |
137 | //1234567890123456 |
137 | //1234567890123456 |
138 | "AngleNick ", //0 |
138 | "AngleNick ", //0 |
139 | "AngleRoll ", |
139 | "AngleRoll ", |
140 | "AccNick ", |
140 | "AccNick ", |
141 | "AccRoll ", |
141 | "AccRoll ", |
142 | "OperatingRadius ", |
142 | "OperatingRadius ", |
143 | "FC-Flags ", //5 |
143 | "FC-Flags ", //5 |
144 | "NC-Flags ", |
144 | "NC-Flags ", |
145 | "NickServo ", |
145 | "NickServo ", |
146 | "RollServo ", |
146 | "RollServo ", |
147 | "GPS Data ", |
147 | "GPS Data ", |
148 | "CompassHeading ", //10 |
148 | "CompassHeading ", //10 |
149 | "GyroHeading ", |
149 | "GyroHeading ", |
150 | "SPI Error ", |
150 | "SPI Error ", |
151 | "SPI Okay ", |
151 | "SPI Okay ", |
152 | "I2C Error ", |
152 | "I2C Error ", |
153 | "I2C Okay ", //15 |
153 | "I2C Okay ", //15 |
154 | "16 ", |
154 | "16 ", |
155 | "17 ", |
155 | "17 ", |
156 | "18 ", |
156 | "18 ", |
157 | "19 ", // SD-Card-time |
157 | "19 ", // SD-Card-time |
158 | "EarthMagnet [%] ", //20 |
158 | "EarthMagnet [%] ", //20 |
159 | "Z_Speed ", |
159 | "Z_Speed ", |
160 | "N_Speed ", |
160 | "N_Speed ", |
161 | "E_Speed ", |
161 | "E_Speed ", |
162 | "Magnet X ", |
162 | "Magnet X ", |
163 | "Magnet Y ", //25 |
163 | "Magnet Y ", //25 |
164 | "Magnet Z ", |
164 | "Magnet Z ", |
165 | "Distance N ", |
165 | "Distance N ", |
166 | "Distance E ", |
166 | "Distance E ", |
167 | "GPS_Nick ", |
167 | "GPS_Nick ", |
168 | "GPS_Roll ", //30 |
168 | "GPS_Roll ", //30 |
169 | "Used_Sats " |
169 | "Used_Sats " |
170 | }; |
170 | }; |
171 | 171 | ||
172 | DebugOut_t DebugOut; |
172 | DebugOut_t DebugOut; |
173 | ExternControl_t ExternControl; |
173 | ExternControl_t ExternControl; |
174 | UART_VersionInfo_t UART_VersionInfo; |
174 | UART_VersionInfo_t UART_VersionInfo; |
175 | NaviData_t NaviData; |
175 | NaviData_t NaviData; |
176 | Data3D_t Data3D; |
176 | Data3D_t Data3D; |
177 | u16 Echo; // 2 bytes recieved will be sent back as echo |
177 | u16 Echo; // 2 bytes recieved will be sent back as echo |
178 | 178 | ||
179 | u32 UART1_DebugData_Timer = 0; |
179 | u32 UART1_DebugData_Timer = 0; |
180 | u32 UART1_DebugData_Interval = 0; // in ms |
180 | u32 UART1_DebugData_Interval = 0; // in ms |
181 | u32 UART1_NaviData_Timer = 0; |
181 | u32 UART1_NaviData_Timer = 0; |
182 | u32 UART1_NaviData_Interval = 0; // in ms |
182 | u32 UART1_NaviData_Interval = 0; // in ms |
183 | u32 UART1_Data3D_Timer = 0; |
183 | u32 UART1_Data3D_Timer = 0; |
184 | u32 UART1_Data3D_Interval = 0; // in ms |
184 | u32 UART1_Data3D_Interval = 0; // in ms |
185 | u32 UART1_MotorData_Timer = 0; |
185 | u32 UART1_MotorData_Timer = 0; |
186 | u32 UART1_MotorData_Interval = 0; // in ms |
186 | u32 UART1_MotorData_Interval = 0; // in ms |
187 | u32 UART1_Display_Timer = 0; |
187 | u32 UART1_Display_Timer = 0; |
188 | u32 UART1_Display_Interval = 0; // in ms |
188 | u32 UART1_Display_Interval = 0; // in ms |
189 | 189 | ||
190 | /********************************************************/ |
190 | /********************************************************/ |
191 | /* Initialization the UART1 */ |
191 | /* Initialization the UART1 */ |
192 | /********************************************************/ |
192 | /********************************************************/ |
193 | void UART1_Init (void) |
193 | void UART1_Init (void) |
194 | { |
194 | { |
195 | GPIO_InitTypeDef GPIO_InitStructure; |
195 | GPIO_InitTypeDef GPIO_InitStructure; |
196 | UART_InitTypeDef UART_InitStructure; |
196 | UART_InitTypeDef UART_InitStructure; |
197 | 197 | ||
198 | // initialize txd buffer |
198 | // initialize txd buffer |
199 | Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN); |
199 | Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN); |
200 | 200 | ||
201 | // initialize rxd buffer |
201 | // initialize rxd buffer |
202 | Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN); |
202 | Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN); |
203 | 203 | ||
204 | // initialize the rx fifo, block UART IRQ geting a byte from fifo |
204 | // initialize the rx fifo, block UART IRQ geting a byte from fifo |
205 | fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine); |
205 | fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine); |
206 | 206 | ||
207 | SCU_APBPeriphClockConfig(__UART1, ENABLE); // Enable the UART1 Clock |
207 | SCU_APBPeriphClockConfig(__UART1, ENABLE); // Enable the UART1 Clock |
208 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
208 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
209 | 209 | ||
210 | /*Configure UART1_Rx pin GPIO3.2*/ |
210 | /*Configure UART1_Rx pin GPIO3.2*/ |
211 | GPIO_StructInit(&GPIO_InitStructure); |
211 | GPIO_StructInit(&GPIO_InitStructure); |
212 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
212 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
213 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
213 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
214 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
214 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
215 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
215 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
216 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART1_RxD |
216 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART1_RxD |
217 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
217 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
218 | 218 | ||
219 | /*Configure UART1_Tx pin GPIO3.3*/ |
219 | /*Configure UART1_Tx pin GPIO3.3*/ |
220 | GPIO_StructInit(&GPIO_InitStructure); |
220 | GPIO_StructInit(&GPIO_InitStructure); |
221 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
221 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
222 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
222 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
223 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
223 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
224 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART1_TX |
224 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART1_TX |
225 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
225 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
226 | 226 | ||
227 | /* UART1 configured as follow: |
227 | /* UART1 configured as follow: |
228 | - Word Length = 8 Bits |
228 | - Word Length = 8 Bits |
229 | - One Stop Bit |
229 | - One Stop Bit |
230 | - No parity |
230 | - No parity |
231 | - BaudRate = 57600 baud |
231 | - BaudRate = 57600 baud |
232 | - Hardware flow control Disabled |
232 | - Hardware flow control Disabled |
233 | - Receive and transmit enabled |
233 | - Receive and transmit enabled |
234 | - Receive and transmit FIFOs are Disabled |
234 | - Receive and transmit FIFOs are Disabled |
235 | */ |
235 | */ |
236 | UART_StructInit(&UART_InitStructure); |
236 | UART_StructInit(&UART_InitStructure); |
237 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
237 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
238 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
238 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
239 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
239 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
240 | UART_InitStructure.UART_BaudRate = UART1_BAUD_RATE; |
240 | UART_InitStructure.UART_BaudRate = UART1_BAUD_RATE; |
241 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
241 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
242 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
242 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
243 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
243 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
244 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
244 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
245 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
245 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
246 | 246 | ||
247 | UART_DeInit(UART1); // reset uart 1 to default |
247 | UART_DeInit(UART1); // reset uart 1 to default |
248 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
248 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
249 | // enable uart 1 interrupts selective |
249 | // enable uart 1 interrupts selective |
250 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
250 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
251 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
251 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
252 | // configure the uart 1 interupt line |
252 | // configure the uart 1 interupt line |
253 | VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1); |
253 | VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1); |
254 | // enable the uart 1 IRQ |
254 | // enable the uart 1 IRQ |
255 | VIC_ITCmd(UART1_ITLine, ENABLE); |
255 | VIC_ITCmd(UART1_ITLine, ENABLE); |
256 | 256 | ||
257 | // initialize the debug timer |
257 | // initialize the debug timer |
258 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
258 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
259 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500; |
259 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500; |
260 | 260 | ||
261 | // Fill Version Info Structure |
261 | // Fill Version Info Structure |
262 | UART_VersionInfo.SWMajor = VERSION_MAJOR; |
262 | UART_VersionInfo.SWMajor = VERSION_MAJOR; |
263 | UART_VersionInfo.SWMinor = VERSION_MINOR; |
263 | UART_VersionInfo.SWMinor = VERSION_MINOR; |
264 | UART_VersionInfo.SWPatch = VERSION_PATCH; |
264 | UART_VersionInfo.SWPatch = VERSION_PATCH; |
265 | UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
265 | UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
266 | UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
266 | UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
267 | 267 | ||
268 | NaviData.Version = NAVIDATA_VERSION; |
268 | NaviData.Version = NAVIDATA_VERSION; |
269 | 269 | ||
270 | UART1_PutString("\r\n UART1 init...ok"); |
270 | UART1_PutString("\r\n UART1 init...ok"); |
271 | } |
271 | } |
272 | 272 | ||
273 | 273 | ||
274 | /****************************************************************/ |
274 | /****************************************************************/ |
275 | /* USART1 receiver ISR */ |
275 | /* USART1 receiver ISR */ |
276 | /****************************************************************/ |
276 | /****************************************************************/ |
277 | void UART1_IRQHandler(void) |
277 | void UART1_IRQHandler(void) |
278 | { |
278 | { |
279 | static u8 abortState = 0; |
279 | static u8 abortState = 0; |
280 | u8 c; |
280 | u8 c; |
281 | 281 | ||
282 | IENABLE; |
282 | IENABLE; |
283 | 283 | ||
284 | if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) ) |
284 | if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) ) |
285 | { |
285 | { |
286 | // clear the pending bits! |
286 | // clear the pending bits! |
287 | UART_ClearITPendingBit(UART1, UART_IT_Receive); |
287 | UART_ClearITPendingBit(UART1, UART_IT_Receive); |
288 | UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut); |
288 | UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut); |
289 | // if debug UART is not UART1 |
289 | // if debug UART is not UART1 |
290 | if (DebugUART != UART1) |
290 | if (DebugUART != UART1) |
291 | { // forward received data to the debug UART tx buffer |
291 | { // forward received data to the debug UART tx buffer |
292 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
292 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
293 | { |
293 | { |
294 | // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART |
294 | // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART |
295 | c = UART_ReceiveData(UART1); |
295 | c = UART_ReceiveData(UART1); |
296 | 296 | ||
297 | // check for abort condition (ESC ESC 0x55 0xAA 0x00) |
297 | // check for abort condition (ESC ESC 0x55 0xAA 0x00) |
298 | switch (abortState) |
298 | switch (abortState) |
299 | { |
299 | { |
300 | case 0: |
300 | case 0: |
301 | if (c == 27) abortState++; |
301 | if (c == 27) abortState++; |
302 | break; |
302 | break; |
303 | case 1: |
303 | case 1: |
304 | if (c == 27) abortState++; |
304 | if (c == 27) abortState++; |
305 | else abortState = 0; |
305 | else abortState = 0; |
306 | break; |
306 | break; |
307 | case 2: |
307 | case 2: |
308 | if (c == 0x55) abortState++; |
308 | if (c == 0x55) abortState++; |
309 | else abortState = 0; |
309 | else abortState = 0; |
310 | break; |
310 | break; |
311 | case 3: |
311 | case 3: |
312 | if (c == 0xAA) abortState++; |
312 | if (c == 0xAA) abortState++; |
313 | else abortState = 0; |
313 | else abortState = 0; |
314 | break; |
314 | break; |
315 | case 4: |
315 | case 4: |
316 | if (c == 0x00) |
316 | if (c == 0x00) |
317 | { |
317 | { |
318 | if(DebugUART == UART0) |
318 | if(DebugUART == UART0) |
319 | { |
319 | { |
320 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); |
320 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); |
321 | TIMER2_Init(); // enbable servo outputs |
321 | TIMER2_Init(); // enbable servo outputs |
322 | fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer |
322 | fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer |
323 | } |
323 | } |
324 | DebugUART = UART1; |
324 | DebugUART = UART1; |
325 | } |
325 | } |
326 | abortState = 0; |
326 | abortState = 0; |
327 | break; |
327 | break; |
328 | } // end switch abort state |
328 | } // end switch abort state |
329 | // if the Debug uart is not UART1, redirect input to the Debug UART |
329 | // if the Debug uart is not UART1, redirect input to the Debug UART |
330 | if (DebugUART != UART1) |
330 | if (DebugUART != UART1) |
331 | { |
331 | { |
332 | // wait for space in the tx buffer of the DebugUART |
332 | // wait for space in the tx buffer of the DebugUART |
333 | while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {}; |
333 | while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {}; |
334 | // move byte to the tx fifo of the debug uart |
334 | // move byte to the tx fifo of the debug uart |
335 | UART_SendData(DebugUART, c); |
335 | UART_SendData(DebugUART, c); |
336 | } |
336 | } |
337 | } |
337 | } |
338 | } |
338 | } |
339 | else // DebugUART == UART1 (normal operation) |
339 | else // DebugUART == UART1 (normal operation) |
340 | { |
340 | { |
341 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
341 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
342 | { // some byes in the hardware fifo |
342 | { // some byes in the hardware fifo |
343 | // get byte from hardware fifo |
343 | // get byte from hardware fifo |
344 | c = UART_ReceiveData(UART1); |
344 | c = UART_ReceiveData(UART1); |
345 | // put into the software fifo |
345 | // put into the software fifo |
346 | if(!fifo_put(&UART1_rx_fifo, c)) |
346 | if(!fifo_put(&UART1_rx_fifo, c)) |
347 | { // fifo overflow |
347 | { // fifo overflow |
348 | //fifo_purge(&UART1_rx_fifo); // flush the whole buffer |
348 | //fifo_purge(&UART1_rx_fifo); // flush the whole buffer |
349 | } |
349 | } |
350 | } // EOF while some byes in the hardware fifo |
350 | } // EOF while some byes in the hardware fifo |
351 | } // eof DebugUart = UART1 |
351 | } // eof DebugUart = UART1 |
352 | } |
352 | } |
353 | 353 | ||
354 | IDISABLE; |
354 | IDISABLE; |
355 | } |
355 | } |
356 | 356 | ||
357 | /**************************************************************/ |
357 | /**************************************************************/ |
358 | /* Process incomming data from debug uart */ |
358 | /* Process incomming data from debug uart */ |
359 | /**************************************************************/ |
359 | /**************************************************************/ |
360 | void UART1_ProcessRxData(void) |
360 | void UART1_ProcessRxData(void) |
361 | { |
361 | { |
362 | // return on forwarding uart or unlocked rx buffer |
362 | // return on forwarding uart or unlocked rx buffer |
363 | if(DebugUART != UART1) return; |
363 | if(DebugUART != UART1) return; |
364 | 364 | ||
365 | u8 c; |
365 | u8 c; |
366 | // if rx buffer is not locked |
366 | // if rx buffer is not locked |
367 | if(UART1_rx_buffer.Locked == FALSE) |
367 | if(UART1_rx_buffer.Locked == FALSE) |
368 | { |
368 | { |
369 | //collect data from primary rx fifo |
369 | //collect data from primary rx fifo |
370 | while(fifo_get(&UART1_rx_fifo, &c)) |
370 | while(fifo_get(&UART1_rx_fifo, &c)) |
371 | { |
371 | { |
372 | // break if complete frame is collected |
372 | // break if complete frame is collected |
373 | if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break; |
373 | if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break; |
374 | } |
374 | } |
375 | } |
375 | } |
376 | if(UART1_rx_buffer.Locked == FALSE) return; |
376 | if(UART1_rx_buffer.Locked == FALSE) return; |
377 | 377 | ||
378 | Point_t * pPoint = NULL; |
378 | Point_t * pPoint = NULL; |
379 | SerialMsg_t SerialMsg; |
379 | SerialMsg_t SerialMsg; |
380 | 380 | ||
381 | // analyze header first |
381 | // analyze header first |
382 | MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg); |
382 | MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg); |
383 | if( SerialMsg.Address == FC_ADDRESS ) |
383 | if( SerialMsg.Address == FC_ADDRESS ) |
384 | { |
384 | { |
385 | switch(SerialMsg.CmdID) |
385 | switch(SerialMsg.CmdID) |
386 | { |
386 | { |
387 | // case 'v': // version |
387 | // case 'v': // version |
388 | case 'y': // serial poti values |
388 | case 'y': // serial poti values |
389 | case 'b': // extern control |
389 | case 'b': // extern control |
390 | Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC |
390 | Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC |
391 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
391 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
392 | return; //end process rx data |
392 | return; //end process rx data |
393 | break; |
393 | break; |
394 | } |
394 | } |
395 | } |
395 | } |
396 | 396 | ||
397 | MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
397 | MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
398 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
398 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
399 | switch(SerialMsg.Address) // check for Slave Address |
399 | switch(SerialMsg.Address) // check for Slave Address |
400 | { |
400 | { |
401 | case NC_ADDRESS: // own Slave Address |
401 | case NC_ADDRESS: // own Slave Address |
402 | switch(SerialMsg.CmdID) |
402 | switch(SerialMsg.CmdID) |
403 | { |
403 | { |
404 | 404 | ||
405 | case 'f': // ftp command |
405 | case 'f': // ftp command |
406 | UART1_Request_FTP = SerialMsg.pData[0]; |
406 | UART1_Request_FTP = SerialMsg.pData[0]; |
407 | 407 | ||
408 | //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE) |
408 | //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE) |
409 | memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter |
409 | memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter |
410 | break; |
410 | break; |
411 | 411 | ||
412 | case 'z': // connection checker |
412 | case 'z': // connection checker |
413 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
413 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
414 | UART1_Request_Echo = TRUE; |
414 | UART1_Request_Echo = TRUE; |
415 | break; |
415 | break; |
416 | 416 | ||
417 | case 'e': // request for the text of the error status |
417 | case 'e': // request for the text of the error status |
418 | UART1_Request_ErrorMessage = TRUE; |
418 | UART1_Request_ErrorMessage = TRUE; |
419 | break; |
419 | break; |
420 | 420 | ||
421 | case 's':// new target position |
421 | case 's':// new target position |
422 | pPoint = (Point_t*)SerialMsg.pData; |
422 | pPoint = (Point_t*)SerialMsg.pData; |
423 | if(pPoint->Position.Status == NEWDATA) |
423 | if(pPoint->Position.Status == NEWDATA) |
424 | { |
424 | { |
425 | //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list |
425 | //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list |
426 | //pPoint->Index = 1; // must be one after empty list |
426 | //pPoint->Index = 1; // must be one after empty list |
427 | PointList_SetAt(pPoint); |
427 | PointList_SetAt(pPoint); |
428 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
428 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
429 | GPS_pWaypoint = PointList_WPBegin(); // updates POI index |
429 | GPS_pWaypoint = PointList_WPBegin(); // updates POI index |
430 | if(GPS_pWaypoint != NULL) // if new WP exist |
430 | if(GPS_pWaypoint != NULL) // if new WP exist |
431 | { // update WP hold time stamp immediately! |
431 | { // update WP hold time stamp immediately! |
432 | /* if(GPS_pWaypoint->Heading > 0 && GPS_pWaypoint->Heading <= 360) |
432 | /* if(GPS_pWaypoint->Heading > 0 && GPS_pWaypoint->Heading <= 360) |
433 | { |
433 | { |
434 | CAM_Orientation.Azimuth = GPS_pWaypoint->Heading; |
434 | CAM_Orientation.Azimuth = GPS_pWaypoint->Heading; |
435 | CAM_Orientation.UpdateMask |= CAM_UPDATE_AZIMUTH; |
435 | CAM_Orientation.UpdateMask |= CAM_UPDATE_AZIMUTH; |
436 | } |
436 | } |
437 | */ |
437 | */ |
438 | } |
438 | } |
439 | BeepTime = 50; |
439 | BeepTime = 50; |
440 | } |
440 | } |
441 | break; |
441 | break; |
442 | 442 | ||
443 | case 'u': // redirect debug uart |
443 | case 'u': // redirect debug uart |
444 | switch(SerialMsg.pData[0]) |
444 | switch(SerialMsg.pData[0]) |
445 | { |
445 | { |
446 | case UART_FLIGHTCTRL: |
446 | case UART_FLIGHTCTRL: |
447 | UART2_Init(); // initialize UART2 to FC pins |
447 | UART2_Init(); // initialize UART2 to FC pins |
448 | fifo_purge(&UART1_rx_fifo); |
448 | fifo_purge(&UART1_rx_fifo); |
449 | TIMER2_Deinit(); // reduce irq load |
449 | TIMER2_Deinit(); // reduce irq load |
450 | DebugUART = UART2; |
450 | DebugUART = UART2; |
451 | break; |
451 | break; |
452 | case UART_MK3MAG: |
452 | case UART_MK3MAG: |
453 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running |
453 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running |
454 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
454 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
455 | GPSData.Status = INVALID; |
455 | GPSData.Status = INVALID; |
456 | fifo_purge(&UART1_rx_fifo); |
456 | fifo_purge(&UART1_rx_fifo); |
457 | DebugUART = UART0; |
457 | DebugUART = UART0; |
458 | break; |
458 | break; |
459 | case UART_MKGPS: |
459 | case UART_MKGPS: |
460 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running |
460 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running |
461 | TIMER2_Deinit(); // disable servo outputs to reduce irq load |
461 | TIMER2_Deinit(); // disable servo outputs to reduce irq load |
462 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); // connect UART0 to MKGPS pins |
462 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); // connect UART0 to MKGPS pins |
463 | GPSData.Status = INVALID; |
463 | GPSData.Status = INVALID; |
464 | fifo_purge(&UART1_rx_fifo); |
464 | fifo_purge(&UART1_rx_fifo); |
465 | DebugUART = UART0; |
465 | DebugUART = UART0; |
466 | break; |
466 | break; |
467 | default: |
467 | default: |
468 | break; |
468 | break; |
469 | } |
469 | } |
470 | break; |
470 | break; |
471 | 471 | ||
472 | case 'w':// Set point in list at index |
472 | case 'w':// Set point in list at index |
473 | { |
473 | { |
474 | pPoint = (Point_t*)SerialMsg.pData; |
474 | pPoint = (Point_t*)SerialMsg.pData; |
475 | 475 | ||
476 | if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0)) |
476 | if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0)) |
477 | { |
477 | { |
478 | PointList_Clear(); |
478 | PointList_Clear(); |
479 | GPS_pWaypoint = PointList_WPBegin(); |
479 | GPS_pWaypoint = PointList_WPBegin(); |
480 | UART1_Request_WritePoint = 0; // return new point count |
480 | UART1_Request_WritePoint = 0; // return new point count |
481 | } |
481 | } |
482 | else |
482 | else |
483 | { // update WP in list at index |
483 | { // update WP in list at index |
484 | if(pPoint->Index > MaxNumberOfWaypoints) |
484 | if(pPoint->Index > MaxNumberOfWaypoints) |
485 | { |
485 | { |
486 | UART1_Request_WritePoint = 254; |
486 | UART1_Request_WritePoint = 254; |
487 | pPoint->Index = MaxNumberOfWaypoints; |
487 | pPoint->Index = MaxNumberOfWaypoints; |
488 | } |
488 | } |
489 | else |
489 | else |
490 | UART1_Request_WritePoint = PointList_SetAt(pPoint); |
490 | UART1_Request_WritePoint = PointList_SetAt(pPoint); |
491 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
491 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
492 | if(UART1_Request_WritePoint == pPoint->Index) |
492 | if(UART1_Request_WritePoint == pPoint->Index) |
493 | { |
493 | { |
494 | BeepTime = 500; |
494 | BeepTime = 500; |
495 | } |
495 | } |
496 | } |
496 | } |
497 | } |
497 | } |
498 | break; |
498 | break; |
499 | 499 | ||
500 | case 'x':// Read Waypoint from List |
500 | case 'x':// Read Waypoint from List |
501 | UART1_Request_ReadPoint = SerialMsg.pData[0]; |
501 | UART1_Request_ReadPoint = SerialMsg.pData[0]; |
502 | break; |
502 | break; |
503 | 503 | ||
504 | case 'j':// Set/Get NC-Parameter |
504 | case 'j':// Set/Get NC-Parameter |
505 | switch(SerialMsg.pData[0]) |
505 | switch(SerialMsg.pData[0]) |
506 | { |
506 | { |
507 | case 0: // get |
507 | case 0: // get |
508 | break; |
508 | break; |
509 | 509 | ||
510 | case 1: // set |
510 | case 1: // set |
511 | { |
511 | { |
512 | s16 value; |
512 | s16 value; |
513 | value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100; |
513 | value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100; |
514 | NCParams_SetValue(SerialMsg.pData[1], &value); |
514 | NCParams_SetValue(SerialMsg.pData[1], &value); |
515 | } |
515 | } |
516 | break; |
516 | break; |
517 | 517 | ||
518 | default: |
518 | default: |
519 | break; |
519 | break; |
520 | } |
520 | } |
521 | UART1_Request_ParameterId = SerialMsg.pData[1]; |
521 | UART1_Request_ParameterId = SerialMsg.pData[1]; |
522 | UART1_Request_Parameter = TRUE; |
522 | UART1_Request_Parameter = TRUE; |
523 | break; |
523 | break; |
524 | default: |
524 | default: |
525 | // unsupported command recieved |
525 | // unsupported command recieved |
526 | break; |
526 | break; |
527 | } // case NC_ADDRESS |
527 | } // case NC_ADDRESS |
528 | // "break;" is missing here to fall thru to the common commands |
528 | // "break;" is missing here to fall thru to the common commands |
529 | 529 | ||
530 | default: // and any other Slave Address |
530 | default: // and any other Slave Address |
531 | 531 | ||
532 | switch(SerialMsg.CmdID) // check CmdID |
532 | switch(SerialMsg.CmdID) // check CmdID |
533 | { |
533 | { |
534 | case 'a':// request for the labels of the analog debug outputs |
534 | case 'a':// request for the labels of the analog debug outputs |
535 | UART1_Request_DebugLabel = SerialMsg.pData[0]; |
535 | UART1_Request_DebugLabel = SerialMsg.pData[0]; |
536 | if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31; |
536 | if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31; |
537 | break; |
537 | break; |
538 | /* |
538 | /* |
539 | case 'b': // submit extern control |
539 | case 'b': // submit extern control |
540 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
540 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
541 | UART1_ConfirmFrame = ExternControl.Frame; |
541 | UART1_ConfirmFrame = ExternControl.Frame; |
542 | break; |
542 | break; |
543 | */ |
543 | */ |
544 | case 'd': // request for debug data; |
544 | case 'd': // request for debug data; |
545 | UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
545 | UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
546 | if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE; |
546 | if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE; |
547 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
547 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
548 | break; |
548 | break; |
549 | 549 | ||
550 | case 'c': // request for 3D data; |
550 | case 'c': // request for 3D data; |
551 | UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
551 | UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
552 | if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE; |
552 | if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE; |
553 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
553 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
554 | break; |
554 | break; |
555 | 555 | ||
556 | case 'k': // request for Motor data; |
556 | case 'k': // request for Motor data; |
557 | UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10; |
557 | UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10; |
558 | if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE; |
558 | if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE; |
559 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
559 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
560 | break; |
560 | break; |
561 | 561 | ||
562 | case 'h':// reqest for display line |
562 | case 'h':// reqest for display line |
563 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
563 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
564 | { |
564 | { |
565 | UART1_DisplayLine = 2; |
565 | UART1_DisplayLine = 2; |
566 | UART1_Display_Interval = 0; |
566 | UART1_Display_Interval = 0; |
567 | } |
567 | } |
568 | else |
568 | else |
569 | { |
569 | { |
570 | UART1_DisplayKeys |= ~SerialMsg.pData[0]; |
570 | UART1_DisplayKeys |= ~SerialMsg.pData[0]; |
571 | UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
571 | UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
572 | UART1_DisplayLine = 4; |
572 | UART1_DisplayLine = 4; |
573 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
573 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
574 | } |
574 | } |
575 | UART1_Request_Display = TRUE; |
575 | UART1_Request_Display = TRUE; |
576 | break; |
576 | break; |
577 | 577 | ||
578 | case 'l':// reqest for display columns |
578 | case 'l':// reqest for display columns |
579 | MenuItem = SerialMsg.pData[0]; |
579 | MenuItem = SerialMsg.pData[0]; |
580 | UART1_Request_Display1 = TRUE; |
580 | UART1_Request_Display1 = TRUE; |
581 | break; |
581 | break; |
582 | 582 | ||
583 | case 'o': // request for navigation information |
583 | case 'o': // request for navigation information |
584 | UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
584 | UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
585 | if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE; |
585 | if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE; |
586 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
586 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
587 | break; |
587 | break; |
588 | 588 | ||
589 | case 'v': // request for version info |
589 | case 'v': // request for version info |
590 | UART1_Request_VersionInfo = TRUE; |
590 | UART1_Request_VersionInfo = TRUE; |
591 | break; |
591 | break; |
592 | default: |
592 | default: |
593 | // unsupported command recieved |
593 | // unsupported command recieved |
594 | break; |
594 | break; |
595 | } |
595 | } |
596 | break; // default: |
596 | break; // default: |
597 | } |
597 | } |
598 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
598 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
599 | } |
599 | } |
600 | 600 | ||
601 | 601 | ||
602 | /*****************************************************/ |
602 | /*****************************************************/ |
603 | /* Send a character */ |
603 | /* Send a character */ |
604 | /*****************************************************/ |
604 | /*****************************************************/ |
605 | s16 UART1_Putchar(char c) |
605 | s16 UART1_Putchar(char c) |
606 | { |
606 | { |
- | 607 | u32 timeout = 10000; |
|
607 | if (c == '\n') UART1_Putchar('\r'); |
608 | if (c == '\n') UART1_Putchar('\r'); |
608 | // wait until txd fifo is not full |
609 | // wait until txd fifo is not full |
609 | while (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET); |
610 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET) if(--timeout == 0) return(0); |
610 | // transmit byte |
611 | // transmit byte |
611 | UART_SendData(UART1, c); |
612 | UART_SendData(UART1, c); |
612 | #ifdef FOLLOW_ME |
613 | #ifdef FOLLOW_ME |
613 | if(TransmitAlsoToFC) UART_SendData(UART2, c); |
614 | if(TransmitAlsoToFC) UART_SendData(UART2, c); |
614 | #endif |
615 | #endif |
615 | return (0); |
616 | return (0); |
616 | } |
617 | } |
617 | 618 | ||
618 | /*****************************************************/ |
619 | /*****************************************************/ |
619 | /* Send a string to the debug uart */ |
620 | /* Send a string to the debug uart */ |
620 | /*****************************************************/ |
621 | /*****************************************************/ |
621 | void UART1_PutString(u8 *s) |
622 | void UART1_PutString(u8 *s) |
622 | { |
623 | { |
623 | if(s == NULL) return; |
624 | if(s == NULL) return; |
624 | while (*s != '\0' && DebugUART == UART1) |
625 | while (*s != '\0' && DebugUART == UART1) |
625 | { |
626 | { |
626 | UART1_Putchar(*s); |
627 | UART1_Putchar(*s); |
627 | s ++; |
628 | s ++; |
628 | } |
629 | } |
629 | } |
630 | } |
630 | 631 | ||
631 | 632 | ||
632 | /**************************************************************/ |
633 | /**************************************************************/ |
633 | /* Transmit tx buffer via debug uart */ |
634 | /* Transmit tx buffer via debug uart */ |
634 | /**************************************************************/ |
635 | /**************************************************************/ |
635 | void UART1_Transmit(void) |
636 | void UART1_Transmit(void) |
636 | { |
637 | { |
637 | u8 tmp_tx; |
638 | u8 tmp_tx; |
638 | if(DebugUART != UART1) return; |
639 | if(DebugUART != UART1) return; |
639 | // if something has to be send and the txd fifo is not full |
640 | // if something has to be send and the txd fifo is not full |
640 | if(UART1_tx_buffer.Locked == TRUE) |
641 | if(UART1_tx_buffer.Locked == TRUE) |
641 | { |
642 | { |
642 | // while there is some space in the tx fifo |
643 | // while there is some space in the tx fifo |
643 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET) |
644 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET) |
644 | { |
645 | { |
645 | tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer |
646 | tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer |
646 | UART_SendData(UART1, tmp_tx); // put character to txd fifo |
647 | UART_SendData(UART1, tmp_tx); // put character to txd fifo |
647 | #ifdef FOLLOW_ME |
648 | #ifdef FOLLOW_ME |
648 | if(TransmitAlsoToFC) |
649 | if(TransmitAlsoToFC) |
649 | { |
650 | { |
650 | UART_SendData(UART2, tmp_tx); // put character to txd fifo |
651 | UART_SendData(UART2, tmp_tx); // put character to txd fifo |
651 | } |
652 | } |
652 | #endif |
653 | #endif |
653 | // if terminating character or end of txd buffer reached |
654 | // if terminating character or end of txd buffer reached |
654 | if((tmp_tx == '\r') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes)) |
655 | if((tmp_tx == '\r') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes)) |
655 | { |
656 | { |
656 | Buffer_Clear(&UART1_tx_buffer); // clear txd buffer |
657 | Buffer_Clear(&UART1_tx_buffer); // clear txd buffer |
657 | #ifdef FOLLOW_ME |
658 | #ifdef FOLLOW_ME |
658 | TransmitAlsoToFC = 0; |
659 | TransmitAlsoToFC = 0; |
659 | #endif |
660 | #endif |
660 | break; // end while loop |
661 | break; // end while loop |
661 | } |
662 | } |
662 | } |
663 | } |
663 | } |
664 | } |
664 | } |
665 | } |
665 | 666 | ||
666 | /**************************************************************/ |
667 | /**************************************************************/ |
667 | /* Send the answers to incomming commands at the debug uart */ |
668 | /* Send the answers to incomming commands at the debug uart */ |
668 | /**************************************************************/ |
669 | /**************************************************************/ |
669 | void UART1_TransmitTxData(void) |
670 | void UART1_TransmitTxData(void) |
670 | { |
671 | { |
671 | static u8 motorindex1 = 255, motorindex2 = 0; |
672 | static u8 motorindex1 = 255, motorindex2 = 0; |
672 | if(DebugUART != UART1) return; |
673 | if(DebugUART != UART1) return; |
673 | 674 | ||
674 | if(CheckDelay(UART1_AboTimeOut)) |
675 | if(CheckDelay(UART1_AboTimeOut)) |
675 | { |
676 | { |
676 | UART1_DebugData_Interval = 0; |
677 | UART1_DebugData_Interval = 0; |
677 | UART1_NaviData_Interval = 0; |
678 | UART1_NaviData_Interval = 0; |
678 | UART1_Data3D_Interval = 0; |
679 | UART1_Data3D_Interval = 0; |
679 | UART1_Display_Interval = 0; |
680 | UART1_Display_Interval = 0; |
680 | } |
681 | } |
681 | 682 | ||
682 | UART1_Transmit(); // output pending bytes in tx buffer |
683 | UART1_Transmit(); // output pending bytes in tx buffer |
683 | if((UART1_tx_buffer.Locked == TRUE)) return; |
684 | if((UART1_tx_buffer.Locked == TRUE)) return; |
684 | 685 | ||
685 | if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE)) |
686 | if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE)) |
686 | { |
687 | { |
687 | s16 ParamValue; |
688 | s16 ParamValue; |
688 | NCParams_GetValue(UART1_Request_ParameterId, &ParamValue); |
689 | NCParams_GetValue(UART1_Request_ParameterId, &ParamValue); |
689 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request |
690 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request |
690 | UART1_Request_Parameter = FALSE; |
691 | UART1_Request_Parameter = FALSE; |
691 | } |
692 | } |
692 | else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE)) |
693 | else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE)) |
693 | { |
694 | { |
694 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request |
695 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request |
695 | Echo = 0; // reset echo value |
696 | Echo = 0; // reset echo value |
696 | UART1_Request_Echo = FALSE; |
697 | UART1_Request_Echo = FALSE; |
697 | } |
698 | } |
698 | else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE)) |
699 | else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE)) |
699 | { |
700 | { |
700 | CheckFTPCommand(UART1_Request_FTP); |
701 | CheckFTPCommand(UART1_Request_FTP); |
701 | UART1_Request_FTP = FALSE; |
702 | UART1_Request_FTP = FALSE; |
702 | } |
703 | } |
703 | else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
704 | else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
704 | { |
705 | { |
705 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint)); |
706 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint)); |
706 | UART1_Request_WritePoint = 0xFF; |
707 | UART1_Request_WritePoint = 0xFF; |
707 | } |
708 | } |
708 | else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE)) |
709 | else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE)) |
709 | { |
710 | { |
710 | u8 PointCount = PointList_GetCount(); |
711 | u8 PointCount = PointList_GetCount(); |
711 | if (UART1_Request_ReadPoint <= PointCount) |
712 | if (UART1_Request_ReadPoint <= PointCount) |
712 | { |
713 | { |
713 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t)); |
714 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t)); |
714 | } |
715 | } |
715 | else |
716 | else |
716 | { |
717 | { |
717 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount)); |
718 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount)); |
718 | } |
719 | } |
719 | UART1_Request_ReadPoint = 0; |
720 | UART1_Request_ReadPoint = 0; |
720 | } |
721 | } |
721 | else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
722 | else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
722 | { |
723 | { |
723 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16); |
724 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16); |
724 | UART1_Request_DebugLabel = 0xFF; |
725 | UART1_Request_DebugLabel = 0xFF; |
725 | } |
726 | } |
726 | else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE)) |
727 | else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE)) |
727 | { |
728 | { |
728 | NaviData.Errorcode = ErrorCode; |
729 | NaviData.Errorcode = ErrorCode; |
729 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
730 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
730 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval); |
731 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval); |
731 | UART1_Request_NaviData = FALSE; |
732 | UART1_Request_NaviData = FALSE; |
732 | LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2; |
733 | LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2; |
733 | } |
734 | } |
734 | else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE)) |
735 | else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE)) |
735 | { |
736 | { |
736 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
737 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
737 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
738 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
738 | UART1_Request_DebugData = FALSE; |
739 | UART1_Request_DebugData = FALSE; |
739 | } |
740 | } |
740 | else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE)) |
741 | else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE)) |
741 | { |
742 | { |
742 | Data3D.StickNick = FC.StickNick; |
743 | Data3D.StickNick = FC.StickNick; |
743 | Data3D.StickRoll = FC.StickRoll; |
744 | Data3D.StickRoll = FC.StickRoll; |
744 | Data3D.StickYaw = FC.StickYaw; |
745 | Data3D.StickYaw = FC.StickYaw; |
745 | Data3D.StickGas = FC.StickGas; |
746 | Data3D.StickGas = FC.StickGas; |
746 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
747 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
747 | UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval); |
748 | UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval); |
748 | UART1_Request_Data3D = FALSE; |
749 | UART1_Request_Data3D = FALSE; |
749 | } |
750 | } |
750 | else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE)) |
751 | else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE)) |
751 | { |
752 | { |
752 | do |
753 | do |
753 | { |
754 | { |
754 | motorindex1++; |
755 | motorindex1++; |
755 | motorindex1%=12; |
756 | motorindex1%=12; |
756 | if(!motorindex1) {motorindex2++; motorindex2 %= 12;}; |
757 | if(!motorindex1) {motorindex2++; motorindex2 %= 12;}; |
757 | if(motorindex1 == motorindex2) break; |
758 | if(motorindex1 == motorindex2) break; |
758 | } |
759 | } |
759 | while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors |
760 | while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors |
760 | 761 | ||
761 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t)); |
762 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t)); |
762 | UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval); |
763 | UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval); |
763 | UART1_Request_MotorData = FALSE; |
764 | UART1_Request_MotorData = FALSE; |
764 | } |
765 | } |
765 | /* |
766 | /* |
766 | else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
767 | else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
767 | { |
768 | { |
768 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame)); |
769 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame)); |
769 | UART1_ConfirmFrame = 0; |
770 | UART1_ConfirmFrame = 0; |
770 | } |
771 | } |
771 | */ |
772 | */ |
772 | /* |
773 | /* |
773 | else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE)) |
774 | else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE)) |
774 | { |
775 | { |
775 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
776 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
776 | UART1_Request_ExternalControl = FALSE; |
777 | UART1_Request_ExternalControl = FALSE; |
777 | } |
778 | } |
778 | */ |
779 | */ |
779 | else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE)) |
780 | else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE)) |
780 | { |
781 | { |
781 | if(UART1_DisplayLine > 3) |
782 | if(UART1_DisplayLine > 3) |
782 | { |
783 | { |
783 | Menu_Update(UART1_DisplayKeys); |
784 | Menu_Update(UART1_DisplayKeys); |
784 | UART1_DisplayKeys = 0; |
785 | UART1_DisplayKeys = 0; |
785 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff)); |
786 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff)); |
786 | } |
787 | } |
787 | else |
788 | else |
788 | { |
789 | { |
789 | UART1_DisplayLine = 2; |
790 | UART1_DisplayLine = 2; |
790 | sprintf(text,"!!! incompatible !!!"); |
791 | sprintf(text,"!!! incompatible !!!"); |
791 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20); |
792 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20); |
792 | if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0; |
793 | if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0; |
793 | } |
794 | } |
794 | UART1_Display_Timer = SetDelay(UART1_Display_Interval); |
795 | UART1_Display_Timer = SetDelay(UART1_Display_Interval); |
795 | UART1_Request_Display = FALSE; |
796 | UART1_Request_Display = FALSE; |
796 | } |
797 | } |
797 | else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE)) |
798 | else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE)) |
798 | { |
799 | { |
799 | Menu_Update(0); |
800 | Menu_Update(0); |
800 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
801 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
801 | UART1_Request_Display1 = FALSE; |
802 | UART1_Request_Display1 = FALSE; |
802 | } |
803 | } |
803 | else if(UART1_Request_VersionInfo && (UART1_tx_buffer.Locked == FALSE)) |
804 | else if(UART1_Request_VersionInfo && (UART1_tx_buffer.Locked == FALSE)) |
804 | { |
805 | { |
805 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
806 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
806 | UART1_Request_VersionInfo = FALSE; |
807 | UART1_Request_VersionInfo = FALSE; |
807 | } |
808 | } |
808 | else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE)) |
809 | else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE)) |
809 | { |
810 | { |
810 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
811 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
811 | UART1_Request_ErrorMessage = FALSE; |
812 | UART1_Request_ErrorMessage = FALSE; |
812 | } |
813 | } |
813 | #ifdef FOLLOW_ME |
814 | #ifdef FOLLOW_ME |
814 | else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE)) |
815 | else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE)) |
815 | { |
816 | { |
816 | if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4)) |
817 | if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4)) |
817 | { |
818 | { |
818 | TransmitAlsoToFC = 1; |
819 | TransmitAlsoToFC = 1; |
819 | // update FollowMe content |
820 | // update FollowMe content |
820 | FollowMe.Position.Longitude = GPSData.Position.Longitude; |
821 | FollowMe.Position.Longitude = GPSData.Position.Longitude; |
821 | FollowMe.Position.Latitude = GPSData.Position.Latitude; |
822 | FollowMe.Position.Latitude = GPSData.Position.Latitude; |
822 | FollowMe.Position.Status = NEWDATA; |
823 | FollowMe.Position.Status = NEWDATA; |
823 | FollowMe.Position.Altitude = 1; |
824 | FollowMe.Position.Altitude = 1; |
824 | // 0 -> no Orientation |
825 | // 0 -> no Orientation |
825 | // 1-360 -> CompassCourse Setpoint |
826 | // 1-360 -> CompassCourse Setpoint |
826 | // -1 -> points to WP1 -> itself |
827 | // -1 -> points to WP1 -> itself |
827 | FollowMe.Heading = -1; |
828 | FollowMe.Heading = -1; |
828 | FollowMe.ToleranceRadius = 1; |
829 | FollowMe.ToleranceRadius = 1; |
829 | FollowMe.HoldTime = 60; |
830 | FollowMe.HoldTime = 60; |
830 | FollowMe.Event_Flag = 1; |
831 | FollowMe.Event_Flag = 1; |
831 | FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list |
832 | FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list |
832 | FollowMe.Type = POINT_TYPE_WP; |
833 | FollowMe.Type = POINT_TYPE_WP; |
833 | FollowMe.WP_EventChannelValue = 100; // set servo value |
834 | FollowMe.WP_EventChannelValue = 100; // set servo value |
834 | FollowMe.AltitudeRate = 0; // do not change height |
835 | FollowMe.AltitudeRate = 0; // do not change height |
835 | FollowMe.reserve[0] = 0; // reserve |
836 | FollowMe.reserve[0] = 0; // reserve |
836 | FollowMe.reserve[1] = 0; // reserve |
837 | FollowMe.reserve[1] = 0; // reserve |
837 | FollowMe.reserve[2] = 0; // reserve |
838 | FollowMe.reserve[2] = 0; // reserve |
838 | FollowMe.reserve[3] = 0; // reserve |
839 | FollowMe.reserve[3] = 0; // reserve |
839 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe)); |
840 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe)); |
840 | } |
841 | } |
841 | UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time |
842 | UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time |
842 | } |
843 | } |
843 | #endif |
844 | #endif |
844 | #ifdef DEBUG // only include functions if DEBUG is defined |
845 | #ifdef DEBUG // only include functions if DEBUG is defined |
845 | else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE)) |
846 | else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE)) |
846 | { |
847 | { |
847 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug)); |
848 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug)); |
848 | SendDebugOutput = 0; |
849 | SendDebugOutput = 0; |
849 | } |
850 | } |
850 | #endif |
851 | #endif |
851 | UART1_Transmit(); // output pending bytes in tx buffer |
852 | UART1_Transmit(); // output pending bytes in tx buffer |
852 | } |
853 | } |
853 | 854 | ||
854 | 855 |