Rev 378 | Rev 398 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 378 | Rev 380 | ||
---|---|---|---|
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 | #include "led.h" |
80 | #include "led.h" |
81 | 81 | ||
82 | #define FALSE 0 |
82 | #define FALSE 0 |
83 | #define TRUE 1 |
83 | #define TRUE 1 |
84 | 84 | ||
85 | #define ABO_TIMEOUT 8000 // disable abo after 8 seconds |
85 | #define ABO_TIMEOUT 8000 // disable abo after 8 seconds |
86 | u32 UART1_AboTimeOut = 0; |
86 | u32 UART1_AboTimeOut = 0; |
87 | 87 | ||
88 | u8 UART1_Request_VersionInfo = FALSE; |
88 | u8 UART1_Request_VersionInfo = FALSE; |
89 | u8 UART1_Request_ExternalControl= FALSE; |
89 | u8 UART1_Request_ExternalControl= FALSE; |
90 | u8 UART1_Request_Display = FALSE; |
90 | u8 UART1_Request_Display = FALSE; |
91 | u8 UART1_Request_Display1 = FALSE; |
91 | u8 UART1_Request_Display1 = FALSE; |
92 | u8 UART1_Request_DebugData = FALSE; |
92 | u8 UART1_Request_DebugData = FALSE; |
93 | u8 UART1_Request_DebugLabel = 255; |
93 | u8 UART1_Request_DebugLabel = 255; |
94 | u8 UART1_Request_NaviData = FALSE; |
94 | u8 UART1_Request_NaviData = FALSE; |
95 | u8 UART1_Request_ErrorMessage = FALSE; |
95 | u8 UART1_Request_ErrorMessage = FALSE; |
96 | u8 UART1_Request_WritePoint = 0xFF; |
96 | u8 UART1_Request_WritePoint = 0xFF; |
97 | u8 UART1_Request_ReadPoint = 0; |
97 | u8 UART1_Request_ReadPoint = 0; |
98 | u8 UART1_Request_Data3D = FALSE; |
98 | u8 UART1_Request_Data3D = FALSE; |
99 | u8 UART1_Request_MotorData = FALSE; |
99 | u8 UART1_Request_MotorData = FALSE; |
100 | u8 UART1_Request_Echo = FALSE; |
100 | u8 UART1_Request_Echo = FALSE; |
101 | u8 UART1_Request_ParameterId = 0; |
101 | u8 UART1_Request_ParameterId = 0; |
102 | u8 UART1_Request_Parameter = FALSE; |
102 | u8 UART1_Request_Parameter = FALSE; |
103 | u8 UART1_DisplayKeys = 0; |
103 | u8 UART1_DisplayKeys = 0; |
104 | u8 UART1_DisplayLine = 0; |
104 | u8 UART1_DisplayLine = 0; |
105 | u8 UART1_ConfirmFrame = 0; |
105 | u8 UART1_ConfirmFrame = 0; |
106 | u8 UART1_Request_FTP = FALSE; |
106 | u8 UART1_Request_FTP = FALSE; |
107 | u8 LastTransmittedFCStatusFlags2 = 0; |
107 | u8 LastTransmittedFCStatusFlags2 = 0; |
108 | 108 | ||
109 | UART_TypeDef *DebugUART = UART1; |
109 | UART_TypeDef *DebugUART = UART1; |
110 | 110 | ||
111 | #ifdef FOLLOW_ME |
111 | #ifdef FOLLOW_ME |
112 | #define FOLLOW_ME_INTERVAL 200 // 5 Hz |
112 | #define FOLLOW_ME_INTERVAL 200 // 5 Hz |
113 | u32 UART1_FollowMe_Timer = 0; |
113 | u32 UART1_FollowMe_Timer = 0; |
114 | Point_t FollowMe; |
114 | Point_t FollowMe; |
115 | #endif |
115 | #endif |
116 | 116 | ||
117 | // the primary rx fifo |
117 | // the primary rx fifo |
118 | #define UART1_RX_FIFO_LEN 1024 |
118 | #define UART1_RX_FIFO_LEN 1024 |
119 | u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN]; |
119 | u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN]; |
120 | fifo_t UART1_rx_fifo; |
120 | fifo_t UART1_rx_fifo; |
121 | 121 | ||
122 | // the rx buffer |
122 | // the rx buffer |
123 | #define UART1_RX_BUFFER_LEN 1024 |
123 | #define UART1_RX_BUFFER_LEN 1024 |
124 | u8 UART1_rbuffer[UART1_RX_BUFFER_LEN]; |
124 | u8 UART1_rbuffer[UART1_RX_BUFFER_LEN]; |
125 | Buffer_t UART1_rx_buffer; |
125 | Buffer_t UART1_rx_buffer; |
126 | 126 | ||
127 | // the tx buffer |
127 | // the tx buffer |
128 | #define UART1_TX_BUFFER_LEN 1024 |
128 | #define UART1_TX_BUFFER_LEN 1024 |
129 | u8 UART1_tbuffer[UART1_TX_BUFFER_LEN]; |
129 | u8 UART1_tbuffer[UART1_TX_BUFFER_LEN]; |
130 | Buffer_t UART1_tx_buffer; |
130 | Buffer_t UART1_tx_buffer; |
131 | 131 | ||
132 | volatile u8 SerialLinkOkay = 0; |
132 | volatile u8 SerialLinkOkay = 0; |
133 | 133 | ||
134 | u8 text[200]; |
134 | u8 text[200]; |
135 | 135 | ||
136 | const u8 ANALOG_LABEL[32][16] = |
136 | const u8 ANALOG_LABEL[32][16] = |
137 | { |
137 | { |
138 | //1234567890123456 |
138 | //1234567890123456 |
139 | "AngleNick ", //0 |
139 | "AngleNick ", //0 |
140 | "AngleRoll ", |
140 | "AngleRoll ", |
141 | "AccNick ", |
141 | "AccNick ", |
142 | "AccRoll ", |
142 | "AccRoll ", |
143 | "OperatingRadius ", |
143 | "OperatingRadius ", |
144 | "FC-Flags ", //5 |
144 | "FC-Flags ", //5 |
145 | "NC-Flags ", |
145 | "NC-Flags ", |
146 | "NickServo ", |
146 | "NickServo ", |
147 | "RollServo ", |
147 | "RollServo ", |
148 | "GPS Data ", |
148 | "GPS Data ", |
149 | "CompassHeading ", //10 |
149 | "CompassHeading ", //10 |
150 | "GyroHeading ", |
150 | "GyroHeading ", |
151 | "SPI Error ", |
151 | "SPI Error ", |
152 | "SPI Okay ", |
152 | "SPI Okay ", |
153 | "I2C Error ", |
153 | "I2C Error ", |
154 | "I2C Okay ", //15 |
154 | "I2C Okay ", //15 |
155 | "16 ", |
155 | "16 ", |
156 | "17 ", |
156 | "17 ", |
157 | "18 ", |
157 | "18 ", |
158 | "19 ", // SD-Card-time |
158 | "19 ", // SD-Card-time |
159 | "EarthMagnet [%] ", //20 |
159 | "EarthMagnet [%] ", //20 |
160 | "Z_Speed ", |
160 | "Z_Speed ", |
161 | "N_Speed ", |
161 | "N_Speed ", |
162 | "E_Speed ", |
162 | "E_Speed ", |
163 | "Magnet X ", |
163 | "Magnet X ", |
164 | "Magnet Y ", //25 |
164 | "Magnet Y ", //25 |
165 | "Magnet Z ", |
165 | "Magnet Z ", |
166 | "Distance N ", |
166 | "Distance N ", |
167 | "Distance E ", |
167 | "Distance E ", |
168 | "GPS_Nick ", |
168 | "GPS_Nick ", |
169 | "GPS_Roll ", //30 |
169 | "GPS_Roll ", //30 |
170 | "Used_Sats " |
170 | "Used_Sats " |
171 | }; |
171 | }; |
172 | 172 | ||
173 | DebugOut_t DebugOut; |
173 | DebugOut_t DebugOut; |
174 | ExternControl_t ExternControl; |
174 | ExternControl_t ExternControl; |
175 | UART_VersionInfo_t UART_VersionInfo; |
175 | UART_VersionInfo_t UART_VersionInfo; |
176 | NaviData_t NaviData; |
176 | NaviData_t NaviData; |
177 | Data3D_t Data3D; |
177 | Data3D_t Data3D; |
178 | u16 Echo; // 2 bytes recieved will be sent back as echo |
178 | u16 Echo; // 2 bytes recieved will be sent back as echo |
179 | 179 | ||
180 | u32 UART1_DebugData_Timer = 0; |
180 | u32 UART1_DebugData_Timer = 0; |
181 | u32 UART1_DebugData_Interval = 0; // in ms |
181 | u32 UART1_DebugData_Interval = 0; // in ms |
182 | u32 UART1_NaviData_Timer = 0; |
182 | u32 UART1_NaviData_Timer = 0; |
183 | u32 UART1_NaviData_Interval = 0; // in ms |
183 | u32 UART1_NaviData_Interval = 0; // in ms |
184 | u32 UART1_Data3D_Timer = 0; |
184 | u32 UART1_Data3D_Timer = 0; |
185 | u32 UART1_Data3D_Interval = 0; // in ms |
185 | u32 UART1_Data3D_Interval = 0; // in ms |
186 | u32 UART1_MotorData_Timer = 0; |
186 | u32 UART1_MotorData_Timer = 0; |
187 | u32 UART1_MotorData_Interval = 0; // in ms |
187 | u32 UART1_MotorData_Interval = 0; // in ms |
188 | u32 UART1_Display_Timer = 0; |
188 | u32 UART1_Display_Timer = 0; |
189 | u32 UART1_Display_Interval = 0; // in ms |
189 | u32 UART1_Display_Interval = 0; // in ms |
190 | 190 | ||
191 | /********************************************************/ |
191 | /********************************************************/ |
192 | /* Initialization the UART1 */ |
192 | /* Initialization the UART1 */ |
193 | /********************************************************/ |
193 | /********************************************************/ |
194 | void UART1_Init (void) |
194 | void UART1_Init (void) |
195 | { |
195 | { |
196 | GPIO_InitTypeDef GPIO_InitStructure; |
196 | GPIO_InitTypeDef GPIO_InitStructure; |
197 | UART_InitTypeDef UART_InitStructure; |
197 | UART_InitTypeDef UART_InitStructure; |
198 | 198 | ||
199 | // initialize txd buffer |
199 | // initialize txd buffer |
200 | Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN); |
200 | Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN); |
201 | 201 | ||
202 | // initialize rxd buffer |
202 | // initialize rxd buffer |
203 | Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN); |
203 | Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN); |
204 | 204 | ||
205 | // initialize the rx fifo, block UART IRQ geting a byte from fifo |
205 | // initialize the rx fifo, block UART IRQ geting a byte from fifo |
206 | fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine); |
206 | fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine); |
207 | 207 | ||
208 | SCU_APBPeriphClockConfig(__UART1, ENABLE); // Enable the UART1 Clock |
208 | SCU_APBPeriphClockConfig(__UART1, ENABLE); // Enable the UART1 Clock |
209 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
209 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
210 | 210 | ||
211 | /*Configure UART1_Rx pin GPIO3.2*/ |
211 | /*Configure UART1_Rx pin GPIO3.2*/ |
212 | GPIO_StructInit(&GPIO_InitStructure); |
212 | GPIO_StructInit(&GPIO_InitStructure); |
213 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
213 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
214 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
214 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
215 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
215 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
216 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
216 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
217 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART1_RxD |
217 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART1_RxD |
218 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
218 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
219 | 219 | ||
220 | /*Configure UART1_Tx pin GPIO3.3*/ |
220 | /*Configure UART1_Tx pin GPIO3.3*/ |
221 | GPIO_StructInit(&GPIO_InitStructure); |
221 | GPIO_StructInit(&GPIO_InitStructure); |
222 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
222 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
223 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
223 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
224 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
224 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
225 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART1_TX |
225 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART1_TX |
226 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
226 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
227 | 227 | ||
228 | /* UART1 configured as follow: |
228 | /* UART1 configured as follow: |
229 | - Word Length = 8 Bits |
229 | - Word Length = 8 Bits |
230 | - One Stop Bit |
230 | - One Stop Bit |
231 | - No parity |
231 | - No parity |
232 | - BaudRate = 57600 baud |
232 | - BaudRate = 57600 baud |
233 | - Hardware flow control Disabled |
233 | - Hardware flow control Disabled |
234 | - Receive and transmit enabled |
234 | - Receive and transmit enabled |
235 | - Receive and transmit FIFOs are Disabled |
235 | - Receive and transmit FIFOs are Disabled |
236 | */ |
236 | */ |
237 | UART_StructInit(&UART_InitStructure); |
237 | UART_StructInit(&UART_InitStructure); |
238 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
238 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
239 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
239 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
240 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
240 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
241 | UART_InitStructure.UART_BaudRate = UART1_BAUD_RATE; |
241 | UART_InitStructure.UART_BaudRate = UART1_BAUD_RATE; |
242 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
242 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
243 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
243 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
244 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
244 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
245 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
245 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
246 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
246 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
247 | 247 | ||
248 | UART_DeInit(UART1); // reset uart 1 to default |
248 | UART_DeInit(UART1); // reset uart 1 to default |
249 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
249 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
250 | // enable uart 1 interrupts selective |
250 | // enable uart 1 interrupts selective |
251 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
251 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
252 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
252 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
253 | // configure the uart 1 interupt line |
253 | // configure the uart 1 interupt line |
254 | VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1); |
254 | VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1); |
255 | // enable the uart 1 IRQ |
255 | // enable the uart 1 IRQ |
256 | VIC_ITCmd(UART1_ITLine, ENABLE); |
256 | VIC_ITCmd(UART1_ITLine, ENABLE); |
257 | 257 | ||
258 | // initialize the debug timer |
258 | // initialize the debug timer |
259 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
259 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
260 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500; |
260 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500; |
261 | 261 | ||
262 | // Fill Version Info Structure |
262 | // Fill Version Info Structure |
263 | UART_VersionInfo.SWMajor = VERSION_MAJOR; |
263 | UART_VersionInfo.SWMajor = VERSION_MAJOR; |
264 | UART_VersionInfo.SWMinor = VERSION_MINOR; |
264 | UART_VersionInfo.SWMinor = VERSION_MINOR; |
265 | UART_VersionInfo.SWPatch = VERSION_PATCH; |
265 | UART_VersionInfo.SWPatch = VERSION_PATCH; |
266 | UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
266 | UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
267 | UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
267 | UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
268 | 268 | ||
269 | NaviData.Version = NAVIDATA_VERSION; |
269 | NaviData.Version = NAVIDATA_VERSION; |
270 | 270 | ||
271 | UART1_PutString("\r\n UART1 init...ok"); |
271 | UART1_PutString("\r\n UART1 init...ok"); |
272 | } |
272 | } |
273 | 273 | ||
274 | 274 | ||
275 | /****************************************************************/ |
275 | /****************************************************************/ |
276 | /* USART1 receiver ISR */ |
276 | /* USART1 receiver ISR */ |
277 | /****************************************************************/ |
277 | /****************************************************************/ |
278 | void UART1_IRQHandler(void) |
278 | void UART1_IRQHandler(void) |
279 | { |
279 | { |
280 | static u8 abortState = 0; |
280 | static u8 abortState = 0; |
281 | u8 c; |
281 | u8 c; |
282 | - | ||
283 | IENABLE; |
- | |
284 | 282 | ||
285 | if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) ) |
283 | if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) ) |
286 | { |
284 | { |
287 | // clear the pending bits! |
285 | // clear the pending bits! |
288 | UART_ClearITPendingBit(UART1, UART_IT_Receive); |
286 | UART_ClearITPendingBit(UART1, UART_IT_Receive); |
289 | UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut); |
287 | UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut); |
290 | // if debug UART is not UART1 |
288 | // if debug UART is not UART1 |
291 | if (DebugUART != UART1) |
289 | if (DebugUART != UART1) |
292 | { // forward received data to the debug UART tx buffer |
290 | { // forward received data to the debug UART tx buffer |
293 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
291 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
294 | { |
292 | { |
295 | // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART |
293 | // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART |
296 | c = UART_ReceiveData(UART1); |
294 | c = UART_ReceiveData(UART1); |
297 | 295 | ||
298 | // check for abort condition (ESC ESC 0x55 0xAA 0x00) |
296 | // check for abort condition (ESC ESC 0x55 0xAA 0x00) |
299 | switch (abortState) |
297 | switch (abortState) |
300 | { |
298 | { |
301 | case 0: |
299 | case 0: |
302 | if (c == 27) abortState++; |
300 | if (c == 27) abortState++; |
303 | break; |
301 | break; |
304 | case 1: |
302 | case 1: |
305 | if (c == 27) abortState++; |
303 | if (c == 27) abortState++; |
306 | else abortState = 0; |
304 | else abortState = 0; |
307 | break; |
305 | break; |
308 | case 2: |
306 | case 2: |
309 | if (c == 0x55) abortState++; |
307 | if (c == 0x55) abortState++; |
310 | else abortState = 0; |
308 | else abortState = 0; |
311 | break; |
309 | break; |
312 | case 3: |
310 | case 3: |
313 | if (c == 0xAA) abortState++; |
311 | if (c == 0xAA) abortState++; |
314 | else abortState = 0; |
312 | else abortState = 0; |
315 | break; |
313 | break; |
316 | case 4: |
314 | case 4: |
317 | if (c == 0x00) |
315 | if (c == 0x00) |
318 | { |
316 | { |
319 | if(DebugUART == UART0) |
317 | if(DebugUART == UART0) |
320 | { |
318 | { |
321 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); |
319 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); |
322 | TIMER2_Init(); // enbable servo outputs |
320 | TIMER2_Init(); // enbable servo outputs |
323 | fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer |
321 | fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer |
324 | } |
322 | } |
325 | DebugUART = UART1; |
323 | DebugUART = UART1; |
326 | } |
324 | } |
327 | abortState = 0; |
325 | abortState = 0; |
328 | break; |
326 | break; |
329 | } // end switch abort state |
327 | } // end switch abort state |
330 | // if the Debug uart is not UART1, redirect input to the Debug UART |
328 | // if the Debug uart is not UART1, redirect input to the Debug UART |
331 | if (DebugUART != UART1) |
329 | if (DebugUART != UART1) |
332 | { |
330 | { |
333 | // wait for space in the tx buffer of the DebugUART |
331 | // wait for space in the tx buffer of the DebugUART |
334 | while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {}; |
332 | while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {}; |
335 | // move byte to the tx fifo of the debug uart |
333 | // move byte to the tx fifo of the debug uart |
336 | UART_SendData(DebugUART, c); |
334 | UART_SendData(DebugUART, c); |
337 | } |
335 | } |
338 | } |
336 | } |
339 | } |
337 | } |
340 | else // DebugUART == UART1 (normal operation) |
338 | else // DebugUART == UART1 (normal operation) |
341 | { |
339 | { |
342 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
340 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
343 | { // some byes in the hardware fifo |
341 | { // some byes in the hardware fifo |
344 | // get byte from hardware fifo |
342 | // get byte from hardware fifo |
345 | c = UART_ReceiveData(UART1); |
343 | c = UART_ReceiveData(UART1); |
346 | // put into the software fifo |
344 | // put into the software fifo |
347 | if(!fifo_put(&UART1_rx_fifo, c)) |
345 | if(!fifo_put(&UART1_rx_fifo, c)) |
348 | { // fifo overflow |
346 | { // fifo overflow |
349 | //fifo_purge(&UART1_rx_fifo); // flush the whole buffer |
347 | //fifo_purge(&UART1_rx_fifo); // flush the whole buffer |
350 | } |
348 | } |
351 | } // EOF while some byes in the hardware fifo |
349 | } // EOF while some byes in the hardware fifo |
352 | } // eof DebugUart = UART1 |
350 | } // eof DebugUart = UART1 |
353 | } |
351 | } |
- | 352 | ||
354 | 353 | ||
355 | IDISABLE; |
354 | |
356 | VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register |
355 | VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register |
357 | } |
356 | } |
358 | 357 | ||
359 | /**************************************************************/ |
358 | /**************************************************************/ |
360 | /* Process incomming data from debug uart */ |
359 | /* Process incomming data from debug uart */ |
361 | /**************************************************************/ |
360 | /**************************************************************/ |
362 | void UART1_ProcessRxData(void) |
361 | void UART1_ProcessRxData(void) |
363 | { |
362 | { |
364 | // return on forwarding uart or unlocked rx buffer |
363 | // return on forwarding uart or unlocked rx buffer |
365 | if(DebugUART != UART1) return; |
- | |
366 | u8 c; |
364 | u8 c; |
- | 365 | if(DebugUART != UART1) return; |
|
367 | // if rx buffer is not locked |
366 | // if rx buffer is not locked |
368 | if(UART1_rx_buffer.Locked == FALSE) |
367 | if(UART1_rx_buffer.Locked == FALSE) |
369 | { |
368 | { |
370 | //collect data from primary rx fifo |
369 | //collect data from primary rx fifo |
371 | while(fifo_get(&UART1_rx_fifo, &c)) |
370 | while(fifo_get(&UART1_rx_fifo, &c)) |
372 | { |
371 | { |
373 | // break if complete frame is collected |
372 | // break if complete frame is collected |
374 | if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break; |
373 | if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break; |
375 | } |
374 | } |
376 | } |
375 | } |
377 | if(UART1_rx_buffer.Locked == FALSE) return; |
376 | if(UART1_rx_buffer.Locked == FALSE) return; |
378 | 377 | ||
379 | Point_t * pPoint = NULL; |
378 | Point_t * pPoint = NULL; |
380 | SerialMsg_t SerialMsg; |
379 | SerialMsg_t SerialMsg; |
381 | 380 | ||
382 | // analyze header first |
381 | // analyze header first |
383 | MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg); |
382 | MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg); |
384 | if( SerialMsg.Address == FC_ADDRESS ) |
383 | if( SerialMsg.Address == FC_ADDRESS ) |
385 | { |
384 | { |
386 | switch(SerialMsg.CmdID) |
385 | switch(SerialMsg.CmdID) |
387 | { |
386 | { |
388 | // case 'v': // version |
387 | // case 'v': // version |
389 | case 'y': // serial poti values |
388 | case 'y': // serial poti values |
390 | case 'b': // extern control |
389 | case 'b': // extern control |
391 | Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC |
390 | Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC |
392 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
391 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
393 | return; //end process rx data |
392 | return; //end process rx data |
394 | break; |
393 | break; |
395 | } |
394 | } |
396 | } |
395 | } |
397 | 396 | ||
398 | 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 |
399 | 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" |
400 | switch(SerialMsg.Address) // check for Slave Address |
399 | switch(SerialMsg.Address) // check for Slave Address |
401 | { |
400 | { |
402 | case NC_ADDRESS: // own Slave Address |
401 | case NC_ADDRESS: // own Slave Address |
403 | switch(SerialMsg.CmdID) |
402 | switch(SerialMsg.CmdID) |
404 | { |
403 | { |
405 | 404 | ||
406 | case 'f': // ftp command |
405 | case 'f': // ftp command |
407 | UART1_Request_FTP = SerialMsg.pData[0]; |
406 | UART1_Request_FTP = SerialMsg.pData[0]; |
408 | 407 | ||
409 | //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) |
410 | 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 |
411 | break; |
410 | break; |
412 | 411 | ||
413 | case 'z': // connection checker |
412 | case 'z': // connection checker |
414 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
413 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
415 | UART1_Request_Echo = TRUE; |
414 | UART1_Request_Echo = TRUE; |
416 | break; |
415 | break; |
417 | 416 | ||
418 | case 'e': // request for the text of the error status |
417 | case 'e': // request for the text of the error status |
419 | UART1_Request_ErrorMessage = TRUE; |
418 | UART1_Request_ErrorMessage = TRUE; |
420 | break; |
419 | break; |
421 | 420 | ||
422 | case 's':// new target position |
421 | case 's':// new target position |
423 | pPoint = (Point_t*)SerialMsg.pData; |
422 | pPoint = (Point_t*)SerialMsg.pData; |
424 | if(pPoint->Position.Status == NEWDATA) |
423 | if(pPoint->Position.Status == NEWDATA) |
425 | { |
424 | { |
426 | //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list |
425 | //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list |
427 | //pPoint->Index = 1; // must be one after empty list |
426 | //pPoint->Index = 1; // must be one after empty list |
428 | PointList_SetAt(pPoint); |
427 | PointList_SetAt(pPoint); |
429 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
428 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
430 | GPS_pWaypoint = PointList_WPBegin(); // updates POI index |
429 | GPS_pWaypoint = PointList_WPBegin(); // updates POI index |
431 | if(GPS_pWaypoint != NULL) // if new WP exist |
430 | if(GPS_pWaypoint != NULL) // if new WP exist |
432 | { // update WP hold time stamp immediately! |
431 | { // update WP hold time stamp immediately! |
433 | /* if(GPS_pWaypoint->Heading > 0 && GPS_pWaypoint->Heading <= 360) |
432 | /* if(GPS_pWaypoint->Heading > 0 && GPS_pWaypoint->Heading <= 360) |
434 | { |
433 | { |
435 | CAM_Orientation.Azimuth = GPS_pWaypoint->Heading; |
434 | CAM_Orientation.Azimuth = GPS_pWaypoint->Heading; |
436 | CAM_Orientation.UpdateMask |= CAM_UPDATE_AZIMUTH; |
435 | CAM_Orientation.UpdateMask |= CAM_UPDATE_AZIMUTH; |
437 | } |
436 | } |
438 | */ |
437 | */ |
439 | } |
438 | } |
440 | BeepTime = 50; |
439 | BeepTime = 50; |
441 | } |
440 | } |
442 | break; |
441 | break; |
443 | 442 | ||
444 | case 'u': // redirect debug uart |
443 | case 'u': // redirect debug uart |
445 | switch(SerialMsg.pData[0]) |
444 | switch(SerialMsg.pData[0]) |
446 | { |
445 | { |
447 | case UART_FLIGHTCTRL: |
446 | case UART_FLIGHTCTRL: |
448 | UART2_Init(); // initialize UART2 to FC pins |
447 | UART2_Init(); // initialize UART2 to FC pins |
449 | fifo_purge(&UART1_rx_fifo); |
448 | fifo_purge(&UART1_rx_fifo); |
450 | TIMER2_Deinit(); // reduce irq load |
449 | TIMER2_Deinit(); // reduce irq load |
451 | DebugUART = UART2; |
450 | DebugUART = UART2; |
452 | break; |
451 | break; |
453 | case UART_MK3MAG: |
452 | case UART_MK3MAG: |
454 | 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 |
455 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
454 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
456 | GPSData.Status = INVALID; |
455 | GPSData.Status = INVALID; |
457 | fifo_purge(&UART1_rx_fifo); |
456 | fifo_purge(&UART1_rx_fifo); |
458 | DebugUART = UART0; |
457 | DebugUART = UART0; |
459 | break; |
458 | break; |
460 | case UART_MKGPS: |
459 | case UART_MKGPS: |
461 | 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 |
462 | TIMER2_Deinit(); // disable servo outputs to reduce irq load |
461 | TIMER2_Deinit(); // disable servo outputs to reduce irq load |
463 | 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 |
464 | GPSData.Status = INVALID; |
463 | GPSData.Status = INVALID; |
465 | fifo_purge(&UART1_rx_fifo); |
464 | fifo_purge(&UART1_rx_fifo); |
466 | DebugUART = UART0; |
465 | DebugUART = UART0; |
467 | break; |
466 | break; |
468 | default: |
467 | default: |
469 | break; |
468 | break; |
470 | } |
469 | } |
471 | break; |
470 | break; |
472 | 471 | ||
473 | case 'w':// Set point in list at index |
472 | case 'w':// Set point in list at index |
474 | { |
473 | { |
475 | pPoint = (Point_t*)SerialMsg.pData; |
474 | pPoint = (Point_t*)SerialMsg.pData; |
476 | 475 | ||
477 | if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0)) |
476 | if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0)) |
478 | { |
477 | { |
479 | PointList_Clear(); |
478 | PointList_Clear(); |
480 | GPS_pWaypoint = PointList_WPBegin(); |
479 | GPS_pWaypoint = PointList_WPBegin(); |
481 | UART1_Request_WritePoint = 0; // return new point count |
480 | UART1_Request_WritePoint = 0; // return new point count |
482 | } |
481 | } |
483 | else |
482 | else |
484 | { // update WP in list at index |
483 | { // update WP in list at index |
485 | if(pPoint->Index > MaxNumberOfWaypoints) |
484 | if(pPoint->Index > MaxNumberOfWaypoints) |
486 | { |
485 | { |
487 | UART1_Request_WritePoint = 254; |
486 | UART1_Request_WritePoint = 254; |
488 | pPoint->Index = MaxNumberOfWaypoints; |
487 | pPoint->Index = MaxNumberOfWaypoints; |
489 | } |
488 | } |
490 | else |
489 | else |
491 | UART1_Request_WritePoint = PointList_SetAt(pPoint); |
490 | UART1_Request_WritePoint = PointList_SetAt(pPoint); |
492 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
491 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
493 | if(UART1_Request_WritePoint == pPoint->Index) |
492 | if(UART1_Request_WritePoint == pPoint->Index) |
494 | { |
493 | { |
495 | BeepTime = 500; |
494 | BeepTime = 500; |
496 | } |
495 | } |
497 | } |
496 | } |
498 | } |
497 | } |
499 | break; |
498 | break; |
500 | 499 | ||
501 | case 'x':// Read Waypoint from List |
500 | case 'x':// Read Waypoint from List |
502 | UART1_Request_ReadPoint = SerialMsg.pData[0]; |
501 | UART1_Request_ReadPoint = SerialMsg.pData[0]; |
503 | break; |
502 | break; |
504 | 503 | ||
505 | case 'j':// Set/Get NC-Parameter |
504 | case 'j':// Set/Get NC-Parameter |
506 | switch(SerialMsg.pData[0]) |
505 | switch(SerialMsg.pData[0]) |
507 | { |
506 | { |
508 | case 0: // get |
507 | case 0: // get |
509 | break; |
508 | break; |
510 | 509 | ||
511 | case 1: // set |
510 | case 1: // set |
512 | { |
511 | { |
513 | s16 value; |
512 | s16 value; |
514 | value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100; |
513 | value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100; |
515 | NCParams_SetValue(SerialMsg.pData[1], &value); |
514 | NCParams_SetValue(SerialMsg.pData[1], &value); |
516 | } |
515 | } |
517 | break; |
516 | break; |
518 | 517 | ||
519 | default: |
518 | default: |
520 | break; |
519 | break; |
521 | } |
520 | } |
522 | UART1_Request_ParameterId = SerialMsg.pData[1]; |
521 | UART1_Request_ParameterId = SerialMsg.pData[1]; |
523 | UART1_Request_Parameter = TRUE; |
522 | UART1_Request_Parameter = TRUE; |
524 | break; |
523 | break; |
525 | default: |
524 | default: |
526 | // unsupported command recieved |
525 | // unsupported command recieved |
527 | break; |
526 | break; |
528 | } // case NC_ADDRESS |
527 | } // case NC_ADDRESS |
529 | // "break;" is missing here to fall thru to the common commands |
528 | // "break;" is missing here to fall thru to the common commands |
530 | 529 | ||
531 | default: // and any other Slave Address |
530 | default: // and any other Slave Address |
532 | 531 | ||
533 | switch(SerialMsg.CmdID) // check CmdID |
532 | switch(SerialMsg.CmdID) // check CmdID |
534 | { |
533 | { |
535 | case 'a':// request for the labels of the analog debug outputs |
534 | case 'a':// request for the labels of the analog debug outputs |
536 | UART1_Request_DebugLabel = SerialMsg.pData[0]; |
535 | UART1_Request_DebugLabel = SerialMsg.pData[0]; |
537 | if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31; |
536 | if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31; |
538 | break; |
537 | break; |
539 | /* |
538 | /* |
540 | case 'b': // submit extern control |
539 | case 'b': // submit extern control |
541 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
540 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
542 | UART1_ConfirmFrame = ExternControl.Frame; |
541 | UART1_ConfirmFrame = ExternControl.Frame; |
543 | break; |
542 | break; |
544 | */ |
543 | */ |
545 | case 'd': // request for debug data; |
544 | case 'd': // request for debug data; |
546 | UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
545 | UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
547 | if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE; |
546 | if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE; |
548 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
547 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
549 | break; |
548 | break; |
550 | 549 | ||
551 | case 'c': // request for 3D data; |
550 | case 'c': // request for 3D data; |
552 | UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
551 | UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
553 | if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE; |
552 | if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE; |
554 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
553 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
555 | break; |
554 | break; |
556 | 555 | ||
557 | case 'k': // request for Motor data; |
556 | case 'k': // request for Motor data; |
558 | UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10; |
557 | UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10; |
559 | if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE; |
558 | if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE; |
560 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
559 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
561 | break; |
560 | break; |
562 | 561 | ||
563 | case 'h':// reqest for display line |
562 | case 'h':// reqest for display line |
564 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
563 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
565 | { |
564 | { |
566 | UART1_DisplayLine = 2; |
565 | UART1_DisplayLine = 2; |
567 | UART1_Display_Interval = 0; |
566 | UART1_Display_Interval = 0; |
568 | } |
567 | } |
569 | else |
568 | else |
570 | { |
569 | { |
571 | UART1_DisplayKeys |= ~SerialMsg.pData[0]; |
570 | UART1_DisplayKeys |= ~SerialMsg.pData[0]; |
572 | UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
571 | UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
573 | UART1_DisplayLine = 4; |
572 | UART1_DisplayLine = 4; |
574 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
573 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
575 | } |
574 | } |
576 | UART1_Request_Display = TRUE; |
575 | UART1_Request_Display = TRUE; |
577 | break; |
576 | break; |
578 | 577 | ||
579 | case 'l':// reqest for display columns |
578 | case 'l':// reqest for display columns |
580 | MenuItem = SerialMsg.pData[0]; |
579 | MenuItem = SerialMsg.pData[0]; |
581 | UART1_Request_Display1 = TRUE; |
580 | UART1_Request_Display1 = TRUE; |
582 | break; |
581 | break; |
583 | 582 | ||
584 | case 'o': // request for navigation information |
583 | case 'o': // request for navigation information |
585 | UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
584 | UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
586 | if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE; |
585 | if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE; |
587 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
586 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
588 | break; |
587 | break; |
589 | 588 | ||
590 | case 'v': // request for version info |
589 | case 'v': // request for version info |
591 | UART1_Request_VersionInfo = TRUE; |
590 | UART1_Request_VersionInfo = TRUE; |
592 | break; |
591 | break; |
593 | default: |
592 | default: |
594 | // unsupported command recieved |
593 | // unsupported command recieved |
595 | break; |
594 | break; |
596 | } |
595 | } |
597 | break; // default: |
596 | break; // default: |
598 | } |
597 | } |
599 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
598 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
600 | } |
599 | } |
601 | 600 | ||
602 | 601 | ||
603 | /*****************************************************/ |
602 | /*****************************************************/ |
604 | /* Send a character */ |
603 | /* Send a character */ |
605 | /*****************************************************/ |
604 | /*****************************************************/ |
606 | s16 UART1_Putchar(char c) |
605 | s16 UART1_Putchar(char c) |
607 | { |
606 | { |
608 | u32 timeout = 10000; |
607 | u32 timeout = 10000; |
609 | if (c == '\n') UART1_Putchar('\r'); |
608 | if (c == '\n') UART1_Putchar('\r'); |
610 | // wait until txd fifo is not full |
609 | // wait until txd fifo is not full |
611 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET) if(--timeout == 0) return(0); |
610 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET) if(--timeout == 0) return(0); |
612 | // transmit byte |
611 | // transmit byte |
613 | UART_SendData(UART1, c); |
612 | UART_SendData(UART1, c); |
614 | #ifdef FOLLOW_ME |
613 | #ifdef FOLLOW_ME |
615 | if(TransmitAlsoToFC) UART_SendData(UART2, c); |
614 | if(TransmitAlsoToFC) UART_SendData(UART2, c); |
616 | #endif |
615 | #endif |
617 | return (0); |
616 | return (0); |
618 | } |
617 | } |
619 | 618 | ||
620 | /*****************************************************/ |
619 | /*****************************************************/ |
621 | /* Send a string to the debug uart */ |
620 | /* Send a string to the debug uart */ |
622 | /*****************************************************/ |
621 | /*****************************************************/ |
623 | void UART1_PutString(u8 *s) |
622 | void UART1_PutString(u8 *s) |
624 | { |
623 | { |
625 | if(s == NULL) return; |
624 | if(s == NULL) return; |
626 | while (*s != '\0' && DebugUART == UART1) |
625 | while (*s != '\0' && DebugUART == UART1) |
627 | { |
626 | { |
628 | UART1_Putchar(*s); |
627 | UART1_Putchar(*s); |
629 | s ++; |
628 | s ++; |
630 | } |
629 | } |
631 | } |
630 | } |
632 | 631 | ||
633 | 632 | ||
634 | /**************************************************************/ |
633 | /**************************************************************/ |
635 | /* Transmit tx buffer via debug uart */ |
634 | /* Transmit tx buffer via debug uart */ |
636 | /**************************************************************/ |
635 | /**************************************************************/ |
637 | void UART1_Transmit(void) |
636 | void UART1_Transmit(void) |
638 | { |
637 | { |
639 | u8 tmp_tx; |
638 | u8 tmp_tx; |
640 | if(DebugUART != UART1) return; |
639 | if(DebugUART != UART1) return; |
641 | // 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 |
642 | if(UART1_tx_buffer.Locked == TRUE) |
641 | if(UART1_tx_buffer.Locked == TRUE) |
643 | { |
642 | { |
644 | // while there is some space in the tx fifo |
643 | // while there is some space in the tx fifo |
645 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET) |
644 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET) |
646 | { |
645 | { |
647 | 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 |
648 | UART_SendData(UART1, tmp_tx); // put character to txd fifo |
647 | UART_SendData(UART1, tmp_tx); // put character to txd fifo |
649 | #ifdef FOLLOW_ME |
648 | #ifdef FOLLOW_ME |
650 | if(TransmitAlsoToFC) |
649 | if(TransmitAlsoToFC) |
651 | { |
650 | { |
652 | UART_SendData(UART2, tmp_tx); // put character to txd fifo |
651 | UART_SendData(UART2, tmp_tx); // put character to txd fifo |
653 | } |
652 | } |
654 | #endif |
653 | #endif |
655 | // if terminating character or end of txd buffer reached |
654 | // if terminating character or end of txd buffer reached |
656 | 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)) |
657 | { |
656 | { |
658 | Buffer_Clear(&UART1_tx_buffer); // clear txd buffer |
657 | Buffer_Clear(&UART1_tx_buffer); // clear txd buffer |
659 | #ifdef FOLLOW_ME |
658 | #ifdef FOLLOW_ME |
660 | TransmitAlsoToFC = 0; |
659 | TransmitAlsoToFC = 0; |
661 | #endif |
660 | #endif |
662 | break; // end while loop |
661 | break; // end while loop |
663 | } |
662 | } |
664 | } |
663 | } |
665 | } |
664 | } |
666 | } |
665 | } |
667 | 666 | ||
668 | 667 | ||
669 | /**************************************************************/ |
668 | /**************************************************************/ |
670 | /* Send the answers to incomming commands at the debug uart */ |
669 | /* Send the answers to incomming commands at the debug uart */ |
671 | /**************************************************************/ |
670 | /**************************************************************/ |
672 | void UART1_TransmitTxData(void) |
671 | void UART1_TransmitTxData(void) |
673 | { |
672 | { |
674 | static u8 motorindex1 = 255, motorindex2 = 0; |
673 | static u8 motorindex1 = 255, motorindex2 = 0; |
675 | if(DebugUART != UART1) return; |
674 | if(DebugUART != UART1) return; |
676 | 675 | ||
677 | if(CheckDelay(UART1_AboTimeOut)) |
676 | if(CheckDelay(UART1_AboTimeOut)) |
678 | { |
677 | { |
679 | UART1_DebugData_Interval = 0; |
678 | UART1_DebugData_Interval = 0; |
680 | UART1_NaviData_Interval = 0; |
679 | UART1_NaviData_Interval = 0; |
681 | UART1_Data3D_Interval = 0; |
680 | UART1_Data3D_Interval = 0; |
682 | UART1_Display_Interval = 0; |
681 | UART1_Display_Interval = 0; |
683 | UART1_MotorData_Interval = 0; |
682 | UART1_MotorData_Interval = 0; |
684 | } |
683 | } |
685 | 684 | ||
686 | UART1_Transmit(); // output pending bytes in tx buffer |
685 | UART1_Transmit(); // output pending bytes in tx buffer |
687 | if((UART1_tx_buffer.Locked == TRUE)) return; |
686 | if((UART1_tx_buffer.Locked == TRUE)) return; |
688 | 687 | ||
689 | if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE)) |
688 | if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE)) |
690 | { |
689 | { |
691 | s16 ParamValue; |
690 | s16 ParamValue; |
692 | NCParams_GetValue(UART1_Request_ParameterId, &ParamValue); |
691 | NCParams_GetValue(UART1_Request_ParameterId, &ParamValue); |
693 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request |
692 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request |
694 | UART1_Request_Parameter = FALSE; |
693 | UART1_Request_Parameter = FALSE; |
695 | } |
694 | } |
696 | else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE)) |
695 | else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE)) |
697 | { |
696 | { |
698 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request |
697 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request |
699 | Echo = 0; // reset echo value |
698 | Echo = 0; // reset echo value |
700 | UART1_Request_Echo = FALSE; |
699 | UART1_Request_Echo = FALSE; |
701 | } |
700 | } |
702 | else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE)) |
701 | else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE)) |
703 | { |
702 | { |
704 | CheckFTPCommand(UART1_Request_FTP); |
703 | CheckFTPCommand(UART1_Request_FTP); |
705 | UART1_Request_FTP = FALSE; |
704 | UART1_Request_FTP = FALSE; |
706 | } |
705 | } |
707 | else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
706 | else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
708 | { |
707 | { |
709 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint)); |
708 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint)); |
710 | UART1_Request_WritePoint = 0xFF; |
709 | UART1_Request_WritePoint = 0xFF; |
711 | } |
710 | } |
712 | else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE)) |
711 | else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE)) |
713 | { |
712 | { |
714 | u8 PointCount = PointList_GetCount(); |
713 | u8 PointCount = PointList_GetCount(); |
715 | if (UART1_Request_ReadPoint <= PointCount) |
714 | if (UART1_Request_ReadPoint <= PointCount) |
716 | { |
715 | { |
717 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t)); |
716 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t)); |
718 | } |
717 | } |
719 | else |
718 | else |
720 | { |
719 | { |
721 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount)); |
720 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount)); |
722 | } |
721 | } |
723 | UART1_Request_ReadPoint = 0; |
722 | UART1_Request_ReadPoint = 0; |
724 | } |
723 | } |
725 | else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
724 | else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
726 | { |
725 | { |
727 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16); |
726 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16); |
728 | UART1_Request_DebugLabel = 0xFF; |
727 | UART1_Request_DebugLabel = 0xFF; |
729 | } |
728 | } |
730 | else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE)) |
729 | else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE)) |
731 | { |
730 | { |
732 | NaviData.Errorcode = ErrorCode; |
731 | NaviData.Errorcode = ErrorCode; |
733 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData, sizeof(NaviData)); |
732 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData, sizeof(NaviData)); |
734 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval); |
733 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval); |
735 | UART1_Request_NaviData = FALSE; |
734 | UART1_Request_NaviData = FALSE; |
736 | LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2; |
735 | LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2; |
737 | } |
736 | } |
738 | else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE)) |
737 | else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE)) |
739 | { |
738 | { |
740 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
739 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
741 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
740 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
742 | UART1_Request_DebugData = FALSE; |
741 | UART1_Request_DebugData = FALSE; |
743 | } |
742 | } |
744 | else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE)) |
743 | else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE)) |
745 | { |
744 | { |
746 | Data3D.StickNick = FC.StickNick; |
745 | Data3D.StickNick = FC.StickNick; |
747 | Data3D.StickRoll = FC.StickRoll; |
746 | Data3D.StickRoll = FC.StickRoll; |
748 | Data3D.StickYaw = FC.StickYaw; |
747 | Data3D.StickYaw = FC.StickYaw; |
749 | Data3D.StickGas = FC.StickGas; |
748 | Data3D.StickGas = FC.StickGas; |
750 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
749 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
751 | UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval); |
750 | UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval); |
752 | UART1_Request_Data3D = FALSE; |
751 | UART1_Request_Data3D = FALSE; |
753 | } |
752 | } |
754 | else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE)) |
753 | else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE)) |
755 | { |
754 | { |
756 | do |
755 | do |
757 | { |
756 | { |
758 | motorindex1++; |
757 | motorindex1++; |
759 | motorindex1%=12; |
758 | motorindex1%=12; |
760 | if(!motorindex1) {motorindex2++; motorindex2 %= 12;}; |
759 | if(!motorindex1) {motorindex2++; motorindex2 %= 12;}; |
761 | if(motorindex1 == motorindex2) break; |
760 | if(motorindex1 == motorindex2) break; |
762 | } |
761 | } |
763 | while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors |
762 | while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors |
764 | 763 | ||
765 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t)); |
764 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t)); |
766 | UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval); |
765 | UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval); |
767 | UART1_Request_MotorData = FALSE; |
766 | UART1_Request_MotorData = FALSE; |
768 | } |
767 | } |
769 | /* |
768 | /* |
770 | else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
769 | else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
771 | { |
770 | { |
772 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame)); |
771 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame)); |
773 | UART1_ConfirmFrame = 0; |
772 | UART1_ConfirmFrame = 0; |
774 | } |
773 | } |
775 | */ |
774 | */ |
776 | /* |
775 | /* |
777 | else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE)) |
776 | else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE)) |
778 | { |
777 | { |
779 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
778 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
780 | UART1_Request_ExternalControl = FALSE; |
779 | UART1_Request_ExternalControl = FALSE; |
781 | } |
780 | } |
782 | */ |
781 | */ |
783 | else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE)) |
782 | else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE)) |
784 | { |
783 | { |
785 | if(UART1_DisplayLine > 3) |
784 | if(UART1_DisplayLine > 3) |
786 | { |
785 | { |
787 | Menu_Update(UART1_DisplayKeys); |
786 | Menu_Update(UART1_DisplayKeys); |
788 | UART1_DisplayKeys = 0; |
787 | UART1_DisplayKeys = 0; |
789 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff)); |
788 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff)); |
790 | } |
789 | } |
791 | else |
790 | else |
792 | { |
791 | { |
793 | UART1_DisplayLine = 2; |
792 | UART1_DisplayLine = 2; |
794 | sprintf(text,"!!! incompatible !!!"); |
793 | sprintf(text,"!!! incompatible !!!"); |
795 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20); |
794 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20); |
796 | if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0; |
795 | if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0; |
797 | } |
796 | } |
798 | UART1_Display_Timer = SetDelay(UART1_Display_Interval); |
797 | UART1_Display_Timer = SetDelay(UART1_Display_Interval); |
799 | UART1_Request_Display = FALSE; |
798 | UART1_Request_Display = FALSE; |
800 | } |
799 | } |
801 | else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE)) |
800 | else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE)) |
802 | { |
801 | { |
803 | Menu_Update(0); |
802 | Menu_Update(0); |
804 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
803 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
805 | UART1_Request_Display1 = FALSE; |
804 | UART1_Request_Display1 = FALSE; |
806 | } |
805 | } |
807 | else if(UART1_Request_VersionInfo && (UART1_tx_buffer.Locked == FALSE)) |
806 | else if(UART1_Request_VersionInfo && (UART1_tx_buffer.Locked == FALSE)) |
808 | { |
807 | { |
809 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
808 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
810 | UART1_Request_VersionInfo = FALSE; |
809 | UART1_Request_VersionInfo = FALSE; |
811 | } |
810 | } |
812 | else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE)) |
811 | else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE)) |
813 | { |
812 | { |
814 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
813 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
815 | UART1_Request_ErrorMessage = FALSE; |
814 | UART1_Request_ErrorMessage = FALSE; |
816 | } |
815 | } |
817 | #ifdef FOLLOW_ME |
816 | #ifdef FOLLOW_ME |
818 | else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE)) |
817 | else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE)) |
819 | { |
818 | { |
820 | if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4)) |
819 | if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4)) |
821 | { |
820 | { |
822 | TransmitAlsoToFC = 1; |
821 | TransmitAlsoToFC = 1; |
823 | // update FollowMe content |
822 | // update FollowMe content |
824 | FollowMe.Position.Longitude = GPSData.Position.Longitude; |
823 | FollowMe.Position.Longitude = GPSData.Position.Longitude; |
825 | FollowMe.Position.Latitude = GPSData.Position.Latitude; |
824 | FollowMe.Position.Latitude = GPSData.Position.Latitude; |
826 | FollowMe.Position.Status = NEWDATA; |
825 | FollowMe.Position.Status = NEWDATA; |
827 | FollowMe.Position.Altitude = 1; |
826 | FollowMe.Position.Altitude = 1; |
828 | // 0 -> no Orientation |
827 | // 0 -> no Orientation |
829 | // 1-360 -> CompassCourse Setpoint |
828 | // 1-360 -> CompassCourse Setpoint |
830 | // -1 -> points to WP1 -> itself |
829 | // -1 -> points to WP1 -> itself |
831 | FollowMe.Heading = -1; |
830 | FollowMe.Heading = -1; |
832 | FollowMe.ToleranceRadius = 1; |
831 | FollowMe.ToleranceRadius = 1; |
833 | FollowMe.HoldTime = 60; |
832 | FollowMe.HoldTime = 60; |
834 | FollowMe.Event_Flag = 1; |
833 | FollowMe.Event_Flag = 1; |
835 | FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list |
834 | FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list |
836 | FollowMe.Type = POINT_TYPE_WP; |
835 | FollowMe.Type = POINT_TYPE_WP; |
837 | FollowMe.WP_EventChannelValue = 100; // set servo value |
836 | FollowMe.WP_EventChannelValue = 100; // set servo value |
838 | FollowMe.AltitudeRate = 0; // do not change height |
837 | FollowMe.AltitudeRate = 0; // do not change height |
839 | FollowMe.reserve[0] = 0; // reserve |
838 | FollowMe.reserve[0] = 0; // reserve |
840 | FollowMe.reserve[1] = 0; // reserve |
839 | FollowMe.reserve[1] = 0; // reserve |
841 | FollowMe.reserve[2] = 0; // reserve |
840 | FollowMe.reserve[2] = 0; // reserve |
842 | FollowMe.reserve[3] = 0; // reserve |
841 | FollowMe.reserve[3] = 0; // reserve |
843 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe)); |
842 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe)); |
844 | } |
843 | } |
845 | UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time |
844 | UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time |
846 | } |
845 | } |
847 | #endif |
846 | #endif |
848 | #ifdef DEBUG // only include functions if DEBUG is defined |
847 | #ifdef DEBUG // only include functions if DEBUG is defined |
849 | else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE)) |
848 | else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE)) |
850 | { |
849 | { |
851 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug)); |
850 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug)); |
852 | SendDebugOutput = 0; |
851 | SendDebugOutput = 0; |
853 | } |
852 | } |
854 | #endif |
853 | #endif |
855 | UART1_Transmit(); // output pending bytes in tx buffer |
854 | UART1_Transmit(); // output pending bytes in tx buffer |
856 | } |
855 | } |
857 | 856 | ||
858 | 857 |