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