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