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