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