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