Rev 519 | Rev 530 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 519 | Rev 529 | ||
---|---|---|---|
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 <stdlib.h> |
57 | #include <stdlib.h> |
58 | #include <stdarg.h> |
58 | #include <stdarg.h> |
59 | #include <string.h> |
59 | #include <string.h> |
60 | 60 | ||
61 | #include "91x_lib.h" |
61 | #include "91x_lib.h" |
62 | #include "main.h" |
62 | #include "main.h" |
63 | #include "config.h" |
63 | #include "config.h" |
64 | #include "menu.h" |
64 | #include "menu.h" |
65 | #include "GPS.h" |
65 | #include "GPS.h" |
66 | #include "i2c.h" |
66 | #include "i2c.h" |
67 | #include "uart0.h" |
67 | #include "uart0.h" |
68 | #include "uart1.h" |
68 | #include "uart1.h" |
69 | #include "uart2.h" |
69 | #include "uart2.h" |
70 | #include "timer1.h" |
70 | #include "timer1.h" |
71 | #include "timer2.h" |
71 | #include "timer2.h" |
72 | #include "analog.h" |
72 | #include "analog.h" |
73 | #include "compass.h" |
73 | #include "compass.h" |
74 | #include "waypoints.h" |
74 | #include "waypoints.h" |
75 | #include "mkprotocol.h" |
75 | #include "mkprotocol.h" |
76 | #include "params.h" |
76 | #include "params.h" |
77 | #include "fifo.h" |
77 | #include "fifo.h" |
78 | #include "debug.h" |
78 | #include "debug.h" |
79 | #include "spi_slave.h" |
79 | #include "spi_slave.h" |
80 | #include "ftphelper.h" |
80 | #include "ftphelper.h" |
81 | #include "led.h" |
81 | #include "led.h" |
82 | #include "fat16.h" |
82 | #include "fat16.h" |
- | 83 | #include "eeprom.h" |
|
- | 84 | ||
- | 85 | #define LIC_CMD_READ_LICENSE 1 |
|
- | 86 | #define LIC_CMD_WRITE_LICENSE 2 |
|
- | 87 | #define LIC_CMD_ERASE_LICENSE 3 |
|
83 | 88 | ||
84 | 89 | ||
85 | #define FALSE 0 |
90 | #define FALSE 0 |
86 | #define TRUE 1 |
91 | #define TRUE 1 |
87 | 92 | ||
88 | #define ABO_TIMEOUT 8000 // disable abo after 8 seconds |
93 | #define ABO_TIMEOUT 8000 // disable abo after 8 seconds |
89 | u32 UART1_AboTimeOut = 0; |
94 | u32 UART1_AboTimeOut = 0; |
90 | 95 | ||
91 | u8 UART1_Request_VersionInfo = FALSE; |
96 | u8 UART1_Request_VersionInfo = FALSE; |
92 | u8 UART1_Request_ExternalControl= FALSE; |
97 | u8 UART1_Request_ExternalControl= FALSE; |
93 | u8 UART1_Request_Display = FALSE; |
98 | u8 UART1_Request_Display = FALSE; |
94 | u8 UART1_Request_Display1 = FALSE; |
99 | u8 UART1_Request_Display1 = FALSE; |
95 | u8 UART1_Request_DebugData = FALSE; |
100 | u8 UART1_Request_DebugData = FALSE; |
96 | u8 UART1_Request_DebugLabel = 255; |
101 | u8 UART1_Request_DebugLabel = 255; |
97 | u8 UART1_Request_NaviData = FALSE; |
102 | u8 UART1_Request_NaviData = FALSE; |
98 | u8 UART1_Request_ErrorMessage = FALSE; |
103 | u8 UART1_Request_ErrorMessage = FALSE; |
99 | u8 UART1_Request_WritePoint = 0xFF; |
104 | u8 UART1_Request_WritePoint = 0xFF; |
100 | u8 UART1_Request_ReadPoint = 0; |
105 | u8 UART1_Request_ReadPoint = 0; |
101 | u8 UART1_Request_Data3D = FALSE; |
106 | u8 UART1_Request_Data3D = FALSE; |
102 | u8 UART1_Request_MotorData = FALSE; |
107 | u8 UART1_Request_MotorData = FALSE; |
103 | u8 UART1_Request_Echo = FALSE; |
108 | u8 UART1_Request_Echo = FALSE; |
104 | u8 UART1_Request_ParameterId = 0; |
109 | u8 UART1_Request_ParameterId = 0; |
105 | u8 UART1_Request_WPLStore = FALSE; |
110 | u8 UART1_Request_WPLStore = FALSE; |
106 | u8 UART1_Request_Parameter = FALSE; |
111 | u8 UART1_Request_Parameter = FALSE; |
107 | u8 UART1_Request_SystemTime = FALSE; |
112 | u8 UART1_Request_SystemTime = FALSE; |
108 | u8 UART1_DisplayKeys = 0; |
113 | u8 UART1_DisplayKeys = 0; |
109 | u8 UART1_DisplayLine = 0; |
114 | u8 UART1_DisplayLine = 0; |
110 | u8 UART1_ConfirmFrame = 0; |
115 | u8 UART1_ConfirmFrame = 0; |
111 | u8 UART1_Request_FTP = FALSE; |
116 | u8 UART1_Request_FTP = FALSE; |
- | 117 | u8 UART1_Request_LicenseString = FALSE; |
|
112 | u8 LastTransmittedFCStatusFlags2 = 0; |
118 | u8 LastTransmittedFCStatusFlags2 = 0; |
113 | u8 UART1_ExternalControlConfirmFrame = FALSE; |
119 | u8 UART1_ExternalControlConfirmFrame = FALSE; |
114 | u8 Send_NMEA_RMC = FALSE; |
120 | u8 Send_NMEA_RMC = FALSE; |
115 | 121 | ||
116 | UART_TypeDef *DebugUART = UART1; |
122 | UART_TypeDef *DebugUART = UART1; |
117 | 123 | ||
118 | #ifdef FOLLOW_ME |
124 | #ifdef FOLLOW_ME |
119 | #define FOLLOW_ME_INTERVAL 200 // 5 Hz |
125 | #define FOLLOW_ME_INTERVAL 200 // 5 Hz |
120 | u32 UART1_FollowMe_Timer = 0; |
126 | u32 UART1_FollowMe_Timer = 0; |
121 | Point_t FollowMe; |
127 | Point_t FollowMe; |
122 | #endif |
128 | #endif |
123 | 129 | ||
124 | // the primary rx fifo |
130 | // the primary rx fifo |
125 | #define UART1_RX_FIFO_LEN 1024 |
131 | #define UART1_RX_FIFO_LEN 1024 |
126 | u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN]; |
132 | u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN]; |
127 | fifo_t UART1_rx_fifo; |
133 | fifo_t UART1_rx_fifo; |
128 | 134 | ||
129 | // the rx buffer |
135 | // the rx buffer |
130 | #define UART1_RX_BUFFER_LEN 1024 |
136 | #define UART1_RX_BUFFER_LEN 1024 |
131 | u8 UART1_rbuffer[UART1_RX_BUFFER_LEN]; |
137 | u8 UART1_rbuffer[UART1_RX_BUFFER_LEN]; |
132 | Buffer_t UART1_rx_buffer; |
138 | Buffer_t UART1_rx_buffer; |
133 | 139 | ||
134 | // the tx buffer |
140 | // the tx buffer |
135 | #define UART1_TX_BUFFER_LEN 1024 |
141 | #define UART1_TX_BUFFER_LEN 1024 |
136 | u8 UART1_tbuffer[UART1_TX_BUFFER_LEN]; |
142 | u8 UART1_tbuffer[UART1_TX_BUFFER_LEN]; |
137 | Buffer_t UART1_tx_buffer; |
143 | Buffer_t UART1_tx_buffer; |
138 | 144 | ||
139 | volatile u8 SerialLinkOkay = 0; |
145 | volatile u8 SerialLinkOkay = 0; |
140 | 146 | ||
141 | u8 text[200]; |
147 | u8 text[200]; |
- | 148 | u8 *LicensePtr = UART1_tbuffer; |
|
142 | 149 | ||
143 | const u8 ANALOG_LABEL[32][16] = |
150 | const u8 ANALOG_LABEL[32][16] = |
144 | { |
151 | { |
145 | //1234567890123456 |
152 | //1234567890123456 |
146 | "AngleNick ", //0 |
153 | "AngleNick ", //0 |
147 | "AngleRoll ", |
154 | "AngleRoll ", |
148 | "AccNick ", |
155 | "AccNick ", |
149 | "AccRoll ", |
156 | "AccRoll ", |
150 | "Altitude [0.1m] ", |
157 | "Altitude [0.1m] ", |
151 | "FC-Flags ", //5 |
158 | "FC-Flags ", //5 |
152 | "NC-Flags ", |
159 | "NC-Flags ", |
153 | "Voltage [0.1V] ", |
160 | "Voltage [0.1V] ", |
154 | "Current [0.1A] ", |
161 | "Current [0.1A] ", |
155 | "GPS Data ", |
162 | "GPS Data ", |
156 | "CompassHeading ", //10 |
163 | "CompassHeading ", //10 |
157 | "GyroHeading ", |
164 | "GyroHeading ", |
158 | "SPI Error ", // achtung: muss auf 12 bleiben |
165 | "SPI Error ", // achtung: muss auf 12 bleiben |
159 | "SPI Okay ", |
166 | "SPI Okay ", |
160 | "I2C Error ", |
167 | "I2C Error ", |
161 | "I2C Okay ", //15 |
168 | "I2C Okay ", //15 |
162 | "16 dist (cm) ", |
169 | "16 ", |
163 | "17 alt dist ", |
170 | "17 ", |
164 | "18 time ", |
171 | "18 ", |
165 | "19 climb ", // SD-Card-time |
172 | "19 ", // SD-Card-time |
166 | "EarthMagnet [%] ", //20 |
173 | "EarthMagnet [%] ", //20 |
167 | "Ground Speed ", // "Z_Speed ", |
174 | "Ground Speed ", // "Z_Speed ", |
168 | "N_Speed ", |
175 | "N_Speed ", |
169 | "E_Speed ", |
176 | "E_Speed ", |
170 | "Magnet X ", |
177 | "Magnet X ", |
171 | "Magnet Y ", //25 |
178 | "Magnet Y ", //25 |
172 | "Magnet Z ", |
179 | "Magnet Z ", |
173 | "Distance N ", |
180 | "Distance N ", |
174 | "Distance E ", |
181 | "Distance E ", |
175 | "-GPS_Nick ", |
182 | "-GPS_Nick ", |
176 | "-GPS_Roll ", //30 |
183 | "-GPS_Roll ", //30 |
177 | "Used_Sats " |
184 | "Used_Sats " |
178 | }; |
185 | }; |
179 | 186 | ||
180 | typedef struct |
187 | typedef struct |
181 | { |
188 | { |
182 | u8 Index; |
189 | u8 Index; |
183 | u8 Status; |
190 | u8 Status; |
184 | } __attribute__((packed)) WPL_Answer_t; |
191 | } __attribute__((packed)) WPL_Answer_t; |
185 | WPL_Answer_t WPL_Answer; |
192 | WPL_Answer_t WPL_Answer; |
186 | 193 | ||
187 | DebugOut_t DebugOut; |
194 | DebugOut_t DebugOut; |
188 | ExternControl_t ExternControl; |
195 | ExternControl_t ExternControl; |
189 | UART_VersionInfo_t UART_VersionInfo; |
196 | UART_VersionInfo_t UART_VersionInfo; |
190 | NaviData_t NaviData; |
197 | NaviData_t NaviData; |
191 | Data3D_t Data3D; |
198 | Data3D_t Data3D; |
192 | 199 | ||
193 | u16 Echo; // 2 bytes recieved will be sent back as echo |
200 | u16 Echo; // 2 bytes recieved will be sent back as echo |
194 | 201 | ||
195 | u32 UART1_DebugData_Timer = 0; |
202 | u32 UART1_DebugData_Timer = 0; |
196 | u32 UART1_DebugData_Interval = 0; // in ms |
203 | u32 UART1_DebugData_Interval = 0; // in ms |
197 | u32 UART1_NaviData_Timer = 0; |
204 | u32 UART1_NaviData_Timer = 0; |
198 | u32 UART1_NaviData_Interval = 0; // in ms |
205 | u32 UART1_NaviData_Interval = 0; // in ms |
199 | u32 UART1_Data3D_Timer = 0; |
206 | u32 UART1_Data3D_Timer = 0; |
200 | u32 UART1_Data3D_Interval = 0; // in ms |
207 | u32 UART1_Data3D_Interval = 0; // in ms |
201 | u32 UART1_MotorData_Timer = 0; |
208 | u32 UART1_MotorData_Timer = 0; |
202 | u32 UART1_MotorData_Interval = 0; // in ms |
209 | u32 UART1_MotorData_Interval = 0; // in ms |
203 | u32 UART1_Display_Timer = 0; |
210 | u32 UART1_Display_Timer = 0; |
204 | u32 UART1_Display_Interval = 0; // in ms |
211 | u32 UART1_Display_Interval = 0; // in ms |
205 | u32 NMEA_Timer = 0; |
212 | u32 NMEA_Timer = 0; |
206 | u32 NMEA_Interval = 500;// in ms |
213 | u32 NMEA_Interval = 500;// in ms |
207 | 214 | ||
208 | /********************************************************/ |
215 | /********************************************************/ |
209 | /* Initialization the UART1 */ |
216 | /* Initialization the UART1 */ |
210 | /********************************************************/ |
217 | /********************************************************/ |
211 | void UART1_Init (void) |
218 | void UART1_Init (void) |
212 | { |
219 | { |
213 | GPIO_InitTypeDef GPIO_InitStructure; |
220 | GPIO_InitTypeDef GPIO_InitStructure; |
214 | UART_InitTypeDef UART_InitStructure; |
221 | UART_InitTypeDef UART_InitStructure; |
215 | 222 | ||
216 | // initialize txd buffer |
223 | // initialize txd buffer |
217 | Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN); |
224 | Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN); |
218 | 225 | ||
219 | // initialize rxd buffer |
226 | // initialize rxd buffer |
220 | Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN); |
227 | Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN); |
221 | 228 | ||
222 | // initialize the rx fifo, block UART IRQ geting a byte from fifo |
229 | // initialize the rx fifo, block UART IRQ geting a byte from fifo |
223 | fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine); |
230 | fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine); |
224 | 231 | ||
225 | SCU_APBPeriphClockConfig(__UART1, ENABLE); // Enable the UART1 Clock |
232 | SCU_APBPeriphClockConfig(__UART1, ENABLE); // Enable the UART1 Clock |
226 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
233 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
227 | 234 | ||
228 | /*Configure UART1_Rx pin GPIO3.2*/ |
235 | /*Configure UART1_Rx pin GPIO3.2*/ |
229 | GPIO_StructInit(&GPIO_InitStructure); |
236 | GPIO_StructInit(&GPIO_InitStructure); |
230 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
237 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
231 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
238 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
232 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
239 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
233 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
240 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
234 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART1_RxD |
241 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART1_RxD |
235 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
242 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
236 | 243 | ||
237 | /*Configure UART1_Tx pin GPIO3.3*/ |
244 | /*Configure UART1_Tx pin GPIO3.3*/ |
238 | GPIO_StructInit(&GPIO_InitStructure); |
245 | GPIO_StructInit(&GPIO_InitStructure); |
239 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
246 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
240 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
247 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
241 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
248 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
242 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART1_TX |
249 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART1_TX |
243 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
250 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
244 | 251 | ||
245 | /* UART1 configured as follow: |
252 | /* UART1 configured as follow: |
246 | - Word Length = 8 Bits |
253 | - Word Length = 8 Bits |
247 | - One Stop Bit |
254 | - One Stop Bit |
248 | - No parity |
255 | - No parity |
249 | - BaudRate = 57600 baud |
256 | - BaudRate = 57600 baud |
250 | - Hardware flow control Disabled |
257 | - Hardware flow control Disabled |
251 | - Receive and transmit enabled |
258 | - Receive and transmit enabled |
252 | - Receive and transmit FIFOs are Disabled |
259 | - Receive and transmit FIFOs are Disabled |
253 | */ |
260 | */ |
254 | UART_StructInit(&UART_InitStructure); |
261 | UART_StructInit(&UART_InitStructure); |
255 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
262 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
256 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
263 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
257 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
264 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
258 | UART_InitStructure.UART_BaudRate = UART1_BAUD_RATE; |
265 | UART_InitStructure.UART_BaudRate = UART1_BAUD_RATE; |
259 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
266 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
260 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
267 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
261 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
268 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
262 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
269 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
263 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; // FIFO size 16 bytes, FIFO level 8 bytes |
270 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; // FIFO size 16 bytes, FIFO level 8 bytes |
264 | 271 | ||
265 | UART_DeInit(UART1); // reset uart 1 to default |
272 | UART_DeInit(UART1); // reset uart 1 to default |
266 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
273 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
267 | // enable uart 1 interrupts selective |
274 | // enable uart 1 interrupts selective |
268 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
275 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
269 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
276 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
270 | // configure the uart 1 interupt line |
277 | // configure the uart 1 interupt line |
271 | VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1); |
278 | VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1); |
272 | // enable the uart 1 IRQ |
279 | // enable the uart 1 IRQ |
273 | VIC_ITCmd(UART1_ITLine, ENABLE); |
280 | VIC_ITCmd(UART1_ITLine, ENABLE); |
274 | 281 | ||
275 | // initialize the debug timer |
282 | // initialize the debug timer |
276 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
283 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
277 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500; |
284 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500; |
278 | NMEA_Timer = SetDelay(14000); |
285 | NMEA_Timer = SetDelay(14000); |
279 | 286 | ||
280 | // Fill Version Info Structure |
287 | // Fill Version Info Structure |
281 | UART_VersionInfo.SWMajor = VERSION_MAJOR; |
288 | UART_VersionInfo.SWMajor = VERSION_MAJOR; |
282 | UART_VersionInfo.SWMinor = VERSION_MINOR; |
289 | UART_VersionInfo.SWMinor = VERSION_MINOR; |
283 | UART_VersionInfo.SWPatch = VERSION_PATCH; |
290 | UART_VersionInfo.SWPatch = VERSION_PATCH; |
284 | UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
291 | UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
285 | UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
292 | UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
286 | UART_VersionInfo.HWMajor = Version_HW & 0x7F; |
293 | UART_VersionInfo.HWMajor = Version_HW & 0x7F; |
287 | UART_VersionInfo.reserved2 = 0; |
294 | UART_VersionInfo.reserved2 = 0; |
288 | UART_VersionInfo.Flags = 0; |
295 | UART_VersionInfo.Flags = 0; |
289 | NaviData.Version = NAVIDATA_VERSION; |
296 | NaviData.Version = NAVIDATA_VERSION; |
290 | 297 | ||
291 | UART1_PutString("\r\n UART1 init...ok"); |
298 | UART1_PutString("\r\n UART1 init...ok"); |
292 | } |
299 | } |
293 | 300 | ||
294 | 301 | ||
295 | /****************************************************************/ |
302 | /****************************************************************/ |
296 | /* USART1 receiver ISR */ |
303 | /* USART1 receiver ISR */ |
297 | /****************************************************************/ |
304 | /****************************************************************/ |
298 | void UART1_IRQHandler(void) |
305 | void UART1_IRQHandler(void) |
299 | { |
306 | { |
300 | static u8 abortState = 0; |
307 | static u8 abortState = 0; |
301 | u8 c; |
308 | u8 c; |
302 | 309 | ||
303 | if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) ) |
310 | if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) ) |
304 | { |
311 | { |
305 | // clear the pending bits! |
312 | // clear the pending bits! |
306 | UART_ClearITPendingBit(UART1, UART_IT_Receive); |
313 | UART_ClearITPendingBit(UART1, UART_IT_Receive); |
307 | UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut); |
314 | UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut); |
308 | // if debug UART is not UART1 |
315 | // if debug UART is not UART1 |
309 | if (DebugUART != UART1) |
316 | if (DebugUART != UART1) |
310 | { // forward received data to the debug UART tx buffer |
317 | { // forward received data to the debug UART tx buffer |
311 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
318 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
312 | { |
319 | { |
313 | // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART |
320 | // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART |
314 | c = UART_ReceiveData(UART1); |
321 | c = UART_ReceiveData(UART1); |
315 | 322 | ||
316 | // check for abort condition (ESC ESC 0x55 0xAA 0x00) |
323 | // check for abort condition (ESC ESC 0x55 0xAA 0x00) |
317 | switch (abortState) |
324 | switch (abortState) |
318 | { |
325 | { |
319 | case 0: |
326 | case 0: |
320 | if (c == 27) abortState++; |
327 | if (c == 27) abortState++; |
321 | break; |
328 | break; |
322 | case 1: |
329 | case 1: |
323 | if (c == 27) abortState++; |
330 | if (c == 27) abortState++; |
324 | else abortState = 0; |
331 | else abortState = 0; |
325 | break; |
332 | break; |
326 | case 2: |
333 | case 2: |
327 | if (c == 0x55) abortState++; |
334 | if (c == 0x55) abortState++; |
328 | else abortState = 0; |
335 | else abortState = 0; |
329 | break; |
336 | break; |
330 | case 3: |
337 | case 3: |
331 | if (c == 0xAA) abortState++; |
338 | if (c == 0xAA) abortState++; |
332 | else abortState = 0; |
339 | else abortState = 0; |
333 | break; |
340 | break; |
334 | case 4: |
341 | case 4: |
335 | if (c == 0x00) |
342 | if (c == 0x00) |
336 | { |
343 | { |
337 | if(DebugUART == UART0) |
344 | if(DebugUART == UART0) |
338 | { |
345 | { |
339 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); |
346 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); |
340 | TIMER2_Init(); // enbable servo outputs |
347 | TIMER2_Init(); // enbable servo outputs |
341 | fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer |
348 | fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer |
342 | } |
349 | } |
343 | DebugUART = UART1; |
350 | DebugUART = UART1; |
344 | } |
351 | } |
345 | abortState = 0; |
352 | abortState = 0; |
346 | break; |
353 | break; |
347 | } // end switch abort state |
354 | } // end switch abort state |
348 | // if the Debug uart is not UART1, redirect input to the Debug UART |
355 | // if the Debug uart is not UART1, redirect input to the Debug UART |
349 | if (DebugUART != UART1) |
356 | if (DebugUART != UART1) |
350 | { |
357 | { |
351 | // wait for space in the tx buffer of the DebugUART |
358 | // wait for space in the tx buffer of the DebugUART |
352 | while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {}; |
359 | while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {}; |
353 | // move byte to the tx fifo of the debug uart |
360 | // move byte to the tx fifo of the debug uart |
354 | UART_SendData(DebugUART, c); |
361 | UART_SendData(DebugUART, c); |
355 | } |
362 | } |
356 | } |
363 | } |
357 | } |
364 | } |
358 | else // DebugUART == UART1 (normal operation) |
365 | else // DebugUART == UART1 (normal operation) |
359 | { |
366 | { |
360 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
367 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
361 | { // some byes in the hardware fifo |
368 | { // some byes in the hardware fifo |
362 | // get byte from hardware fifo |
369 | // get byte from hardware fifo |
363 | c = UART_ReceiveData(UART1); |
370 | c = UART_ReceiveData(UART1); |
364 | // put into the software fifo |
371 | // put into the software fifo |
365 | if(!fifo_put(&UART1_rx_fifo, c)) |
372 | if(!fifo_put(&UART1_rx_fifo, c)) |
366 | { // fifo overflow |
373 | { // fifo overflow |
367 | //fifo_purge(&UART1_rx_fifo); // flush the whole buffer |
374 | //fifo_purge(&UART1_rx_fifo); // flush the whole buffer |
368 | } |
375 | } |
369 | } // EOF while some byes in the hardware fifo |
376 | } // EOF while some byes in the hardware fifo |
370 | } // eof DebugUart = UART1 |
377 | } // eof DebugUart = UART1 |
371 | } |
378 | } |
372 | 379 | ||
373 | 380 | ||
374 | 381 | ||
375 | VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register |
382 | VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register |
376 | } |
383 | } |
377 | 384 | ||
378 | /**************************************************************/ |
385 | /**************************************************************/ |
379 | /* Process incomming data from debug uart */ |
386 | /* Process incomming data from debug uart */ |
380 | /**************************************************************/ |
387 | /**************************************************************/ |
381 | void UART1_ProcessRxData(void) |
388 | void UART1_ProcessRxData(void) |
382 | { |
389 | { |
383 | // return on forwarding uart or unlocked rx buffer |
390 | // return on forwarding uart or unlocked rx buffer |
384 | u8 c; |
391 | u8 c; |
385 | if(DebugUART != UART1) return; |
392 | if(DebugUART != UART1) return; |
386 | // if rx buffer is not locked |
393 | // if rx buffer is not locked |
387 | if(UART1_rx_buffer.Locked == FALSE) |
394 | if(UART1_rx_buffer.Locked == FALSE) |
388 | { |
395 | { |
389 | //collect data from primary rx fifo |
396 | //collect data from primary rx fifo |
390 | while(fifo_get(&UART1_rx_fifo, &c)) |
397 | while(fifo_get(&UART1_rx_fifo, &c)) |
391 | { |
398 | { |
392 | // break if complete frame is collected |
399 | // break if complete frame is collected |
393 | if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break; |
400 | if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break; |
394 | } |
401 | } |
395 | } |
402 | } |
396 | if(UART1_rx_buffer.Locked == FALSE) return; |
403 | if(UART1_rx_buffer.Locked == FALSE) return; |
397 | 404 | ||
398 | Point_t * pPoint = NULL; |
405 | Point_t * pPoint = NULL; |
399 | SerialMsg_t SerialMsg; |
406 | SerialMsg_t SerialMsg; |
400 | 407 | ||
401 | // analyze header first |
408 | // analyze header first |
402 | MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg); |
409 | MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg); |
403 | if( SerialMsg.Address == FC_ADDRESS ) |
410 | if( SerialMsg.Address == FC_ADDRESS ) |
404 | { |
411 | { |
405 | switch(SerialMsg.CmdID) |
412 | switch(SerialMsg.CmdID) |
406 | { |
413 | { |
407 | // case 'v': // version |
414 | // case 'v': // version |
408 | case 'b': // extern control |
415 | case 'b': // extern control |
409 | UART1_ExternalControlConfirmFrame = 1; |
416 | UART1_ExternalControlConfirmFrame = 1; |
410 | case 'y': // serial poti values |
417 | case 'y': // serial poti values |
411 | Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC |
418 | Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC |
412 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
419 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
413 | return; //end process rx data |
420 | return; //end process rx data |
414 | break; |
421 | break; |
415 | } |
422 | } |
416 | } |
423 | } |
417 | 424 | ||
418 | MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
425 | MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
419 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
426 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
420 | switch(SerialMsg.Address) // check for Slave Address |
427 | switch(SerialMsg.Address) // check for Slave Address |
421 | { |
428 | { |
422 | case NC_ADDRESS: // own Slave Address |
429 | case NC_ADDRESS: // own Slave Address |
423 | switch(SerialMsg.CmdID) |
430 | switch(SerialMsg.CmdID) |
424 | { |
431 | { |
425 | case 't': // request for the GPS time |
432 | case 't': // request for the GPS time |
426 | UART1_Request_SystemTime = TRUE; |
433 | UART1_Request_SystemTime = TRUE; |
427 | break; |
434 | break; |
- | 435 | ||
- | 436 | case 'm': // request for the license string |
|
- | 437 | UART1_Request_LicenseString = SerialMsg.pData[0]; |
|
- | 438 | if(UART1_Request_LicenseString == LIC_CMD_WRITE_LICENSE) |
|
- | 439 | { |
|
- | 440 | memcpy(LicensePtr, &SerialMsg.pData[1],LICENSE_SIZE_TEXT); // copy ftp parameter |
|
- | 441 | } |
|
428 | 442 | break; |
|
429 | case 'f': // ftp command |
443 | case 'f': // ftp command |
430 | UART1_Request_FTP = SerialMsg.pData[0]; |
444 | UART1_Request_FTP = SerialMsg.pData[0]; |
431 | //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE) |
445 | //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE) |
432 | memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter |
446 | memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter |
433 | break; |
447 | break; |
434 | 448 | ||
435 | case 'z': // connection checker |
449 | case 'z': // connection checker |
436 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
450 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
437 | UART1_Request_Echo = TRUE; |
451 | UART1_Request_Echo = TRUE; |
438 | break; |
452 | break; |
439 | 453 | ||
440 | case 'e': // request for the text of the error status |
454 | case 'e': // request for the text of the error status |
441 | UART1_Request_ErrorMessage = TRUE; |
455 | UART1_Request_ErrorMessage = TRUE; |
442 | break; |
456 | break; |
443 | 457 | ||
444 | case 's':// new target position |
458 | case 's':// new target position |
445 | pPoint = (Point_t*)SerialMsg.pData; |
459 | pPoint = (Point_t*)SerialMsg.pData; |
446 | if(pPoint->Position.Status == NEWDATA) |
460 | if(pPoint->Position.Status == NEWDATA) |
447 | { |
461 | { |
448 | //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list |
462 | //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list |
449 | //pPoint->Index = 1; // must be one after empty list |
463 | //pPoint->Index = 1; // must be one after empty list |
450 | PointList_SetAt(pPoint); |
464 | PointList_SetAt(pPoint); |
451 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
465 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
452 | GPS_pWaypoint = PointList_WPBegin(); // updates POI index |
466 | GPS_pWaypoint = PointList_WPBegin(); // updates POI index |
453 | BeepTime = 50; |
467 | BeepTime = 50; |
454 | } |
468 | } |
455 | break; |
469 | break; |
456 | 470 | ||
457 | case 'u': // redirect debug uart |
471 | case 'u': // redirect debug uart |
458 | switch(SerialMsg.pData[0]) |
472 | switch(SerialMsg.pData[0]) |
459 | { |
473 | { |
460 | case UART_FLIGHTCTRL: |
474 | case UART_FLIGHTCTRL: |
461 | UART2_Init(); // initialize UART2 to FC pins |
475 | UART2_Init(); // initialize UART2 to FC pins |
462 | fifo_purge(&UART1_rx_fifo); |
476 | fifo_purge(&UART1_rx_fifo); |
463 | TIMER2_Deinit(); // reduce irq load |
477 | TIMER2_Deinit(); // reduce irq load |
464 | DebugUART = UART2; |
478 | DebugUART = UART2; |
465 | break; |
479 | break; |
466 | case UART_MK3MAG: |
480 | case UART_MK3MAG: |
467 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running |
481 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running |
468 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
482 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
469 | GPSData.Status = INVALID; |
483 | GPSData.Status = INVALID; |
470 | fifo_purge(&UART1_rx_fifo); |
484 | fifo_purge(&UART1_rx_fifo); |
471 | DebugUART = UART0; |
485 | DebugUART = UART0; |
472 | break; |
486 | break; |
473 | case UART_MKGPS: |
487 | case UART_MKGPS: |
474 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running |
488 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running |
475 | TIMER2_Deinit(); // disable servo outputs to reduce irq load |
489 | TIMER2_Deinit(); // disable servo outputs to reduce irq load |
476 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); // connect UART0 to MKGPS pins |
490 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); // connect UART0 to MKGPS pins |
477 | GPSData.Status = INVALID; |
491 | GPSData.Status = INVALID; |
478 | fifo_purge(&UART1_rx_fifo); |
492 | fifo_purge(&UART1_rx_fifo); |
479 | DebugUART = UART0; |
493 | DebugUART = UART0; |
480 | break; |
494 | break; |
481 | default: |
495 | default: |
482 | break; |
496 | break; |
483 | } |
497 | } |
484 | break; |
498 | break; |
485 | 499 | ||
486 | case 'w':// Set point in list at index |
500 | case 'w':// Set point in list at index |
487 | { |
501 | { |
488 | pPoint = (Point_t*)SerialMsg.pData; |
502 | pPoint = (Point_t*)SerialMsg.pData; |
489 | 503 | ||
490 | if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0)) |
504 | if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0)) |
491 | { |
505 | { |
492 | PointList_Clear(); |
506 | PointList_Clear(); |
493 | GPS_pWaypoint = PointList_WPBegin(); |
507 | GPS_pWaypoint = PointList_WPBegin(); |
494 | UART1_Request_WritePoint = 0; // return new point count |
508 | UART1_Request_WritePoint = 0; // return new point count |
495 | } |
509 | } |
496 | else |
510 | else |
497 | { // update WP in list at index |
511 | { // update WP in list at index |
498 | if(pPoint->Index > MaxNumberOfWaypoints) |
512 | if(pPoint->Index > MaxNumberOfWaypoints) |
499 | { |
513 | { |
500 | UART1_Request_WritePoint = 254; |
514 | UART1_Request_WritePoint = 254; |
501 | pPoint->Index = MaxNumberOfWaypoints; |
515 | pPoint->Index = MaxNumberOfWaypoints; |
502 | } |
516 | } |
503 | else UART1_Request_WritePoint = PointList_SetAt(pPoint); |
517 | else UART1_Request_WritePoint = PointList_SetAt(pPoint); |
504 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
518 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
505 | SpeakWaypointRached = 1; // Speak once when the last Point is reached |
519 | SpeakWaypointRached = 1; // Speak once when the last Point is reached |
506 | if(UART1_Request_WritePoint == pPoint->Index) |
520 | if(UART1_Request_WritePoint == pPoint->Index) |
507 | { |
521 | { |
508 | BeepTime = 500; |
522 | BeepTime = 500; |
509 | if(UART1_Request_WritePoint == 1) SpeakNextWaypoint = 1; // Speak once as soon as the Points are active |
523 | if(UART1_Request_WritePoint == 1) SpeakNextWaypoint = 1; // Speak once as soon as the Points are active |
510 | } |
524 | } |
511 | } |
525 | } |
512 | } |
526 | } |
513 | break; |
527 | break; |
514 | 528 | ||
515 | case 'x':// Read Waypoint from List |
529 | case 'x':// Read Waypoint from List |
516 | UART1_Request_ReadPoint = SerialMsg.pData[0]; |
530 | UART1_Request_ReadPoint = SerialMsg.pData[0]; |
517 | break; |
531 | break; |
518 | 532 | ||
519 | case 'i':// Store WP List to file |
533 | case 'i':// Store WP List to file |
520 | memcpy((u8*)&WPL_Store, SerialMsg.pData, sizeof(WPL_Store_t)); |
534 | memcpy((u8*)&WPL_Store, SerialMsg.pData, sizeof(WPL_Store_t)); |
521 | WPL_Store.Name[11] = 0; // make sure the name string is terminated |
535 | WPL_Store.Name[11] = 0; // make sure the name string is terminated |
522 | WPL_Answer.Index = WPL_Store.Index; // echo Index in cmd answer |
536 | WPL_Answer.Index = WPL_Store.Index; // echo Index in cmd answer |
523 | WPL_Answer.Status = PointList_WriteToFile(&WPL_Store); |
537 | WPL_Answer.Status = PointList_WriteToFile(&WPL_Store); |
524 | UART1_Request_WPLStore = TRUE; |
538 | UART1_Request_WPLStore = TRUE; |
525 | break; |
539 | break; |
526 | 540 | ||
527 | 541 | ||
528 | case 'j':// Set/Get NC-Parameter |
542 | case 'j':// Set/Get NC-Parameter |
529 | switch(SerialMsg.pData[0]) |
543 | switch(SerialMsg.pData[0]) |
530 | { |
544 | { |
531 | case 0: // get |
545 | case 0: // get |
532 | break; |
546 | break; |
533 | 547 | ||
534 | case 1: // set |
548 | case 1: // set |
535 | { |
549 | { |
536 | s16 value; |
550 | s16 value; |
537 | value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100; |
551 | value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100; |
538 | NCParams_SetValue(SerialMsg.pData[1], &value); |
552 | NCParams_SetValue(SerialMsg.pData[1], &value); |
539 | } |
553 | } |
540 | break; |
554 | break; |
541 | 555 | ||
542 | default: |
556 | default: |
543 | break; |
557 | break; |
544 | } |
558 | } |
545 | UART1_Request_ParameterId = SerialMsg.pData[1]; |
559 | UART1_Request_ParameterId = SerialMsg.pData[1]; |
546 | UART1_Request_Parameter = TRUE; |
560 | UART1_Request_Parameter = TRUE; |
547 | break; |
561 | break; |
548 | default: |
562 | default: |
549 | // unsupported command recieved |
563 | // unsupported command recieved |
550 | break; |
564 | break; |
551 | } // case NC_ADDRESS |
565 | } // case NC_ADDRESS |
552 | // "break;" is missing here to fall thru to the common commands |
566 | // "break;" is missing here to fall thru to the common commands |
553 | 567 | ||
554 | default: // and any other Slave Address |
568 | default: // and any other Slave Address |
555 | 569 | ||
556 | switch(SerialMsg.CmdID) // check CmdID |
570 | switch(SerialMsg.CmdID) // check CmdID |
557 | { |
571 | { |
558 | case 'a':// request for the labels of the analog debug outputs |
572 | case 'a':// request for the labels of the analog debug outputs |
559 | UART1_Request_DebugLabel = SerialMsg.pData[0]; |
573 | UART1_Request_DebugLabel = SerialMsg.pData[0]; |
560 | if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31; |
574 | if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31; |
561 | break; |
575 | break; |
562 | /* |
576 | /* |
563 | case 'b': // submit extern control |
577 | case 'b': // submit extern control |
564 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
578 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
565 | UART1_ConfirmFrame = ExternControl.Frame; |
579 | UART1_ConfirmFrame = ExternControl.Frame; |
566 | break; |
580 | break; |
567 | */ |
581 | */ |
568 | case 'd': // request for debug data; |
582 | case 'd': // request for debug data; |
569 | UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
583 | UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
570 | if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE; |
584 | if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE; |
571 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
585 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
572 | break; |
586 | break; |
573 | 587 | ||
574 | case 'c': // request for 3D data; |
588 | case 'c': // request for 3D data; |
575 | UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
589 | UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
576 | if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE; |
590 | if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE; |
577 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
591 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
578 | break; |
592 | break; |
579 | 593 | ||
580 | case 'k': // request for Motor data; |
594 | case 'k': // request for Motor data; |
581 | UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10; |
595 | UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10; |
582 | if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE; |
596 | if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE; |
583 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
597 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
584 | break; |
598 | break; |
585 | 599 | ||
586 | case 'h':// reqest for display line |
600 | case 'h':// reqest for display line |
587 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
601 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
588 | { |
602 | { |
589 | UART1_DisplayLine = 2; |
603 | UART1_DisplayLine = 2; |
590 | UART1_Display_Interval = 0; |
604 | UART1_Display_Interval = 0; |
591 | } |
605 | } |
592 | else |
606 | else |
593 | { |
607 | { |
594 | UART1_DisplayKeys |= ~SerialMsg.pData[0]; |
608 | UART1_DisplayKeys |= ~SerialMsg.pData[0]; |
595 | UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
609 | UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
596 | UART1_DisplayLine = 4; |
610 | UART1_DisplayLine = 4; |
597 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
611 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
598 | } |
612 | } |
599 | UART1_Request_Display = TRUE; |
613 | UART1_Request_Display = TRUE; |
600 | break; |
614 | break; |
601 | 615 | ||
602 | case 'l':// reqest for display columns |
616 | case 'l':// reqest for display columns |
603 | MenuItem = SerialMsg.pData[0]; |
617 | MenuItem = SerialMsg.pData[0]; |
604 | UART1_Request_Display1 = TRUE; |
618 | UART1_Request_Display1 = TRUE; |
605 | break; |
619 | break; |
606 | 620 | ||
607 | case 'o': // request for navigation information |
621 | case 'o': // request for navigation information |
608 | UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
622 | UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
609 | if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE; |
623 | if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE; |
610 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
624 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
611 | break; |
625 | break; |
612 | 626 | ||
613 | case 'v': // request for version info |
627 | case 'v': // request for version info |
614 | UART1_Request_VersionInfo = TRUE; |
628 | UART1_Request_VersionInfo = TRUE; |
615 | break; |
629 | break; |
616 | default: |
630 | default: |
617 | // unsupported command recieved |
631 | // unsupported command recieved |
618 | break; |
632 | break; |
619 | } |
633 | } |
620 | break; // default: |
634 | break; // default: |
621 | } |
635 | } |
622 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
636 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
623 | } |
637 | } |
624 | 638 | ||
625 | 639 | ||
626 | /*****************************************************/ |
640 | /*****************************************************/ |
627 | /* Send a character */ |
641 | /* Send a character */ |
628 | /*****************************************************/ |
642 | /*****************************************************/ |
629 | s16 UART1_Putchar(char c) |
643 | s16 UART1_Putchar(char c) |
630 | { |
644 | { |
631 | u32 timeout = 10000; |
645 | u32 timeout = 10000; |
632 | if (c == '\n') UART1_Putchar('\r'); |
646 | if (c == '\n') UART1_Putchar('\r'); |
633 | // wait until txd fifo is not full |
647 | // wait until txd fifo is not full |
634 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET) if(--timeout == 0) return(0); |
648 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET) if(--timeout == 0) return(0); |
635 | // transmit byte |
649 | // transmit byte |
636 | UART_SendData(UART1, c); |
650 | UART_SendData(UART1, c); |
637 | #ifdef FOLLOW_ME |
651 | #ifdef FOLLOW_ME |
638 | if(TransmitAlsoToFC) UART_SendData(UART2, c); |
652 | if(TransmitAlsoToFC) UART_SendData(UART2, c); |
639 | #endif |
653 | #endif |
640 | return (0); |
654 | return (0); |
641 | } |
655 | } |
642 | 656 | ||
643 | /*****************************************************/ |
657 | /*****************************************************/ |
644 | /* Send a string to the debug uart */ |
658 | /* Send a string to the debug uart */ |
645 | /*****************************************************/ |
659 | /*****************************************************/ |
646 | void UART1_PutString(u8 *s) |
660 | void UART1_PutString(u8 *s) |
647 | { |
661 | { |
648 | if(s == NULL) return; |
662 | if(s == NULL) return; |
649 | while (*s != '\0' && DebugUART == UART1) |
663 | while (*s != '\0' && DebugUART == UART1) |
650 | { |
664 | { |
651 | UART1_Putchar(*s); |
665 | UART1_Putchar(*s); |
652 | s ++; |
666 | s ++; |
653 | } |
667 | } |
654 | } |
668 | } |
655 | 669 | ||
656 | 670 | ||
657 | /**************************************************************/ |
671 | /**************************************************************/ |
658 | /* Transmit tx buffer via debug uart */ |
672 | /* Transmit tx buffer via debug uart */ |
659 | /**************************************************************/ |
673 | /**************************************************************/ |
660 | void UART1_Transmit(void) |
674 | void UART1_Transmit(void) |
661 | { |
675 | { |
662 | u8 tmp_tx; |
676 | u8 tmp_tx; |
663 | if(DebugUART != UART1) return; |
677 | if(DebugUART != UART1) return; |
664 | // if something has to be send and the txd fifo is not full |
678 | // if something has to be send and the txd fifo is not full |
665 | if(UART1_tx_buffer.Locked == TRUE) |
679 | if(UART1_tx_buffer.Locked == TRUE) |
666 | { |
680 | { |
667 | // while there is some space in the tx fifo |
681 | // while there is some space in the tx fifo |
668 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET) |
682 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET) |
669 | { |
683 | { |
670 | tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer |
684 | tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer |
671 | UART_SendData(UART1, tmp_tx); // put character to txd fifo |
685 | UART_SendData(UART1, tmp_tx); // put character to txd fifo |
672 | #ifdef FOLLOW_ME |
686 | #ifdef FOLLOW_ME |
673 | if(TransmitAlsoToFC) |
687 | if(TransmitAlsoToFC) |
674 | { |
688 | { |
675 | UART_SendData(UART2, tmp_tx); // put character to txd fifo |
689 | UART_SendData(UART2, tmp_tx); // put character to txd fifo |
676 | } |
690 | } |
677 | #endif |
691 | #endif |
678 | // if terminating character or end of txd buffer reached |
692 | // if terminating character or end of txd buffer reached |
679 | if((tmp_tx == '\0') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes)) |
693 | if((tmp_tx == '\0') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes)) |
680 | { |
694 | { |
681 | Buffer_Clear(&UART1_tx_buffer); // clear txd buffer |
695 | Buffer_Clear(&UART1_tx_buffer); // clear txd buffer |
682 | #ifdef FOLLOW_ME |
696 | #ifdef FOLLOW_ME |
683 | TransmitAlsoToFC = 0; |
697 | TransmitAlsoToFC = 0; |
684 | #endif |
698 | #endif |
685 | break; // end while loop |
699 | break; // end while loop |
686 | } |
700 | } |
687 | } |
701 | } |
688 | } |
702 | } |
689 | } |
703 | } |
690 | 704 | ||
691 | //$GPGGA,HHMMSS.ss,BBBB.BBBB,b,LLLLL.LLLL,l,Q,NN,D.D,H.H,h,G.G,g,A.A,RRRR*PP |
705 | //$GPGGA,HHMMSS.ss,BBBB.BBBB,b,LLLLL.LLLL,l,Q,NN,D.D,H.H,h,G.G,g,A.A,RRRR*PP |
692 | //$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M,48.0,M,,*45 |
706 | //$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M,48.0,M,,*45 |
693 | //$GPGGA,092120.20,,,,,0,00,99.99,,,,,,*6C |
707 | //$GPGGA,092120.20,,,,,0,00,99.99,,,,,,*6C |
694 | //http://www.kowoma.de/gps/zusatzerklaerungen/NMEA.htm |
708 | //http://www.kowoma.de/gps/zusatzerklaerungen/NMEA.htm |
695 | void CreateNmeaGGA(void) |
709 | void CreateNmeaGGA(void) |
696 | { |
710 | { |
697 | u8 array[200], i = 0, crc = 0, x; |
711 | u8 array[200], i = 0, crc = 0, x; |
698 | s32 tmp1, tmp2; |
712 | s32 tmp1, tmp2; |
699 | 713 | ||
700 | i += sprintf(array, "$GPGGA,"); |
714 | i += sprintf(array, "$GPGGA,"); |
701 | // +++++++++++++++++++++++++++++++++++++++++++ |
715 | // +++++++++++++++++++++++++++++++++++++++++++ |
702 | if(SystemTime.Valid) |
716 | if(SystemTime.Valid) |
703 | { |
717 | { |
704 | i += sprintf(&array[i], "%02d%02d%02d.%02d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec/10); |
718 | i += sprintf(&array[i], "%02d%02d%02d.%02d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec/10); |
705 | } |
719 | } |
706 | else |
720 | else |
707 | { |
721 | { |
708 | i += sprintf(&array[i], ","); |
722 | i += sprintf(&array[i], ","); |
709 | } |
723 | } |
710 | // +++++++++++++++++++++++++++++++++++++++++++ |
724 | // +++++++++++++++++++++++++++++++++++++++++++ |
711 | if(GPSData.Flags & FLAG_GPSFIXOK) |
725 | if(GPSData.Flags & FLAG_GPSFIXOK) |
712 | { |
726 | { |
713 | tmp1 = abs(GPSData.Position.Latitude)/10000000L; |
727 | tmp1 = abs(GPSData.Position.Latitude)/10000000L; |
714 | i += sprintf(&array[i],"%02d",(s16)tmp1); |
728 | i += sprintf(&array[i],"%02d",(s16)tmp1); |
715 | 729 | ||
716 | tmp1 = abs(GPSData.Position.Latitude)%10000000L; |
730 | tmp1 = abs(GPSData.Position.Latitude)%10000000L; |
717 | tmp1 *= 6; // in Minuten |
731 | tmp1 *= 6; // in Minuten |
718 | tmp2 = tmp1 / 1000000L; |
732 | tmp2 = tmp1 / 1000000L; |
719 | i += sprintf(&array[i],"%02d", (s16)tmp2); |
733 | i += sprintf(&array[i],"%02d", (s16)tmp2); |
720 | tmp2 = tmp1 % 1000000L; |
734 | tmp2 = tmp1 % 1000000L; |
721 | tmp2 /= 10; // eine Stelle zu viel |
735 | tmp2 /= 10; // eine Stelle zu viel |
722 | i += sprintf(&array[i],".%05d,", (s16)tmp2); |
736 | i += sprintf(&array[i],".%05d,", (s16)tmp2); |
723 | 737 | ||
724 | if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,"); |
738 | if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,"); |
725 | else i += sprintf(&array[i],"S,"); |
739 | else i += sprintf(&array[i],"S,"); |
726 | // +++++++++++++++++++++++++++++++++++++++++++ |
740 | // +++++++++++++++++++++++++++++++++++++++++++ |
727 | 741 | ||
728 | tmp1 = abs(GPSData.Position.Longitude)/10000000L; |
742 | tmp1 = abs(GPSData.Position.Longitude)/10000000L; |
729 | i += sprintf(&array[i],"%03d", (s16)tmp1); |
743 | i += sprintf(&array[i],"%03d", (s16)tmp1); |
730 | 744 | ||
731 | tmp1 = abs(GPSData.Position.Longitude)%10000000L; |
745 | tmp1 = abs(GPSData.Position.Longitude)%10000000L; |
732 | tmp1 *= 6; // in Minuten |
746 | tmp1 *= 6; // in Minuten |
733 | tmp2 = tmp1 / 1000000L; |
747 | tmp2 = tmp1 / 1000000L; |
734 | i += sprintf(&array[i],"%02d", (s16)tmp2); |
748 | i += sprintf(&array[i],"%02d", (s16)tmp2); |
735 | tmp2 = tmp1 % 1000000L; |
749 | tmp2 = tmp1 % 1000000L; |
736 | tmp2 /= 10; // eine Stelle zu viel |
750 | tmp2 /= 10; // eine Stelle zu viel |
737 | i += sprintf(&array[i],".%05d,", (s16)tmp2); |
751 | i += sprintf(&array[i],".%05d,", (s16)tmp2); |
738 | 752 | ||
739 | 753 | ||
740 | if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,"); |
754 | if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,"); |
741 | else i += sprintf(&array[i],"W,"); |
755 | else i += sprintf(&array[i],"W,"); |
742 | i += sprintf(&array[i],"%d,",GPSData.SatFix); |
756 | i += sprintf(&array[i],"%d,",GPSData.SatFix); |
743 | i += sprintf(&array[i],"%d,",GPSData.NumOfSats); |
757 | i += sprintf(&array[i],"%d,",GPSData.NumOfSats); |
744 | i += sprintf(&array[i],"%d.%d,",(s16)(GPSData.Position_Accuracy/100),abs(GPSData.Position_Accuracy%100)); |
758 | i += sprintf(&array[i],"%d.%d,",(s16)(GPSData.Position_Accuracy/100),abs(GPSData.Position_Accuracy%100)); |
745 | // i += sprintf(&array[i],"%d.%d,M,",GPSData.Position.Altitude/1000,abs(GPSData.Position.Altitude%1000)/100); |
759 | // i += sprintf(&array[i],"%d.%d,M,",GPSData.Position.Altitude/1000,abs(GPSData.Position.Altitude%1000)/100); |
746 | tmp1 = NaviData.Altimeter / 2; // in dm |
760 | tmp1 = NaviData.Altimeter / 2; // in dm |
747 | i += sprintf(&array[i],"%d.%d,M,",(s16)tmp1 / 10,abs((s16)tmp1 % 10)); |
761 | i += sprintf(&array[i],"%d.%d,M,",(s16)tmp1 / 10,abs((s16)tmp1 % 10)); |
748 | i += sprintf(&array[i],",,,*"); |
762 | i += sprintf(&array[i],",,,*"); |
749 | } |
763 | } |
750 | else |
764 | else |
751 | { |
765 | { |
752 | i += sprintf(&array[i], ",,,,%d,00,99.99,,,,,,*",GPSData.NumOfSats); |
766 | i += sprintf(&array[i], ",,,,%d,00,99.99,,,,,,*",GPSData.NumOfSats); |
753 | } |
767 | } |
754 | for(x = 1; x < i-1; x++) |
768 | for(x = 1; x < i-1; x++) |
755 | { |
769 | { |
756 | crc ^= array[x]; |
770 | crc ^= array[x]; |
757 | } |
771 | } |
758 | i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a); |
772 | i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a); |
759 | AddSerialData(&UART1_tx_buffer,array,i); |
773 | AddSerialData(&UART1_tx_buffer,array,i); |
760 | 774 | ||
761 | // +++++++++++++++++++++++++++++++++++++++++++ |
775 | // +++++++++++++++++++++++++++++++++++++++++++ |
762 | } |
776 | } |
763 | 777 | ||
764 | //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13 |
778 | //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13 |
765 | //$GPRMC,HHMMSS.sss,A,BBBB.BBBB,b,LLLLL.LLLL,l,GG.G,RR.R,DDMMYY,M.M,m,F*PP |
779 | //$GPRMC,HHMMSS.sss,A,BBBB.BBBB,b,LLLLL.LLLL,l,GG.G,RR.R,DDMMYY,M.M,m,F*PP |
766 | 780 | ||
767 | void CreateNmeaRMC(void) |
781 | void CreateNmeaRMC(void) |
768 | { |
782 | { |
769 | u8 array[200], i = 0, crc = 0, x; |
783 | u8 array[200], i = 0, crc = 0, x; |
770 | s16 tmp_int; |
784 | s16 tmp_int; |
771 | s32 tmp1, tmp2; |
785 | s32 tmp1, tmp2; |
772 | // +++++++++++++++++++++++++++++++++++++++++++ |
786 | // +++++++++++++++++++++++++++++++++++++++++++ |
773 | i += sprintf(array, "$GPRMC,"); |
787 | i += sprintf(array, "$GPRMC,"); |
774 | // +++++++++++++++++++++++++++++++++++++++++++ |
788 | // +++++++++++++++++++++++++++++++++++++++++++ |
775 | if(SystemTime.Valid) |
789 | if(SystemTime.Valid) |
776 | { |
790 | { |
777 | i += sprintf(&array[i], "%02d%02d%02d.%03d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec); |
791 | i += sprintf(&array[i], "%02d%02d%02d.%03d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec); |
778 | } |
792 | } |
779 | else |
793 | else |
780 | { |
794 | { |
781 | i += sprintf(&array[i], ","); |
795 | i += sprintf(&array[i], ","); |
782 | } |
796 | } |
783 | if(GPSData.Flags & FLAG_GPSFIXOK) |
797 | if(GPSData.Flags & FLAG_GPSFIXOK) |
784 | { |
798 | { |
785 | // +++++++++++++++++++++++++++++++++++++++++++ |
799 | // +++++++++++++++++++++++++++++++++++++++++++ |
786 | tmp1 = abs(GPSData.Position.Latitude)/10000000L; |
800 | tmp1 = abs(GPSData.Position.Latitude)/10000000L; |
787 | i += sprintf(&array[i],"A,%02d", (s16)tmp1); // Status: A = Okay V = Warnung |
801 | i += sprintf(&array[i],"A,%02d", (s16)tmp1); // Status: A = Okay V = Warnung |
788 | 802 | ||
789 | tmp1 = abs(GPSData.Position.Latitude)%10000000L; |
803 | tmp1 = abs(GPSData.Position.Latitude)%10000000L; |
790 | tmp1 *= 6; // in Minuten |
804 | tmp1 *= 6; // in Minuten |
791 | tmp2 = tmp1 / 1000000L; |
805 | tmp2 = tmp1 / 1000000L; |
792 | i += sprintf(&array[i],"%02d", (s16)tmp2); |
806 | i += sprintf(&array[i],"%02d", (s16)tmp2); |
793 | tmp2 = tmp1 % 1000000L; |
807 | tmp2 = tmp1 % 1000000L; |
794 | tmp2 /= 10; // eine Stelle zu viel |
808 | tmp2 /= 10; // eine Stelle zu viel |
795 | i += sprintf(&array[i],".%05d,", (s16)tmp2); |
809 | i += sprintf(&array[i],".%05d,", (s16)tmp2); |
796 | if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,"); |
810 | if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,"); |
797 | else i += sprintf(&array[i],"S,"); |
811 | else i += sprintf(&array[i],"S,"); |
798 | // +++++++++++++++++++++++++++++++++++++++++++ |
812 | // +++++++++++++++++++++++++++++++++++++++++++ |
799 | tmp1 = abs(GPSData.Position.Longitude)/10000000L; |
813 | tmp1 = abs(GPSData.Position.Longitude)/10000000L; |
800 | i += sprintf(&array[i],"%03d", (s16)tmp1); |
814 | i += sprintf(&array[i],"%03d", (s16)tmp1); |
801 | 815 | ||
802 | tmp1 = abs(GPSData.Position.Longitude)%10000000L; |
816 | tmp1 = abs(GPSData.Position.Longitude)%10000000L; |
803 | tmp1 *= 6; // in Minuten |
817 | tmp1 *= 6; // in Minuten |
804 | tmp2 = tmp1 / 1000000L; |
818 | tmp2 = tmp1 / 1000000L; |
805 | i += sprintf(&array[i],"%02d", (s16)tmp2); |
819 | i += sprintf(&array[i],"%02d", (s16)tmp2); |
806 | tmp2 = tmp1 % 1000000L; |
820 | tmp2 = tmp1 % 1000000L; |
807 | tmp2 /= 10; // eine Stelle zu viel |
821 | tmp2 /= 10; // eine Stelle zu viel |
808 | i += sprintf(&array[i],".%05d,", (s16)tmp2); |
822 | i += sprintf(&array[i],".%05d,", (s16)tmp2); |
809 | if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,"); |
823 | if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,"); |
810 | else i += sprintf(&array[i],"W,"); |
824 | else i += sprintf(&array[i],"W,"); |
811 | // +++++++++++++++++++++++++++++++++++++++++++ |
825 | // +++++++++++++++++++++++++++++++++++++++++++ |
812 | tmp_int = GPSData.Speed_Ground; // in cm/sek |
826 | tmp_int = GPSData.Speed_Ground; // in cm/sek |
813 | tmp_int *= 90; |
827 | tmp_int *= 90; |
814 | tmp_int /= 463; |
828 | tmp_int /= 463; |
815 | i += sprintf(&array[i],"%02d.%d,",tmp_int/10,tmp_int%10); // in Knoten |
829 | i += sprintf(&array[i],"%02d.%d,",tmp_int/10,tmp_int%10); // in Knoten |
816 | // +++++++++++++++++++++++++++++++++++++++++++ |
830 | // +++++++++++++++++++++++++++++++++++++++++++ |
817 | i += sprintf(&array[i],"%03d.%d,",GyroCompassCorrected/10,GyroCompassCorrected%10); |
831 | i += sprintf(&array[i],"%03d.%d,",GyroCompassCorrected/10,GyroCompassCorrected%10); |
818 | // +++++++++++++++++++++++++++++++++++++++++++ |
832 | // +++++++++++++++++++++++++++++++++++++++++++ |
819 | if(SystemTime.Valid) |
833 | if(SystemTime.Valid) |
820 | { |
834 | { |
821 | i += sprintf(&array[i], "%02d%02d%02d,",SystemTime.Day,SystemTime.Month,SystemTime.Year); |
835 | i += sprintf(&array[i], "%02d%02d%02d,",SystemTime.Day,SystemTime.Month,SystemTime.Year); |
822 | } |
836 | } |
823 | else |
837 | else |
824 | { |
838 | { |
825 | i += sprintf(&array[i], ","); |
839 | i += sprintf(&array[i], ","); |
826 | } |
840 | } |
827 | // +++++++++++++++++++++++++++++++++++++++++++ |
841 | // +++++++++++++++++++++++++++++++++++++++++++ |
828 | i += sprintf(&array[i],"%d.%1d,", abs(GeoMagDec)/10,abs(GeoMagDec)%10); |
842 | i += sprintf(&array[i],"%d.%1d,", abs(GeoMagDec)/10,abs(GeoMagDec)%10); |
829 | if(GeoMagDec < 0) i += sprintf(&array[i], "W,"); else i += sprintf(&array[i], "E,"); |
843 | if(GeoMagDec < 0) i += sprintf(&array[i], "W,"); else i += sprintf(&array[i], "E,"); |
830 | // +++++++++++++++++++++++++++++++++++++++++++ |
844 | // +++++++++++++++++++++++++++++++++++++++++++ |
831 | if(GPSData.Flags & FLAG_DIFFSOLN) i += sprintf(&array[i], "D,"); |
845 | if(GPSData.Flags & FLAG_DIFFSOLN) i += sprintf(&array[i], "D,"); |
832 | else i += sprintf(&array[i], "A,"); |
846 | else i += sprintf(&array[i], "A,"); |
833 | } |
847 | } |
834 | else // kein Satfix |
848 | else // kein Satfix |
835 | { |
849 | { |
836 | i += sprintf(&array[i], "V,,,,,,,,,,N*"); |
850 | i += sprintf(&array[i], "V,,,,,,,,,,N*"); |
837 | } |
851 | } |
838 | // +++++++++++++++++++++++++++++++++++++++++++ |
852 | // +++++++++++++++++++++++++++++++++++++++++++ |
839 | // CRC |
853 | // CRC |
840 | // +++++++++++++++++++++++++++++++++++++++++++ |
854 | // +++++++++++++++++++++++++++++++++++++++++++ |
841 | for(x=1; x<i-1; x++) |
855 | for(x=1; x<i-1; x++) |
842 | { |
856 | { |
843 | crc ^= array[x]; |
857 | crc ^= array[x]; |
844 | } |
858 | } |
845 | i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a); |
859 | i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a); |
846 | // +++++++++++++++++++++++++++++++++++++++++++ |
860 | // +++++++++++++++++++++++++++++++++++++++++++ |
847 | AddSerialData(&UART1_tx_buffer,array,i); |
861 | AddSerialData(&UART1_tx_buffer,array,i); |
848 | // +++++++++++++++++++++++++++++++++++++++++++ |
862 | // +++++++++++++++++++++++++++++++++++++++++++ |
849 | /* |
863 | /* |
850 | 864 | ||
851 | 865 | ||
852 | 866 | ||
853 | GPSData.Flags = (GPSData.Flags & 0xf0) | (UbxSol.Flags & 0x0f); // we take only the lower bits |
867 | GPSData.Flags = (GPSData.Flags & 0xf0) | (UbxSol.Flags & 0x0f); // we take only the lower bits |
854 | GPSData.NumOfSats = UbxSol.numSV; |
868 | GPSData.NumOfSats = UbxSol.numSV; |
855 | GPSData.SatFix = UbxSol.GPSfix; |
869 | GPSData.SatFix = UbxSol.GPSfix; |
856 | GPSData.Position_Accuracy = UbxSol.PAcc; |
870 | GPSData.Position_Accuracy = UbxSol.PAcc; |
857 | GPSData.Speed_Accuracy = UbxSol.SAcc; |
871 | GPSData.Speed_Accuracy = UbxSol.SAcc; |
858 | SetGPSTime(&SystemTime); // update system time |
872 | SetGPSTime(&SystemTime); // update system time |
859 | // NAV POSLLH |
873 | // NAV POSLLH |
860 | GPSData.Position.Status = INVALID; |
874 | GPSData.Position.Status = INVALID; |
861 | GPSData.Position.Longitude = UbxPosLlh.LON; |
875 | GPSData.Position.Longitude = UbxPosLlh.LON; |
862 | GPSData.Position.Latitude = UbxPosLlh.LAT; |
876 | GPSData.Position.Latitude = UbxPosLlh.LAT; |
863 | GPSData.Position.Altitude = UbxPosLlh.HMSL; |
877 | GPSData.Position.Altitude = UbxPosLlh.HMSL; |
864 | GPSData.Position.Status = NEWDATA; |
878 | GPSData.Position.Status = NEWDATA; |
865 | // NAV VELNED |
879 | // NAV VELNED |
866 | GPSData.Speed_East = UbxVelNed.VEL_E; |
880 | GPSData.Speed_East = UbxVelNed.VEL_E; |
867 | GPSData.Speed_North = UbxVelNed.VEL_N; |
881 | GPSData.Speed_North = UbxVelNed.VEL_N; |
868 | GPSData.Speed_Top = -UbxVelNed.VEL_D; |
882 | GPSData.Speed_Top = -UbxVelNed.VEL_D; |
869 | GPSData.Speed_Ground = UbxVelNed.GSpeed; |
883 | GPSData.Speed_Ground = UbxVelNed.GSpeed; |
870 | GPSData.Heading = UbxVelNed.Heading; |
884 | GPSData.Heading = UbxVelNed.Heading; |
871 | SystemTime.Year = 0; |
885 | SystemTime.Year = 0; |
872 | SystemTime.Month = 0; |
886 | SystemTime.Month = 0; |
873 | SystemTime.Day = 0; |
887 | SystemTime.Day = 0; |
874 | SystemTime.Hour = 0; |
888 | SystemTime.Hour = 0; |
875 | SystemTime.Min = 0; |
889 | SystemTime.Min = 0; |
876 | SystemTime.Sec = 0; |
890 | SystemTime.Sec = 0; |
877 | SystemTime.mSec = 0; |
891 | SystemTime.mSec = 0; |
878 | SystemTime.Valid = 0; |
892 | SystemTime.Valid = 0; |
879 | 893 | ||
880 | FromFlightCtrl.GyroHeading / 10;//NaviData.HomePositionDeviation.Bearing / 2; |
894 | FromFlightCtrl.GyroHeading / 10;//NaviData.HomePositionDeviation.Bearing / 2; |
881 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 1; // 1 = S |
895 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 1; // 1 = S |
882 | else ToFlightCtrl.Param.Byte[5] = 0; // 1 = S |
896 | else ToFlightCtrl.Param.Byte[5] = 0; // 1 = S |
883 | i1 = abs(GPSData.Position.Latitude)/10000000L; |
897 | i1 = abs(GPSData.Position.Latitude)/10000000L; |
884 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
898 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
885 | 899 | ||
886 | 900 | ||
887 | 901 | ||
888 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
902 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
889 | i1 *= 100; |
903 | i1 *= 100; |
890 | i1 += i2 / 100000; |
904 | i1 += i2 / 100000; |
891 | i2 = i2 % 100000; |
905 | i2 = i2 % 100000; |
892 | i2 /= 10; |
906 | i2 /= 10; |
893 | ToFlightCtrl.Param.Byte[6] = i1 % 256; |
907 | ToFlightCtrl.Param.Byte[6] = i1 % 256; |
894 | ToFlightCtrl.Param.Byte[7] = i1 / 256; |
908 | ToFlightCtrl.Param.Byte[7] = i1 / 256; |
895 | ToFlightCtrl.Param.Byte[8] = i2 % 256; |
909 | ToFlightCtrl.Param.Byte[8] = i2 % 256; |
896 | ToFlightCtrl.Param.Byte[9] = i2 / 256; |
910 | ToFlightCtrl.Param.Byte[9] = i2 / 256; |
897 | break; |
911 | break; |
898 | case 1: |
912 | case 1: |
899 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
913 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
900 | ToFlightCtrl.Param.Byte[0] = 11+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
914 | ToFlightCtrl.Param.Byte[0] = 11+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
901 | ToFlightCtrl.Param.Byte[1] = 8-1; // how many |
915 | ToFlightCtrl.Param.Byte[1] = 8-1; // how many |
902 | //----------------------------- |
916 | //----------------------------- |
903 | if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2] = 1; // 1 = E |
917 | if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2] = 1; // 1 = E |
904 | else ToFlightCtrl.Param.Byte[2] = 0; // 1 = S |
918 | else ToFlightCtrl.Param.Byte[2] = 0; // 1 = S |
905 | i1 = abs(GPSData.Position.Longitude)/10000000L; |
919 | i1 = abs(GPSData.Position.Longitude)/10000000L; |
906 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
920 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
907 | 921 | ||
908 | */ |
922 | */ |
909 | } |
923 | } |
910 | 924 | ||
911 | 925 | ||
912 | /**************************************************************/ |
926 | /**************************************************************/ |
913 | /* Send the answers to incomming commands at the debug uart */ |
927 | /* Send the answers to incomming commands at the debug uart */ |
914 | /**************************************************************/ |
928 | /**************************************************************/ |
915 | void UART1_TransmitTxData(void) |
929 | void UART1_TransmitTxData(void) |
916 | { |
930 | { |
917 | static u8 motorindex1 = 255, motorindex2 = 0; |
931 | static u8 motorindex1 = 255, motorindex2 = 0; |
918 | if(DebugUART != UART1) return; |
932 | if(DebugUART != UART1) return; |
919 | 933 | ||
920 | if(CheckDelay(UART1_AboTimeOut)) |
934 | if(CheckDelay(UART1_AboTimeOut)) |
921 | { |
935 | { |
922 | UART1_DebugData_Interval = 0; |
936 | UART1_DebugData_Interval = 0; |
923 | UART1_NaviData_Interval = 0; |
937 | UART1_NaviData_Interval = 0; |
924 | UART1_Data3D_Interval = 0; |
938 | UART1_Data3D_Interval = 0; |
925 | UART1_Display_Interval = 0; |
939 | UART1_Display_Interval = 0; |
926 | UART1_MotorData_Interval = 0; |
940 | UART1_MotorData_Interval = 0; |
927 | } |
941 | } |
928 | 942 | ||
929 | UART1_Transmit(); // output pending bytes in tx buffer |
943 | UART1_Transmit(); // output pending bytes in tx buffer |
930 | if((UART1_tx_buffer.Locked == TRUE)) return; |
944 | if((UART1_tx_buffer.Locked == TRUE)) return; |
931 | 945 | ||
932 | if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE)) |
946 | if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE)) |
933 | { |
947 | { |
934 | s16 ParamValue; |
948 | s16 ParamValue; |
935 | NCParams_GetValue(UART1_Request_ParameterId, &ParamValue); |
949 | NCParams_GetValue(UART1_Request_ParameterId, &ParamValue); |
936 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request |
950 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request |
937 | UART1_Request_Parameter = FALSE; |
951 | UART1_Request_Parameter = FALSE; |
938 | } |
952 | } |
939 | else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE)) |
953 | else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE)) |
940 | { |
954 | { |
941 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request |
955 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request |
942 | Echo = 0; // reset echo value |
956 | Echo = 0; // reset echo value |
943 | UART1_Request_Echo = FALSE; |
957 | UART1_Request_Echo = FALSE; |
944 | } |
958 | } |
945 | else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE)) |
959 | else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE)) |
946 | { |
960 | { |
947 | u8 errorcode = FTP_ERROR_NONE; |
961 | u8 errorcode = FTP_ERROR_NONE; |
948 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) errorcode = FTP_ERROR_MOTOR_RUN; |
962 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) errorcode = FTP_ERROR_MOTOR_RUN; |
949 | else if (!Partition.IsValid) errorcode = FTP_ERROR_NO_SDCARD; |
963 | else if (!Partition.IsValid) errorcode = FTP_ERROR_NO_SDCARD; |
950 | 964 | ||
951 | if (!errorcode) CheckFTPCommand(UART1_Request_FTP); |
965 | if (!errorcode) CheckFTPCommand(UART1_Request_FTP); |
952 | else |
966 | else |
953 | { |
967 | { |
954 | u8 cmd = FTP_CMD_ERROR; |
968 | u8 cmd = FTP_CMD_ERROR; |
955 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &cmd, 1, &errorcode, 1); |
969 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &cmd, 1, &errorcode, 1); |
956 | } |
970 | } |
957 | 971 | ||
958 | UART1_Request_FTP = FALSE; |
972 | UART1_Request_FTP = FALSE; |
959 | } |
973 | } |
960 | else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
974 | else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
961 | { |
975 | { |
962 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint)); |
976 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint)); |
963 | UART1_Request_WritePoint = 0xFF; |
977 | UART1_Request_WritePoint = 0xFF; |
964 | } |
978 | } |
965 | else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE)) |
979 | else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE)) |
966 | { |
980 | { |
967 | u8 PointCount = PointList_GetCount(); |
981 | u8 PointCount = PointList_GetCount(); |
968 | if (UART1_Request_ReadPoint <= PointCount) |
982 | if (UART1_Request_ReadPoint <= PointCount) |
969 | { |
983 | { |
970 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t)); |
984 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t)); |
971 | } |
985 | } |
972 | else |
986 | else |
973 | { |
987 | { |
974 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount)); |
988 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount)); |
975 | } |
989 | } |
976 | UART1_Request_ReadPoint = 0; |
990 | UART1_Request_ReadPoint = 0; |
977 | } |
991 | } |
978 | else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
992 | else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
979 | { |
993 | { |
980 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16); |
994 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16); |
981 | UART1_Request_DebugLabel = 0xFF; |
995 | UART1_Request_DebugLabel = 0xFF; |
982 | } |
996 | } |
983 | else if(UART1_ExternalControlConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
997 | else if(UART1_ExternalControlConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
984 | { |
998 | { |
985 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1,(u8 *)&UART1_ExternalControlConfirmFrame, sizeof(UART1_ExternalControlConfirmFrame)); |
999 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1,(u8 *)&UART1_ExternalControlConfirmFrame, sizeof(UART1_ExternalControlConfirmFrame)); |
986 | UART1_ExternalControlConfirmFrame = 0; |
1000 | UART1_ExternalControlConfirmFrame = 0; |
987 | } |
1001 | } |
988 | else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE)) |
1002 | else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE)) |
989 | { |
1003 | { |
990 | NaviData.Errorcode = ErrorCode; |
1004 | NaviData.Errorcode = ErrorCode; |
991 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData, sizeof(NaviData)); |
1005 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData, sizeof(NaviData)); |
992 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval); |
1006 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval); |
993 | UART1_Request_NaviData = FALSE; |
1007 | UART1_Request_NaviData = FALSE; |
994 | LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2; |
1008 | LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2; |
995 | } |
1009 | } |
996 | else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE)) |
1010 | else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE)) |
997 | { |
1011 | { |
998 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
1012 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
999 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
1013 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
1000 | UART1_Request_DebugData = FALSE; |
1014 | UART1_Request_DebugData = FALSE; |
1001 | } |
1015 | } |
1002 | else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE)) |
1016 | else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE)) |
1003 | { |
1017 | { |
1004 | Data3D.StickNick = FC.StickNick; |
1018 | Data3D.StickNick = FC.StickNick; |
1005 | Data3D.StickRoll = FC.StickRoll; |
1019 | Data3D.StickRoll = FC.StickRoll; |
1006 | Data3D.StickYaw = FC.StickYaw; |
1020 | Data3D.StickYaw = FC.StickYaw; |
1007 | Data3D.StickGas = FC.StickGas; |
1021 | Data3D.StickGas = FC.StickGas; |
1008 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
1022 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
1009 | UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval); |
1023 | UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval); |
1010 | UART1_Request_Data3D = FALSE; |
1024 | UART1_Request_Data3D = FALSE; |
1011 | } |
1025 | } |
1012 | else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE)) |
1026 | else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE)) |
1013 | { |
1027 | { |
1014 | do |
1028 | do |
1015 | { |
1029 | { |
1016 | motorindex1++; |
1030 | motorindex1++; |
1017 | motorindex1%=12; |
1031 | motorindex1%=12; |
1018 | if(!motorindex1) {motorindex2++; motorindex2 %= 12;}; |
1032 | if(!motorindex1) {motorindex2++; motorindex2 %= 12;}; |
1019 | if(motorindex1 == motorindex2) break; |
1033 | if(motorindex1 == motorindex2) break; |
1020 | } |
1034 | } |
1021 | while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors |
1035 | while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors |
1022 | 1036 | ||
1023 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t)); |
1037 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t)); |
1024 | UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval); |
1038 | UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval); |
1025 | UART1_Request_MotorData = FALSE; |
1039 | UART1_Request_MotorData = FALSE; |
1026 | } |
1040 | } |
1027 | else if(UART1_Request_WPLStore) |
1041 | else if(UART1_Request_WPLStore) |
1028 | { |
1042 | { |
1029 | /* |
1043 | /* |
1030 | s8 txt[50]; |
1044 | s8 txt[50]; |
1031 | sprintf(txt, "\r\nWPL Overwride = %d, Type = %d, Index = %d, Status = %d\r\n", WPL_Store.OverwriteFile, WPL_Store.Type, WPL_Answer.Index, WPL_Answer.Status); |
1045 | sprintf(txt, "\r\nWPL Overwride = %d, Type = %d, Index = %d, Status = %d\r\n", WPL_Store.OverwriteFile, WPL_Store.Type, WPL_Answer.Index, WPL_Answer.Status); |
1032 | UART1_PutString(txt); |
1046 | UART1_PutString(txt); |
1033 | */ |
1047 | */ |
1034 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'I', NC_ADDRESS, 1,(u8 *)&(WPL_Answer), sizeof(WPL_Answer_t)); |
1048 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'I', NC_ADDRESS, 1,(u8 *)&(WPL_Answer), sizeof(WPL_Answer_t)); |
1035 | UART1_Request_WPLStore = FALSE; |
1049 | UART1_Request_WPLStore = FALSE; |
1036 | } |
1050 | } |
1037 | else if((((NMEA_Interval > 0) && CheckDelay(NMEA_Timer))) && (UART1_tx_buffer.Locked == FALSE)) |
1051 | else if((((NMEA_Interval > 0) && CheckDelay(NMEA_Timer))) && (UART1_tx_buffer.Locked == FALSE)) |
1038 | { |
1052 | { |
1039 | CreateNmeaGGA(); |
1053 | CreateNmeaGGA(); |
1040 | Send_NMEA_RMC = TRUE; // das muss noch da hinter |
1054 | Send_NMEA_RMC = TRUE; // das muss noch da hinter |
1041 | NMEA_Timer = SetDelay(NMEA_Interval); |
1055 | NMEA_Timer = SetDelay(NMEA_Interval); |
1042 | } |
1056 | } |
1043 | else if(Send_NMEA_RMC == TRUE && (UART1_tx_buffer.Locked == FALSE)) |
1057 | else if(Send_NMEA_RMC == TRUE && (UART1_tx_buffer.Locked == FALSE)) |
1044 | { |
1058 | { |
1045 | CreateNmeaRMC(); |
1059 | CreateNmeaRMC(); |
1046 | Send_NMEA_RMC = FALSE; |
1060 | Send_NMEA_RMC = FALSE; |
1047 | } |
1061 | } |
1048 | 1062 | ||
1049 | /* |
1063 | /* |
1050 | else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
1064 | else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
1051 | { |
1065 | { |
1052 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame)); |
1066 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame)); |
1053 | UART1_ConfirmFrame = 0; |
1067 | UART1_ConfirmFrame = 0; |
1054 | } |
1068 | } |
1055 | */ |
1069 | */ |
1056 | /* |
1070 | /* |
1057 | else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE)) |
1071 | else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE)) |
1058 | { |
1072 | { |
1059 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
1073 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
1060 | UART1_Request_ExternalControl = FALSE; |
1074 | UART1_Request_ExternalControl = FALSE; |
1061 | } |
1075 | } |
1062 | */ |
1076 | */ |
1063 | else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE)) |
1077 | else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE)) |
1064 | { |
1078 | { |
1065 | if(UART1_DisplayLine > 3) |
1079 | if(UART1_DisplayLine > 3) |
1066 | { |
1080 | { |
1067 | Menu_Update(UART1_DisplayKeys); |
1081 | Menu_Update(UART1_DisplayKeys); |
1068 | UART1_DisplayKeys = 0; |
1082 | UART1_DisplayKeys = 0; |
1069 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff)); |
1083 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff)); |
1070 | } |
1084 | } |
1071 | else |
1085 | else |
1072 | { |
1086 | { |
1073 | UART1_DisplayLine = 2; |
1087 | UART1_DisplayLine = 2; |
1074 | sprintf(text,"!!! incompatible !!!"); |
1088 | sprintf(text,"!!! incompatible !!!"); |
1075 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20); |
1089 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20); |
1076 | if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0; |
1090 | if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0; |
1077 | } |
1091 | } |
1078 | UART1_Display_Timer = SetDelay(UART1_Display_Interval); |
1092 | UART1_Display_Timer = SetDelay(UART1_Display_Interval); |
1079 | UART1_Request_Display = FALSE; |
1093 | UART1_Request_Display = FALSE; |
1080 | } |
1094 | } |
1081 | else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE)) |
1095 | else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE)) |
1082 | { |
1096 | { |
1083 | Menu_Update(0); |
1097 | Menu_Update(0); |
1084 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
1098 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
1085 | UART1_Request_Display1 = FALSE; |
1099 | UART1_Request_Display1 = FALSE; |
1086 | } |
1100 | } |
1087 | else if(UART1_Request_VersionInfo && (UART1_tx_buffer.Locked == FALSE)) |
1101 | else if(UART1_Request_VersionInfo && (UART1_tx_buffer.Locked == FALSE)) |
1088 | { |
1102 | { |
1089 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
1103 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
1090 | UART1_Request_VersionInfo = FALSE; |
1104 | UART1_Request_VersionInfo = FALSE; |
1091 | } |
1105 | } |
1092 | else if(UART1_Request_SystemTime && (UART1_tx_buffer.Locked == FALSE)) |
1106 | else if(UART1_Request_SystemTime && (UART1_tx_buffer.Locked == FALSE)) |
1093 | { |
1107 | { |
1094 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'T', NC_ADDRESS,1, (u8 *)&SystemTime, sizeof(SystemTime)); |
1108 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'T', NC_ADDRESS,1, (u8 *)&SystemTime, sizeof(SystemTime)); |
1095 | UART1_Request_SystemTime = FALSE; |
1109 | UART1_Request_SystemTime = FALSE; |
1096 | } |
1110 | } |
1097 | else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE)) |
1111 | else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE)) |
1098 | { |
1112 | { |
1099 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
1113 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
1100 | UART1_Request_ErrorMessage = FALSE; |
1114 | UART1_Request_ErrorMessage = FALSE; |
1101 | } |
1115 | } |
- | 1116 | else if(UART1_Request_LicenseString && (UART1_tx_buffer.Locked == FALSE)) |
|
- | 1117 | { |
|
- | 1118 | u8 result = 1; |
|
- | 1119 | if(UART1_Request_LicenseString == LIC_CMD_READ_LICENSE) |
|
- | 1120 | { |
|
- | 1121 | result = LIC_CMD_READ_LICENSE; |
|
- | 1122 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 2, &result, 1, LicensePtr, LICENSE_SIZE); |
|
- | 1123 | } |
|
- | 1124 | else |
|
- | 1125 | if((UART1_Request_LicenseString == LIC_CMD_ERASE_LICENSE) && !(FC.StatusFlags & FC_STATUS_MOTOR_RUN)) |
|
- | 1126 | { |
|
- | 1127 | result = LIC_CMD_ERASE_LICENSE; |
|
- | 1128 | DeleteLicenseInEEPROM(); |
|
- | 1129 | CheckLicense(GET_LICENSE); |
|
- | 1130 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 1, &result, 1); |
|
- | 1131 | } |
|
- | 1132 | else |
|
- | 1133 | if((UART1_Request_LicenseString == LIC_CMD_WRITE_LICENSE) && !(FC.StatusFlags & FC_STATUS_MOTOR_RUN)) |
|
- | 1134 | { |
|
- | 1135 | result = LIC_CMD_WRITE_LICENSE; |
|
- | 1136 | if(CheckLicense(CHECK_ONLY)) //new license is okay |
|
- | 1137 | { |
|
- | 1138 | WriteLicenseToEEPROM(EEPROM_LICENSE_DATA_KOMPATIBEL); |
|
- | 1139 | result = 0; |
|
- | 1140 | } |
|
- | 1141 | else //new license is NOT okay |
|
- | 1142 | { |
|
- | 1143 | ClearLicenseText(); |
|
- | 1144 | CheckLicense(GET_LICENSE); // fetch a license if available |
|
- | 1145 | } |
|
- | 1146 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 1, &result, 1); |
|
- | 1147 | } |
|
- | 1148 | UART1_Request_LicenseString = 0; |
|
- | 1149 | } |
|
1102 | #ifdef FOLLOW_ME |
1150 | #ifdef FOLLOW_ME |
1103 | else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE)) |
1151 | else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE)) |
1104 | { |
1152 | { |
1105 | if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4)) |
1153 | if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4)) |
1106 | { |
1154 | { |
1107 | TransmitAlsoToFC = 1; |
1155 | TransmitAlsoToFC = 1; |
1108 | // update FollowMe content |
1156 | // update FollowMe content |
1109 | FollowMe.Position.Longitude = GPSData.Position.Longitude; |
1157 | FollowMe.Position.Longitude = GPSData.Position.Longitude; |
1110 | FollowMe.Position.Latitude = GPSData.Position.Latitude; |
1158 | FollowMe.Position.Latitude = GPSData.Position.Latitude; |
1111 | FollowMe.Position.Status = NEWDATA; |
1159 | FollowMe.Position.Status = NEWDATA; |
1112 | FollowMe.Position.Altitude = 1; |
1160 | FollowMe.Position.Altitude = 1; |
1113 | // 0 -> no Orientation |
1161 | // 0 -> no Orientation |
1114 | // 1-360 -> CompassCourse Setpoint |
1162 | // 1-360 -> CompassCourse Setpoint |
1115 | // -1 -> points to WP1 -> itself |
1163 | // -1 -> points to WP1 -> itself |
1116 | FollowMe.Heading = -1; |
1164 | FollowMe.Heading = -1; |
1117 | FollowMe.ToleranceRadius = 1; |
1165 | FollowMe.ToleranceRadius = 1; |
1118 | FollowMe.HoldTime = 60; |
1166 | FollowMe.HoldTime = 60; |
1119 | FollowMe.Event_Flag = 1; |
1167 | FollowMe.Event_Flag = 1; |
1120 | FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list |
1168 | FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list |
1121 | FollowMe.Type = POINT_TYPE_WP; |
1169 | FollowMe.Type = POINT_TYPE_WP; |
1122 | FollowMe.WP_EventChannelValue = 100; // set servo value |
1170 | FollowMe.WP_EventChannelValue = 100; // set servo value |
1123 | FollowMe.AltitudeRate = 0; // do not change height |
1171 | FollowMe.AltitudeRate = 0; // do not change height |
1124 | FollowMe.Speed = 0; // rate to change the Position (0 = max) |
1172 | FollowMe.Speed = 0; // rate to change the Position (0 = max) |
1125 | FollowMe.CamAngle = 255; // Camera servo angle in degree (255 -> POI-Automatic) |
1173 | FollowMe.CamAngle = 255; // Camera servo angle in degree (255 -> POI-Automatic) |
1126 | FollowMe.Name[0] = 'F'; // Name of that point (ASCII) |
1174 | FollowMe.Name[0] = 'F'; // Name of that point (ASCII) |
1127 | FollowMe.Name[1] = 'O'; // Name of that point (ASCII) |
1175 | FollowMe.Name[1] = 'O'; // Name of that point (ASCII) |
1128 | FollowMe.Name[2] = 'L'; // Name of that point (ASCII) |
1176 | FollowMe.Name[2] = 'L'; // Name of that point (ASCII) |
1129 | FollowMe.Name[3] = 'L'; // Name of that point (ASCII) |
1177 | FollowMe.Name[3] = 'L'; // Name of that point (ASCII) |
1130 | FollowMe.reserve[0] = 0; // reserve |
1178 | FollowMe.reserve[0] = 0; // reserve |
1131 | FollowMe.reserve[1] = 0; // reserve |
1179 | FollowMe.reserve[1] = 0; // reserve |
1132 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe)); |
1180 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe)); |
1133 | } |
1181 | } |
1134 | UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time |
1182 | UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time |
1135 | } |
1183 | } |
1136 | #endif |
1184 | #endif |
1137 | #ifdef DEBUG // only include functions if DEBUG is defined |
1185 | #ifdef DEBUG // only include functions if DEBUG is defined |
1138 | else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE)) |
1186 | else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE)) |
1139 | { |
1187 | { |
1140 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug)); |
1188 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug)); |
1141 | SendDebugOutput = 0; |
1189 | SendDebugOutput = 0; |
1142 | } |
1190 | } |
1143 | #endif |
1191 | #endif |
1144 | UART1_Transmit(); // output pending bytes in tx buffer |
1192 | UART1_Transmit(); // output pending bytes in tx buffer |
1145 | } |
1193 | } |
1146 | 1194 | ||
1147 | 1195 |