Go to most recent revision | Details | 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 |
||
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
||
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
||
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 |
||
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
||
22 | // + des Mitverschuldens offen. |
||
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 - |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
||
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
||
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> |
||
57 | #include <stdarg.h> |
||
58 | #include <string.h> |
||
59 | |||
60 | #include "91x_lib.h" |
||
251 | killagreg | 61 | #include "main.h" |
136 | killagreg | 62 | #include "config.h" |
41 | ingob | 63 | #include "menu.h" |
64 | #include "GPS.h" |
||
65 | #include "i2c.h" |
||
66 | #include "uart0.h" |
||
67 | #include "uart1.h" |
||
68 | #include "uart2.h" |
||
119 | killagreg | 69 | #include "timer1.h" |
139 | killagreg | 70 | #include "timer2.h" |
71 | #include "analog.h" |
||
243 | killagreg | 72 | #include "compass.h" |
41 | ingob | 73 | #include "waypoints.h" |
110 | killagreg | 74 | #include "mkprotocol.h" |
156 | killagreg | 75 | #include "params.h" |
153 | killagreg | 76 | #include "fifo.h" |
315 | killagreg | 77 | #include "debug.h" |
358 | holgerb | 78 | #include "spi_slave.h" |
349 | ingob | 79 | #include "ftphelper.h" |
378 | holgerb | 80 | #include "led.h" |
433 | ingob | 81 | #include "fat16.h" |
41 | ingob | 82 | |
433 | ingob | 83 | |
41 | ingob | 84 | #define FALSE 0 |
85 | #define TRUE 1 |
||
86 | |||
351 | holgerb | 87 | #define ABO_TIMEOUT 8000 // disable abo after 8 seconds |
198 | killagreg | 88 | u32 UART1_AboTimeOut = 0; |
92 | killagreg | 89 | |
110 | killagreg | 90 | u8 UART1_Request_VersionInfo = FALSE; |
91 | u8 UART1_Request_ExternalControl= FALSE; |
||
92 | u8 UART1_Request_Display = FALSE; |
||
93 | u8 UART1_Request_Display1 = FALSE; |
||
94 | u8 UART1_Request_DebugData = FALSE; |
||
95 | u8 UART1_Request_DebugLabel = 255; |
||
96 | u8 UART1_Request_NaviData = FALSE; |
||
97 | u8 UART1_Request_ErrorMessage = FALSE; |
||
295 | killagreg | 98 | u8 UART1_Request_WritePoint = 0xFF; |
280 | killagreg | 99 | u8 UART1_Request_ReadPoint = 0; |
110 | killagreg | 100 | u8 UART1_Request_Data3D = FALSE; |
358 | holgerb | 101 | u8 UART1_Request_MotorData = FALSE; |
110 | killagreg | 102 | u8 UART1_Request_Echo = FALSE; |
156 | killagreg | 103 | u8 UART1_Request_ParameterId = 0; |
158 | killagreg | 104 | u8 UART1_Request_Parameter = FALSE; |
447 | holgerb | 105 | u8 UART1_Request_SystemTime = FALSE; |
201 | killagreg | 106 | u8 UART1_DisplayKeys = 0; |
112 | killagreg | 107 | u8 UART1_DisplayLine = 0; |
108 | u8 UART1_ConfirmFrame = 0; |
||
349 | ingob | 109 | u8 UART1_Request_FTP = FALSE; |
360 | holgerb | 110 | u8 LastTransmittedFCStatusFlags2 = 0; |
398 | holgerb | 111 | u8 UART1_ExternalControlConfirmFrame = FALSE; |
41 | ingob | 112 | |
113 | UART_TypeDef *DebugUART = UART1; |
||
114 | |||
314 | killagreg | 115 | #ifdef FOLLOW_ME |
116 | #define FOLLOW_ME_INTERVAL 200 // 5 Hz |
||
315 | killagreg | 117 | u32 UART1_FollowMe_Timer = 0; |
314 | killagreg | 118 | Point_t FollowMe; |
119 | #endif |
||
120 | |||
153 | killagreg | 121 | // the primary rx fifo |
378 | holgerb | 122 | #define UART1_RX_FIFO_LEN 1024 |
153 | killagreg | 123 | u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN]; |
124 | fifo_t UART1_rx_fifo; |
||
110 | killagreg | 125 | |
126 | // the rx buffer |
||
378 | holgerb | 127 | #define UART1_RX_BUFFER_LEN 1024 |
110 | killagreg | 128 | u8 UART1_rbuffer[UART1_RX_BUFFER_LEN]; |
129 | Buffer_t UART1_rx_buffer; |
||
130 | |||
153 | killagreg | 131 | // the tx buffer |
349 | ingob | 132 | #define UART1_TX_BUFFER_LEN 1024 |
153 | killagreg | 133 | u8 UART1_tbuffer[UART1_TX_BUFFER_LEN]; |
134 | Buffer_t UART1_tx_buffer; |
||
135 | |||
92 | killagreg | 136 | volatile u8 SerialLinkOkay = 0; |
41 | ingob | 137 | |
150 | killagreg | 138 | u8 text[200]; |
41 | ingob | 139 | |
140 | const u8 ANALOG_LABEL[32][16] = |
||
141 | { |
||
90 | killagreg | 142 | //1234567890123456 |
41 | ingob | 143 | "AngleNick ", //0 |
144 | "AngleRoll ", |
||
145 | "AccNick ", |
||
146 | "AccRoll ", |
||
214 | killagreg | 147 | "OperatingRadius ", |
200 | killagreg | 148 | "FC-Flags ", //5 |
95 | killagreg | 149 | "NC-Flags ", |
121 | killagreg | 150 | "NickServo ", |
151 | "RollServo ", |
||
41 | ingob | 152 | "GPS Data ", |
61 | holgerb | 153 | "CompassHeading ", //10 |
154 | "GyroHeading ", |
||
419 | holgerb | 155 | "SPI Error ", // achtung: muss auf 12 bleiben |
41 | ingob | 156 | "SPI Okay ", |
189 | killagreg | 157 | "I2C Error ", |
41 | ingob | 158 | "I2C Okay ", //15 |
339 | holgerb | 159 | "16 ", |
437 | holgerb | 160 | "17 ", |
161 | "18 ", |
||
162 | "19 ", // SD-Card-time |
||
330 | holgerb | 163 | "EarthMagnet [%] ", //20 |
338 | holgerb | 164 | "Z_Speed ", |
165 | "N_Speed ", |
||
166 | "E_Speed ", |
||
310 | holgerb | 167 | "Magnet X ", |
338 | holgerb | 168 | "Magnet Y ", //25 |
310 | holgerb | 169 | "Magnet Z ", |
41 | ingob | 170 | "Distance N ", |
171 | "Distance E ", |
||
172 | "GPS_Nick ", |
||
173 | "GPS_Roll ", //30 |
||
174 | "Used_Sats " |
||
175 | }; |
||
176 | |||
112 | killagreg | 177 | DebugOut_t DebugOut; |
178 | ExternControl_t ExternControl; |
||
179 | UART_VersionInfo_t UART_VersionInfo; |
||
180 | NaviData_t NaviData; |
||
181 | Data3D_t Data3D; |
||
182 | u16 Echo; // 2 bytes recieved will be sent back as echo |
||
41 | ingob | 183 | |
193 | killagreg | 184 | u32 UART1_DebugData_Timer = 0; |
198 | killagreg | 185 | u32 UART1_DebugData_Interval = 0; // in ms |
193 | killagreg | 186 | u32 UART1_NaviData_Timer = 0; |
198 | killagreg | 187 | u32 UART1_NaviData_Interval = 0; // in ms |
188 | u32 UART1_Data3D_Timer = 0; |
||
189 | u32 UART1_Data3D_Interval = 0; // in ms |
||
358 | holgerb | 190 | u32 UART1_MotorData_Timer = 0; |
191 | u32 UART1_MotorData_Interval = 0; // in ms |
||
193 | killagreg | 192 | u32 UART1_Display_Timer = 0; |
201 | killagreg | 193 | u32 UART1_Display_Interval = 0; // in ms |
112 | killagreg | 194 | |
41 | ingob | 195 | /********************************************************/ |
196 | /* Initialization the UART1 */ |
||
197 | /********************************************************/ |
||
198 | void UART1_Init (void) |
||
199 | { |
||
200 | GPIO_InitTypeDef GPIO_InitStructure; |
||
201 | UART_InitTypeDef UART_InitStructure; |
||
202 | |||
153 | killagreg | 203 | // initialize txd buffer |
204 | Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN); |
||
165 | killagreg | 205 | |
153 | killagreg | 206 | // initialize rxd buffer |
207 | Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN); |
||
208 | |||
244 | killagreg | 209 | // initialize the rx fifo, block UART IRQ geting a byte from fifo |
210 | fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine); |
||
153 | killagreg | 211 | |
41 | ingob | 212 | SCU_APBPeriphClockConfig(__UART1, ENABLE); // Enable the UART1 Clock |
213 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
||
214 | |||
215 | /*Configure UART1_Rx pin GPIO3.2*/ |
||
216 | GPIO_StructInit(&GPIO_InitStructure); |
||
217 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
||
218 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
||
219 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
||
196 | killagreg | 220 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
41 | ingob | 221 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART1_RxD |
222 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
||
223 | |||
224 | /*Configure UART1_Tx pin GPIO3.3*/ |
||
225 | GPIO_StructInit(&GPIO_InitStructure); |
||
226 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
||
227 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
||
228 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
||
229 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART1_TX |
||
230 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
||
231 | |||
232 | /* UART1 configured as follow: |
||
233 | - Word Length = 8 Bits |
||
234 | - One Stop Bit |
||
235 | - No parity |
||
236 | - BaudRate = 57600 baud |
||
237 | - Hardware flow control Disabled |
||
238 | - Receive and transmit enabled |
||
239 | - Receive and transmit FIFOs are Disabled |
||
240 | */ |
||
241 | UART_StructInit(&UART_InitStructure); |
||
242 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
||
243 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
||
244 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
||
110 | killagreg | 245 | UART_InitStructure.UART_BaudRate = UART1_BAUD_RATE; |
41 | ingob | 246 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
247 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
||
248 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
||
249 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
||
139 | killagreg | 250 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
41 | ingob | 251 | |
252 | UART_DeInit(UART1); // reset uart 1 to default |
||
165 | killagreg | 253 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
41 | ingob | 254 | // enable uart 1 interrupts selective |
255 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
||
256 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
||
136 | killagreg | 257 | // configure the uart 1 interupt line |
258 | VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1); |
||
244 | killagreg | 259 | // enable the uart 1 IRQ |
41 | ingob | 260 | VIC_ITCmd(UART1_ITLine, ENABLE); |
153 | killagreg | 261 | |
41 | ingob | 262 | // initialize the debug timer |
110 | killagreg | 263 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
264 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500; |
||
265 | |||
41 | ingob | 266 | // Fill Version Info Structure |
267 | UART_VersionInfo.SWMajor = VERSION_MAJOR; |
||
268 | UART_VersionInfo.SWMinor = VERSION_MINOR; |
||
269 | UART_VersionInfo.SWPatch = VERSION_PATCH; |
||
270 | UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
||
271 | UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
||
454 | holgerb | 272 | UART_VersionInfo.HWMajor = Version_HW; |
273 | UART_VersionInfo.reserved2 = 0; |
||
274 | UART_VersionInfo.Flags = 0; |
||
89 | killagreg | 275 | NaviData.Version = NAVIDATA_VERSION; |
92 | killagreg | 276 | |
212 | killagreg | 277 | UART1_PutString("\r\n UART1 init...ok"); |
41 | ingob | 278 | } |
279 | |||
280 | |||
281 | /****************************************************************/ |
||
282 | /* USART1 receiver ISR */ |
||
283 | /****************************************************************/ |
||
284 | void UART1_IRQHandler(void) |
||
285 | { |
||
286 | static u8 abortState = 0; |
||
287 | u8 c; |
||
288 | |||
289 | if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) ) |
||
290 | { |
||
153 | killagreg | 291 | // clear the pending bits! |
41 | ingob | 292 | UART_ClearITPendingBit(UART1, UART_IT_Receive); |
293 | UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut); |
||
294 | // if debug UART is not UART1 |
||
295 | if (DebugUART != UART1) |
||
296 | { // forward received data to the debug UART tx buffer |
||
297 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
||
298 | { |
||
299 | // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART |
||
300 | c = UART_ReceiveData(UART1); |
||
301 | |||
302 | // check for abort condition (ESC ESC 0x55 0xAA 0x00) |
||
303 | switch (abortState) |
||
304 | { |
||
165 | killagreg | 305 | case 0: |
139 | killagreg | 306 | if (c == 27) abortState++; |
41 | ingob | 307 | break; |
165 | killagreg | 308 | case 1: |
309 | if (c == 27) abortState++; |
||
139 | killagreg | 310 | else abortState = 0; |
41 | ingob | 311 | break; |
139 | killagreg | 312 | case 2: |
165 | killagreg | 313 | if (c == 0x55) abortState++; |
139 | killagreg | 314 | else abortState = 0; |
41 | ingob | 315 | break; |
139 | killagreg | 316 | case 3: |
317 | if (c == 0xAA) abortState++; |
||
318 | else abortState = 0; |
||
41 | ingob | 319 | break; |
165 | killagreg | 320 | case 4: |
139 | killagreg | 321 | if (c == 0x00) |
322 | { |
||
323 | if(DebugUART == UART0) |
||
324 | { |
||
245 | killagreg | 325 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); |
179 | killagreg | 326 | TIMER2_Init(); // enbable servo outputs |
153 | killagreg | 327 | fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer |
139 | killagreg | 328 | } |
329 | DebugUART = UART1; |
||
165 | killagreg | 330 | } |
139 | killagreg | 331 | abortState = 0; |
332 | break; |
||
333 | } // end switch abort state |
||
136 | killagreg | 334 | // if the Debug uart is not UART1, redirect input to the Debug UART |
110 | killagreg | 335 | if (DebugUART != UART1) |
336 | { |
||
337 | // wait for space in the tx buffer of the DebugUART |
||
338 | while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {}; |
||
141 | killagreg | 339 | // move byte to the tx fifo of the debug uart |
110 | killagreg | 340 | UART_SendData(DebugUART, c); |
341 | } |
||
41 | ingob | 342 | } |
343 | } |
||
344 | else // DebugUART == UART1 (normal operation) |
||
345 | { |
||
110 | killagreg | 346 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
154 | killagreg | 347 | { // some byes in the hardware fifo |
153 | killagreg | 348 | // get byte from hardware fifo |
41 | ingob | 349 | c = UART_ReceiveData(UART1); |
153 | killagreg | 350 | // put into the software fifo |
351 | if(!fifo_put(&UART1_rx_fifo, c)) |
||
352 | { // fifo overflow |
||
155 | killagreg | 353 | //fifo_purge(&UART1_rx_fifo); // flush the whole buffer |
153 | killagreg | 354 | } |
154 | killagreg | 355 | } // EOF while some byes in the hardware fifo |
41 | ingob | 356 | } // eof DebugUart = UART1 |
357 | } |
||
195 | killagreg | 358 | |
380 | holgerb | 359 | |
360 | |||
378 | holgerb | 361 | VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register |
41 | ingob | 362 | } |
363 | |||
364 | /**************************************************************/ |
||
365 | /* Process incomming data from debug uart */ |
||
366 | /**************************************************************/ |
||
367 | void UART1_ProcessRxData(void) |
||
368 | { |
||
154 | killagreg | 369 | // return on forwarding uart or unlocked rx buffer |
380 | holgerb | 370 | u8 c; |
155 | killagreg | 371 | if(DebugUART != UART1) return; |
372 | // if rx buffer is not locked |
||
373 | if(UART1_rx_buffer.Locked == FALSE) |
||
315 | killagreg | 374 | { |
244 | killagreg | 375 | //collect data from primary rx fifo |
155 | killagreg | 376 | while(fifo_get(&UART1_rx_fifo, &c)) |
315 | killagreg | 377 | { |
244 | killagreg | 378 | // break if complete frame is collected |
155 | killagreg | 379 | if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break; |
380 | } |
||
381 | } |
||
382 | if(UART1_rx_buffer.Locked == FALSE) return; |
||
383 | |||
280 | killagreg | 384 | Point_t * pPoint = NULL; |
153 | killagreg | 385 | SerialMsg_t SerialMsg; |
41 | ingob | 386 | |
190 | killagreg | 387 | // analyze header first |
388 | MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg); |
||
194 | killagreg | 389 | if( SerialMsg.Address == FC_ADDRESS ) |
41 | ingob | 390 | { |
192 | killagreg | 391 | switch(SerialMsg.CmdID) |
392 | { |
||
231 | holgerb | 393 | // case 'v': // version |
398 | holgerb | 394 | case 'b': // extern control |
395 | UART1_ExternalControlConfirmFrame = 1; |
||
192 | killagreg | 396 | case 'y': // serial poti values |
397 | Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC |
||
398 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
||
194 | killagreg | 399 | return; //end process rx data |
192 | killagreg | 400 | break; |
401 | } |
||
195 | killagreg | 402 | } |
190 | killagreg | 403 | |
404 | MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
||
405 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
||
406 | switch(SerialMsg.Address) // check for Slave Address |
||
407 | { |
||
41 | ingob | 408 | case NC_ADDRESS: // own Slave Address |
190 | killagreg | 409 | switch(SerialMsg.CmdID) |
41 | ingob | 410 | { |
447 | holgerb | 411 | case 't': // request for the GPS time |
412 | UART1_Request_SystemTime = TRUE; |
||
413 | break; |
||
414 | |||
349 | ingob | 415 | case 'f': // ftp command |
416 | UART1_Request_FTP = SerialMsg.pData[0]; |
||
417 | //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE) |
||
418 | memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter |
||
419 | break; |
||
420 | |||
101 | holgerb | 421 | case 'z': // connection checker |
110 | killagreg | 422 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
423 | UART1_Request_Echo = TRUE; |
||
92 | killagreg | 424 | break; |
425 | |||
41 | ingob | 426 | case 'e': // request for the text of the error status |
110 | killagreg | 427 | UART1_Request_ErrorMessage = TRUE; |
41 | ingob | 428 | break; |
429 | |||
430 | case 's':// new target position |
||
280 | killagreg | 431 | pPoint = (Point_t*)SerialMsg.pData; |
432 | if(pPoint->Position.Status == NEWDATA) |
||
41 | ingob | 433 | { |
315 | killagreg | 434 | //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list |
300 | holgerb | 435 | //pPoint->Index = 1; // must be one after empty list |
296 | killagreg | 436 | PointList_SetAt(pPoint); |
315 | killagreg | 437 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
295 | killagreg | 438 | GPS_pWaypoint = PointList_WPBegin(); // updates POI index |
302 | holgerb | 439 | if(GPS_pWaypoint != NULL) // if new WP exist |
440 | { // update WP hold time stamp immediately! |
||
451 | holgerb | 441 | EnableNewWpHeading(); |
302 | holgerb | 442 | /* if(GPS_pWaypoint->Heading > 0 && GPS_pWaypoint->Heading <= 360) |
443 | { |
||
444 | CAM_Orientation.Azimuth = GPS_pWaypoint->Heading; |
||
445 | CAM_Orientation.UpdateMask |= CAM_UPDATE_AZIMUTH; |
||
446 | } |
||
447 | */ |
||
448 | } |
||
295 | killagreg | 449 | BeepTime = 50; |
41 | ingob | 450 | } |
451 | break; |
||
452 | |||
453 | case 'u': // redirect debug uart |
||
110 | killagreg | 454 | switch(SerialMsg.pData[0]) |
41 | ingob | 455 | { |
456 | case UART_FLIGHTCTRL: |
||
457 | UART2_Init(); // initialize UART2 to FC pins |
||
153 | killagreg | 458 | fifo_purge(&UART1_rx_fifo); |
180 | killagreg | 459 | TIMER2_Deinit(); // reduce irq load |
41 | ingob | 460 | DebugUART = UART2; |
461 | break; |
||
462 | case UART_MK3MAG: |
||
255 | killagreg | 463 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running |
41 | ingob | 464 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
465 | GPSData.Status = INVALID; |
||
153 | killagreg | 466 | fifo_purge(&UART1_rx_fifo); |
41 | ingob | 467 | DebugUART = UART0; |
468 | break; |
||
469 | case UART_MKGPS: |
||
255 | killagreg | 470 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running |
179 | killagreg | 471 | TIMER2_Deinit(); // disable servo outputs to reduce irq load |
245 | killagreg | 472 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); // connect UART0 to MKGPS pins |
41 | ingob | 473 | GPSData.Status = INVALID; |
153 | killagreg | 474 | fifo_purge(&UART1_rx_fifo); |
41 | ingob | 475 | DebugUART = UART0; |
476 | break; |
||
153 | killagreg | 477 | default: |
478 | break; |
||
41 | ingob | 479 | } |
480 | break; |
||
481 | |||
295 | killagreg | 482 | case 'w':// Set point in list at index |
165 | killagreg | 483 | { |
280 | killagreg | 484 | pPoint = (Point_t*)SerialMsg.pData; |
224 | killagreg | 485 | |
280 | killagreg | 486 | if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0)) |
224 | killagreg | 487 | { |
280 | killagreg | 488 | PointList_Clear(); |
489 | GPS_pWaypoint = PointList_WPBegin(); |
||
315 | killagreg | 490 | UART1_Request_WritePoint = 0; // return new point count |
165 | killagreg | 491 | } |
227 | killagreg | 492 | else |
295 | killagreg | 493 | { // update WP in list at index |
351 | holgerb | 494 | if(pPoint->Index > MaxNumberOfWaypoints) |
495 | { |
||
496 | UART1_Request_WritePoint = 254; |
||
497 | pPoint->Index = MaxNumberOfWaypoints; |
||
498 | } |
||
499 | else |
||
500 | UART1_Request_WritePoint = PointList_SetAt(pPoint); |
||
315 | killagreg | 501 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
295 | killagreg | 502 | if(UART1_Request_WritePoint == pPoint->Index) |
225 | killagreg | 503 | { |
504 | BeepTime = 500; |
||
165 | killagreg | 505 | } |
506 | } |
||
41 | ingob | 507 | } |
508 | break; |
||
509 | |||
92 | killagreg | 510 | case 'x':// Read Waypoint from List |
280 | killagreg | 511 | UART1_Request_ReadPoint = SerialMsg.pData[0]; |
92 | killagreg | 512 | break; |
513 | |||
160 | holgerb | 514 | case 'j':// Set/Get NC-Parameter |
156 | killagreg | 515 | switch(SerialMsg.pData[0]) |
516 | { |
||
517 | case 0: // get |
||
518 | break; |
||
165 | killagreg | 519 | |
156 | killagreg | 520 | case 1: // set |
159 | killagreg | 521 | { |
522 | s16 value; |
||
523 | value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100; |
||
524 | NCParams_SetValue(SerialMsg.pData[1], &value); |
||
525 | } |
||
156 | killagreg | 526 | break; |
527 | |||
528 | default: |
||
165 | killagreg | 529 | break; |
156 | killagreg | 530 | } |
531 | UART1_Request_ParameterId = SerialMsg.pData[1]; |
||
532 | UART1_Request_Parameter = TRUE; |
||
533 | break; |
||
41 | ingob | 534 | default: |
535 | // unsupported command recieved |
||
536 | break; |
||
537 | } // case NC_ADDRESS |
||
65 | killagreg | 538 | // "break;" is missing here to fall thru to the common commands |
41 | ingob | 539 | |
540 | default: // and any other Slave Address |
||
541 | |||
190 | killagreg | 542 | switch(SerialMsg.CmdID) // check CmdID |
41 | ingob | 543 | { |
544 | case 'a':// request for the labels of the analog debug outputs |
||
110 | killagreg | 545 | UART1_Request_DebugLabel = SerialMsg.pData[0]; |
546 | if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31; |
||
41 | ingob | 547 | break; |
193 | killagreg | 548 | /* |
41 | ingob | 549 | case 'b': // submit extern control |
121 | killagreg | 550 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
112 | killagreg | 551 | UART1_ConfirmFrame = ExternControl.Frame; |
41 | ingob | 552 | break; |
195 | killagreg | 553 | */ |
41 | ingob | 554 | case 'd': // request for debug data; |
110 | killagreg | 555 | UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
556 | if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE; |
||
198 | killagreg | 557 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
41 | ingob | 558 | break; |
559 | |||
63 | killagreg | 560 | case 'c': // request for 3D data; |
110 | killagreg | 561 | UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
562 | if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE; |
||
198 | killagreg | 563 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
63 | killagreg | 564 | break; |
275 | killagreg | 565 | |
358 | holgerb | 566 | case 'k': // request for Motor data; |
567 | UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10; |
||
568 | if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE; |
||
569 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
||
570 | break; |
||
571 | |||
41 | ingob | 572 | case 'h':// reqest for display line |
193 | killagreg | 573 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
574 | { |
||
575 | UART1_DisplayLine = 2; |
||
195 | killagreg | 576 | UART1_Display_Interval = 0; |
193 | killagreg | 577 | } |
578 | else |
||
579 | { |
||
201 | killagreg | 580 | UART1_DisplayKeys |= ~SerialMsg.pData[0]; |
193 | killagreg | 581 | UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
582 | UART1_DisplayLine = 4; |
||
198 | killagreg | 583 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
193 | killagreg | 584 | } |
110 | killagreg | 585 | UART1_Request_Display = TRUE; |
41 | ingob | 586 | break; |
587 | |||
588 | case 'l':// reqest for display columns |
||
110 | killagreg | 589 | MenuItem = SerialMsg.pData[0]; |
590 | UART1_Request_Display1 = TRUE; |
||
41 | ingob | 591 | break; |
64 | holgerb | 592 | |
593 | case 'o': // request for navigation information |
||
110 | killagreg | 594 | UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
595 | if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE; |
||
198 | killagreg | 596 | UART1_AboTimeOut = SetDelay(ABO_TIMEOUT); |
64 | holgerb | 597 | break; |
598 | |||
41 | ingob | 599 | case 'v': // request for version info |
110 | killagreg | 600 | UART1_Request_VersionInfo = TRUE; |
41 | ingob | 601 | break; |
602 | default: |
||
603 | // unsupported command recieved |
||
604 | break; |
||
605 | } |
||
606 | break; // default: |
||
607 | } |
||
153 | killagreg | 608 | Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame |
41 | ingob | 609 | } |
610 | |||
611 | |||
612 | /*****************************************************/ |
||
613 | /* Send a character */ |
||
614 | /*****************************************************/ |
||
110 | killagreg | 615 | s16 UART1_Putchar(char c) |
41 | ingob | 616 | { |
362 | holgerb | 617 | u32 timeout = 10000; |
110 | killagreg | 618 | if (c == '\n') UART1_Putchar('\r'); |
41 | ingob | 619 | // wait until txd fifo is not full |
362 | holgerb | 620 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET) if(--timeout == 0) return(0); |
41 | ingob | 621 | // transmit byte |
622 | UART_SendData(UART1, c); |
||
314 | killagreg | 623 | #ifdef FOLLOW_ME |
624 | if(TransmitAlsoToFC) UART_SendData(UART2, c); |
||
625 | #endif |
||
41 | ingob | 626 | return (0); |
627 | } |
||
628 | |||
629 | /*****************************************************/ |
||
630 | /* Send a string to the debug uart */ |
||
631 | /*****************************************************/ |
||
110 | killagreg | 632 | void UART1_PutString(u8 *s) |
41 | ingob | 633 | { |
634 | if(s == NULL) return; |
||
635 | while (*s != '\0' && DebugUART == UART1) |
||
636 | { |
||
110 | killagreg | 637 | UART1_Putchar(*s); |
41 | ingob | 638 | s ++; |
639 | } |
||
640 | } |
||
641 | |||
113 | killagreg | 642 | |
110 | killagreg | 643 | /**************************************************************/ |
644 | /* Transmit tx buffer via debug uart */ |
||
645 | /**************************************************************/ |
||
646 | void UART1_Transmit(void) |
||
647 | { |
||
648 | u8 tmp_tx; |
||
649 | if(DebugUART != UART1) return; |
||
650 | // if something has to be send and the txd fifo is not full |
||
113 | killagreg | 651 | if(UART1_tx_buffer.Locked == TRUE) |
110 | killagreg | 652 | { |
113 | killagreg | 653 | // while there is some space in the tx fifo |
654 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET) |
||
110 | killagreg | 655 | { |
113 | killagreg | 656 | tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer |
657 | UART_SendData(UART1, tmp_tx); // put character to txd fifo |
||
314 | killagreg | 658 | #ifdef FOLLOW_ME |
315 | killagreg | 659 | if(TransmitAlsoToFC) |
660 | { |
||
314 | killagreg | 661 | UART_SendData(UART2, tmp_tx); // put character to txd fifo |
662 | } |
||
663 | #endif |
||
113 | killagreg | 664 | // if terminating character or end of txd buffer reached |
665 | if((tmp_tx == '\r') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes)) |
||
666 | { |
||
667 | Buffer_Clear(&UART1_tx_buffer); // clear txd buffer |
||
314 | killagreg | 668 | #ifdef FOLLOW_ME |
669 | TransmitAlsoToFC = 0; |
||
670 | #endif |
||
113 | killagreg | 671 | break; // end while loop |
672 | } |
||
110 | killagreg | 673 | } |
674 | } |
||
675 | } |
||
41 | ingob | 676 | |
378 | holgerb | 677 | |
41 | ingob | 678 | /**************************************************************/ |
679 | /* Send the answers to incomming commands at the debug uart */ |
||
680 | /**************************************************************/ |
||
681 | void UART1_TransmitTxData(void) |
||
682 | { |
||
358 | holgerb | 683 | static u8 motorindex1 = 255, motorindex2 = 0; |
110 | killagreg | 684 | if(DebugUART != UART1) return; |
198 | killagreg | 685 | |
686 | if(CheckDelay(UART1_AboTimeOut)) |
||
687 | { |
||
688 | UART1_DebugData_Interval = 0; |
||
689 | UART1_NaviData_Interval = 0; |
||
690 | UART1_Data3D_Interval = 0; |
||
691 | UART1_Display_Interval = 0; |
||
378 | holgerb | 692 | UART1_MotorData_Interval = 0; |
198 | killagreg | 693 | } |
694 | |||
110 | killagreg | 695 | UART1_Transmit(); // output pending bytes in tx buffer |
696 | if((UART1_tx_buffer.Locked == TRUE)) return; |
||
41 | ingob | 697 | |
156 | killagreg | 698 | if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE)) |
92 | killagreg | 699 | { |
315 | killagreg | 700 | s16 ParamValue; |
299 | killagreg | 701 | NCParams_GetValue(UART1_Request_ParameterId, &ParamValue); |
160 | holgerb | 702 | 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 | 703 | UART1_Request_Parameter = FALSE; |
704 | } |
||
705 | else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE)) |
||
706 | { |
||
110 | killagreg | 707 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request |
92 | killagreg | 708 | Echo = 0; // reset echo value |
110 | killagreg | 709 | UART1_Request_Echo = FALSE; |
92 | killagreg | 710 | } |
349 | ingob | 711 | else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE)) |
712 | { |
||
433 | ingob | 713 | u8 errorcode = FTP_ERROR_NONE; |
714 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) errorcode = FTP_ERROR_MOTOR_RUN; |
||
715 | else if (!Partition.IsValid) errorcode = FTP_ERROR_NO_SDCARD; |
||
716 | |||
717 | if (!errorcode) CheckFTPCommand(UART1_Request_FTP); |
||
718 | else |
||
719 | { |
||
720 | u8 cmd = FTP_CMD_ERROR; |
||
721 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &cmd, 1, &errorcode, 1); |
||
722 | } |
||
723 | |||
349 | ingob | 724 | UART1_Request_FTP = FALSE; |
725 | } |
||
295 | killagreg | 726 | else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
154 | killagreg | 727 | { |
295 | killagreg | 728 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint)); |
729 | UART1_Request_WritePoint = 0xFF; |
||
154 | killagreg | 730 | } |
280 | killagreg | 731 | else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE)) |
154 | killagreg | 732 | { |
280 | killagreg | 733 | u8 PointCount = PointList_GetCount(); |
734 | if (UART1_Request_ReadPoint <= PointCount) |
||
154 | killagreg | 735 | { |
280 | killagreg | 736 | 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 | 737 | } |
738 | else |
||
739 | { |
||
280 | killagreg | 740 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount)); |
154 | killagreg | 741 | } |
280 | killagreg | 742 | UART1_Request_ReadPoint = 0; |
154 | killagreg | 743 | } |
744 | else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
||
745 | { |
||
746 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16); |
||
747 | UART1_Request_DebugLabel = 0xFF; |
||
748 | } |
||
398 | holgerb | 749 | else if(UART1_ExternalControlConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
750 | { |
||
751 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1,(u8 *)&UART1_ExternalControlConfirmFrame, sizeof(UART1_ExternalControlConfirmFrame)); |
||
752 | UART1_ExternalControlConfirmFrame = 0; |
||
753 | } |
||
151 | killagreg | 754 | else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 755 | { |
151 | killagreg | 756 | NaviData.Errorcode = ErrorCode; |
378 | holgerb | 757 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData, sizeof(NaviData)); |
151 | killagreg | 758 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval); |
759 | UART1_Request_NaviData = FALSE; |
||
360 | holgerb | 760 | LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2; |
151 | killagreg | 761 | } |
762 | else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE)) |
||
763 | { |
||
110 | killagreg | 764 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
765 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
||
766 | UART1_Request_DebugData = FALSE; |
||
41 | ingob | 767 | } |
151 | killagreg | 768 | else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE)) |
61 | holgerb | 769 | { |
358 | holgerb | 770 | Data3D.StickNick = FC.StickNick; |
771 | Data3D.StickRoll = FC.StickRoll; |
||
772 | Data3D.StickYaw = FC.StickYaw; |
||
773 | Data3D.StickGas = FC.StickGas; |
||
110 | killagreg | 774 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
775 | UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval); |
||
776 | UART1_Request_Data3D = FALSE; |
||
61 | holgerb | 777 | } |
358 | holgerb | 778 | else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE)) |
779 | { |
||
780 | do |
||
781 | { |
||
782 | motorindex1++; |
||
783 | motorindex1%=12; |
||
784 | if(!motorindex1) {motorindex2++; motorindex2 %= 12;}; |
||
785 | if(motorindex1 == motorindex2) break; |
||
786 | } |
||
787 | while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors |
||
788 | |||
789 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t)); |
||
790 | UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval); |
||
791 | UART1_Request_MotorData = FALSE; |
||
792 | } |
||
193 | killagreg | 793 | /* |
153 | killagreg | 794 | else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
795 | { |
||
796 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame)); |
||
797 | UART1_ConfirmFrame = 0; |
||
798 | } |
||
193 | killagreg | 799 | */ |
800 | /* |
||
151 | killagreg | 801 | else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 802 | { |
110 | killagreg | 803 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
804 | UART1_Request_ExternalControl = FALSE; |
||
41 | ingob | 805 | } |
193 | killagreg | 806 | */ |
807 | else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE)) |
||
195 | killagreg | 808 | { |
193 | killagreg | 809 | if(UART1_DisplayLine > 3) |
810 | { |
||
201 | killagreg | 811 | Menu_Update(UART1_DisplayKeys); |
812 | UART1_DisplayKeys = 0; |
||
193 | killagreg | 813 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff)); |
814 | } |
||
815 | else |
||
816 | { |
||
817 | UART1_DisplayLine = 2; |
||
818 | sprintf(text,"!!! incompatible !!!"); |
||
819 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20); |
||
820 | if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0; |
||
821 | } |
||
822 | UART1_Display_Timer = SetDelay(UART1_Display_Interval); |
||
110 | killagreg | 823 | UART1_Request_Display = FALSE; |
41 | ingob | 824 | } |
151 | killagreg | 825 | else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 826 | { |
201 | killagreg | 827 | Menu_Update(0); |
110 | killagreg | 828 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
829 | UART1_Request_Display1 = FALSE; |
||
41 | ingob | 830 | } |
151 | killagreg | 831 | else if(UART1_Request_VersionInfo && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 832 | { |
110 | killagreg | 833 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
834 | UART1_Request_VersionInfo = FALSE; |
||
41 | ingob | 835 | } |
447 | holgerb | 836 | else if(UART1_Request_SystemTime && (UART1_tx_buffer.Locked == FALSE)) |
837 | { |
||
838 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'T', NC_ADDRESS,1, (u8 *)&SystemTime, sizeof(SystemTime)); |
||
839 | UART1_Request_SystemTime = FALSE; |
||
840 | } |
||
151 | killagreg | 841 | else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 842 | { |
110 | killagreg | 843 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
844 | UART1_Request_ErrorMessage = FALSE; |
||
41 | ingob | 845 | } |
314 | killagreg | 846 | #ifdef FOLLOW_ME |
847 | else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE)) |
||
848 | { |
||
849 | if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4)) |
||
315 | killagreg | 850 | { |
314 | killagreg | 851 | TransmitAlsoToFC = 1; |
852 | // update FollowMe content |
||
853 | FollowMe.Position.Longitude = GPSData.Position.Longitude; |
||
854 | FollowMe.Position.Latitude = GPSData.Position.Latitude; |
||
855 | FollowMe.Position.Status = NEWDATA; |
||
856 | FollowMe.Position.Altitude = 1; |
||
857 | // 0 -> no Orientation |
||
858 | // 1-360 -> CompassCourse Setpoint |
||
859 | // -1 -> points to WP1 -> itself |
||
860 | FollowMe.Heading = -1; |
||
861 | FollowMe.ToleranceRadius = 1; |
||
862 | FollowMe.HoldTime = 60; |
||
863 | FollowMe.Event_Flag = 1; |
||
864 | FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list |
||
865 | FollowMe.Type = POINT_TYPE_WP; |
||
866 | FollowMe.WP_EventChannelValue = 100; // set servo value |
||
867 | FollowMe.AltitudeRate = 0; // do not change height |
||
403 | holgerb | 868 | FollowMe.Speed = 0; // rate to change the Position (0 = max) |
869 | FollowMe.CamAngle = 255; // Camera servo angle in degree (255 -> POI-Automatic) |
||
870 | FollowMe.Name[0] = 'F'; // Name of that point (ASCII) |
||
871 | FollowMe.Name[1] = 'O'; // Name of that point (ASCII) |
||
872 | FollowMe.Name[2] = 'L'; // Name of that point (ASCII) |
||
873 | FollowMe.Name[3] = 'L'; // Name of that point (ASCII) |
||
314 | killagreg | 874 | FollowMe.reserve[0] = 0; // reserve |
875 | FollowMe.reserve[1] = 0; // reserve |
||
876 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe)); |
||
877 | } |
||
878 | UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time |
||
879 | } |
||
880 | #endif |
||
250 | ingob | 881 | #ifdef DEBUG // only include functions if DEBUG is defined |
314 | killagreg | 882 | else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE)) |
254 | killagreg | 883 | { |
884 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug)); |
||
885 | SendDebugOutput = 0; |
||
886 | } |
||
315 | killagreg | 887 | #endif |
110 | killagreg | 888 | UART1_Transmit(); // output pending bytes in tx buffer |
41 | ingob | 889 | } |
890 |