Rev 864 | Rev 871 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 864 | Rev 865 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | // + Software Nutzungsbedingungen (english version: see below) |
7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
22 | // + des Mitverschuldens offen. |
22 | // + des Mitverschuldens offen. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Software LICENSING TERMS |
32 | // + Software LICENSING TERMS |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
37 | // + The Software may only be used with the Licensor's products. |
37 | // + The Software may only be used with the Licensor's products. |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
40 | // + agreement shall be the property of the Licensor. |
40 | // + agreement shall be the property of the Licensor. |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
43 | // + The customer shall be responsible for taking reasonable precautions |
43 | // + The customer shall be responsible for taking reasonable precautions |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
53 | // + #### END OF LICENSING TERMS #### |
53 | // + #### END OF LICENSING TERMS #### |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | #include <stdio.h> |
56 | #include <stdio.h> |
57 | #include <stdlib.h> |
57 | #include <stdlib.h> |
58 | #include <stdarg.h> |
58 | #include <stdarg.h> |
59 | #include <string.h> |
59 | #include <string.h> |
60 | 60 | ||
61 | #include "91x_lib.h" |
61 | #include "91x_lib.h" |
62 | #include "main.h" |
62 | #include "main.h" |
63 | #include "config.h" |
63 | #include "config.h" |
64 | #include "menu.h" |
64 | #include "menu.h" |
65 | #include "GPS.h" |
65 | #include "GPS.h" |
66 | #include "i2c.h" |
66 | #include "i2c.h" |
67 | #include "uart0.h" |
67 | #include "uart0.h" |
68 | #include "uart1.h" |
68 | #include "uart1.h" |
69 | #include "uart2.h" |
69 | #include "uart2.h" |
70 | #include "timer1.h" |
70 | #include "timer1.h" |
71 | #include "timer2.h" |
71 | #include "timer2.h" |
72 | #include "analog.h" |
72 | #include "analog.h" |
73 | #include "compass.h" |
73 | #include "compass.h" |
74 | #include "waypoints.h" |
74 | #include "waypoints.h" |
75 | #include "mkprotocol.h" |
75 | #include "mkprotocol.h" |
76 | #include "params.h" |
76 | #include "params.h" |
77 | #include "fifo.h" |
77 | #include "fifo.h" |
78 | #include "debug.h" |
78 | #include "debug.h" |
79 | #include "spi_slave.h" |
79 | #include "spi_slave.h" |
80 | #include "ftphelper.h" |
80 | #include "ftphelper.h" |
81 | #include "led.h" |
81 | #include "led.h" |
82 | #include "fat16.h" |
82 | #include "fat16.h" |
83 | #include "crc16.h" |
83 | #include "crc16.h" |
84 | #include "eeprom.h" |
84 | #include "eeprom.h" |
85 | #include "triggerlog.h" |
85 | #include "triggerlog.h" |
86 | #include "settings.h" |
86 | #include "settings.h" |
87 | #include "MobileMenu.h" |
87 | #include "MobileMenu.h" |
88 | #include "CamCtrl.h" |
88 | #include "CamCtrl.h" |
89 | 89 | ||
90 | #define LIC_CMD_READ_LICENSE 1 |
90 | #define LIC_CMD_READ_LICENSE 1 |
91 | #define LIC_CMD_WRITE_LICENSE 2 |
91 | #define LIC_CMD_WRITE_LICENSE 2 |
92 | #define LIC_CMD_ERASE_LICENSE 3 |
92 | #define LIC_CMD_ERASE_LICENSE 3 |
93 | 93 | ||
94 | #define FALSE 0 |
94 | #define FALSE 0 |
95 | #define TRUE 1 |
95 | #define TRUE 1 |
96 | 96 | ||
97 | const u32 BAUDRATES[MAX_BD_RATES] = {1200,2400,4800,9600,14400,19200,28800,38400,57600,115200,256000}; |
97 | const u32 BAUDRATES[MAX_BD_RATES] = {1200,2400,4800,9600,14400,19200,28800,38400,57600,115200,256000}; |
98 | 98 | ||
99 | #define ABO_TIMEOUT 8000 // disable abo after 8 seconds |
99 | #define ABO_TIMEOUT 8000 // disable abo after 8 seconds |
100 | u32 UART1_AboTimeOut = 0; |
100 | u32 UART1_AboTimeOut = 0; |
101 | 101 | ||
102 | NaviData_Volatile_t NaviData_Volatile; |
102 | NaviData_Volatile_t NaviData_Volatile; |
103 | NaviData_WP_t NaviData_WP; |
103 | NaviData_WP_t NaviData_WP; |
104 | NaviData_Deviation_t NaviData_Deviation; |
104 | NaviData_Deviation_t NaviData_Deviation; |
105 | NaviData_Home_t NaviData_Home; |
105 | NaviData_Home_t NaviData_Home; |
106 | NaviData_Target_t NaviData_Target; |
106 | NaviData_Target_t NaviData_Target; |
107 | NaviData_Flags_t NaviData_Flags; |
107 | NaviData_Flags_t NaviData_Flags; |
108 | NaviData_Tiny_t NaviData_Tiny; |
108 | NaviData_Tiny_t NaviData_Tiny; |
109 | NaviData_FS_Pos_t NaviData_Failsafe; |
109 | NaviData_FS_Pos_t NaviData_Failsafe; |
110 | NaviData_Out_t NaviData_Out1Trigger; |
110 | NaviData_Out_t NaviData_Out1Trigger; |
111 | NaviData_t NaviData; |
111 | NaviData_t NaviData; |
112 | NaviData_HoTT_Text_t NaviData_HoTT_Text; |
112 | NaviData_HoTT_Text_t NaviData_HoTT_Text; |
113 | WP_MissionParameter_t WP_MissionParameter; |
113 | WP_MissionParameter_t WP_MissionParameter; |
114 | NaviData_Laser_t NaviData_Laser; |
114 | NaviData_Laser_t NaviData_Laser; |
115 | 115 | ||
116 | u8 UART1_Request_VersionInfo = FALSE; |
116 | u8 UART1_Request_VersionInfo = FALSE; |
117 | u8 UART1_Request_ExternalControl= FALSE; |
117 | u8 UART1_Request_ExternalControl= FALSE; |
118 | u8 UART1_Request_Display = FALSE; |
118 | u8 UART1_Request_Display = FALSE; |
119 | u8 UART1_Request_Display1 = FALSE; |
119 | u8 UART1_Request_Display1 = FALSE; |
120 | u8 UART1_Request_DebugData = FALSE; |
120 | u8 UART1_Request_DebugData = FALSE; |
121 | u8 UART1_Request_DebugLabel = 255; |
121 | u8 UART1_Request_DebugLabel = 255; |
122 | u8 UART1_Request_NaviData = FALSE; |
122 | u8 UART1_Request_NaviData = FALSE; |
123 | u8 UART1_Request_ErrorMessage = FALSE; |
123 | u8 UART1_Request_ErrorMessage = FALSE; |
124 | u8 UART1_Request_WritePoint = 0xFF; |
124 | u8 UART1_Request_WritePoint = 0xFF; |
125 | u8 UART1_Request_ReadPoint = 0; |
125 | u8 UART1_Request_ReadPoint = 0; |
126 | u8 UART1_Request_Data3D = FALSE; |
126 | u8 UART1_Request_Data3D = FALSE; |
127 | u8 UART1_Request_MotorData = FALSE; |
127 | u8 UART1_Request_MotorData = FALSE; |
128 | u8 UART1_Request_Echo = FALSE; |
128 | u8 UART1_Request_Echo = FALSE; |
129 | u8 UART1_Request_ParameterId = 0; |
129 | u8 UART1_Request_ParameterId = 0; |
130 | u8 UART1_Request_WPLStore = FALSE; |
130 | u8 UART1_Request_WPLStore = FALSE; |
131 | u8 UART1_Request_Parameter = FALSE; |
131 | u8 UART1_Request_Parameter = FALSE; |
132 | u8 UART1_Request_SystemTime = FALSE; |
132 | u8 UART1_Request_SystemTime = FALSE; |
133 | u8 UART1_DisplayKeys = 0; |
133 | u8 UART1_DisplayKeys = 0; |
134 | u8 UART1_DisplayLine = 0; |
134 | u8 UART1_DisplayLine = 0; |
135 | u8 UART1_ConfirmFrame = 0; |
135 | u8 UART1_ConfirmFrame = 0; |
136 | u8 UART1_Request_FTP = FALSE; |
136 | u8 UART1_Request_FTP = FALSE; |
137 | u8 UART1_Request_LicenseString = FALSE; |
137 | u8 UART1_Request_LicenseString = FALSE; |
138 | u8 UART1_Request_PPM_Channels = FALSE; |
138 | u8 UART1_Request_PPM_Channels = FALSE; |
139 | u8 UART1_Request_MobileLabel = 0xff; |
139 | u8 UART1_Request_MobileLabel = 0xff; |
140 | u8 UART1_Request_MobileMenu = 0; |
140 | u8 UART1_Request_MobileMenu = 0; |
141 | u8 UART1_Request_MobileInfo = 0; |
141 | u8 UART1_Request_MobileInfo = 0; |
142 | u8 UART1_Request_MissonParameter = 0; |
142 | u8 UART1_Request_MissonParameter = 0; |
143 | u8 StopAllAbbos = 0; |
143 | u8 StopAllAbbos = 0; |
144 | 144 | ||
145 | u8 LastTransmittedFCStatusFlags2 = 0; |
145 | u8 LastTransmittedFCStatusFlags2 = 0; |
146 | u8 UART1_ExternalControlConfirmFrame = FALSE; |
146 | u8 UART1_ExternalControlConfirmFrame = FALSE; |
147 | u8 Send_NMEA_RMC = FALSE; |
147 | u8 Send_NMEA_RMC = FALSE; |
148 | u8 NaviData_Flags_SpeakHoTT_Processed = 0; |
148 | u8 NaviData_Flags_SpeakHoTT_Processed = 0; |
149 | u8 NewExternalControlFrame = 0; // flag that sends the Frame to FC |
149 | u8 NewExternalControlFrame = 0; // flag that sends the Frame to FC |
150 | u16 UART1_BaudrateFallbackTimeout = 0; |
150 | u16 UART1_BaudrateFallbackTimeout = 0; |
151 | u32 Uart1Baudrate = UART1_BAUD_RATE; |
151 | u32 Uart1Baudrate = UART1_BAUD_RATE; |
152 | u8 FromFC_ExternalCtrlCfg = 0; // answer from FC |
152 | u8 FromFC_ExternalCtrlCfg = 0,FromFC_ExternalCtrlSwitch = 0; // answer from FC |
153 | 153 | ||
154 | SerialChannel_t SerialChannel; |
154 | SerialChannel_t SerialChannel; |
155 | u8 NewSerialChannelFrame = 0; // flag that sends the Frame to FC |
155 | u8 NewSerialChannelFrame = 0; // flag that sends the Frame to FC |
156 | 156 | ||
157 | UART_TypeDef *DebugUART = UART1; |
157 | UART_TypeDef *DebugUART = UART1; |
158 | 158 | ||
159 | #ifdef FOLLOW_ME |
159 | #ifdef FOLLOW_ME |
160 | #define FOLLOW_ME_INTERVAL 200 // 5 Hz |
160 | #define FOLLOW_ME_INTERVAL 200 // 5 Hz |
161 | u32 UART1_FollowMe_Timer = 0; |
161 | u32 UART1_FollowMe_Timer = 0; |
162 | Point_t FollowMe; |
162 | Point_t FollowMe; |
163 | #endif |
163 | #endif |
164 | 164 | ||
165 | // the primary rx fifo |
165 | // the primary rx fifo |
166 | #define UART1_RX_FIFO_LEN 1500 |
166 | #define UART1_RX_FIFO_LEN 1500 |
167 | u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN]; |
167 | u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN]; |
168 | fifo_t UART1_rx_fifo; |
168 | fifo_t UART1_rx_fifo; |
169 | 169 | ||
170 | // the rx buffer |
170 | // the rx buffer |
171 | #define UART1_RX_BUFFER_LEN 1500 |
171 | #define UART1_RX_BUFFER_LEN 1500 |
172 | u8 UART1_rbuffer[UART1_RX_BUFFER_LEN]; |
172 | u8 UART1_rbuffer[UART1_RX_BUFFER_LEN]; |
173 | Buffer_t UART1_rx_buffer; |
173 | Buffer_t UART1_rx_buffer; |
174 | 174 | ||
175 | // the tx buffer |
175 | // the tx buffer |
176 | //#define UART1_TX_BUFFER_LEN 1024 |
176 | //#define UART1_TX_BUFFER_LEN 1024 |
177 | #define UART1_TX_BUFFER_LEN 1500 |
177 | #define UART1_TX_BUFFER_LEN 1500 |
178 | u8 UART1_tbuffer[UART1_TX_BUFFER_LEN]; |
178 | u8 UART1_tbuffer[UART1_TX_BUFFER_LEN]; |
179 | Buffer_t UART1_tx_buffer; |
179 | Buffer_t UART1_tx_buffer; |
180 | 180 | ||
181 | volatile u8 SerialLinkOkay = 0; |
181 | volatile u8 SerialLinkOkay = 0; |
182 | 182 | ||
183 | u8 text[200]; |
183 | u8 text[200]; |
184 | u8 *LicensePtr = UART1_tbuffer; |
184 | u8 *LicensePtr = UART1_tbuffer; |
185 | 185 | ||
186 | const u8 ANALOG_LABEL[32][16] = |
186 | const u8 ANALOG_LABEL[32][16] = |
187 | { |
187 | { |
188 | //1234567890123456 |
188 | //1234567890123456 |
189 | "AngleNick ", //0 |
189 | "AngleNick ", //0 |
190 | "AngleRoll ", |
190 | "AngleRoll ", |
191 | "AccNick ", |
191 | "AccNick ", |
192 | "AccRoll ", |
192 | "AccRoll ", |
193 | "Altitude [0.1m] ", |
193 | "Altitude [0.1m] ", |
194 | "FC-Flags ", //5 |
194 | "FC-Flags ", //5 |
195 | "NC-Flags ", |
195 | "NC-Flags ", |
196 | "Voltage [0.1V] ", |
196 | "Voltage [0.1V] ", |
197 | "Current [0.1A] ", |
197 | "Current [0.1A] ", |
198 | "GPS Data ", |
198 | "GPS Data ", |
199 | "CompassHeading ", //10 |
199 | "CompassHeading ", //10 |
200 | "GyroHeading ", |
200 | "GyroHeading ", |
201 | "SPI Error ", // achtung: muss auf 12 bleiben |
201 | "SPI Error ", // achtung: muss auf 12 bleiben |
202 | "Laser [cm] ",//"GPS CRC Error ", |
202 | "Laser [cm] ",//"GPS CRC Error ", |
203 | "I2C Error ", |
203 | "I2C Error ", |
204 | "I2C Okay ", //15 |
204 | "I2C Okay ", //15 |
205 | "16 ", |
205 | "16 ", |
206 | "17 ", |
206 | "17 ", |
207 | "18 ", |
207 | "18 ", |
208 | "19 ", |
208 | "19 ", |
209 | "EarthMagnet [%] ", //20 |
209 | "EarthMagnet [%] ", //20 |
210 | "Ground Speed ", // "Z_Speed ", |
210 | "Ground Speed ", // "Z_Speed ", |
211 | "N_Speed ", |
211 | "N_Speed ", |
212 | "E_Speed ", |
212 | "E_Speed ", |
213 | "Magnet X ", |
213 | "Magnet X ", |
214 | "Magnet Y ", //25 |
214 | "Magnet Y ", //25 |
215 | "Magnet Z ", |
215 | "Magnet Z ", |
216 | "Distance N ", |
216 | "Distance N ", |
217 | "Distance E ", |
217 | "Distance E ", |
218 | "-GPS_Nick ", |
218 | "-GPS_Nick ", |
219 | "-GPS_Roll ", //30 |
219 | "-GPS_Roll ", //30 |
220 | "Used_Sats " |
220 | "Used_Sats " |
221 | }; |
221 | }; |
222 | 222 | ||
223 | typedef struct |
223 | typedef struct |
224 | { |
224 | { |
225 | u8 Index; |
225 | u8 Index; |
226 | u8 Status; |
226 | u8 Status; |
227 | } __attribute__((packed)) WPL_Answer_t; |
227 | } __attribute__((packed)) WPL_Answer_t; |
228 | WPL_Answer_t WPL_Answer; |
228 | WPL_Answer_t WPL_Answer; |
229 | 229 | ||
230 | DebugOut_t DebugOut; |
230 | DebugOut_t DebugOut; |
231 | ExternControl_t ExternControl; |
231 | ExternControl_t ExternControl; |
232 | UART_VersionInfo_t UART_VersionInfo; |
232 | UART_VersionInfo_t UART_VersionInfo; |
233 | NaviData_t NaviData; |
233 | NaviData_t NaviData; |
234 | Data3D_t Data3D; |
234 | Data3D_t Data3D; |
235 | 235 | ||
236 | u16 Echo; // 2 bytes recieved will be sent back as echo |
236 | u16 Echo; // 2 bytes recieved will be sent back as echo |
237 | 237 | ||
238 | u32 UART1_DebugData_Timer = 0; |
238 | u32 UART1_DebugData_Timer = 0; |
239 | u32 UART1_DebugData_Interval = 0; // in ms |
239 | u32 UART1_DebugData_Interval = 0; // in ms |
240 | u32 UART1_NaviData_Timer = 0; |
240 | u32 UART1_NaviData_Timer = 0; |
241 | u32 UART1_NaviData_Interval = 0; // in ms |
241 | u32 UART1_NaviData_Interval = 0; // in ms |
242 | u16 UART1_NaviData_MaxBytes = 0; // newer protocol? |
242 | u16 UART1_NaviData_MaxBytes = 0; // newer protocol? |
243 | u32 UART1_Data3D_Timer = 0; |
243 | u32 UART1_Data3D_Timer = 0; |
244 | u32 UART1_Data3D_Interval = 0; // in ms |
244 | u32 UART1_Data3D_Interval = 0; // in ms |
245 | u32 UART1_MotorData_Timer = 0; |
245 | u32 UART1_MotorData_Timer = 0; |
246 | u32 UART1_MotorData_Interval = 0; // in ms |
246 | u32 UART1_MotorData_Interval = 0; // in ms |
247 | u32 UART1_Display_Timer = 0; |
247 | u32 UART1_Display_Timer = 0; |
248 | u32 UART1_Display_Interval = 0; // in ms |
248 | u32 UART1_Display_Interval = 0; // in ms |
249 | u32 UART1_MobileMenu_Timer = 0; |
249 | u32 UART1_MobileMenu_Timer = 0; |
250 | u32 NMEA_Timer = 0; |
250 | u32 NMEA_Timer = 0; |
251 | u32 NMEA_Interval = 0;// in ms |
251 | u32 NMEA_Interval = 0;// in ms |
252 | 252 | ||
253 | 253 | ||
254 | void GetBaudrateFromSdCard(u32 oldBd) |
254 | void GetBaudrateFromSdCard(u32 oldBd) |
255 | { |
255 | { |
256 | u16 baud; |
256 | u16 baud; |
257 | if(Settings_GetParamValue(PID_BAUDRATE,&baud)) |
257 | if(Settings_GetParamValue(PID_BAUDRATE,&baud)) |
258 | { |
258 | { |
259 | u8 i; |
259 | u8 i; |
260 | Uart1Baudrate = baud * 100; |
260 | Uart1Baudrate = baud * 100; |
261 | for(i=0;i<MAX_BD_RATES;i++) if(Uart1Baudrate == BAUDRATES[i]) break; // search the index and check if it is a valid baudrate |
261 | for(i=0;i<MAX_BD_RATES;i++) if(Uart1Baudrate == BAUDRATES[i]) break; // search the index and check if it is a valid baudrate |
262 | if(i == 0 || i >= MAX_BD_RATES) |
262 | if(i == 0 || i >= MAX_BD_RATES) |
263 | { |
263 | { |
264 | UART1_PutString(" Unknown!"); |
264 | UART1_PutString(" Unknown!"); |
265 | ToFcBaudrateIndex = 8; |
265 | ToFcBaudrateIndex = 8; |
266 | Uart1Baudrate = UART1_BAUD_RATE; |
266 | Uart1Baudrate = UART1_BAUD_RATE; |
267 | } |
267 | } |
268 | ToFcBaudrateIndex = i; |
268 | ToFcBaudrateIndex = i; |
269 | WriteBaudrateIndexToEEprom(); |
269 | WriteBaudrateIndexToEEprom(); |
270 | if(Uart1Baudrate != oldBd) |
270 | if(Uart1Baudrate != oldBd) |
271 | { |
271 | { |
272 | u8 msg[30]; |
272 | u8 msg[30]; |
273 | sprintf(msg, "\r\n -> Changing Baudrate to:%iBd (%u)\n\r",Uart1Baudrate, ToFcBaudrateIndex); |
273 | sprintf(msg, "\r\n -> Changing Baudrate to:%iBd (%u)\n\r",Uart1Baudrate, ToFcBaudrateIndex); |
274 | UART1_PutString(msg); |
274 | UART1_PutString(msg); |
275 | DELAY(100); |
275 | DELAY(100); |
276 | UART1_Init(); |
276 | UART1_Init(); |
277 | } |
277 | } |
278 | } else if(oldBd != 57600) UART1_PutString("\r\n No Baudrate on the SD-Card"); |
278 | } else if(oldBd != 57600) UART1_PutString("\r\n No Baudrate on the SD-Card"); |
279 | } |
279 | } |
280 | 280 | ||
281 | u8 CalculateDebugLableCrc(void) |
281 | u8 CalculateDebugLableCrc(void) |
282 | { |
282 | { |
283 | u16 i; |
283 | u16 i; |
284 | u8 crc = 0; |
284 | u8 crc = 0; |
285 | for(i=0;i<sizeof(ANALOG_LABEL);i++) crc += ANALOG_LABEL[0][i]; |
285 | for(i=0;i<sizeof(ANALOG_LABEL);i++) crc += ANALOG_LABEL[0][i]; |
286 | return(crc); |
286 | return(crc); |
287 | } |
287 | } |
288 | 288 | ||
289 | /********************************************************/ |
289 | /********************************************************/ |
290 | /* Initialization the UART1 */ |
290 | /* Initialization the UART1 */ |
291 | /********************************************************/ |
291 | /********************************************************/ |
292 | void UART1_Init (void) |
292 | void UART1_Init (void) |
293 | { |
293 | { |
294 | GPIO_InitTypeDef GPIO_InitStructure; |
294 | GPIO_InitTypeDef GPIO_InitStructure; |
295 | UART_InitTypeDef UART_InitStructure; |
295 | UART_InitTypeDef UART_InitStructure; |
296 | 296 | ||
297 | // initialize txd buffer |
297 | // initialize txd buffer |
298 | Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN); |
298 | Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN); |
299 | 299 | ||
300 | // initialize rxd buffer |
300 | // initialize rxd buffer |
301 | Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN); |
301 | Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN); |
302 | 302 | ||
303 | // initialize the rx fifo, block UART IRQ geting a byte from fifo |
303 | // initialize the rx fifo, block UART IRQ geting a byte from fifo |
304 | fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine); |
304 | fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine); |
305 | 305 | ||
306 | SCU_APBPeriphClockConfig(__UART1, ENABLE); // Enable the UART1 Clock |
306 | SCU_APBPeriphClockConfig(__UART1, ENABLE); // Enable the UART1 Clock |
307 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
307 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
308 | 308 | ||
309 | /*Configure UART1_Rx pin GPIO3.2*/ |
309 | /*Configure UART1_Rx pin GPIO3.2*/ |
310 | GPIO_StructInit(&GPIO_InitStructure); |
310 | GPIO_StructInit(&GPIO_InitStructure); |
311 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
311 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
312 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
312 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
313 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
313 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
314 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
314 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
315 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART1_RxD |
315 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART1_RxD |
316 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
316 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
317 | 317 | ||
318 | /*Configure UART1_Tx pin GPIO3.3*/ |
318 | /*Configure UART1_Tx pin GPIO3.3*/ |
319 | GPIO_StructInit(&GPIO_InitStructure); |
319 | GPIO_StructInit(&GPIO_InitStructure); |
320 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
320 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
321 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
321 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
322 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
322 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
323 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART1_TX |
323 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART1_TX |
324 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
324 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
325 | 325 | ||
326 | // Control of PORT3.7 (FC-UART) |
326 | // Control of PORT3.7 (FC-UART) |
327 | GPIO_StructInit(&GPIO_InitStructure); |
327 | GPIO_StructInit(&GPIO_InitStructure); |
328 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
328 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
329 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
329 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
330 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
330 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
331 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1; |
331 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1; |
332 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
332 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
333 | DISABLE_FC_UART; |
333 | DISABLE_FC_UART; |
334 | 334 | ||
335 | /* UART1 configured as follow: |
335 | /* UART1 configured as follow: |
336 | - Word Length = 8 Bits |
336 | - Word Length = 8 Bits |
337 | - One Stop Bit |
337 | - One Stop Bit |
338 | - No parity |
338 | - No parity |
339 | - BaudRate = 57600 baud |
339 | - BaudRate = 57600 baud |
340 | - Hardware flow control Disabled |
340 | - Hardware flow control Disabled |
341 | - Receive and transmit enabled |
341 | - Receive and transmit enabled |
342 | - Receive and transmit FIFOs are Disabled |
342 | - Receive and transmit FIFOs are Disabled |
343 | */ |
343 | */ |
344 | UART_StructInit(&UART_InitStructure); |
344 | UART_StructInit(&UART_InitStructure); |
345 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
345 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
346 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
346 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
347 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
347 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
348 | UART_InitStructure.UART_BaudRate = Uart1Baudrate; |
348 | UART_InitStructure.UART_BaudRate = Uart1Baudrate; |
349 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
349 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
350 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
350 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
351 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
351 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
352 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
352 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
353 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; // FIFO size 16 bytes, FIFO level 8 bytes |
353 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; // FIFO size 16 bytes, FIFO level 8 bytes |
354 | 354 | ||
355 | UART_DeInit(UART1); // reset uart 1 to default |
355 | UART_DeInit(UART1); // reset uart 1 to default |
356 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
356 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
357 | // enable uart 1 interrupts selective |
357 | // enable uart 1 interrupts selective |
358 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
358 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
359 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
359 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
360 | // configure the uart 1 interupt line |
360 | // configure the uart 1 interupt line |
361 | VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1); |
361 | VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1); |
362 | // enable the uart 1 IRQ |
362 | // enable the uart 1 IRQ |
363 | VIC_ITCmd(UART1_ITLine, ENABLE); |
363 | VIC_ITCmd(UART1_ITLine, ENABLE); |
364 | 364 | ||
365 | // initialize the debug timer |
365 | // initialize the debug timer |
366 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
366 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
367 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500; |
367 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500; |
368 | NMEA_Timer = SetDelay(14000); |
368 | NMEA_Timer = SetDelay(14000); |
369 | 369 | ||
370 | // Fill Version Info Structure |
370 | // Fill Version Info Structure |
371 | UART_VersionInfo.SWMajor = VERSION_MAJOR; |
371 | UART_VersionInfo.SWMajor = VERSION_MAJOR; |
372 | UART_VersionInfo.SWMinor = VERSION_MINOR; |
372 | UART_VersionInfo.SWMinor = VERSION_MINOR; |
373 | UART_VersionInfo.SWPatch = VERSION_PATCH; |
373 | UART_VersionInfo.SWPatch = VERSION_PATCH; |
374 | UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
374 | UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
375 | UART_VersionInfo.HWMajor = Version_HW & 0x7F; |
375 | UART_VersionInfo.HWMajor = Version_HW & 0x7F; |
376 | UART_VersionInfo.BL_Firmware = 255; |
376 | UART_VersionInfo.BL_Firmware = 255; |
377 | UART_VersionInfo.Flags = 0; |
377 | UART_VersionInfo.Flags = 0; |
378 | UART_VersionInfo.LabelTextCRC = CalculateDebugLableCrc(); |
378 | UART_VersionInfo.LabelTextCRC = CalculateDebugLableCrc(); |
379 | NaviData.Version = NAVIDATA_VERSION; |
379 | NaviData.Version = NAVIDATA_VERSION; |
380 | 380 | ||
381 | PPM_In[PPM_IN_MAX] = +127; |
381 | PPM_In[PPM_IN_MAX] = +127; |
382 | PPM_In[PPM_IN_OFF] = -127; |
382 | PPM_In[PPM_IN_OFF] = -127; |
383 | PPM_In[PPM_IN_MID] = 0; |
383 | PPM_In[PPM_IN_MID] = 0; |
384 | 384 | ||
385 | // UART1_PutString("\r\n UART1 init...ok"); |
385 | // UART1_PutString("\r\n UART1 init...ok"); |
386 | } |
386 | } |
387 | 387 | ||
388 | /****************************************************************/ |
388 | /****************************************************************/ |
389 | /* USART1 change baudrate */ |
389 | /* USART1 change baudrate */ |
390 | /****************************************************************/ |
390 | /****************************************************************/ |
391 | void UART1_Configure(u32 baudrate) |
391 | void UART1_Configure(u32 baudrate) |
392 | { |
392 | { |
393 | UART_InitTypeDef UART_InitStructure; |
393 | UART_InitTypeDef UART_InitStructure; |
394 | 394 | ||
395 | UART_Cmd(UART1, DISABLE); |
395 | UART_Cmd(UART1, DISABLE); |
396 | 396 | ||
397 | UART_StructInit(&UART_InitStructure); |
397 | UART_StructInit(&UART_InitStructure); |
398 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
398 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
399 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
399 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
400 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
400 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
401 | UART_InitStructure.UART_BaudRate = baudrate; |
401 | UART_InitStructure.UART_BaudRate = baudrate; |
402 | UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
402 | UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
403 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
403 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
404 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
404 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
405 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
405 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
406 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; // FIFO size 16 bytes, FIFO level 8 bytes |
406 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; // FIFO size 16 bytes, FIFO level 8 bytes |
407 | 407 | ||
408 | UART_DeInit(UART1); // reset uart 1 to default |
408 | UART_DeInit(UART1); // reset uart 1 to default |
409 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
409 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
410 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
410 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
411 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
411 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
412 | } |
412 | } |
413 | 413 | ||
414 | /****************************************************************/ |
414 | /****************************************************************/ |
415 | /* USART1 receiver ISR */ |
415 | /* USART1 receiver ISR */ |
416 | /****************************************************************/ |
416 | /****************************************************************/ |
417 | void UART1_IRQHandler(void) |
417 | void UART1_IRQHandler(void) |
418 | { |
418 | { |
419 | static u8 abortState = 0; |
419 | static u8 abortState = 0; |
420 | u8 c; |
420 | u8 c; |
421 | 421 | ||
422 | if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) ) |
422 | if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) ) |
423 | { |
423 | { |
424 | // clear the pending bits! |
424 | // clear the pending bits! |
425 | UART_ClearITPendingBit(UART1, UART_IT_Receive); |
425 | UART_ClearITPendingBit(UART1, UART_IT_Receive); |
426 | UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut); |
426 | UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut); |
427 | // if debug UART is not UART1 |
427 | // if debug UART is not UART1 |
428 | if (DebugUART != UART1) |
428 | if (DebugUART != UART1) |
429 | { // forward received data to the debug UART tx buffer |
429 | { // forward received data to the debug UART tx buffer |
430 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
430 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
431 | { |
431 | { |
432 | // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART |
432 | // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART |
433 | c = UART_ReceiveData(UART1); |
433 | c = UART_ReceiveData(UART1); |
434 | 434 | ||
435 | // check for abort condition (ESC ESC 0x55 0xAA 0x00) |
435 | // check for abort condition (ESC ESC 0x55 0xAA 0x00) |
436 | switch (abortState) |
436 | switch (abortState) |
437 | { |
437 | { |
438 | case 0: |
438 | case 0: |
439 | if (c == 27) abortState++; |
439 | if (c == 27) abortState++; |
440 | break; |
440 | break; |
441 | case 1: |
441 | case 1: |
442 | if (c == 27) abortState++; |
442 | if (c == 27) abortState++; |
443 | else abortState = 0; |
443 | else abortState = 0; |
444 | break; |
444 | break; |
445 | case 2: |
445 | case 2: |
446 | if (c == 0x55) abortState++; |
446 | if (c == 0x55) abortState++; |
447 | else abortState = 0; |
447 | else abortState = 0; |
448 | break; |
448 | break; |
449 | case 3: |
449 | case 3: |
450 | if (c == 0xAA) abortState++; |
450 | if (c == 0xAA) abortState++; |
451 | else abortState = 0; |
451 | else abortState = 0; |
452 | break; |
452 | break; |
453 | case 4: |
453 | case 4: |
454 | if (c == 0x00) |
454 | if (c == 0x00) |
455 | { |
455 | { |
456 | if(DebugUART == UART0) |
456 | if(DebugUART == UART0) |
457 | { |
457 | { |
458 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); |
458 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); |
459 | TIMER2_Init(); // enbable servo outputs |
459 | TIMER2_Init(); // enbable servo outputs |
460 | fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer |
460 | fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer |
461 | } |
461 | } |
462 | DebugUART = UART1; |
462 | DebugUART = UART1; |
463 | DISABLE_FC_UART; |
463 | DISABLE_FC_UART; |
464 | } |
464 | } |
465 | abortState = 0; |
465 | abortState = 0; |
466 | break; |
466 | break; |
467 | } // end switch abort state |
467 | } // end switch abort state |
468 | // if the Debug uart is not UART1, redirect input to the Debug UART |
468 | // if the Debug uart is not UART1, redirect input to the Debug UART |
469 | if (DebugUART != UART1) |
469 | if (DebugUART != UART1) |
470 | { |
470 | { |
471 | // wait for space in the tx buffer of the DebugUART |
471 | // wait for space in the tx buffer of the DebugUART |
472 | while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {}; |
472 | while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {}; |
473 | // move byte to the tx fifo of the debug uart |
473 | // move byte to the tx fifo of the debug uart |
474 | UART_SendData(DebugUART, c); |
474 | UART_SendData(DebugUART, c); |
475 | } |
475 | } |
476 | } |
476 | } |
477 | } |
477 | } |
478 | else // DebugUART == UART1 (normal operation) |
478 | else // DebugUART == UART1 (normal operation) |
479 | { |
479 | { |
480 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
480 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
481 | { // some byes in the hardware fifo |
481 | { // some byes in the hardware fifo |
482 | // get byte from hardware fifo |
482 | // get byte from hardware fifo |
483 | c = UART_ReceiveData(UART1); |
483 | c = UART_ReceiveData(UART1); |
484 | // put into the software fifo |
484 | // put into the software fifo |
485 | if(!fifo_put(&UART1_rx_fifo, c)) |
485 | if(!fifo_put(&UART1_rx_fifo, c)) |
486 | { // fifo overflow |
486 | { // fifo overflow |
487 | //fifo_purge(&UART1_rx_fifo); // flush the whole buffer |
487 | //fifo_purge(&UART1_rx_fifo); // flush the whole buffer |
488 | } |
488 | } |
489 | } // EOF while some byes in the hardware fifo |
489 | } // EOF while some byes in the hardware fifo |
490 | } // eof DebugUart = UART1 |
490 | } // eof DebugUart = UART1 |
491 | } |
491 | } |
492 | 492 | ||
493 | 493 | ||
494 | 494 | ||
495 | VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register |
495 | VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register |
496 | } |
496 | } |
497 | 497 | ||
498 | /**************************************************************/ |
498 | /**************************************************************/ |
499 | /* Process incomming data from debug uart */ |
499 | /* Process incomming data from debug uart */ |
500 | /**************************************************************/ |
500 | /**************************************************************/ |
501 | void UART1_ProcessRxData(void) |
501 | void UART1_ProcessRxData(void) |
502 | { |
502 | { |
503 | // return on forwarding uart or unlocked rx buffer |
503 | // return on forwarding uart or unlocked rx buffer |
504 | u8 c; |
504 | u8 c; |
505 | if(DebugUART != UART1) return; |
505 | if(DebugUART != UART1) return; |
506 | // if rx buffer is not locked |
506 | // if rx buffer is not locked |
507 | if(UART1_rx_buffer.Locked == FALSE) |
507 | if(UART1_rx_buffer.Locked == FALSE) |
508 | { |
508 | { |
509 | //collect data from primary rx fifo |
509 | //collect data from primary rx fifo |
510 | while(fifo_get(&UART1_rx_fifo, &c)) |
510 | while(fifo_get(&UART1_rx_fifo, &c)) |
511 | { |
511 | { |
512 | // break if complete frame is collected |
512 | // break if complete frame is collected |
513 | if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break; |
513 | if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break; |
514 | } |
514 | } |
515 | } |
515 | } |
516 | if(UART1_rx_buffer.Locked == FALSE) return; |
516 | if(UART1_rx_buffer.Locked == FALSE) return; |
517 | 517 | ||
518 | Point_t * pPoint = NULL; |
518 | Point_t * pPoint = NULL; |
519 | SerialMsg_t SerialMsg; |
519 | SerialMsg_t SerialMsg; |
520 | 520 | ||
521 | // analyze header first |
521 | // analyze header first |
522 | MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg); |
522 | MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg); |
523 | /* |
523 | /* |
524 | if( SerialMsg.Address == FC_ADDRESS ) |
524 | if( SerialMsg.Address == FC_ADDRESS ) |
525 | { |
525 | { |
526 | switch(SerialMsg.CmdID) |
526 | switch(SerialMsg.CmdID) |
527 | { |
527 | { |
528 | // case 'b': // extern control |
528 | // case 'b': // extern control |
529 | // UART1_ExternalControlConfirmFrame = 1; |
529 | // UART1_ExternalControlConfirmFrame = 1; |
530 | // case 'y': // serial poti values |
530 | // case 'y': // serial poti values |
531 | // Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC |
531 | // Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC |
532 | // Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
532 | // Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
533 | // return; //end process rx data |
533 | // return; //end process rx data |
534 | break; |
534 | break; |
535 | } |
535 | } |
536 | } |
536 | } |
537 | */ |
537 | */ |
538 | MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
538 | MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
539 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
539 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
540 | switch(SerialMsg.Address) // check for Slave Address |
540 | switch(SerialMsg.Address) // check for Slave Address |
541 | { |
541 | { |
542 | case NC_ADDRESS: // own Slave Address |
542 | case NC_ADDRESS: // own Slave Address |
543 | switch(SerialMsg.CmdID) |
543 | switch(SerialMsg.CmdID) |
544 | { |
544 | { |
545 | case 'n':// request for the labels of the analog debug outputs |
545 | case 'n':// request for the labels of the analog debug outputs |
546 | switch(SerialMsg.pData[0]) |
546 | switch(SerialMsg.pData[0]) |
547 | { |
547 | { |
548 | case MOBILE_LABLE: |
548 | case MOBILE_LABLE: |
549 | UART1_Request_MobileLabel = SerialMsg.pData[1]; |
549 | UART1_Request_MobileLabel = SerialMsg.pData[1]; |
550 | if(UART1_Request_MobileLabel > MOBILE_MAX_MENU) UART1_Request_MobileLabel = MOBILE_MAX_MENU; |
550 | if(UART1_Request_MobileLabel > MOBILE_MAX_MENU) UART1_Request_MobileLabel = MOBILE_MAX_MENU; |
551 | break; |
551 | break; |
552 | case MOBILE_MENU: |
552 | case MOBILE_MENU: |
553 | UART1_Request_MobileMenu = 1; |
553 | UART1_Request_MobileMenu = 1; |
554 | memcpy(&MobileDataRequest.MenuItem, &SerialMsg.pData[1],sizeof(MobileDataRequest)); // copy |
554 | memcpy(&MobileDataRequest.MenuItem, &SerialMsg.pData[1],sizeof(MobileDataRequest)); // copy |
555 | break; |
555 | break; |
556 | case MOBILE_INFO: |
556 | case MOBILE_INFO: |
557 | UART1_Request_MobileInfo = 1; |
557 | UART1_Request_MobileInfo = 1; |
558 | break; |
558 | break; |
559 | } |
559 | } |
560 | break; |
560 | break; |
561 | 561 | ||
562 | case 't': // request for the GPS time |
562 | case 't': // request for the GPS time |
563 | UART1_Request_SystemTime = TRUE; |
563 | UART1_Request_SystemTime = TRUE; |
564 | break; |
564 | break; |
565 | 565 | ||
566 | case 'm': // request for the license string |
566 | case 'm': // request for the license string |
567 | UART1_Request_LicenseString = SerialMsg.pData[0]; |
567 | UART1_Request_LicenseString = SerialMsg.pData[0]; |
568 | if((UART1_Request_LicenseString == LIC_CMD_WRITE_LICENSE) && (UART_VersionInfo.HWMajor >= 20)) |
568 | if((UART1_Request_LicenseString == LIC_CMD_WRITE_LICENSE) && (UART_VersionInfo.HWMajor >= 20)) |
569 | { |
569 | { |
570 | memcpy(LicensePtr, &SerialMsg.pData[1],LICENSE_SIZE_TEXT); // copy license |
570 | memcpy(LicensePtr, &SerialMsg.pData[1],LICENSE_SIZE_TEXT); // copy license |
571 | memcpy(&LicensePtr[460], &SerialMsg.pData[1+460],OEM_NAME_LENGHT); // copy license |
571 | memcpy(&LicensePtr[460], &SerialMsg.pData[1+460],OEM_NAME_LENGHT); // copy license |
572 | } |
572 | } |
573 | break; |
573 | break; |
574 | case 'f': // ftp command |
574 | case 'f': // ftp command |
575 | UART1_Request_FTP = SerialMsg.pData[0]; |
575 | UART1_Request_FTP = SerialMsg.pData[0]; |
576 | //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE) |
576 | //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE) |
577 | memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter |
577 | memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter |
578 | break; |
578 | break; |
579 | 579 | ||
580 | case 'z': // connection checker |
580 | case 'z': // connection checker |
581 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
581 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
582 | UART1_Request_Echo = TRUE; |
582 | UART1_Request_Echo = TRUE; |
583 | break; |
583 | break; |
584 | 584 | ||
585 | case 'e': // request for the text of the error status |
585 | case 'e': // request for the text of the error status |
586 | UART1_Request_ErrorMessage = TRUE; |
586 | UART1_Request_ErrorMessage = TRUE; |
587 | break; |
587 | break; |
588 | 588 | ||
589 | case 's':// new target position |
589 | case 's':// new target position |
590 | pPoint = (Point_t*)SerialMsg.pData; |
590 | pPoint = (Point_t*)SerialMsg.pData; |
591 | if(pPoint->Position.Status == NEWDATA) |
591 | if(pPoint->Position.Status == NEWDATA) |
592 | { |
592 | { |
593 | u32 start = 0; |
593 | u32 start = 0; |
594 | //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list |
594 | //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list |
595 | //pPoint->Index = 1; // must be one after empty list |
595 | //pPoint->Index = 1; // must be one after empty list |
596 | PointList_SetAt(pPoint); |
596 | PointList_SetAt(pPoint); |
597 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
597 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
598 | // GPS_pWaypoint = PointList_WPBegin(); // updates POI index |
598 | // GPS_pWaypoint = PointList_WPBegin(); // updates POI index |
599 | if(pPoint->Index) start = pPoint->Index-1; |
599 | if(pPoint->Index) start = pPoint->Index-1; |
600 | if(CurrentlyFlyingWaypoints) |
600 | if(CurrentlyFlyingWaypoints) |
601 | { |
601 | { |
602 | GPS_pWaypoint = PointList_WPBegin(start); |
602 | GPS_pWaypoint = PointList_WPBegin(start); |
603 | NewWaypointsReceived = 0; // Only an update |
603 | NewWaypointsReceived = 0; // Only an update |
604 | } |
604 | } |
605 | BeepTime = 50; |
605 | BeepTime = 50; |
606 | } |
606 | } |
607 | else |
607 | else |
608 | if((pPoint->Position.Status == SIMULATION) && !(FC.RealStatusFlags & FC_STATUS_MOTOR_RUN)) |
608 | if((pPoint->Position.Status == SIMULATION) && !(FC.RealStatusFlags & FC_STATUS_MOTOR_RUN)) |
609 | { |
609 | { |
610 | if(pPoint->Event_Flag & SIMULATION_MOTOR_ON) |
610 | if(pPoint->Event_Flag & SIMULATION_MOTOR_ON) |
611 | { |
611 | { |
612 | GPSPos_Copy(&(pPoint->Position), &SimulationPosition); // update hold position |
612 | GPSPos_Copy(&(pPoint->Position), &SimulationPosition); // update hold position |
613 | CompassDirectionAtMotorStart = SimulatedDirection*10; |
613 | CompassDirectionAtMotorStart = SimulatedDirection*10; |
614 | SimulationFlags = pPoint->Event_Flag | SIMULATION_MOTOR_START; // dann steht da noch nicht "SIMULATION_MOTOR_ON" drin |
614 | SimulationFlags = pPoint->Event_Flag | SIMULATION_MOTOR_START; // dann steht da noch nicht "SIMULATION_MOTOR_ON" drin |
615 | } |
615 | } |
616 | if(!(SimulationFlags & SIMULATION_MOTOR_ON) && (pPoint->Event_Flag & SIMULATION_MOTOR_ON)) |
616 | if(!(SimulationFlags & SIMULATION_MOTOR_ON) && (pPoint->Event_Flag & SIMULATION_MOTOR_ON)) |
617 | { |
617 | { |
618 | SimulationFlags = pPoint->Event_Flag | SIMULATION_MOTOR_START; // dann steht da noch nicht "SIMULATION_MOTOR_ON" drin |
618 | SimulationFlags = pPoint->Event_Flag | SIMULATION_MOTOR_START; // dann steht da noch nicht "SIMULATION_MOTOR_ON" drin |
619 | SpeakHoTT = SPEAK_STARTING; |
619 | SpeakHoTT = SPEAK_STARTING; |
620 | } |
620 | } |
621 | else |
621 | else |
622 | if(!(pPoint->Event_Flag & SIMULATION_MOTOR_ON) && (SimulationFlags & SIMULATION_MOTOR_ON)) |
622 | if(!(pPoint->Event_Flag & SIMULATION_MOTOR_ON) && (SimulationFlags & SIMULATION_MOTOR_ON)) |
623 | { |
623 | { |
624 | SimulationFlags = pPoint->Event_Flag; |
624 | SimulationFlags = pPoint->Event_Flag; |
625 | SpeakHoTT = SPEAK_MK_OFF; |
625 | SpeakHoTT = SPEAK_MK_OFF; |
626 | BeepTime = 50; |
626 | BeepTime = 50; |
627 | } |
627 | } |
628 | else |
628 | else |
629 | SimulationFlags = pPoint->Event_Flag | (SimulationFlags & SIMULATION_MOTOR_START); |
629 | SimulationFlags = pPoint->Event_Flag | (SimulationFlags & SIMULATION_MOTOR_START); |
630 | } |
630 | } |
631 | break; |
631 | break; |
632 | case 'u': // redirect debug uart |
632 | case 'u': // redirect debug uart |
633 | switch(SerialMsg.pData[0]) |
633 | switch(SerialMsg.pData[0]) |
634 | { |
634 | { |
635 | case UART_FLIGHTCTRL: |
635 | case UART_FLIGHTCTRL: |
636 | ENABLE_FC_UART; |
636 | ENABLE_FC_UART; |
637 | UART2_Init(); // initialize UART2 to FC pins |
637 | UART2_Init(); // initialize UART2 to FC pins |
638 | fifo_purge(&UART1_rx_fifo); |
638 | fifo_purge(&UART1_rx_fifo); |
639 | TIMER2_Deinit(); // reduce irq load |
639 | TIMER2_Deinit(); // reduce irq load |
640 | DebugUART = UART2; |
640 | DebugUART = UART2; |
641 | break; |
641 | break; |
642 | case UART_MK3MAG: |
642 | case UART_MK3MAG: |
643 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running |
643 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running |
644 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
644 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
645 | GPSData.Status = INVALID; |
645 | GPSData.Status = INVALID; |
646 | fifo_purge(&UART1_rx_fifo); |
646 | fifo_purge(&UART1_rx_fifo); |
647 | DebugUART = UART0; |
647 | DebugUART = UART0; |
648 | break; |
648 | break; |
649 | case UART_MKGPS: |
649 | case UART_MKGPS: |
650 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running |
650 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running |
651 | TIMER2_Deinit(); // disable servo outputs to reduce irq load |
651 | TIMER2_Deinit(); // disable servo outputs to reduce irq load |
652 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); // connect UART0 to MKGPS pins |
652 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); // connect UART0 to MKGPS pins |
653 | GPSData.Status = INVALID; |
653 | GPSData.Status = INVALID; |
654 | fifo_purge(&UART1_rx_fifo); |
654 | fifo_purge(&UART1_rx_fifo); |
655 | DebugUART = UART0; |
655 | DebugUART = UART0; |
656 | break; |
656 | break; |
657 | default: |
657 | default: |
658 | break; |
658 | break; |
659 | } |
659 | } |
660 | break; |
660 | break; |
661 | 661 | ||
662 | case 'w':// Set point in list at index |
662 | case 'w':// Set point in list at index |
663 | { |
663 | { |
664 | pPoint = (Point_t*)SerialMsg.pData; |
664 | pPoint = (Point_t*)SerialMsg.pData; |
665 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
665 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
666 | if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0)) |
666 | if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0)) |
667 | { |
667 | { |
668 | PointList_Clear(); |
668 | PointList_Clear(); |
669 | GPS_pWaypoint = PointList_WPBegin(0); |
669 | GPS_pWaypoint = PointList_WPBegin(0); |
670 | UART1_Request_WritePoint = 0; // return new point count |
670 | UART1_Request_WritePoint = 0; // return new point count |
671 | NewWaypointsReceived = 1; |
671 | NewWaypointsReceived = 1; |
672 | } |
672 | } |
673 | else |
673 | else |
674 | { // update WP in list at index |
674 | { // update WP in list at index |
675 | if(pPoint->Index > MaxNumberOfWaypoints) |
675 | if(pPoint->Index > MaxNumberOfWaypoints) |
676 | { |
676 | { |
677 | UART1_Request_WritePoint = 254; |
677 | UART1_Request_WritePoint = 254; |
678 | pPoint->Index = MaxNumberOfWaypoints; |
678 | pPoint->Index = MaxNumberOfWaypoints; |
679 | } |
679 | } |
680 | else UART1_Request_WritePoint = PointList_SetAt(pPoint); |
680 | else UART1_Request_WritePoint = PointList_SetAt(pPoint); |
681 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
681 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
682 | SpeakWaypointRached = 1; // Speak once when the last Point is reached |
682 | SpeakWaypointRached = 1; // Speak once when the last Point is reached |
683 | if(UART1_Request_WritePoint == pPoint->Index) |
683 | if(UART1_Request_WritePoint == pPoint->Index) |
684 | { |
684 | { |
685 | BeepTime = 500; |
685 | BeepTime = 500; |
686 | if(UART1_Request_WritePoint == 1) SpeakNextWaypoint = 1; // Speak once as soon as the Points are active |
686 | if(UART1_Request_WritePoint == 1) SpeakNextWaypoint = 1; // Speak once as soon as the Points are active |
687 | } |
687 | } |
688 | } |
688 | } |
689 | } |
689 | } |
690 | break; |
690 | break; |
691 | 691 | ||
692 | case 'x':// Read Waypoint from List |
692 | case 'x':// Read Waypoint from List |
693 | UART1_Request_ReadPoint = SerialMsg.pData[0]; |
693 | UART1_Request_ReadPoint = SerialMsg.pData[0]; |
694 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
694 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
695 | break; |
695 | break; |
696 | 696 | ||
697 | case 'i':// Store WP List to file |
697 | case 'i':// Store WP List to file |
698 | memcpy((u8*)&WPL_Store, SerialMsg.pData, sizeof(WPL_Store_t)); |
698 | memcpy((u8*)&WPL_Store, SerialMsg.pData, sizeof(WPL_Store_t)); |
699 | WPL_Store.Name[11] = 0; // make sure the name string is terminated |
699 | WPL_Store.Name[11] = 0; // make sure the name string is terminated |
700 | WPL_Answer.Index = WPL_Store.Index; // echo Index in cmd answer |
700 | WPL_Answer.Index = WPL_Store.Index; // echo Index in cmd answer |
701 | WPL_Answer.Status = PointList_WriteToFile(&WPL_Store); |
701 | WPL_Answer.Status = PointList_WriteToFile(&WPL_Store); |
702 | UART1_Request_WPLStore = TRUE; |
702 | UART1_Request_WPLStore = TRUE; |
703 | break; |
703 | break; |
704 | 704 | ||
705 | case 'j': |
705 | case 'j': |
706 | switch(SerialMsg.pData[0]) |
706 | switch(SerialMsg.pData[0]) |
707 | { |
707 | { |
708 | case 0: // Get NC-Parameter |
708 | case 0: // Get NC-Parameter |
709 | UART1_Request_ParameterId = SerialMsg.pData[1]; |
709 | UART1_Request_ParameterId = SerialMsg.pData[1]; |
710 | UART1_Request_Parameter = TRUE; |
710 | UART1_Request_Parameter = TRUE; |
711 | break; |
711 | break; |
712 | 712 | ||
713 | case 1: // Set NC-Parameter |
713 | case 1: // Set NC-Parameter |
714 | { |
714 | { |
715 | s16 value; |
715 | s16 value; |
716 | value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100; |
716 | value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100; |
717 | NCParams_SetValue(SerialMsg.pData[1], &value); |
717 | NCParams_SetValue(SerialMsg.pData[1], &value); |
718 | UART1_Request_ParameterId = SerialMsg.pData[1]; |
718 | UART1_Request_ParameterId = SerialMsg.pData[1]; |
719 | UART1_Request_Parameter = TRUE; |
719 | UART1_Request_Parameter = TRUE; |
720 | } |
720 | } |
721 | break; |
721 | break; |
722 | case 3: // Get Mission-Parameter |
722 | case 3: // Get Mission-Parameter |
723 | UART1_Request_MissonParameter = SerialMsg.pData[0]; |
723 | UART1_Request_MissonParameter = SerialMsg.pData[0]; |
724 | break; |
724 | break; |
725 | 725 | ||
726 | case 4: // Set Mission-Parameter |
726 | case 4: // Set Mission-Parameter |
727 | memcpy(&WP_MissionParameter, &SerialMsg.pData[1], sizeof(WP_MissionParameter)); |
727 | memcpy(&WP_MissionParameter, &SerialMsg.pData[1], sizeof(WP_MissionParameter)); |
728 | UART1_Request_MissonParameter = SerialMsg.pData[0]; // answer request with 4 |
728 | UART1_Request_MissonParameter = SerialMsg.pData[0]; // answer request with 4 |
729 | break; |
729 | break; |
730 | case 5: // stop all abbos |
730 | case 5: // stop all abbos |
731 | StopAllAbbos = 1; |
731 | StopAllAbbos = 1; |
732 | break; |
732 | break; |
733 | 733 | ||
734 | default: |
734 | default: |
735 | break; |
735 | break; |
736 | } |
736 | } |
737 | break; |
737 | break; |
738 | default: |
738 | default: |
739 | // unsupported command recieved |
739 | // unsupported command recieved |
740 | break; |
740 | break; |
741 | } // case NC_ADDRESS |
741 | } // case NC_ADDRESS |
742 | // "break;" is missing here to fall thru to the common commands |
742 | // "break;" is missing here to fall thru to the common commands |
743 | 743 | ||
744 | default: // and any other Slave Address |
744 | default: // and any other Slave Address |
745 | 745 | ||
746 | switch(SerialMsg.CmdID) // check CmdID |
746 | switch(SerialMsg.CmdID) // check CmdID |
747 | { |
747 | { |
748 | case 'a':// request for the labels of the analog debug outputs |
748 | case 'a':// request for the labels of the analog debug outputs |
749 | UART1_Request_DebugLabel = SerialMsg.pData[0]; |
749 | UART1_Request_DebugLabel = SerialMsg.pData[0]; |
750 | if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31; |
750 | if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31; |
751 | break; |
751 | break; |
752 | 752 | ||
753 | case 'b': // submit extern control |
753 | case 'b': // submit extern control |
754 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
754 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
755 | UART1_ConfirmFrame = ExternControl.Frame; |
755 | UART1_ConfirmFrame = ExternControl.Frame; |
756 | NewExternalControlFrame = 1; |
756 | NewExternalControlFrame = 1; |
757 | break; |
757 | break; |
758 | 758 | ||
759 | case 'y': // serial Channels |
759 | case 'y': // serial Channels |
760 | memcpy(&SerialChannel, SerialMsg.pData, sizeof(SerialChannel)); |
760 | memcpy(&SerialChannel, SerialMsg.pData, sizeof(SerialChannel)); |
761 | memcpy((u8 *) &(PPM_In[SERIAL_POTI_START]), (u8 *) &SerialChannel, 12); // copy the 12 Bytes Serial Channels into the PPM_In array |
761 | memcpy((u8 *) &(PPM_In[SERIAL_POTI_START]), (u8 *) &SerialChannel, 12); // copy the 12 Bytes Serial Channels into the PPM_In array |
762 | NewSerialChannelFrame = 1; |
762 | NewSerialChannelFrame = 1; |
763 | break; |
763 | break; |
764 | 764 | ||
765 | case 'g':// request for the externalControl |
765 | case 'g':// request for the externalControl |
766 | UART1_Request_ExternalControl = TRUE; |
766 | UART1_Request_ExternalControl = TRUE; |
767 | break; |
767 | break; |
768 | 768 | ||
769 | case 'p':// request for the PPM_In |
769 | case 'p':// request for the PPM_In |
770 | UART1_Request_PPM_Channels = TRUE; |
770 | UART1_Request_PPM_Channels = TRUE; |
771 | break; |
771 | break; |
772 | 772 | ||
773 | case 'd': // request for debug data; |
773 | case 'd': // request for debug data; |
774 | UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
774 | UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
775 | if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE; |
775 | if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE; |
776 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
776 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
777 | break; |
777 | break; |
778 | 778 | ||
779 | case 'c': // request for 3D data; |
779 | case 'c': // request for 3D data; |
780 | UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
780 | UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
781 | if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE; |
781 | if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE; |
782 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
782 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
783 | break; |
783 | break; |
784 | 784 | ||
785 | case 'k': // request for Motor data; |
785 | case 'k': // request for Motor data; |
786 | UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10; |
786 | UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10; |
787 | if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE; |
787 | if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE; |
788 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
788 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
789 | break; |
789 | break; |
790 | 790 | ||
791 | case 'h':// reqest for display line |
791 | case 'h':// reqest for display line |
792 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
792 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
793 | { |
793 | { |
794 | UART1_DisplayLine = 2; |
794 | UART1_DisplayLine = 2; |
795 | UART1_Display_Interval = 0; |
795 | UART1_Display_Interval = 0; |
796 | UART1_Request_Display = TRUE; |
796 | UART1_Request_Display = TRUE; |
797 | } |
797 | } |
798 | else |
798 | else |
799 | { |
799 | { |
800 | UART1_DisplayKeys |= ~SerialMsg.pData[0]; |
800 | UART1_DisplayKeys |= ~SerialMsg.pData[0]; |
801 | UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
801 | UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
802 | UART1_DisplayLine = 4; |
802 | UART1_DisplayLine = 4; |
803 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
803 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
804 | if(UART1_Display_Interval) UART1_Request_Display = TRUE; |
804 | if(UART1_Display_Interval) UART1_Request_Display = TRUE; |
805 | } |
805 | } |
806 | break; |
806 | break; |
807 | 807 | ||
808 | case 'l':// reqest for display columns |
808 | case 'l':// reqest for display columns |
809 | MenuItem = SerialMsg.pData[0]; |
809 | MenuItem = SerialMsg.pData[0]; |
810 | UART1_Request_Display1 = TRUE; |
810 | UART1_Request_Display1 = TRUE; |
811 | break; |
811 | break; |
812 | 812 | ||
813 | case 'o': // request for navigation information |
813 | case 'o': // request for navigation information |
814 | UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; // PC sends: 10 = 100ms or 20 = 200 (since 2.19) |
814 | UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; // PC sends: 10 = 100ms or 20 = 200 (since 2.19) |
815 | if(SerialMsg.DataLen > 2) UART1_NaviData_MaxBytes = SerialMsg.pData[1] * 256 + SerialMsg.pData[2]; // PC sends: 4 & 0 = 1024 Bytes per second and 150 if TX-Limiting is active |
815 | if(SerialMsg.DataLen > 2) UART1_NaviData_MaxBytes = SerialMsg.pData[1] * 256 + SerialMsg.pData[2]; // PC sends: 4 & 0 = 1024 Bytes per second and 150 if TX-Limiting is active |
816 | else UART1_NaviData_MaxBytes = 0; |
816 | else UART1_NaviData_MaxBytes = 0; |
817 | if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE; |
817 | if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE; |
818 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
818 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
819 | if(UART1_NaviData_Interval && UART1_NaviData_Interval < 100) UART1_NaviData_Interval = 100; |
819 | if(UART1_NaviData_Interval && UART1_NaviData_Interval < 100) UART1_NaviData_Interval = 100; |
820 | break; |
820 | break; |
821 | 821 | ||
822 | case 'v': // request for version info |
822 | case 'v': // request for version info |
823 | if(SerialMsg.DataLen > 0 && SerialMsg.pData[0] == 1) UART1_Request_VersionInfo = 1; |
823 | if(SerialMsg.DataLen > 0 && SerialMsg.pData[0] == 1) UART1_Request_VersionInfo = 1; |
824 | else UART1_Request_VersionInfo = 2; |
824 | else UART1_Request_VersionInfo = 2; |
825 | break; |
825 | break; |
826 | default: |
826 | default: |
827 | // unsupported command recieved |
827 | // unsupported command recieved |
828 | break; |
828 | break; |
829 | } |
829 | } |
830 | break; // default: |
830 | break; // default: |
831 | } |
831 | } |
832 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
832 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
833 | } |
833 | } |
834 | 834 | ||
835 | 835 | ||
836 | /*****************************************************/ |
836 | /*****************************************************/ |
837 | /* Send a character */ |
837 | /* Send a character */ |
838 | /*****************************************************/ |
838 | /*****************************************************/ |
839 | s16 UART1_Putchar(char c) |
839 | s16 UART1_Putchar(char c) |
840 | { |
840 | { |
841 | u32 timeout = 10000; |
841 | u32 timeout = 10000; |
842 | if(DebugUART != UART1) return(0); |
842 | if(DebugUART != UART1) return(0); |
843 | if (c == '\n') UART1_Putchar('\r'); |
843 | if (c == '\n') UART1_Putchar('\r'); |
844 | // wait until txd fifo is not full |
844 | // wait until txd fifo is not full |
845 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET) if(--timeout == 0) return(0); |
845 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET) if(--timeout == 0) return(0); |
846 | // transmit byte |
846 | // transmit byte |
847 | UART_SendData(UART1, c); |
847 | UART_SendData(UART1, c); |
848 | #ifdef FOLLOW_ME |
848 | #ifdef FOLLOW_ME |
849 | if(TransmitAlsoToFC) UART_SendData(UART2, c); |
849 | if(TransmitAlsoToFC) UART_SendData(UART2, c); |
850 | #endif |
850 | #endif |
851 | return (0); |
851 | return (0); |
852 | } |
852 | } |
853 | 853 | ||
854 | /*****************************************************/ |
854 | /*****************************************************/ |
855 | /* Send a string to the debug uart */ |
855 | /* Send a string to the debug uart */ |
856 | /*****************************************************/ |
856 | /*****************************************************/ |
857 | void UART1_PutString(u8 *s) |
857 | void UART1_PutString(u8 *s) |
858 | { |
858 | { |
859 | if(DebugUART != UART1) return; |
859 | if(DebugUART != UART1) return; |
860 | if(s == NULL) return; |
860 | if(s == NULL) return; |
861 | while (*s != '\0') |
861 | while (*s != '\0') |
862 | { |
862 | { |
863 | UART1_Putchar(*s); |
863 | UART1_Putchar(*s); |
864 | s ++; |
864 | s ++; |
865 | } |
865 | } |
866 | } |
866 | } |
867 | 867 | ||
868 | 868 | ||
869 | /**************************************************************/ |
869 | /**************************************************************/ |
870 | /* Transmit tx buffer via debug uart */ |
870 | /* Transmit tx buffer via debug uart */ |
871 | /**************************************************************/ |
871 | /**************************************************************/ |
872 | void UART1_Transmit(void) |
872 | void UART1_Transmit(void) |
873 | { |
873 | { |
874 | u8 tmp_tx; |
874 | u8 tmp_tx; |
875 | if(DebugUART != UART1) return; |
875 | if(DebugUART != UART1) return; |
876 | // if something has to be send and the txd fifo is not full |
876 | // if something has to be send and the txd fifo is not full |
877 | if(UART1_tx_buffer.Locked == TRUE) |
877 | if(UART1_tx_buffer.Locked == TRUE) |
878 | { |
878 | { |
879 | // while there is some space in the tx fifo |
879 | // while there is some space in the tx fifo |
880 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET) |
880 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET) |
881 | { |
881 | { |
882 | tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer |
882 | tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer |
883 | UART_SendData(UART1, tmp_tx); // put character to txd fifo |
883 | UART_SendData(UART1, tmp_tx); // put character to txd fifo |
884 | #ifdef FOLLOW_ME |
884 | #ifdef FOLLOW_ME |
885 | if(TransmitAlsoToFC) |
885 | if(TransmitAlsoToFC) |
886 | { |
886 | { |
887 | UART_SendData(UART2, tmp_tx); // put character to txd fifo |
887 | UART_SendData(UART2, tmp_tx); // put character to txd fifo |
888 | } |
888 | } |
889 | #endif |
889 | #endif |
890 | // if terminating character or end of txd buffer reached |
890 | // if terminating character or end of txd buffer reached |
891 | if((tmp_tx == '\0') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes)) |
891 | if((tmp_tx == '\0') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes)) |
892 | { |
892 | { |
893 | Buffer_Clear(&UART1_tx_buffer); // clear txd buffer |
893 | Buffer_Clear(&UART1_tx_buffer); // clear txd buffer |
894 | #ifdef FOLLOW_ME |
894 | #ifdef FOLLOW_ME |
895 | TransmitAlsoToFC = 0; |
895 | TransmitAlsoToFC = 0; |
896 | #endif |
896 | #endif |
897 | break; // end while loop |
897 | break; // end while loop |
898 | } |
898 | } |
899 | } |
899 | } |
900 | } |
900 | } |
901 | } |
901 | } |
902 | 902 | ||
903 | //$GPGGA,HHMMSS.ss,BBBB.BBBB,b,LLLLL.LLLL,l,Q,NN,D.D,H.H,h,G.G,g,A.A,RRRR*PP |
903 | //$GPGGA,HHMMSS.ss,BBBB.BBBB,b,LLLLL.LLLL,l,Q,NN,D.D,H.H,h,G.G,g,A.A,RRRR*PP |
904 | //$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M,48.0,M,,*45 |
904 | //$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M,48.0,M,,*45 |
905 | //$GPGGA,092120.20,,,,,0,00,99.99,,,,,,*6C |
905 | //$GPGGA,092120.20,,,,,0,00,99.99,,,,,,*6C |
906 | //http://www.kowoma.de/gps/zusatzerklaerungen/NMEA.htm |
906 | //http://www.kowoma.de/gps/zusatzerklaerungen/NMEA.htm |
907 | 907 | ||
908 | void CreateNmeaGGA(void) |
908 | void CreateNmeaGGA(void) |
909 | { |
909 | { |
910 | u8 array[200], i = 0, crc = 0, x; |
910 | u8 array[200], i = 0, crc = 0, x; |
911 | s32 tmp1, tmp2; |
911 | s32 tmp1, tmp2; |
912 | 912 | ||
913 | i += sprintf(array, "$GPGGA,"); |
913 | i += sprintf(array, "$GPGGA,"); |
914 | // +++++++++++++++++++++++++++++++++++++++++++ |
914 | // +++++++++++++++++++++++++++++++++++++++++++ |
915 | if(SystemTime.Valid) |
915 | if(SystemTime.Valid) |
916 | { |
916 | { |
917 | i += sprintf(&array[i], "%02d%02d%02d.%02d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec/10); |
917 | i += sprintf(&array[i], "%02d%02d%02d.%02d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec/10); |
918 | } |
918 | } |
919 | else |
919 | else |
920 | { |
920 | { |
921 | i += sprintf(&array[i], ","); |
921 | i += sprintf(&array[i], ","); |
922 | } |
922 | } |
923 | // +++++++++++++++++++++++++++++++++++++++++++ |
923 | // +++++++++++++++++++++++++++++++++++++++++++ |
924 | if(GPSData.Flags & FLAG_GPSFIXOK) |
924 | if(GPSData.Flags & FLAG_GPSFIXOK) |
925 | { |
925 | { |
926 | tmp1 = abs(GPSData.Position.Latitude)/10000000L; |
926 | tmp1 = abs(GPSData.Position.Latitude)/10000000L; |
927 | i += sprintf(&array[i],"%02d",(s16)tmp1); |
927 | i += sprintf(&array[i],"%02d",(s16)tmp1); |
928 | 928 | ||
929 | tmp1 = abs(GPSData.Position.Latitude)%10000000L; |
929 | tmp1 = abs(GPSData.Position.Latitude)%10000000L; |
930 | tmp1 *= 6; // in Minuten |
930 | tmp1 *= 6; // in Minuten |
931 | tmp2 = tmp1 / 1000000L; |
931 | tmp2 = tmp1 / 1000000L; |
932 | i += sprintf(&array[i],"%02d", (u16)tmp2); |
932 | i += sprintf(&array[i],"%02d", (u16)tmp2); |
933 | tmp2 = tmp1 % 1000000L; |
933 | tmp2 = tmp1 % 1000000L; |
934 | tmp2 /= 100; // zwei Stellen zu viel |
934 | tmp2 /= 100; // zwei Stellen zu viel |
935 | i += sprintf(&array[i],".%04d,", (u16)tmp2); |
935 | i += sprintf(&array[i],".%04d,", (u16)tmp2); |
936 | 936 | ||
937 | if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,"); |
937 | if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,"); |
938 | else i += sprintf(&array[i],"S,"); |
938 | else i += sprintf(&array[i],"S,"); |
939 | // +++++++++++++++++++++++++++++++++++++++++++ |
939 | // +++++++++++++++++++++++++++++++++++++++++++ |
940 | 940 | ||
941 | tmp1 = abs(GPSData.Position.Longitude)/10000000L; |
941 | tmp1 = abs(GPSData.Position.Longitude)/10000000L; |
942 | i += sprintf(&array[i],"%03d", (u16)tmp1); |
942 | i += sprintf(&array[i],"%03d", (u16)tmp1); |
943 | 943 | ||
944 | tmp1 = abs(GPSData.Position.Longitude)%10000000L; |
944 | tmp1 = abs(GPSData.Position.Longitude)%10000000L; |
945 | tmp1 *= 6; // in Minuten |
945 | tmp1 *= 6; // in Minuten |
946 | tmp2 = tmp1 / 1000000L; |
946 | tmp2 = tmp1 / 1000000L; |
947 | i += sprintf(&array[i],"%02d", (u16)tmp2); |
947 | i += sprintf(&array[i],"%02d", (u16)tmp2); |
948 | tmp2 = tmp1 % 1000000L; |
948 | tmp2 = tmp1 % 1000000L; |
949 | tmp2 /= 100; // zwei Stellen zu viel |
949 | tmp2 /= 100; // zwei Stellen zu viel |
950 | i += sprintf(&array[i],".%04d,", (u16)tmp2); |
950 | i += sprintf(&array[i],".%04d,", (u16)tmp2); |
951 | 951 | ||
952 | 952 | ||
953 | if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,"); |
953 | if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,"); |
954 | else i += sprintf(&array[i],"W,"); |
954 | else i += sprintf(&array[i],"W,"); |
955 | i += sprintf(&array[i],"%d,",GPSData.SatFix); |
955 | i += sprintf(&array[i],"%d,",GPSData.SatFix); |
956 | i += sprintf(&array[i],"%d,",GPSData.NumOfSats); |
956 | i += sprintf(&array[i],"%d,",GPSData.NumOfSats); |
957 | i += sprintf(&array[i],"%d.%d,",(s16)(GPSData.Position_Accuracy/100),abs(GPSData.Position_Accuracy%100)); |
957 | i += sprintf(&array[i],"%d.%d,",(s16)(GPSData.Position_Accuracy/100),abs(GPSData.Position_Accuracy%100)); |
958 | // i += sprintf(&array[i],"%d.%d,M,",GPSData.Position.Altitude/1000,abs(GPSData.Position.Altitude%1000)/100); |
958 | // i += sprintf(&array[i],"%d.%d,M,",GPSData.Position.Altitude/1000,abs(GPSData.Position.Altitude%1000)/100); |
959 | tmp1 = NaviData.Altimeter_5cm / 2; // in dm |
959 | tmp1 = NaviData.Altimeter_5cm / 2; // in dm |
960 | i += sprintf(&array[i],"%d.%d,M,",(s16)tmp1 / 10,abs((s16)tmp1 % 10)); |
960 | i += sprintf(&array[i],"%d.%d,M,",(s16)tmp1 / 10,abs((s16)tmp1 % 10)); |
961 | i += sprintf(&array[i],",,,*"); |
961 | i += sprintf(&array[i],",,,*"); |
962 | } |
962 | } |
963 | else |
963 | else |
964 | { |
964 | { |
965 | i += sprintf(&array[i], ",,,,%d,00,99.99,,,,,,*",GPSData.NumOfSats); |
965 | i += sprintf(&array[i], ",,,,%d,00,99.99,,,,,,*",GPSData.NumOfSats); |
966 | } |
966 | } |
967 | for(x = 1; x < i-1; x++) |
967 | for(x = 1; x < i-1; x++) |
968 | { |
968 | { |
969 | crc ^= array[x]; |
969 | crc ^= array[x]; |
970 | } |
970 | } |
971 | i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a); |
971 | i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a); |
972 | AddSerialData(&UART1_tx_buffer,array,i); |
972 | AddSerialData(&UART1_tx_buffer,array,i); |
973 | 973 | ||
974 | // +++++++++++++++++++++++++++++++++++++++++++ |
974 | // +++++++++++++++++++++++++++++++++++++++++++ |
975 | } |
975 | } |
976 | 976 | ||
977 | //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13 |
977 | //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13 |
978 | //$GPRMC,HHMMSS.sss,A,BBBB.BBBB,b,LLLLL.LLLL,l,GG.G,RR.R,DDMMYY,M.M,m,F*PP |
978 | //$GPRMC,HHMMSS.sss,A,BBBB.BBBB,b,LLLLL.LLLL,l,GG.G,RR.R,DDMMYY,M.M,m,F*PP |
979 | 979 | ||
980 | void CreateNmeaRMC(void) |
980 | void CreateNmeaRMC(void) |
981 | { |
981 | { |
982 | u8 array[200], i = 0, crc = 0, x; |
982 | u8 array[200], i = 0, crc = 0, x; |
983 | s16 tmp_int; |
983 | s16 tmp_int; |
984 | s32 tmp1, tmp2; |
984 | s32 tmp1, tmp2; |
985 | // +++++++++++++++++++++++++++++++++++++++++++ |
985 | // +++++++++++++++++++++++++++++++++++++++++++ |
986 | i += sprintf(array, "$GPRMC,"); |
986 | i += sprintf(array, "$GPRMC,"); |
987 | // +++++++++++++++++++++++++++++++++++++++++++ |
987 | // +++++++++++++++++++++++++++++++++++++++++++ |
988 | if(SystemTime.Valid) |
988 | if(SystemTime.Valid) |
989 | { |
989 | { |
990 | i += sprintf(&array[i], "%02d%02d%02d.%03d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec); |
990 | i += sprintf(&array[i], "%02d%02d%02d.%03d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec); |
991 | } |
991 | } |
992 | else |
992 | else |
993 | { |
993 | { |
994 | i += sprintf(&array[i], ","); |
994 | i += sprintf(&array[i], ","); |
995 | } |
995 | } |
996 | if(GPSData.Flags & FLAG_GPSFIXOK) |
996 | if(GPSData.Flags & FLAG_GPSFIXOK) |
997 | { |
997 | { |
998 | // +++++++++++++++++++++++++++++++++++++++++++ |
998 | // +++++++++++++++++++++++++++++++++++++++++++ |
999 | tmp1 = abs(GPSData.Position.Latitude)/10000000L; |
999 | tmp1 = abs(GPSData.Position.Latitude)/10000000L; |
1000 | i += sprintf(&array[i],"A,%02d", (s16)tmp1); // Status: A = Okay V = Warnung |
1000 | i += sprintf(&array[i],"A,%02d", (s16)tmp1); // Status: A = Okay V = Warnung |
1001 | 1001 | ||
1002 | tmp1 = abs(GPSData.Position.Latitude)%10000000L; |
1002 | tmp1 = abs(GPSData.Position.Latitude)%10000000L; |
1003 | tmp1 *= 6; // in Minuten |
1003 | tmp1 *= 6; // in Minuten |
1004 | tmp2 = tmp1 / 1000000L; |
1004 | tmp2 = tmp1 / 1000000L; |
1005 | i += sprintf(&array[i],"%02d", (s16)tmp2); |
1005 | i += sprintf(&array[i],"%02d", (s16)tmp2); |
1006 | tmp2 = tmp1 % 1000000L; |
1006 | tmp2 = tmp1 % 1000000L; |
1007 | tmp2 /= 100; // zwei Stellen zu viel |
1007 | tmp2 /= 100; // zwei Stellen zu viel |
1008 | i += sprintf(&array[i],".%04d,", (s16)tmp2); |
1008 | i += sprintf(&array[i],".%04d,", (s16)tmp2); |
1009 | if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,"); |
1009 | if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,"); |
1010 | else i += sprintf(&array[i],"S,"); |
1010 | else i += sprintf(&array[i],"S,"); |
1011 | // +++++++++++++++++++++++++++++++++++++++++++ |
1011 | // +++++++++++++++++++++++++++++++++++++++++++ |
1012 | tmp1 = abs(GPSData.Position.Longitude)/10000000L; |
1012 | tmp1 = abs(GPSData.Position.Longitude)/10000000L; |
1013 | i += sprintf(&array[i],"%03d", (s16)tmp1); |
1013 | i += sprintf(&array[i],"%03d", (s16)tmp1); |
1014 | 1014 | ||
1015 | tmp1 = abs(GPSData.Position.Longitude)%10000000L; |
1015 | tmp1 = abs(GPSData.Position.Longitude)%10000000L; |
1016 | tmp1 *= 6; // in Minuten |
1016 | tmp1 *= 6; // in Minuten |
1017 | tmp2 = tmp1 / 1000000L; |
1017 | tmp2 = tmp1 / 1000000L; |
1018 | i += sprintf(&array[i],"%02d", (s16)tmp2); |
1018 | i += sprintf(&array[i],"%02d", (s16)tmp2); |
1019 | tmp2 = tmp1 % 1000000L; |
1019 | tmp2 = tmp1 % 1000000L; |
1020 | tmp2 /= 100; // zwei Stellen zu viel |
1020 | tmp2 /= 100; // zwei Stellen zu viel |
1021 | i += sprintf(&array[i],".%04d,", (s16)tmp2); |
1021 | i += sprintf(&array[i],".%04d,", (s16)tmp2); |
1022 | if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,"); |
1022 | if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,"); |
1023 | else i += sprintf(&array[i],"W,"); |
1023 | else i += sprintf(&array[i],"W,"); |
1024 | // +++++++++++++++++++++++++++++++++++++++++++ |
1024 | // +++++++++++++++++++++++++++++++++++++++++++ |
1025 | tmp_int = GPSData.Speed_Ground; // in cm/sek |
1025 | tmp_int = GPSData.Speed_Ground; // in cm/sek |
1026 | tmp_int *= 90; |
1026 | tmp_int *= 90; |
1027 | tmp_int /= 463; |
1027 | tmp_int /= 463; |
1028 | i += sprintf(&array[i],"%02d.%d,",tmp_int/10,tmp_int%10); // in Knoten |
1028 | i += sprintf(&array[i],"%02d.%d,",tmp_int/10,tmp_int%10); // in Knoten |
1029 | // +++++++++++++++++++++++++++++++++++++++++++ |
1029 | // +++++++++++++++++++++++++++++++++++++++++++ |
1030 | i += sprintf(&array[i],"%03d.%d,",GyroCompassCorrected/10,GyroCompassCorrected%10); |
1030 | i += sprintf(&array[i],"%03d.%d,",GyroCompassCorrected/10,GyroCompassCorrected%10); |
1031 | // +++++++++++++++++++++++++++++++++++++++++++ |
1031 | // +++++++++++++++++++++++++++++++++++++++++++ |
1032 | if(SystemTime.Valid) |
1032 | if(SystemTime.Valid) |
1033 | { |
1033 | { |
1034 | i += sprintf(&array[i], "%02d%02d%02d,",SystemTime.Day,SystemTime.Month,SystemTime.Year); |
1034 | i += sprintf(&array[i], "%02d%02d%02d,",SystemTime.Day,SystemTime.Month,SystemTime.Year); |
1035 | } |
1035 | } |
1036 | else |
1036 | else |
1037 | { |
1037 | { |
1038 | i += sprintf(&array[i], ","); |
1038 | i += sprintf(&array[i], ","); |
1039 | } |
1039 | } |
1040 | // +++++++++++++++++++++++++++++++++++++++++++ |
1040 | // +++++++++++++++++++++++++++++++++++++++++++ |
1041 | i += sprintf(&array[i],"%d.%1d,", abs(GeoMagDec)/10,abs(GeoMagDec)%10); |
1041 | i += sprintf(&array[i],"%d.%1d,", abs(GeoMagDec)/10,abs(GeoMagDec)%10); |
1042 | if(GeoMagDec < 0) i += sprintf(&array[i], "W,"); else i += sprintf(&array[i], "E,"); |
1042 | if(GeoMagDec < 0) i += sprintf(&array[i], "W,"); else i += sprintf(&array[i], "E,"); |
1043 | // +++++++++++++++++++++++++++++++++++++++++++ |
1043 | // +++++++++++++++++++++++++++++++++++++++++++ |
1044 | if(GPSData.Flags & FLAG_DIFFSOLN) i += sprintf(&array[i], "D*"); |
1044 | if(GPSData.Flags & FLAG_DIFFSOLN) i += sprintf(&array[i], "D*"); |
1045 | else i += sprintf(&array[i], "A*"); |
1045 | else i += sprintf(&array[i], "A*"); |
1046 | } |
1046 | } |
1047 | else // kein Satfix |
1047 | else // kein Satfix |
1048 | { |
1048 | { |
1049 | i += sprintf(&array[i], "V,,,,,,,,,,N*"); |
1049 | i += sprintf(&array[i], "V,,,,,,,,,,N*"); |
1050 | } |
1050 | } |
1051 | // +++++++++++++++++++++++++++++++++++++++++++ |
1051 | // +++++++++++++++++++++++++++++++++++++++++++ |
1052 | // CRC |
1052 | // CRC |
1053 | // +++++++++++++++++++++++++++++++++++++++++++ |
1053 | // +++++++++++++++++++++++++++++++++++++++++++ |
1054 | for(x=1; x<i-1; x++) |
1054 | for(x=1; x<i-1; x++) |
1055 | { |
1055 | { |
1056 | crc ^= array[x]; |
1056 | crc ^= array[x]; |
1057 | } |
1057 | } |
1058 | i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a); |
1058 | i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a); |
1059 | // +++++++++++++++++++++++++++++++++++++++++++ |
1059 | // +++++++++++++++++++++++++++++++++++++++++++ |
1060 | AddSerialData(&UART1_tx_buffer,array,i); |
1060 | AddSerialData(&UART1_tx_buffer,array,i); |
1061 | // +++++++++++++++++++++++++++++++++++++++++++ |
1061 | // +++++++++++++++++++++++++++++++++++++++++++ |
1062 | /* |
1062 | /* |
1063 | 1063 | ||
1064 | 1064 | ||
1065 | 1065 | ||
1066 | GPSData.Flags = (GPSData.Flags & 0xf0) | (UbxSol.Flags & 0x0f); // we take only the lower bits |
1066 | GPSData.Flags = (GPSData.Flags & 0xf0) | (UbxSol.Flags & 0x0f); // we take only the lower bits |
1067 | GPSData.NumOfSats = UbxSol.numSV; |
1067 | GPSData.NumOfSats = UbxSol.numSV; |
1068 | GPSData.SatFix = UbxSol.GPSfix; |
1068 | GPSData.SatFix = UbxSol.GPSfix; |
1069 | GPSData.Position_Accuracy = UbxSol.PAcc; |
1069 | GPSData.Position_Accuracy = UbxSol.PAcc; |
1070 | GPSData.Speed_Accuracy = UbxSol.SAcc; |
1070 | GPSData.Speed_Accuracy = UbxSol.SAcc; |
1071 | SetGPSTime(&SystemTime); // update system time |
1071 | SetGPSTime(&SystemTime); // update system time |
1072 | // NAV POSLLH |
1072 | // NAV POSLLH |
1073 | GPSData.Position.Status = INVALID; |
1073 | GPSData.Position.Status = INVALID; |
1074 | GPSData.Position.Longitude = UbxPosLlh.LON; |
1074 | GPSData.Position.Longitude = UbxPosLlh.LON; |
1075 | GPSData.Position.Latitude = UbxPosLlh.LAT; |
1075 | GPSData.Position.Latitude = UbxPosLlh.LAT; |
1076 | GPSData.Position.Altitude = UbxPosLlh.HMSL; |
1076 | GPSData.Position.Altitude = UbxPosLlh.HMSL; |
1077 | GPSData.Position.Status = NEWDATA; |
1077 | GPSData.Position.Status = NEWDATA; |
1078 | // NAV VELNED |
1078 | // NAV VELNED |
1079 | GPSData.Speed_East = UbxVelNed.VEL_E; |
1079 | GPSData.Speed_East = UbxVelNed.VEL_E; |
1080 | GPSData.Speed_North = UbxVelNed.VEL_N; |
1080 | GPSData.Speed_North = UbxVelNed.VEL_N; |
1081 | GPSData.Speed_Top = -UbxVelNed.VEL_D; |
1081 | GPSData.Speed_Top = -UbxVelNed.VEL_D; |
1082 | GPSData.Speed_Ground = UbxVelNed.GSpeed; |
1082 | GPSData.Speed_Ground = UbxVelNed.GSpeed; |
1083 | GPSData.Heading = UbxVelNed.Heading; |
1083 | GPSData.Heading = UbxVelNed.Heading; |
1084 | SystemTime.Year = 0; |
1084 | SystemTime.Year = 0; |
1085 | SystemTime.Month = 0; |
1085 | SystemTime.Month = 0; |
1086 | SystemTime.Day = 0; |
1086 | SystemTime.Day = 0; |
1087 | SystemTime.Hour = 0; |
1087 | SystemTime.Hour = 0; |
1088 | SystemTime.Min = 0; |
1088 | SystemTime.Min = 0; |
1089 | SystemTime.Sec = 0; |
1089 | SystemTime.Sec = 0; |
1090 | SystemTime.mSec = 0; |
1090 | SystemTime.mSec = 0; |
1091 | SystemTime.Valid = 0; |
1091 | SystemTime.Valid = 0; |
1092 | 1092 | ||
1093 | FromFlightCtrl.GyroHeading / 10;//NaviData.HomePositionDeviation.Bearing / 2; |
1093 | FromFlightCtrl.GyroHeading / 10;//NaviData.HomePositionDeviation.Bearing / 2; |
1094 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 1; // 1 = S |
1094 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 1; // 1 = S |
1095 | else ToFlightCtrl.Param.Byte[5] = 0; // 1 = S |
1095 | else ToFlightCtrl.Param.Byte[5] = 0; // 1 = S |
1096 | i1 = abs(GPSData.Position.Latitude)/10000000L; |
1096 | i1 = abs(GPSData.Position.Latitude)/10000000L; |
1097 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
1097 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
1098 | 1098 | ||
1099 | 1099 | ||
1100 | 1100 | ||
1101 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
1101 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
1102 | i1 *= 100; |
1102 | i1 *= 100; |
1103 | i1 += i2 / 100000; |
1103 | i1 += i2 / 100000; |
1104 | i2 = i2 % 100000; |
1104 | i2 = i2 % 100000; |
1105 | i2 /= 10; |
1105 | i2 /= 10; |
1106 | ToFlightCtrl.Param.Byte[6] = i1 % 256; |
1106 | ToFlightCtrl.Param.Byte[6] = i1 % 256; |
1107 | ToFlightCtrl.Param.Byte[7] = i1 / 256; |
1107 | ToFlightCtrl.Param.Byte[7] = i1 / 256; |
1108 | ToFlightCtrl.Param.Byte[8] = i2 % 256; |
1108 | ToFlightCtrl.Param.Byte[8] = i2 % 256; |
1109 | ToFlightCtrl.Param.Byte[9] = i2 / 256; |
1109 | ToFlightCtrl.Param.Byte[9] = i2 / 256; |
1110 | break; |
1110 | break; |
1111 | case 1: |
1111 | case 1: |
1112 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
1112 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
1113 | ToFlightCtrl.Param.Byte[0] = 11+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
1113 | ToFlightCtrl.Param.Byte[0] = 11+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
1114 | ToFlightCtrl.Param.Byte[1] = 8-1; // how many |
1114 | ToFlightCtrl.Param.Byte[1] = 8-1; // how many |
1115 | //----------------------------- |
1115 | //----------------------------- |
1116 | if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2] = 1; // 1 = E |
1116 | if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2] = 1; // 1 = E |
1117 | else ToFlightCtrl.Param.Byte[2] = 0; // 1 = S |
1117 | else ToFlightCtrl.Param.Byte[2] = 0; // 1 = S |
1118 | i1 = abs(GPSData.Position.Longitude)/10000000L; |
1118 | i1 = abs(GPSData.Position.Longitude)/10000000L; |
1119 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
1119 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
1120 | 1120 | ||
1121 | */ |
1121 | */ |
1122 | } |
1122 | } |
1123 | 1123 | ||
1124 | u16 SendTriggerPos(void) |
1124 | u16 SendTriggerPos(void) |
1125 | { |
1125 | { |
1126 | u16 sent = 0; |
1126 | u16 sent = 0; |
1127 | NaviData_Out1Trigger.Index = 18; |
1127 | NaviData_Out1Trigger.Index = 18; |
1128 | sent = MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Out1Trigger, sizeof(NaviData_Out1Trigger)) + 1; |
1128 | sent = MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Out1Trigger, sizeof(NaviData_Out1Trigger)) + 1; |
1129 | if(sent) Out1TriggerUpdateNewData = 0; |
1129 | if(sent) Out1TriggerUpdateNewData = 0; |
1130 | // BeepTime = 50; // beep |
1130 | // BeepTime = 50; // beep |
1131 | return(sent); |
1131 | return(sent); |
1132 | } |
1132 | } |
1133 | 1133 | ||
1134 | 1134 | ||
1135 | u16 TransmitNavigationData(u16 MaxBytesPerSecond, u8 clear) // returns the minumum pause time in ms |
1135 | u16 TransmitNavigationData(u16 MaxBytesPerSecond, u8 clear) // returns the minumum pause time in ms |
1136 | { |
1136 | { |
1137 | static u8 state = 0, count_flags = 2, count_target = 3, count_home = 4, count_wp = 5 , count_tiny = 6, count_fs = 7, count_txt = 5; |
1137 | static u8 state = 0, count_flags = 2, count_target = 3, count_home = 4, count_wp = 5 , count_tiny = 6, count_fs = 7, count_txt = 5; |
1138 | static u16 CRC_Home = 0, CRC_Target = 0, CRC_Flags = 0, CRC_Wp = 0, CRC_Fs = 0, CRC_Txt = 0, crc_Tiny = 0; |
1138 | static u16 CRC_Home = 0, CRC_Target = 0, CRC_Flags = 0, CRC_Wp = 0, CRC_Fs = 0, CRC_Txt = 0, crc_Tiny = 0; |
1139 | u16 pause, sent = 0, crc_home, crc_target, crc_flags, crc_wp, crc_fs, crc_txt; |
1139 | u16 pause, sent = 0, crc_home, crc_target, crc_flags, crc_wp, crc_fs, crc_txt; |
1140 | 1140 | ||
1141 | if(clear) |
1141 | if(clear) |
1142 | { |
1142 | { |
1143 | state = 0; |
1143 | state = 0; |
1144 | CRC_Home++; |
1144 | CRC_Home++; |
1145 | CRC_Target++; |
1145 | CRC_Target++; |
1146 | CRC_Flags++; |
1146 | CRC_Flags++; |
1147 | CRC_Wp++; |
1147 | CRC_Wp++; |
1148 | CRC_Fs++; |
1148 | CRC_Fs++; |
1149 | if(ErrorCode) NaviData_Flags.SpeakHoTT = FC.FromFC_SpeakHoTT; |
1149 | if(ErrorCode) NaviData_Flags.SpeakHoTT = FC.FromFC_SpeakHoTT; |
1150 | else NaviData_Flags.SpeakHoTT = SPEAK_CONNECTED; |
1150 | else NaviData_Flags.SpeakHoTT = SPEAK_CONNECTED; |
1151 | NaviData_Flags_SpeakHoTT_Processed = 0; // don't overwrite in SPI.C |
1151 | NaviData_Flags_SpeakHoTT_Processed = 0; // don't overwrite in SPI.C |
1152 | return(1); |
1152 | return(1); |
1153 | } |
1153 | } |
1154 | while(!sent) |
1154 | while(!sent) |
1155 | { |
1155 | { |
1156 | // if(Out1TriggerUpdateNewData && MaxBytesPerSecond > 200) // (only if the data link can transmit more than 200Bytes per secons) -> it wouldn't fit into the data-flow if there are too few bytes available |
1156 | // if(Out1TriggerUpdateNewData && MaxBytesPerSecond > 200) // (only if the data link can transmit more than 200Bytes per secons) -> it wouldn't fit into the data-flow if there are too few bytes available |
1157 | // sent += SendTriggerPos(); // dann passen die 35 Bytes noch ohne Verzögerung |
1157 | // sent += SendTriggerPos(); // dann passen die 35 Bytes noch ohne Verzögerung |
1158 | 1158 | ||
1159 | switch(state++) |
1159 | switch(state++) |
1160 | { |
1160 | { |
1161 | case 0: if(LaserCtrlTimeout > 0) // send only, if LaserCtrl is connected |
1161 | case 0: if(LaserCtrlTimeout > 0) // send only, if LaserCtrl is connected |
1162 | { |
1162 | { |
1163 | NaviData_Laser.Index = 20; |
1163 | NaviData_Laser.Index = 20; |
1164 | NaviData_Laser.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1164 | NaviData_Laser.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1165 | NaviData_Laser.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1165 | NaviData_Laser.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1166 | NaviData_Laser.Altimeter_5cm = NaviData.Altimeter_5cm; |
1166 | NaviData_Laser.Altimeter_5cm = NaviData.Altimeter_5cm; |
1167 | NaviData_Laser.GroundSpeed = NaviData.GroundSpeed / 10; |
1167 | NaviData_Laser.GroundSpeed = NaviData.GroundSpeed / 10; |
1168 | NaviData_Laser.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1168 | NaviData_Laser.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1169 | NaviData_Laser.Distance = FromLaserCtrl.Distance; |
1169 | NaviData_Laser.Distance = FromLaserCtrl.Distance; |
1170 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Laser, sizeof(NaviData_Laser)) + 1; |
1170 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Laser, sizeof(NaviData_Laser)) + 1; |
1171 | break; |
1171 | break; |
1172 | } |
1172 | } |
1173 | case 6: |
1173 | case 6: |
1174 | case 5: |
1174 | case 5: |
1175 | // belegt 35 ASCII-Zeichen |
1175 | // belegt 35 ASCII-Zeichen |
1176 | NaviData_Flags.Index = 11; |
1176 | NaviData_Flags.Index = 11; |
1177 | NaviData_Flags.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1177 | NaviData_Flags.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1178 | NaviData_Flags.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1178 | NaviData_Flags.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1179 | NaviData_Flags.Altimeter_5cm = NaviData.Altimeter_5cm; |
1179 | NaviData_Flags.Altimeter_5cm = NaviData.Altimeter_5cm; |
1180 | NaviData_Flags.GroundSpeed = NaviData.GroundSpeed / 10; |
1180 | NaviData_Flags.GroundSpeed = NaviData.GroundSpeed / 10; |
1181 | NaviData_Flags.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1181 | NaviData_Flags.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1182 | NaviData_Flags.OSDStatusFlags2 = (FC.StatusFlags & ~OSD_FLAG_MASK1) | (FC.StatusFlags2 & ~OSD_FLAG_MASK2); |
1182 | NaviData_Flags.OSDStatusFlags2 = (FC.StatusFlags & ~OSD_FLAG_MASK1) | (FC.StatusFlags2 & ~OSD_FLAG_MASK2); |
1183 | NaviData_Flags.NCFlags = NaviData.NCFlags; |
1183 | NaviData_Flags.NCFlags = NaviData.NCFlags; |
1184 | NaviData_Flags.Errorcode = ErrorCode; |
1184 | NaviData_Flags.Errorcode = ErrorCode; |
1185 | NaviData_Flags.ReserveFlags = 0; |
1185 | NaviData_Flags.ReserveFlags = 0; |
1186 | //NaviData_Flags.SpeakHoTT = FC.FromFC_SpeakHoTT; -> in SPI.c |
1186 | //NaviData_Flags.SpeakHoTT = FC.FromFC_SpeakHoTT; -> in SPI.c |
1187 | NaviData_Flags.VarioCharacter = FromFC_VarioCharacter; |
1187 | NaviData_Flags.VarioCharacter = FromFC_VarioCharacter; |
1188 | NaviData_Flags.GPS_ModeCharacter = NC_GPS_ModeCharacter; |
1188 | NaviData_Flags.GPS_ModeCharacter = NC_GPS_ModeCharacter; |
1189 | NaviData_Flags.BL_MinOfMaxPWM = BL_MinOfMaxPWM; |
1189 | NaviData_Flags.BL_MinOfMaxPWM = BL_MinOfMaxPWM; |
1190 | crc_flags = CRC16((unsigned char*)(&NaviData_Flags.OSDStatusFlags2), sizeof(NaviData_Flags) - START_PAYLOAD_DATA); |
1190 | crc_flags = CRC16((unsigned char*)(&NaviData_Flags.OSDStatusFlags2), sizeof(NaviData_Flags) - START_PAYLOAD_DATA); |
1191 | if((crc_flags != CRC_Flags) || (--count_flags == 0)) |
1191 | if((crc_flags != CRC_Flags) || (--count_flags == 0)) |
1192 | { |
1192 | { |
1193 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Flags, sizeof(NaviData_Flags)) + 1; |
1193 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Flags, sizeof(NaviData_Flags)) + 1; |
1194 | CRC_Flags = crc_flags; |
1194 | CRC_Flags = crc_flags; |
1195 | count_flags = 11*2; |
1195 | count_flags = 11*2; |
1196 | } |
1196 | } |
1197 | NaviData_Flags_SpeakHoTT_Processed = 1; // allow update in SPI now |
1197 | NaviData_Flags_SpeakHoTT_Processed = 1; // allow update in SPI now |
1198 | break; |
1198 | break; |
1199 | case 1: |
1199 | case 1: |
1200 | case 7: |
1200 | case 7: |
1201 | // belegt 43 ASCII-Zeichen |
1201 | // belegt 43 ASCII-Zeichen |
1202 | NaviData_Target.Index = 12; |
1202 | NaviData_Target.Index = 12; |
1203 | NaviData_Target.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1203 | NaviData_Target.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1204 | NaviData_Target.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1204 | NaviData_Target.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1205 | NaviData_Target.Altimeter_5cm = NaviData.Altimeter_5cm; |
1205 | NaviData_Target.Altimeter_5cm = NaviData.Altimeter_5cm; |
1206 | NaviData_Target.GroundSpeed = NaviData.GroundSpeed / 10; |
1206 | NaviData_Target.GroundSpeed = NaviData.GroundSpeed / 10; |
1207 | NaviData_Target.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1207 | NaviData_Target.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1208 | NaviData_Target.TargetLongitude = NaviData.TargetPosition.Longitude; |
1208 | NaviData_Target.TargetLongitude = NaviData.TargetPosition.Longitude; |
1209 | NaviData_Target.TargetLatitude = NaviData.TargetPosition.Latitude; |
1209 | NaviData_Target.TargetLatitude = NaviData.TargetPosition.Latitude; |
1210 | NaviData_Target.TargetAltitude = NaviData.TargetPosition.Altitude; |
1210 | NaviData_Target.TargetAltitude = NaviData.TargetPosition.Altitude; |
1211 | NaviData_Target.RC_Quality = NaviData.RC_Quality; |
1211 | NaviData_Target.RC_Quality = NaviData.RC_Quality; |
1212 | crc_target = CRC16((unsigned char*)(&NaviData_Target.TargetLongitude), sizeof(NaviData_Target) - START_PAYLOAD_DATA); |
1212 | crc_target = CRC16((unsigned char*)(&NaviData_Target.TargetLongitude), sizeof(NaviData_Target) - START_PAYLOAD_DATA); |
1213 | if((crc_target != CRC_Target) || (--count_target == 0)) |
1213 | if((crc_target != CRC_Target) || (--count_target == 0)) |
1214 | { |
1214 | { |
1215 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Target, sizeof(NaviData_Target)) + 1; |
1215 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Target, sizeof(NaviData_Target)) + 1; |
1216 | CRC_Target = crc_target; |
1216 | CRC_Target = crc_target; |
1217 | count_target = 10*2; |
1217 | count_target = 10*2; |
1218 | } |
1218 | } |
1219 | break; |
1219 | break; |
1220 | case 2: |
1220 | case 2: |
1221 | case 8: |
1221 | case 8: |
1222 | // belegt 31 ASCII-Zeichen |
1222 | // belegt 31 ASCII-Zeichen |
1223 | NaviData_WP.Index = 15; |
1223 | NaviData_WP.Index = 15; |
1224 | NaviData_WP.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1224 | NaviData_WP.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1225 | NaviData_WP.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1225 | NaviData_WP.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1226 | NaviData_WP.Altimeter_5cm = NaviData.Altimeter_5cm; |
1226 | NaviData_WP.Altimeter_5cm = NaviData.Altimeter_5cm; |
1227 | NaviData_WP.GroundSpeed = NaviData.GroundSpeed / 10; |
1227 | NaviData_WP.GroundSpeed = NaviData.GroundSpeed / 10; |
1228 | NaviData_WP.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1228 | NaviData_WP.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1229 | NaviData_WP.WaypointIndex = NaviData.WaypointIndex; |
1229 | NaviData_WP.WaypointIndex = NaviData.WaypointIndex; |
1230 | NaviData_WP.WaypointNumber = NaviData.WaypointNumber; |
1230 | NaviData_WP.WaypointNumber = NaviData.WaypointNumber; |
1231 | NaviData_WP.TargetHoldTime = NaviData.TargetHoldTime; |
1231 | NaviData_WP.TargetHoldTime = NaviData.TargetHoldTime; |
1232 | // NaviData_WP.WP_Eventchannel = FC_WP_EventChannel; -> happends already in SPI.c |
1232 | // NaviData_WP.WP_Eventchannel = FC_WP_EventChannel; -> happends already in SPI.c |
1233 | crc_wp = CRC16((unsigned char*)(&NaviData_WP.WaypointIndex), sizeof(NaviData_WP) - START_PAYLOAD_DATA); // update crc |
1233 | crc_wp = CRC16((unsigned char*)(&NaviData_WP.WaypointIndex), sizeof(NaviData_WP) - START_PAYLOAD_DATA); // update crc |
1234 | if((crc_wp != CRC_Wp) || (--count_wp == 0)) |
1234 | if((crc_wp != CRC_Wp) || (--count_wp == 0)) |
1235 | { |
1235 | { |
1236 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_WP, sizeof(NaviData_WP)) + 1; |
1236 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_WP, sizeof(NaviData_WP)) + 1; |
1237 | CRC_Wp = crc_wp; |
1237 | CRC_Wp = crc_wp; |
1238 | count_wp = 12*2; |
1238 | count_wp = 12*2; |
1239 | } |
1239 | } |
1240 | break; |
1240 | break; |
1241 | case 3: |
1241 | case 3: |
1242 | case 9: |
1242 | case 9: |
1243 | // 35 ASCII-Zeichen |
1243 | // 35 ASCII-Zeichen |
1244 | NaviData_Failsafe.Index = 17; |
1244 | NaviData_Failsafe.Index = 17; |
1245 | NaviData_Failsafe.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1245 | NaviData_Failsafe.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1246 | NaviData_Failsafe.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1246 | NaviData_Failsafe.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1247 | NaviData_Failsafe.Altimeter_5cm = NaviData.Altimeter_5cm; |
1247 | NaviData_Failsafe.Altimeter_5cm = NaviData.Altimeter_5cm; |
1248 | NaviData_Failsafe.GroundSpeed = NaviData.GroundSpeed / 10; |
1248 | NaviData_Failsafe.GroundSpeed = NaviData.GroundSpeed / 10; |
1249 | NaviData_Failsafe.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1249 | NaviData_Failsafe.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1250 | NaviData_Failsafe.Longitude = GPS_FailsafePosition.Longitude; |
1250 | NaviData_Failsafe.Longitude = GPS_FailsafePosition.Longitude; |
1251 | NaviData_Failsafe.Latitude = GPS_FailsafePosition.Latitude; |
1251 | NaviData_Failsafe.Latitude = GPS_FailsafePosition.Latitude; |
1252 | crc_fs = CRC16((unsigned char*)(&NaviData_Failsafe.Longitude), sizeof(NaviData_FS_Pos_t) - START_PAYLOAD_DATA); // update crc for the structure |
1252 | crc_fs = CRC16((unsigned char*)(&NaviData_Failsafe.Longitude), sizeof(NaviData_FS_Pos_t) - START_PAYLOAD_DATA); // update crc for the structure |
1253 | if((crc_fs != CRC_Fs) || (--count_fs == 0)) |
1253 | if((crc_fs != CRC_Fs) || (--count_fs == 0)) |
1254 | { |
1254 | { |
1255 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Failsafe, sizeof(NaviData_Failsafe)) + 1; |
1255 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Failsafe, sizeof(NaviData_Failsafe)) + 1; |
1256 | CRC_Fs = crc_fs; |
1256 | CRC_Fs = crc_fs; |
1257 | count_fs = 20*2; |
1257 | count_fs = 20*2; |
1258 | } |
1258 | } |
1259 | break; |
1259 | break; |
1260 | case 4: |
1260 | case 4: |
1261 | case 10: |
1261 | case 10: |
1262 | // belegt 43 ASCII-Zeichen |
1262 | // belegt 43 ASCII-Zeichen |
1263 | NaviData_Home.Index = 13; |
1263 | NaviData_Home.Index = 13; |
1264 | NaviData_Home.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1264 | NaviData_Home.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1265 | NaviData_Home.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1265 | NaviData_Home.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1266 | NaviData_Home.Altimeter_5cm = NaviData.Altimeter_5cm; |
1266 | NaviData_Home.Altimeter_5cm = NaviData.Altimeter_5cm; |
1267 | NaviData_Home.GroundSpeed = NaviData.GroundSpeed / 10; |
1267 | NaviData_Home.GroundSpeed = NaviData.GroundSpeed / 10; |
1268 | NaviData_Home.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1268 | NaviData_Home.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1269 | NaviData_Home.HomeLongitude = NaviData.HomePosition.Longitude; |
1269 | NaviData_Home.HomeLongitude = NaviData.HomePosition.Longitude; |
1270 | NaviData_Home.HomeLatitude = NaviData.HomePosition.Latitude; |
1270 | NaviData_Home.HomeLatitude = NaviData.HomePosition.Latitude; |
1271 | NaviData_Home.HomeAltitude = NaviData.HomePosition.Altitude; |
1271 | NaviData_Home.HomeAltitude = NaviData.HomePosition.Altitude; |
1272 | NaviData_Home.WP_OperatingRadius = MaxWP_Radius_in_m; |
1272 | NaviData_Home.WP_OperatingRadius = MaxWP_Radius_in_m; |
1273 | // ++++++++++++++ |
1273 | // ++++++++++++++ |
1274 | // + Fix Type |
1274 | // + Fix Type |
1275 | // ++++++++++++++ |
1275 | // ++++++++++++++ |
1276 | if(!(GPSData.Flags & FLAG_GPSFIXOK)) NaviData_Home.OSDStatusFlags3 = (NaviData_Home.OSDStatusFlags3 & 0xf8) | OSD_FIX_NONE; |
1276 | if(!(GPSData.Flags & FLAG_GPSFIXOK)) NaviData_Home.OSDStatusFlags3 = (NaviData_Home.OSDStatusFlags3 & 0xf8) | OSD_FIX_NONE; |
1277 | else |
1277 | else |
1278 | if(GPSData.SatFix == SATFIX_2D) NaviData_Home.OSDStatusFlags3 = (NaviData_Home.OSDStatusFlags3 & 0xf8) | OSD_FIX_2D; |
1278 | if(GPSData.SatFix == SATFIX_2D) NaviData_Home.OSDStatusFlags3 = (NaviData_Home.OSDStatusFlags3 & 0xf8) | OSD_FIX_2D; |
1279 | else |
1279 | else |
1280 | if(GPSData.Flags & FLAG_DIFFSOLN) NaviData_Home.OSDStatusFlags3 = (NaviData_Home.OSDStatusFlags3 & 0xf8) | OSD_FIX_DGPS; |
1280 | if(GPSData.Flags & FLAG_DIFFSOLN) NaviData_Home.OSDStatusFlags3 = (NaviData_Home.OSDStatusFlags3 & 0xf8) | OSD_FIX_DGPS; |
1281 | else |
1281 | else |
1282 | if(GPSData.SatFix == SATFIX_3D) NaviData_Home.OSDStatusFlags3 = (NaviData_Home.OSDStatusFlags3 & 0xf8) | OSD_FIX_3D; |
1282 | if(GPSData.SatFix == SATFIX_3D) NaviData_Home.OSDStatusFlags3 = (NaviData_Home.OSDStatusFlags3 & 0xf8) | OSD_FIX_3D; |
1283 | // ++++++++++++++ |
1283 | // ++++++++++++++ |
1284 | if(BlitzSchuhConnected) NaviData_Home.OSDStatusFlags3 |= OSD3_FLAG_HOTSHOE; else NaviData_Home.OSDStatusFlags3 &= ~OSD3_FLAG_HOTSHOE; |
1284 | if(BlitzSchuhConnected) NaviData_Home.OSDStatusFlags3 |= OSD3_FLAG_HOTSHOE; else NaviData_Home.OSDStatusFlags3 &= ~OSD3_FLAG_HOTSHOE; |
1285 | // ++++++++++++++ |
1285 | // ++++++++++++++ |
1286 | if(FC.StatusFlags3 & FC_STATUS3_BOAT) NaviData_Home.OSDStatusFlags3 |= OSD3_FLAG_BOAT_MODE; else NaviData_Home.OSDStatusFlags3 &= ~OSD3_FLAG_BOAT_MODE; |
1286 | if(FC.StatusFlags3 & FC_STATUS3_BOAT) NaviData_Home.OSDStatusFlags3 |= OSD3_FLAG_BOAT_MODE; else NaviData_Home.OSDStatusFlags3 &= ~OSD3_FLAG_BOAT_MODE; |
1287 | // ++++++++++++++ |
1287 | // ++++++++++++++ |
1288 | if(!(FC.StatusFlags3 & FC_STATUS3_NOT_CALIBRATED) && !ErrorCode && !Partner.ErrorCode && (NCFlags & NC_FLAG_GPS_OK)) |
1288 | if(!(FC.StatusFlags3 & FC_STATUS3_NOT_CALIBRATED) && !ErrorCode && !Partner.ErrorCode && (NCFlags & NC_FLAG_GPS_OK)) |
1289 | NaviData_Home.OSDStatusFlags3 |= OSD3_FLAG_MK_IS_READY; else NaviData_Home.OSDStatusFlags3 &= ~OSD3_FLAG_MK_IS_READY; |
1289 | NaviData_Home.OSDStatusFlags3 |= OSD3_FLAG_MK_IS_READY; else NaviData_Home.OSDStatusFlags3 &= ~OSD3_FLAG_MK_IS_READY; |
1290 | // ++++++++++++++ |
1290 | // ++++++++++++++ |
1291 | crc_home = CRC16((unsigned char*)(&NaviData_Home.HomeLongitude), sizeof(NaviData_Home_t) - START_PAYLOAD_DATA); // update crc for the structure |
1291 | crc_home = CRC16((unsigned char*)(&NaviData_Home.HomeLongitude), sizeof(NaviData_Home_t) - START_PAYLOAD_DATA); // update crc for the structure |
1292 | if((crc_home != CRC_Home) || (--count_home == 0)) |
1292 | if((crc_home != CRC_Home) || (--count_home == 0)) |
1293 | { |
1293 | { |
1294 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Home, sizeof(NaviData_Home)) + 1; |
1294 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Home, sizeof(NaviData_Home)) + 1; |
1295 | CRC_Home = crc_home; |
1295 | CRC_Home = crc_home; |
1296 | count_home = 25; |
1296 | count_home = 25; |
1297 | } |
1297 | } |
1298 | break; |
1298 | break; |
1299 | case 11: |
1299 | case 11: |
1300 | // belegt 39 ASCII-Zeichen |
1300 | // belegt 39 ASCII-Zeichen |
1301 | NaviData_Deviation.Index = 14; |
1301 | NaviData_Deviation.Index = 14; |
1302 | NaviData_Deviation.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1302 | NaviData_Deviation.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1303 | NaviData_Deviation.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1303 | NaviData_Deviation.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1304 | NaviData_Deviation.Altimeter_5cm = NaviData.Altimeter_5cm; |
1304 | NaviData_Deviation.Altimeter_5cm = NaviData.Altimeter_5cm; |
1305 | NaviData_Deviation.GroundSpeed = NaviData.GroundSpeed / 10; |
1305 | NaviData_Deviation.GroundSpeed = NaviData.GroundSpeed / 10; |
1306 | NaviData_Deviation.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1306 | NaviData_Deviation.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1307 | NaviData_Deviation.FlyingTime = NaviData.FlyingTime; |
1307 | NaviData_Deviation.FlyingTime = NaviData.FlyingTime; |
1308 | NaviData_Deviation.DistanceToHome = NaviData.HomePositionDeviation.Distance_dm; |
1308 | NaviData_Deviation.DistanceToHome = NaviData.HomePositionDeviation.Distance_dm; |
1309 | NaviData_Deviation.HeadingToHome = NaviData.HomePositionDeviation.Bearing/2; |
1309 | NaviData_Deviation.HeadingToHome = NaviData.HomePositionDeviation.Bearing/2; |
1310 | NaviData_Deviation.DistanceToTarget = NaviData.TargetPositionDeviation.Distance_dm; |
1310 | NaviData_Deviation.DistanceToTarget = NaviData.TargetPositionDeviation.Distance_dm; |
1311 | NaviData_Deviation.HeadingToTarget = NaviData.TargetPositionDeviation.Bearing/2; |
1311 | NaviData_Deviation.HeadingToTarget = NaviData.TargetPositionDeviation.Bearing/2; |
1312 | NaviData_Deviation.AngleNick = NaviData.AngleNick; |
1312 | NaviData_Deviation.AngleNick = NaviData.AngleNick; |
1313 | NaviData_Deviation.AngleRoll = NaviData.AngleRoll; |
1313 | NaviData_Deviation.AngleRoll = NaviData.AngleRoll; |
1314 | NaviData_Deviation.SatsInUse = NaviData.SatsInUse; |
1314 | NaviData_Deviation.SatsInUse = NaviData.SatsInUse; |
1315 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Deviation, sizeof(NaviData_Deviation)) + 1; |
1315 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Deviation, sizeof(NaviData_Deviation)) + 1; |
1316 | break; |
1316 | break; |
1317 | case 12: |
1317 | case 12: |
1318 | // belegt 43 ASCII-Zeichen |
1318 | // belegt 43 ASCII-Zeichen |
1319 | NaviData_Volatile.Index = 16; |
1319 | NaviData_Volatile.Index = 16; |
1320 | NaviData_Volatile.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1320 | NaviData_Volatile.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1321 | NaviData_Volatile.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1321 | NaviData_Volatile.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1322 | NaviData_Volatile.Altimeter_5cm = NaviData.Altimeter_5cm; |
1322 | NaviData_Volatile.Altimeter_5cm = NaviData.Altimeter_5cm; |
1323 | NaviData_Volatile.GroundSpeed = NaviData.GroundSpeed / 10; |
1323 | NaviData_Volatile.GroundSpeed = NaviData.GroundSpeed / 10; |
1324 | NaviData_Volatile.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1324 | NaviData_Volatile.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1325 | NaviData_Volatile.UBat = FC.BAT_Voltage; |
1325 | NaviData_Volatile.UBat = FC.BAT_Voltage; |
1326 | NaviData_Volatile.Current = NaviData.Current; |
1326 | NaviData_Volatile.Current = NaviData.Current; |
1327 | NaviData_Volatile.UsedCapacity = NaviData.UsedCapacity; |
1327 | NaviData_Volatile.UsedCapacity = NaviData.UsedCapacity; |
1328 | NaviData_Volatile.Variometer = NaviData.Variometer; |
1328 | NaviData_Volatile.Variometer = NaviData.Variometer; |
1329 | NaviData_Volatile.Heading = NaviData.Heading / 2; |
1329 | NaviData_Volatile.Heading = NaviData.Heading / 2; |
1330 | NaviData_Volatile.CompassHeading = NaviData.CompassHeading / 2; |
1330 | NaviData_Volatile.CompassHeading = NaviData.CompassHeading / 2; |
1331 | NaviData_Volatile.Gas = NaviData.Gas; |
1331 | NaviData_Volatile.Gas = NaviData.Gas; |
1332 | NaviData_Volatile.SetpointAltitude = NaviData.SetpointAltitude; |
1332 | NaviData_Volatile.SetpointAltitude = NaviData.SetpointAltitude; |
1333 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Volatile, sizeof(NaviData_Volatile)) + 1; |
1333 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Volatile, sizeof(NaviData_Volatile)) + 1; |
1334 | break; |
1334 | break; |
1335 | case 13: |
1335 | case 13: |
1336 | // belegt 27 ASCII-Zeichen |
1336 | // belegt 27 ASCII-Zeichen |
1337 | NaviData_Tiny.Index = 10; |
1337 | NaviData_Tiny.Index = 10; |
1338 | NaviData_Tiny.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1338 | NaviData_Tiny.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1339 | NaviData_Tiny.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1339 | NaviData_Tiny.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1340 | NaviData_Tiny.Altimeter_5cm = NaviData.Altimeter_5cm; |
1340 | NaviData_Tiny.Altimeter_5cm = NaviData.Altimeter_5cm; |
1341 | NaviData_Tiny.GroundSpeed = NaviData.GroundSpeed / 10; |
1341 | NaviData_Tiny.GroundSpeed = NaviData.GroundSpeed / 10; |
1342 | NaviData_Tiny.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1342 | NaviData_Tiny.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1343 | NaviData_Tiny.CamCtrlChar = CamCtrlCharacter; |
1343 | NaviData_Tiny.CamCtrlChar = CamCtrlCharacter; |
1344 | if((crc_Tiny != NaviData_Tiny.CamCtrlChar) || (--count_tiny == 0)) |
1344 | if((crc_Tiny != NaviData_Tiny.CamCtrlChar) || (--count_tiny == 0)) |
1345 | { |
1345 | { |
1346 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Tiny, sizeof(NaviData_Tiny)) + 1; |
1346 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Tiny, sizeof(NaviData_Tiny)) + 1; |
1347 | count_tiny = 200; // just to make sure that it comes sometimes |
1347 | count_tiny = 200; // just to make sure that it comes sometimes |
1348 | crc_Tiny = NaviData_Tiny.CamCtrlChar; |
1348 | crc_Tiny = NaviData_Tiny.CamCtrlChar; |
1349 | } |
1349 | } |
1350 | break; |
1350 | break; |
1351 | case 14: |
1351 | case 14: |
1352 | // 55 ASCII-Zeichen |
1352 | // 55 ASCII-Zeichen |
1353 | NaviData_HoTT_Text.Index = 19; |
1353 | NaviData_HoTT_Text.Index = 19; |
1354 | NaviData_HoTT_Text.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1354 | NaviData_HoTT_Text.ActualLongitude = NaviData.CurrentPosition.Longitude; |
1355 | NaviData_HoTT_Text.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1355 | NaviData_HoTT_Text.ActualLatitude = NaviData.CurrentPosition.Latitude; |
1356 | NaviData_HoTT_Text.Altimeter_5cm = NaviData.Altimeter_5cm; |
1356 | NaviData_HoTT_Text.Altimeter_5cm = NaviData.Altimeter_5cm; |
1357 | NaviData_HoTT_Text.GroundSpeed = NaviData.GroundSpeed / 10; |
1357 | NaviData_HoTT_Text.GroundSpeed = NaviData.GroundSpeed / 10; |
1358 | NaviData_HoTT_Text.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1358 | NaviData_HoTT_Text.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2); |
1359 | NaviData_HoTT_Text.MagnetField = (u16) (EarthMagneticField/5); |
1359 | NaviData_HoTT_Text.MagnetField = (u16) (EarthMagneticField/5); |
1360 | crc_txt = CRC16((unsigned char*)(&NaviData_HoTT_Text.HoTT_DisplayText), sizeof(NaviData_HoTT_Text_t) - START_PAYLOAD_DATA); // update crc for the structure |
1360 | crc_txt = CRC16((unsigned char*)(&NaviData_HoTT_Text.HoTT_DisplayText), sizeof(NaviData_HoTT_Text_t) - START_PAYLOAD_DATA); // update crc for the structure |
1361 | if((crc_txt != CRC_Txt) || (--count_txt == 0)) |
1361 | if((crc_txt != CRC_Txt) || (--count_txt == 0)) |
1362 | { |
1362 | { |
1363 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_HoTT_Text, sizeof(NaviData_HoTT_Text)) + 1; |
1363 | sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_HoTT_Text, sizeof(NaviData_HoTT_Text)) + 1; |
1364 | CRC_Txt = crc_txt; |
1364 | CRC_Txt = crc_txt; |
1365 | count_txt = 50; |
1365 | count_txt = 50; |
1366 | } |
1366 | } |
1367 | break; |
1367 | break; |
1368 | 1368 | ||
1369 | 1369 | ||
1370 | default: state = 0; |
1370 | default: state = 0; |
1371 | break; |
1371 | break; |
1372 | } |
1372 | } |
1373 | } |
1373 | } |
1374 | pause = (sent * 1000) / MaxBytesPerSecond; |
1374 | pause = (sent * 1000) / MaxBytesPerSecond; |
1375 | 1375 | ||
1376 | UART1_Request_NaviData = FALSE; |
1376 | UART1_Request_NaviData = FALSE; |
1377 | LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2; |
1377 | LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2; |
1378 | return(pause); |
1378 | return(pause); |
1379 | // Clear at timeout: |
1379 | // Clear at timeout: |
1380 | // NaviData_WP.WP_Eventchannel |
1380 | // NaviData_WP.WP_Eventchannel |
1381 | } |
1381 | } |
1382 | 1382 | ||
1383 | /**************************************************************/ |
1383 | /**************************************************************/ |
1384 | /* Send the answers to incomming commands at the debug uart */ |
1384 | /* Send the answers to incomming commands at the debug uart */ |
1385 | /**************************************************************/ |
1385 | /**************************************************************/ |
1386 | void UART1_TransmitTxData(void) |
1386 | void UART1_TransmitTxData(void) |
1387 | { |
1387 | { |
1388 | static u8 motorindex1 = 255, motorindex2 = 0; |
1388 | static u8 motorindex1 = 255, motorindex2 = 0; |
1389 | if(DebugUART != UART1) return; |
1389 | if(DebugUART != UART1) return; |
1390 | 1390 | ||
1391 | if(CheckDelay(UART1_AboTimeOut) || StopAllAbbos) |
1391 | if(CheckDelay(UART1_AboTimeOut) || StopAllAbbos) |
1392 | { |
1392 | { |
1393 | UART1_DebugData_Interval = 0; |
1393 | UART1_DebugData_Interval = 0; |
1394 | UART1_NaviData_Interval = 0; |
1394 | UART1_NaviData_Interval = 0; |
1395 | UART1_NaviData_MaxBytes = 0; |
1395 | UART1_NaviData_MaxBytes = 0; |
1396 | UART1_Data3D_Interval = 0; |
1396 | UART1_Data3D_Interval = 0; |
1397 | UART1_Display_Interval = 0; |
1397 | UART1_Display_Interval = 0; |
1398 | UART1_MotorData_Interval = 0; |
1398 | UART1_MotorData_Interval = 0; |
1399 | UART1_NaviData_Timer = SetDelay(500); |
1399 | UART1_NaviData_Timer = SetDelay(500); |
1400 | UART1_AboTimeOut = SetDelay(1000); |
1400 | UART1_AboTimeOut = SetDelay(1000); |
1401 | UART1_MobileMenu_Timer = 0; |
1401 | UART1_MobileMenu_Timer = 0; |
1402 | TransmitNavigationData(0,1); // clear the CRC values |
1402 | TransmitNavigationData(0,1); // clear the CRC values |
1403 | StopAllAbbos = 0; |
1403 | StopAllAbbos = 0; |
1404 | } |
1404 | } |
1405 | //if(UART1_NaviData_MaxBytes > 150) UART1_NaviData_MaxBytes = 150; |
1405 | //if(UART1_NaviData_MaxBytes > 150) UART1_NaviData_MaxBytes = 150; |
1406 | //UART1_NaviData_MaxBytes = 150; |
1406 | //UART1_NaviData_MaxBytes = 150; |
1407 | /* |
1407 | /* |
1408 | #define CHK_MIN_INTERVAL(a,b) {if(a && a < b) a = b;} |
1408 | #define CHK_MIN_INTERVAL(a,b) {if(a && a < b) a = b;} |
1409 | UART1_NaviData_Interval = 500; |
1409 | UART1_NaviData_Interval = 500; |
1410 | CHK_MIN_INTERVAL(UART1_DebugData_Interval,500); |
1410 | CHK_MIN_INTERVAL(UART1_DebugData_Interval,500); |
1411 | CHK_MIN_INTERVAL(UART1_NaviData_Interval,1000); |
1411 | CHK_MIN_INTERVAL(UART1_NaviData_Interval,1000); |
1412 | CHK_MIN_INTERVAL(UART1_Data3D_Interval,255); |
1412 | CHK_MIN_INTERVAL(UART1_Data3D_Interval,255); |
1413 | CHK_MIN_INTERVAL(UART1_Display_Interval,1500); |
1413 | CHK_MIN_INTERVAL(UART1_Display_Interval,1500); |
1414 | CHK_MIN_INTERVAL(UART1_MotorData_Interval,750); |
1414 | CHK_MIN_INTERVAL(UART1_MotorData_Interval,750); |
1415 | */ |
1415 | */ |
1416 | UART1_Transmit(); // output pending bytes in tx buffer |
1416 | UART1_Transmit(); // output pending bytes in tx buffer |
1417 | if((UART1_tx_buffer.Locked == TRUE)) return; |
1417 | if((UART1_tx_buffer.Locked == TRUE)) return; |
1418 | 1418 | ||
1419 | if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE)) |
1419 | if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE)) |
1420 | { |
1420 | { |
1421 | s16 ParamValue; |
1421 | s16 ParamValue; |
1422 | NCParams_GetValue(UART1_Request_ParameterId, &ParamValue); |
1422 | NCParams_GetValue(UART1_Request_ParameterId, &ParamValue); |
1423 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request |
1423 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request |
1424 | UART1_Request_Parameter = FALSE; |
1424 | UART1_Request_Parameter = FALSE; |
1425 | } |
1425 | } |
1426 | else if(UART1_Request_MissonParameter && (UART1_tx_buffer.Locked == FALSE)) |
1426 | else if(UART1_Request_MissonParameter && (UART1_tx_buffer.Locked == FALSE)) |
1427 | { |
1427 | { |
1428 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_MissonParameter, sizeof(UART1_Request_MissonParameter), &WP_MissionParameter, sizeof(WP_MissionParameter)); // answer the param request |
1428 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_MissonParameter, sizeof(UART1_Request_MissonParameter), &WP_MissionParameter, sizeof(WP_MissionParameter)); // answer the param request |
1429 | UART1_Request_MissonParameter = 0; |
1429 | UART1_Request_MissonParameter = 0; |
1430 | } |
1430 | } |
1431 | else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE)) |
1431 | else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE)) |
1432 | { |
1432 | { |
1433 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request |
1433 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request |
1434 | Echo = 0; // reset echo value |
1434 | Echo = 0; // reset echo value |
1435 | UART1_Request_Echo = FALSE; |
1435 | UART1_Request_Echo = FALSE; |
1436 | } |
1436 | } |
1437 | else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE)) |
1437 | else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE)) |
1438 | { |
1438 | { |
1439 | u8 errorcode = FTP_ERROR_NONE; |
1439 | u8 errorcode = FTP_ERROR_NONE; |
1440 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) errorcode = FTP_ERROR_MOTOR_RUN; |
1440 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) errorcode = FTP_ERROR_MOTOR_RUN; |
1441 | else if (!Partition.IsValid) errorcode = FTP_ERROR_NO_SDCARD; |
1441 | else if (!Partition.IsValid) errorcode = FTP_ERROR_NO_SDCARD; |
1442 | 1442 | ||
1443 | if (!errorcode) CheckFTPCommand(UART1_Request_FTP); |
1443 | if (!errorcode) CheckFTPCommand(UART1_Request_FTP); |
1444 | else |
1444 | else |
1445 | { |
1445 | { |
1446 | u8 cmd = FTP_CMD_ERROR; |
1446 | u8 cmd = FTP_CMD_ERROR; |
1447 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &cmd, 1, &errorcode, 1); |
1447 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &cmd, 1, &errorcode, 1); |
1448 | } |
1448 | } |
1449 | 1449 | ||
1450 | UART1_Request_FTP = FALSE; |
1450 | UART1_Request_FTP = FALSE; |
1451 | } |
1451 | } |
1452 | else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
1452 | else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
1453 | { |
1453 | { |
1454 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint)); |
1454 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint)); |
1455 | UART1_Request_WritePoint = 0xFF; |
1455 | UART1_Request_WritePoint = 0xFF; |
1456 | } |
1456 | } |
1457 | else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE)) |
1457 | else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE)) |
1458 | { |
1458 | { |
1459 | u8 PointCount = PointList_GetCount(); |
1459 | u8 PointCount = PointList_GetCount(); |
1460 | if (UART1_Request_ReadPoint <= PointCount) |
1460 | if (UART1_Request_ReadPoint <= PointCount) |
1461 | { |
1461 | { |
1462 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t)); |
1462 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t)); |
1463 | } |
1463 | } |
1464 | else |
1464 | else |
1465 | { |
1465 | { |
1466 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount)); |
1466 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount)); |
1467 | } |
1467 | } |
1468 | UART1_Request_ReadPoint = 0; |
1468 | UART1_Request_ReadPoint = 0; |
1469 | } |
1469 | } |
1470 | else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
1470 | else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
1471 | { |
1471 | { |
1472 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16); |
1472 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16); |
1473 | UART1_Request_DebugLabel = 0xFF; |
1473 | UART1_Request_DebugLabel = 0xFF; |
1474 | } |
1474 | } |
1475 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1475 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1476 | //+ Mobile menu |
1476 | //+ Mobile menu |
1477 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1477 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1478 | else if((UART1_Request_MobileInfo) && (UART1_tx_buffer.Locked == FALSE)) // Infos |
1478 | else if((UART1_Request_MobileInfo) && (UART1_tx_buffer.Locked == FALSE)) // Infos |
1479 | { |
1479 | { |
1480 | u8 cmd = MOBILE_INFO; |
1480 | u8 cmd = MOBILE_INFO; |
1481 | MobileDataInfo.Count = MOBILE_MAX_MENU; |
1481 | MobileDataInfo.Count = MOBILE_MAX_MENU; |
1482 | MobileDataInfo.Compatibel = MOBILE_COMPATIBLITY; |
1482 | MobileDataInfo.Compatibel = MOBILE_COMPATIBLITY; |
1483 | MobileDataInfo.CheckSumLable = CRC16((unsigned char*)(&MobileLabel[0].MenuLabel[0]), sizeof(MobileLabel)); // update crc for the structure |
1483 | MobileDataInfo.CheckSumLable = CRC16((unsigned char*)(&MobileLabel[0].MenuLabel[0]), sizeof(MobileLabel)); // update crc for the structure |
1484 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'N', NC_ADDRESS, 2, &cmd ,1, &MobileDataInfo, sizeof(MobileDataInfo)); |
1484 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'N', NC_ADDRESS, 2, &cmd ,1, &MobileDataInfo, sizeof(MobileDataInfo)); |
1485 | UART1_Request_MobileInfo = 0; |
1485 | UART1_Request_MobileInfo = 0; |
1486 | } |
1486 | } |
1487 | else if((UART1_Request_MobileLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) // Lables |
1487 | else if((UART1_Request_MobileLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) // Lables |
1488 | { |
1488 | { |
1489 | u8 cmd = MOBILE_LABLE; |
1489 | u8 cmd = MOBILE_LABLE; |
1490 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'N', NC_ADDRESS, 3, &cmd ,1, &UART1_Request_MobileLabel, sizeof(UART1_Request_MobileLabel), (u8 *) &MobileLabel[UART1_Request_MobileLabel].MenuLabel[0], sizeof(MobileLabel_t)); |
1490 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'N', NC_ADDRESS, 3, &cmd ,1, &UART1_Request_MobileLabel, sizeof(UART1_Request_MobileLabel), (u8 *) &MobileLabel[UART1_Request_MobileLabel].MenuLabel[0], sizeof(MobileLabel_t)); |
1491 | UART1_Request_MobileLabel = 0xFF; |
1491 | UART1_Request_MobileLabel = 0xFF; |
1492 | } |
1492 | } |
1493 | else if((((UART1_Request_MobileMenu) && CheckDelay(UART1_MobileMenu_Timer)) || (UART1_Request_MobileMenu == 1)) && (UART1_tx_buffer.Locked == FALSE)) // menu |
1493 | else if((((UART1_Request_MobileMenu) && CheckDelay(UART1_MobileMenu_Timer)) || (UART1_Request_MobileMenu == 1)) && (UART1_tx_buffer.Locked == FALSE)) // menu |
1494 | { |
1494 | { |
1495 | u8 cmd = MOBILE_MENU, event; |
1495 | u8 cmd = MOBILE_MENU, event; |
1496 | static u16 lastcrc = 0; |
1496 | static u16 lastcrc = 0; |
1497 | u16 crc; |
1497 | u16 crc; |
1498 | event = MobileDataRequest.Event; |
1498 | event = MobileDataRequest.Event; |
1499 | MobileMenuUpdate(MobileDataRequest.MenuItem,event,MobileDataRequest.Value); |
1499 | MobileMenuUpdate(MobileDataRequest.MenuItem,event,MobileDataRequest.Value); |
1500 | MobileDataRequest.Event = 0; |
1500 | MobileDataRequest.Event = 0; |
1501 | //++++ has the data changed ? +++++ |
1501 | //++++ has the data changed ? +++++ |
1502 | crc = CRC16((unsigned char*)(&Mobile), sizeof(Mobile_t)); |
1502 | crc = CRC16((unsigned char*)(&Mobile), sizeof(Mobile_t)); |
1503 | if(crc != lastcrc || UART1_Request_MobileMenu == 1) |
1503 | if(crc != lastcrc || UART1_Request_MobileMenu == 1) |
1504 | { |
1504 | { |
1505 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'N', NC_ADDRESS, 2, &cmd ,1, &Mobile, sizeof(Mobile_t)); |
1505 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'N', NC_ADDRESS, 2, &cmd ,1, &Mobile, sizeof(Mobile_t)); |
1506 | lastcrc = crc; |
1506 | lastcrc = crc; |
1507 | } |
1507 | } |
1508 | //+++++++++++++++++++++++++++++++++ |
1508 | //+++++++++++++++++++++++++++++++++ |
1509 | if(++UART1_Request_MobileMenu >= 16) UART1_Request_MobileMenu = 0; |
1509 | if(++UART1_Request_MobileMenu >= 16) UART1_Request_MobileMenu = 0; |
1510 | else UART1_MobileMenu_Timer = SetDelay(500); |
1510 | else UART1_MobileMenu_Timer = SetDelay(500); |
1511 | } |
1511 | } |
1512 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1512 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1513 | else if(UART1_ExternalControlConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
1513 | else if(UART1_ExternalControlConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
1514 | { |
1514 | { |
1515 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1,(u8 *)&UART1_ExternalControlConfirmFrame, sizeof(UART1_ExternalControlConfirmFrame)); |
1515 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1,(u8 *)&UART1_ExternalControlConfirmFrame, sizeof(UART1_ExternalControlConfirmFrame)); |
1516 | UART1_ExternalControlConfirmFrame = 0; |
1516 | UART1_ExternalControlConfirmFrame = 0; |
1517 | } |
1517 | } |
1518 | else |
1518 | else |
1519 | if((UART1_NaviData_Interval > 0) && Out1TriggerUpdateNewData && UART1_NaviData_MaxBytes > 200) // (only if the data link can transmit more than 200Bytes per secons) -> it wouldn't fit into the data-flow if there are too few bytes available |
1519 | if((UART1_NaviData_Interval > 0) && Out1TriggerUpdateNewData && UART1_NaviData_MaxBytes > 200) // (only if the data link can transmit more than 200Bytes per secons) -> it wouldn't fit into the data-flow if there are too few bytes available |
1520 | { |
1520 | { |
1521 | //sent += |
1521 | //sent += |
1522 | SendTriggerPos(); // dann passen die 35 Bytes noch ohne Verzögerung |
1522 | SendTriggerPos(); // dann passen die 35 Bytes noch ohne Verzögerung |
1523 | } |
1523 | } |
1524 | else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE)) |
1524 | else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE)) |
1525 | { |
1525 | { |
1526 | u16 time = 0; |
1526 | u16 time = 0; |
1527 | //UART1_NaviData_MaxBytes = 250; |
1527 | //UART1_NaviData_MaxBytes = 250; |
1528 | if(UART1_NaviData_MaxBytes == 0) // Transmit the big NC Data frame |
1528 | if(UART1_NaviData_MaxBytes == 0) // Transmit the big NC Data frame |
1529 | { |
1529 | { |
1530 | NaviData.Errorcode = ErrorCode; |
1530 | NaviData.Errorcode = ErrorCode; |
1531 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData, sizeof(NaviData)); |
1531 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData, sizeof(NaviData)); |
1532 | LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2; |
1532 | LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2; |
1533 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval); |
1533 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval); |
1534 | } |
1534 | } |
1535 | else |
1535 | else |
1536 | if(CheckDelay(UART1_NaviData_Timer)) |
1536 | if(CheckDelay(UART1_NaviData_Timer)) |
1537 | { |
1537 | { |
1538 | // Wert = 50 -> Sekunden laufen in 2 s-Abstand (im Wegpunkteflug mit aktivem Countdown in 3-4s) |
1538 | // Wert = 50 -> Sekunden laufen in 2 s-Abstand (im Wegpunkteflug mit aktivem Countdown in 3-4s) |
1539 | // Wert = 100 -> Sekunden laufen in 1-2 s-Abstand (im Wegpunkteflug mit aktivem Countdown in 2s) |
1539 | // Wert = 100 -> Sekunden laufen in 1-2 s-Abstand (im Wegpunkteflug mit aktivem Countdown in 2s) |
1540 | // Wert = 150 -> Sekunden laufen flüssig (im Wegpunkteflug mit aktivem Countdown und gleichzeitig Target verschieben manchmal in 2s) |
1540 | // Wert = 150 -> Sekunden laufen flüssig (im Wegpunkteflug mit aktivem Countdown und gleichzeitig Target verschieben manchmal in 2s) |
1541 | // Wert = 200 -> Sekunden laufen flüssig |
1541 | // Wert = 200 -> Sekunden laufen flüssig |
1542 | // Wert >= 250 -> optimal |
1542 | // Wert >= 250 -> optimal |
1543 | //UART1_NaviData_MaxBytes = 45; |
1543 | //UART1_NaviData_MaxBytes = 45; |
1544 | time = TransmitNavigationData(UART1_NaviData_MaxBytes,0); |
1544 | time = TransmitNavigationData(UART1_NaviData_MaxBytes,0); |
1545 | if(UART1_NaviData_Interval > time) time = UART1_NaviData_Interval; |
1545 | if(UART1_NaviData_Interval > time) time = UART1_NaviData_Interval; |
1546 | UART1_NaviData_Timer = SetDelay(time); |
1546 | UART1_NaviData_Timer = SetDelay(time); |
1547 | } |
1547 | } |
1548 | UART1_Request_NaviData = FALSE; |
1548 | UART1_Request_NaviData = FALSE; |
1549 | } |
1549 | } |
1550 | else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE)) |
1550 | else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE)) |
1551 | { |
1551 | { |
1552 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
1552 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
1553 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
1553 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
1554 | UART1_Request_DebugData = FALSE; |
1554 | UART1_Request_DebugData = FALSE; |
1555 | } |
1555 | } |
1556 | else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE)) |
1556 | else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE)) |
1557 | { |
1557 | { |
1558 | Data3D.StickNick = FC.StickNick; |
1558 | Data3D.StickNick = FC.StickNick; |
1559 | Data3D.StickRoll = FC.StickRoll; |
1559 | Data3D.StickRoll = FC.StickRoll; |
1560 | Data3D.StickYaw = FC.StickYaw; |
1560 | Data3D.StickYaw = FC.StickYaw; |
1561 | Data3D.StickGas = FC.StickGas; |
1561 | Data3D.StickGas = FC.StickGas; |
1562 | Data3D.AngleNick = FromFlightCtrl.AngleNick; // in 0.1 deg |
1562 | Data3D.AngleNick = FromFlightCtrl.AngleNick; // in 0.1 deg |
1563 | Data3D.AngleRoll = FromFlightCtrl.AngleRoll; // in 0.1 deg |
1563 | Data3D.AngleRoll = FromFlightCtrl.AngleRoll; // in 0.1 deg |
1564 | Data3D.Heading = FromFlightCtrl.GyroHeading; // in 0.1 deg |
1564 | Data3D.Heading = FromFlightCtrl.GyroHeading; // in 0.1 deg |
1565 | Data3D.Altimeter_5cm = FC.Altimeter_5cm; // in 5cm -> 20 = 1m |
1565 | Data3D.Altimeter_5cm = FC.Altimeter_5cm; // in 5cm -> 20 = 1m |
1566 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
1566 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
1567 | UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval); |
1567 | UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval); |
1568 | UART1_Request_Data3D = FALSE; |
1568 | UART1_Request_Data3D = FALSE; |
1569 | } |
1569 | } |
1570 | else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE)) |
1570 | else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE)) |
1571 | { |
1571 | { |
1572 | do |
1572 | do |
1573 | { |
1573 | { |
1574 | motorindex1++; |
1574 | motorindex1++; |
1575 | motorindex1%=12; |
1575 | motorindex1%=12; |
1576 | if(!motorindex1) {motorindex2++; motorindex2 %= 12;}; |
1576 | if(!motorindex1) {motorindex2++; motorindex2 %= 12;}; |
1577 | if(motorindex1 == motorindex2) break; |
1577 | if(motorindex1 == motorindex2) break; |
1578 | } |
1578 | } |
1579 | while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors |
1579 | while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors |
1580 | 1580 | ||
1581 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t)); |
1581 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t)); |
1582 | UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval); |
1582 | UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval); |
1583 | UART1_Request_MotorData = FALSE; |
1583 | UART1_Request_MotorData = FALSE; |
1584 | } |
1584 | } |
1585 | else if(UART1_Request_WPLStore) |
1585 | else if(UART1_Request_WPLStore) |
1586 | { |
1586 | { |
1587 | /* |
1587 | /* |
1588 | s8 txt[50]; |
1588 | s8 txt[50]; |
1589 | sprintf(txt, "\r\nWPL Overwride = %d, Type = %d, Index = %d, Status = %d\r\n", WPL_Store.OverwriteFile, WPL_Store.Type, WPL_Answer.Index, WPL_Answer.Status); |
1589 | sprintf(txt, "\r\nWPL Overwride = %d, Type = %d, Index = %d, Status = %d\r\n", WPL_Store.OverwriteFile, WPL_Store.Type, WPL_Answer.Index, WPL_Answer.Status); |
1590 | UART1_PutString(txt); |
1590 | UART1_PutString(txt); |
1591 | */ |
1591 | */ |
1592 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'I', NC_ADDRESS, 1,(u8 *)&(WPL_Answer), sizeof(WPL_Answer_t)); |
1592 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'I', NC_ADDRESS, 1,(u8 *)&(WPL_Answer), sizeof(WPL_Answer_t)); |
1593 | UART1_Request_WPLStore = FALSE; |
1593 | UART1_Request_WPLStore = FALSE; |
1594 | } |
1594 | } |
1595 | else if((((NMEA_Interval > 0) && CheckDelay(NMEA_Timer))) && (UART1_tx_buffer.Locked == FALSE)) |
1595 | else if((((NMEA_Interval > 0) && CheckDelay(NMEA_Timer))) && (UART1_tx_buffer.Locked == FALSE)) |
1596 | { |
1596 | { |
1597 | CreateNmeaGGA(); |
1597 | CreateNmeaGGA(); |
1598 | Send_NMEA_RMC = TRUE; // das muss noch da hinter |
1598 | Send_NMEA_RMC = TRUE; // das muss noch da hinter |
1599 | NMEA_Timer = SetDelay(NMEA_Interval); |
1599 | NMEA_Timer = SetDelay(NMEA_Interval); |
1600 | } |
1600 | } |
1601 | else if(Send_NMEA_RMC == TRUE && (UART1_tx_buffer.Locked == FALSE)) |
1601 | else if(Send_NMEA_RMC == TRUE && (UART1_tx_buffer.Locked == FALSE)) |
1602 | { |
1602 | { |
1603 | CreateNmeaRMC(); |
1603 | CreateNmeaRMC(); |
1604 | Send_NMEA_RMC = FALSE; |
1604 | Send_NMEA_RMC = FALSE; |
1605 | } |
1605 | } |
1606 | else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
1606 | else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
1607 | { |
1607 | { |
1608 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame)); |
1608 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame)); |
1609 | UART1_ConfirmFrame = 0; |
1609 | UART1_ConfirmFrame = 0; |
1610 | } |
1610 | } |
1611 | else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE)) |
1611 | else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE)) |
1612 | { |
1612 | { |
1613 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
1613 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
1614 | UART1_Request_ExternalControl = FALSE; |
1614 | UART1_Request_ExternalControl = FALSE; |
1615 | } |
1615 | } |
1616 | else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE)) |
1616 | else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE)) |
1617 | { |
1617 | { |
1618 | if(UART1_DisplayLine > 3) |
1618 | if(UART1_DisplayLine > 3) |
1619 | { |
1619 | { |
1620 | Menu_Update(UART1_DisplayKeys); |
1620 | Menu_Update(UART1_DisplayKeys); |
1621 | UART1_DisplayKeys = 0; |
1621 | UART1_DisplayKeys = 0; |
1622 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff)); |
1622 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff)); |
1623 | } |
1623 | } |
1624 | else |
1624 | else |
1625 | { |
1625 | { |
1626 | UART1_DisplayLine = 2; |
1626 | UART1_DisplayLine = 2; |
1627 | sprintf(text,"!!! incompatible !!!"); |
1627 | sprintf(text,"!!! incompatible !!!"); |
1628 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20); |
1628 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20); |
1629 | if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0; |
1629 | if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0; |
1630 | } |
1630 | } |
1631 | UART1_Display_Timer = SetDelay(UART1_Display_Interval); |
1631 | UART1_Display_Timer = SetDelay(UART1_Display_Interval); |
1632 | UART1_Request_Display = FALSE; |
1632 | UART1_Request_Display = FALSE; |
1633 | } |
1633 | } |
1634 | else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE)) |
1634 | else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE)) |
1635 | { |
1635 | { |
1636 | Menu_Update(0); |
1636 | Menu_Update(0); |
1637 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
1637 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
1638 | UART1_Request_Display1 = FALSE; |
1638 | UART1_Request_Display1 = FALSE; |
1639 | } |
1639 | } |
1640 | else if(UART1_Request_VersionInfo == 1 && (UART1_tx_buffer.Locked == FALSE)) // get FC-Versions |
1640 | else if(UART1_Request_VersionInfo == 1 && (UART1_tx_buffer.Locked == FALSE)) // get FC-Versions |
1641 | { |
1641 | { |
1642 | UART_VersionInfo_t version_tmp; |
1642 | UART_VersionInfo_t version_tmp; |
1643 | version_tmp.SWMajor = FC_Version.Major; |
1643 | version_tmp.SWMajor = FC_Version.Major; |
1644 | version_tmp.SWMinor = FC_Version.Minor; |
1644 | version_tmp.SWMinor = FC_Version.Minor; |
1645 | version_tmp.SWPatch = FC_Version.Patch; |
1645 | version_tmp.SWPatch = FC_Version.Patch; |
1646 | version_tmp.HWMajor = FC_Version.Hardware; |
1646 | version_tmp.HWMajor = FC_Version.Hardware; |
1647 | version_tmp.HardwareError[0] = 0xff; // tells the KopterTool that it is the FC-version |
1647 | version_tmp.HardwareError[0] = 0xff; // tells the KopterTool that it is the FC-version |
1648 | version_tmp.HardwareError[1] = 0xff; // tells the KopterTool that it is the FC-version |
1648 | version_tmp.HardwareError[1] = 0xff; // tells the KopterTool that it is the FC-version |
1649 | version_tmp.ProtoMajor = UART_VersionInfo.ProtoMajor; |
1649 | version_tmp.ProtoMajor = UART_VersionInfo.ProtoMajor; |
1650 | version_tmp.BL_Firmware = UART_VersionInfo.BL_Firmware; |
1650 | version_tmp.BL_Firmware = UART_VersionInfo.BL_Firmware; |
1651 | version_tmp.Flags = 0; |
1651 | version_tmp.Flags = 0; |
1652 | version_tmp.LabelTextCRC = 0;//UART_VersionInfo.DebugTextCRC; |
1652 | version_tmp.LabelTextCRC = 0;//UART_VersionInfo.DebugTextCRC; |
1653 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&version_tmp, sizeof(version_tmp)); |
1653 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&version_tmp, sizeof(version_tmp)); |
1654 | UART1_Request_VersionInfo = FALSE; |
1654 | UART1_Request_VersionInfo = FALSE; |
1655 | } |
1655 | } |
1656 | else if(UART1_Request_VersionInfo == 2 && (UART1_tx_buffer.Locked == FALSE)) // get NC-Versions |
1656 | else if(UART1_Request_VersionInfo == 2 && (UART1_tx_buffer.Locked == FALSE)) // get NC-Versions |
1657 | { |
1657 | { |
1658 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
1658 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
1659 | UART1_Request_VersionInfo = FALSE; |
1659 | UART1_Request_VersionInfo = FALSE; |
1660 | } |
1660 | } |
1661 | else if(UART1_Request_SystemTime && (UART1_tx_buffer.Locked == FALSE)) |
1661 | else if(UART1_Request_SystemTime && (UART1_tx_buffer.Locked == FALSE)) |
1662 | { |
1662 | { |
1663 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'T', NC_ADDRESS,1, (u8 *)&SystemTime, sizeof(SystemTime)); |
1663 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'T', NC_ADDRESS,1, (u8 *)&SystemTime, sizeof(SystemTime)); |
1664 | UART1_Request_SystemTime = FALSE; |
1664 | UART1_Request_SystemTime = FALSE; |
1665 | } |
1665 | } |
1666 | else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE)) |
1666 | else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE)) |
1667 | { |
1667 | { |
1668 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
1668 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
1669 | UART1_Request_ErrorMessage = FALSE; |
1669 | UART1_Request_ErrorMessage = FALSE; |
1670 | } |
1670 | } |
1671 | else if(UART1_Request_PPM_Channels && (UART1_tx_buffer.Locked == FALSE)) |
1671 | else if(UART1_Request_PPM_Channels && (UART1_tx_buffer.Locked == FALSE)) |
1672 | { |
1672 | { |
1673 | s16 ppm_tmp[MAX_RC_IN], i; |
1673 | s16 ppm_tmp[MAX_RC_IN], i; |
1674 | for(i=0; i<MAX_RC_IN;i++) ppm_tmp[i] = PPM_In[i]; // because the serial Data expects s16 |
1674 | for(i=0; i<MAX_RC_IN;i++) ppm_tmp[i] = PPM_In[i]; // because the serial Data expects s16 |
1675 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'P', NC_ADDRESS, 1, (u8 *)&ppm_tmp, sizeof(ppm_tmp)); |
1675 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'P', NC_ADDRESS, 1, (u8 *)&ppm_tmp, sizeof(ppm_tmp)); |
1676 | UART1_Request_PPM_Channels = FALSE; |
1676 | UART1_Request_PPM_Channels = FALSE; |
1677 | } |
1677 | } |
1678 | else if(UART1_Request_LicenseString && (UART1_tx_buffer.Locked == FALSE)) |
1678 | else if(UART1_Request_LicenseString && (UART1_tx_buffer.Locked == FALSE)) |
1679 | { |
1679 | { |
1680 | u8 result = 1, cmd = 0; |
1680 | u8 result = 1, cmd = 0; |
1681 | if(UART1_Request_LicenseString == LIC_CMD_READ_LICENSE) |
1681 | if(UART1_Request_LicenseString == LIC_CMD_READ_LICENSE) |
1682 | { |
1682 | { |
1683 | result = LIC_CMD_READ_LICENSE; |
1683 | result = LIC_CMD_READ_LICENSE; |
1684 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 2, &result, 1, LicensePtr, LICENSE_SIZE); |
1684 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 2, &result, 1, LicensePtr, LICENSE_SIZE); |
1685 | } |
1685 | } |
1686 | else |
1686 | else |
1687 | if((UART1_Request_LicenseString == LIC_CMD_ERASE_LICENSE) && !(FC.StatusFlags & FC_STATUS_MOTOR_RUN) && (UART_VersionInfo.HWMajor >= 20)) |
1687 | if((UART1_Request_LicenseString == LIC_CMD_ERASE_LICENSE) && !(FC.StatusFlags & FC_STATUS_MOTOR_RUN) && (UART_VersionInfo.HWMajor >= 20)) |
1688 | { |
1688 | { |
1689 | result = LIC_CMD_ERASE_LICENSE; |
1689 | result = LIC_CMD_ERASE_LICENSE; |
1690 | DeleteLicenseInEEPROM(); |
1690 | DeleteLicenseInEEPROM(); |
1691 | CheckLicense(GET_LICENSE); |
1691 | CheckLicense(GET_LICENSE); |
1692 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 1, &result, 1); |
1692 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 1, &result, 1); |
1693 | } |
1693 | } |
1694 | else |
1694 | else |
1695 | if((UART1_Request_LicenseString == LIC_CMD_WRITE_LICENSE) && !(FC.StatusFlags & FC_STATUS_MOTOR_RUN) && (UART_VersionInfo.HWMajor >= 20)) |
1695 | if((UART1_Request_LicenseString == LIC_CMD_WRITE_LICENSE) && !(FC.StatusFlags & FC_STATUS_MOTOR_RUN) && (UART_VersionInfo.HWMajor >= 20)) |
1696 | { |
1696 | { |
1697 | cmd = LIC_CMD_WRITE_LICENSE; |
1697 | cmd = LIC_CMD_WRITE_LICENSE; |
1698 | if(CheckLicense(CHECK_ONLY)) //new license is okay |
1698 | if(CheckLicense(CHECK_ONLY)) //new license is okay |
1699 | { |
1699 | { |
1700 | WriteLicenseToEEPROM(EEPROM_LICENSE_DATA_KOMPATIBEL); |
1700 | WriteLicenseToEEPROM(EEPROM_LICENSE_DATA_KOMPATIBEL); |
1701 | result = 1; |
1701 | result = 1; |
1702 | } |
1702 | } |
1703 | else //new license is NOT okay |
1703 | else //new license is NOT okay |
1704 | { |
1704 | { |
1705 | ClearLicenseText(); |
1705 | ClearLicenseText(); |
1706 | result = 0; |
1706 | result = 0; |
1707 | CheckLicense(GET_LICENSE); // fetch a license if available |
1707 | CheckLicense(GET_LICENSE); // fetch a license if available |
1708 | } |
1708 | } |
1709 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 2, &cmd, 1,&result, 1 ); |
1709 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 2, &cmd, 1,&result, 1 ); |
1710 | } |
1710 | } |
1711 | UART1_Request_LicenseString = 0; |
1711 | UART1_Request_LicenseString = 0; |
1712 | } |
1712 | } |
1713 | #ifdef FOLLOW_ME |
1713 | #ifdef FOLLOW_ME |
1714 | else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE)) |
1714 | else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE)) |
1715 | { |
1715 | { |
1716 | if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4)) |
1716 | if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4)) |
1717 | { |
1717 | { |
1718 | TransmitAlsoToFC = 1; |
1718 | TransmitAlsoToFC = 1; |
1719 | // update FollowMe content |
1719 | // update FollowMe content |
1720 | FollowMe.Position.Longitude = GPSData.Position.Longitude; |
1720 | FollowMe.Position.Longitude = GPSData.Position.Longitude; |
1721 | FollowMe.Position.Latitude = GPSData.Position.Latitude; |
1721 | FollowMe.Position.Latitude = GPSData.Position.Latitude; |
1722 | FollowMe.Position.Status = NEWDATA; |
1722 | FollowMe.Position.Status = NEWDATA; |
1723 | FollowMe.Position.Altitude = 1; |
1723 | FollowMe.Position.Altitude = 1; |
1724 | // 0 -> no Orientation |
1724 | // 0 -> no Orientation |
1725 | // 1-360 -> CompassCourse Setpoint |
1725 | // 1-360 -> CompassCourse Setpoint |
1726 | // -1 -> points to WP1 -> itself |
1726 | // -1 -> points to WP1 -> itself |
1727 | FollowMe.Heading = -1; |
1727 | FollowMe.Heading = -1; |
1728 | FollowMe.ToleranceRadius = 1; |
1728 | FollowMe.ToleranceRadius = 1; |
1729 | FollowMe.HoldTime = 60; |
1729 | FollowMe.HoldTime = 60; |
1730 | FollowMe.Event_Flag = 1; |
1730 | FollowMe.Event_Flag = 1; |
1731 | FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list |
1731 | FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list |
1732 | FollowMe.Type = POINT_TYPE_WP; |
1732 | FollowMe.Type = POINT_TYPE_WP; |
1733 | FollowMe.WP_EventChannelValue = 100; // set servo value |
1733 | FollowMe.WP_EventChannelValue = 100; // set servo value |
1734 | FollowMe.AltitudeRate = 0; // do not change height |
1734 | FollowMe.AltitudeRate = 0; // do not change height |
1735 | FollowMe.Speed = 0; // rate to change the Position (0 = max) |
1735 | FollowMe.Speed = 0; // rate to change the Position (0 = max) |
1736 | FollowMe.CamAngle = 255; // Camera servo angle in degree (255 -> POI-Automatic) |
1736 | FollowMe.CamAngle = 255; // Camera servo angle in degree (255 -> POI-Automatic) |
1737 | FollowMe.Name[0] = 'F'; // Name of that point (ASCII) |
1737 | FollowMe.Name[0] = 'F'; // Name of that point (ASCII) |
1738 | FollowMe.Name[1] = 'O'; // Name of that point (ASCII) |
1738 | FollowMe.Name[1] = 'O'; // Name of that point (ASCII) |
1739 | FollowMe.Name[2] = 'L'; // Name of that point (ASCII) |
1739 | FollowMe.Name[2] = 'L'; // Name of that point (ASCII) |
1740 | FollowMe.Name[3] = 'L'; // Name of that point (ASCII) |
1740 | FollowMe.Name[3] = 'L'; // Name of that point (ASCII) |
1741 | FollowMe.reserve[0] = 0; // reserve |
1741 | FollowMe.reserve[0] = 0; // reserve |
1742 | FollowMe.reserve[1] = 0; // reserve |
1742 | FollowMe.reserve[1] = 0; // reserve |
1743 | /* |
1743 | /* |
1744 | { |
1744 | { |
1745 | static u32 distance; |
1745 | static u32 distance; |
1746 | distance = (10 + distance + AnalogData.Ch5 * 5) / 2; |
1746 | distance = (10 + distance + AnalogData.Ch5 * 5) / 2; |
1747 | |
1747 | |
1748 | GPSPos_ShiftGeodetic(&(FollowMe.Position), (s16)GyroCompassCorrected/10, distance); |
1748 | GPSPos_ShiftGeodetic(&(FollowMe.Position), (s16)GyroCompassCorrected/10, distance); |
1749 | FollowMe.Heading = (s16)GyroCompassCorrected/10; |
1749 | FollowMe.Heading = (s16)GyroCompassCorrected/10; |
1750 | FollowMe.CamAngle = 0; // Camera servo angle in degree (255 -> POI-Automatic) |
1750 | FollowMe.CamAngle = 0; // Camera servo angle in degree (255 -> POI-Automatic) |
1751 | FollowMe.Speed = 50 + GPSData.Speed_Ground / 10; |
1751 | FollowMe.Speed = 50 + GPSData.Speed_Ground / 10; |
1752 | } |
1752 | } |
1753 | */ |
1753 | */ |
1754 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe)); |
1754 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe)); |
1755 | } |
1755 | } |
1756 | UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time |
1756 | UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time |
1757 | } |
1757 | } |
1758 | #endif |
1758 | #endif |
1759 | #ifdef DEBUG // only include functions if DEBUG is defined |
1759 | #ifdef DEBUG // only include functions if DEBUG is defined |
1760 | else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE)) |
1760 | else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE)) |
1761 | { |
1761 | { |
1762 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug)); |
1762 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug)); |
1763 | SendDebugOutput = 0; |
1763 | SendDebugOutput = 0; |
1764 | } |
1764 | } |
1765 | #endif |
1765 | #endif |
1766 | UART1_Transmit(); // output pending bytes in tx buffer |
1766 | UART1_Transmit(); // output pending bytes in tx buffer |
1767 | } |
1767 | } |
1768 | 1768 | ||
1769 | 1769 |