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