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 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
||
6 | // + Nur für den privaten Gebrauch |
||
7 | // + FOR NON COMMERCIAL USE ONLY |
||
8 | // + www.MikroKopter.com |
||
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
||
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
||
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
||
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
||
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
||
15 | // + Verkauf von Luftbildaufnahmen, usw. |
||
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
||
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
||
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
||
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
||
22 | // + eindeutig als Ursprung verlinkt werden |
||
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
||
25 | // + Benutzung auf eigene Gefahr |
||
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
||
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
28 | // + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
||
29 | // + mit unserer Zustimmung zulässig |
||
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
||
34 | // + this list of conditions and the following disclaimer. |
||
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
||
36 | // + from this software without specific prior written permission. |
||
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
||
38 | // + for non-commercial use (directly or indirectly) |
||
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
||
40 | // + with our written permission |
||
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
||
42 | // + clearly linked as origin |
||
43 | // + * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
||
44 | // |
||
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
55 | // + POSSIBILITY OF SUCH DAMAGE. |
||
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
57 | #include <stdio.h> |
||
58 | #include <stdarg.h> |
||
59 | #include <string.h> |
||
60 | |||
61 | #include "91x_lib.h" |
||
62 | #include "menu.h" |
||
63 | #include "printf_P.h" |
||
64 | #include "GPS.h" |
||
65 | #include "i2c.h" |
||
66 | #include "uart0.h" |
||
67 | #include "uart1.h" |
||
68 | #include "uart2.h" |
||
69 | #include "timer.h" |
||
70 | #include "main.h" |
||
71 | #include "waypoints.h" |
||
110 | killagreg | 72 | #include "mkprotocol.h" |
41 | ingob | 73 | |
74 | #define FALSE 0 |
||
75 | #define TRUE 1 |
||
76 | |||
92 | killagreg | 77 | typedef struct |
78 | { |
||
79 | u8 SWMajor; |
||
80 | u8 SWMinor; |
||
81 | u8 ProtoMajor; |
||
82 | u8 ProtoMinor; |
||
83 | u8 SWPatch; |
||
84 | u8 Reserved[5]; |
||
85 | } __attribute__((packed)) UART_VersionInfo_t; |
||
86 | |||
87 | |||
110 | killagreg | 88 | u8 UART1_Request_VersionInfo = FALSE; |
89 | u8 UART1_Request_SendFollowMe = FALSE; |
||
90 | u8 UART1_Request_ExternalControl= FALSE; |
||
91 | u8 UART1_Request_Display = FALSE; |
||
92 | u8 UART1_Request_Display1 = FALSE; |
||
93 | u8 UART1_Request_DebugData = FALSE; |
||
94 | u8 UART1_Request_DebugLabel = 255; |
||
95 | u8 UART1_Request_NaviData = FALSE; |
||
96 | u8 UART1_Request_ErrorMessage = FALSE; |
||
97 | u8 UART1_Request_NewWaypoint = FALSE; |
||
98 | u8 UART1_Request_ReadWaypoint = 255; |
||
99 | u8 UART1_Request_Data3D = FALSE; |
||
100 | u8 UART1_Request_Echo = FALSE; |
||
41 | ingob | 101 | |
102 | u8 DisplayLine = 0; |
||
103 | |||
104 | UART_TypeDef *DebugUART = UART1; |
||
105 | |||
110 | killagreg | 106 | #define UART1_BAUD_RATE 57600 //Baud Rate for the serial interfaces |
107 | |||
108 | // the tx buffer |
||
109 | #define UART1_TX_BUFFER_LEN 150 |
||
110 | u8 UART1_tbuffer[UART1_TX_BUFFER_LEN]; |
||
111 | Buffer_t UART1_tx_buffer; |
||
112 | |||
113 | // the rx buffer |
||
114 | #define UART1_RX_BUFFER_LEN 150 |
||
115 | u8 UART1_rbuffer[UART1_RX_BUFFER_LEN]; |
||
116 | Buffer_t UART1_rx_buffer; |
||
117 | |||
92 | killagreg | 118 | volatile u8 SerialLinkOkay = 0; |
41 | ingob | 119 | |
120 | u8 text[100]; |
||
121 | |||
122 | u8 PcAccess = 100; |
||
123 | u8 ConfirmFrame = 0; |
||
124 | |||
125 | DebugOut_t DebugOut; |
||
126 | ExternControl_t ExternControl; |
||
127 | UART_VersionInfo_t UART_VersionInfo; |
||
128 | NaviData_t NaviData; |
||
129 | Waypoint_t FollowMe; |
||
61 | holgerb | 130 | Data3D_t Data3D; |
92 | killagreg | 131 | u16 Echo; // 2 bytes recieved will be sent back as echo |
41 | ingob | 132 | |
110 | killagreg | 133 | u32 UART1_DebugData_Timer; |
134 | u32 UART1_DebugData_Interval = 5000; // in ms |
||
135 | u32 UART1_NaviData_Timer; |
||
136 | u32 UART1_NaviData_Interval = 5000; // in ms |
||
137 | u32 UART1_Data3D_Timer = 0; // in ms |
||
138 | u32 UART1_Data3D_Interval = 0; |
||
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 ", |
||
147 | " ", |
||
75 | holgerb | 148 | "MK-Flags ", //5 |
95 | killagreg | 149 | "NC-Flags ", |
41 | ingob | 150 | " ", |
151 | " ", |
||
152 | "GPS Data ", |
||
61 | holgerb | 153 | "CompassHeading ", //10 |
154 | "GyroHeading ", |
||
41 | ingob | 155 | "SPI Error ", |
156 | "SPI Okay ", |
||
157 | "I2C Error ", |
||
158 | "I2C Okay ", //15 |
||
159 | " ",// "FC_Kalman_K ", |
||
160 | "ACC_Speed_N ", |
||
161 | "ACC_Speed_E ", |
||
162 | " ",// "GPS ACC ", |
||
163 | " ",// "MAXDrift ", //20 |
||
164 | "N_Speed ", |
||
165 | "E_Speed ", |
||
99 | killagreg | 166 | "P-Part ", |
167 | "I-Part ", |
||
168 | "D-Part ",//25 |
||
169 | "PID-Part ", |
||
41 | ingob | 170 | "Distance N ", |
171 | "Distance E ", |
||
172 | "GPS_Nick ", |
||
173 | "GPS_Roll ", //30 |
||
174 | "Used_Sats " |
||
175 | }; |
||
176 | |||
177 | |||
178 | /********************************************************/ |
||
179 | /* Initialization the UART1 */ |
||
180 | /********************************************************/ |
||
181 | void UART1_Init (void) |
||
182 | { |
||
183 | GPIO_InitTypeDef GPIO_InitStructure; |
||
184 | UART_InitTypeDef UART_InitStructure; |
||
185 | |||
186 | SCU_APBPeriphClockConfig(__UART1, ENABLE); // Enable the UART1 Clock |
||
187 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
||
188 | |||
189 | /*Configure UART1_Rx pin GPIO3.2*/ |
||
190 | GPIO_StructInit(&GPIO_InitStructure); |
||
191 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
||
192 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
||
193 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
||
194 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
||
195 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART1_RxD |
||
196 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
||
197 | |||
198 | /*Configure UART1_Tx pin GPIO3.3*/ |
||
199 | GPIO_StructInit(&GPIO_InitStructure); |
||
200 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
||
201 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
||
202 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
||
203 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART1_TX |
||
204 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
||
205 | |||
206 | /* UART1 configured as follow: |
||
207 | - Word Length = 8 Bits |
||
208 | - One Stop Bit |
||
209 | - No parity |
||
210 | - BaudRate = 57600 baud |
||
211 | - Hardware flow control Disabled |
||
212 | - Receive and transmit enabled |
||
213 | - Receive and transmit FIFOs are Disabled |
||
214 | */ |
||
215 | UART_StructInit(&UART_InitStructure); |
||
216 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
||
217 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
||
218 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
||
110 | killagreg | 219 | UART_InitStructure.UART_BaudRate = UART1_BAUD_RATE; |
41 | ingob | 220 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
221 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
||
222 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
||
223 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
||
224 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
||
225 | |||
226 | UART_DeInit(UART1); // reset uart 1 to default |
||
227 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
||
228 | // enable uart 1 interrupts selective |
||
229 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
||
230 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
||
231 | // configure the uart 1 interupt line as an IRQ with priority 4 (0 is highest) |
||
232 | VIC_Config(UART1_ITLine, VIC_IRQ, 4); |
||
233 | // enable the uart 1 IRQ |
||
234 | VIC_ITCmd(UART1_ITLine, ENABLE); |
||
235 | // initialize the debug timer |
||
110 | killagreg | 236 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
237 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500; |
||
238 | |||
239 | // initialize txd buffer |
||
240 | UART1_tx_buffer.pData = UART1_tbuffer; |
||
241 | UART1_tx_buffer.Size = UART1_TX_BUFFER_LEN; |
||
242 | UART1_tx_buffer.Position = 0; |
||
243 | UART1_tx_buffer.Locked = FALSE; |
||
244 | |||
245 | // initialize rxd buffer |
||
246 | UART1_rx_buffer.pData = UART1_rbuffer; |
||
247 | UART1_rx_buffer.Size = UART1_RX_BUFFER_LEN; |
||
248 | UART1_rx_buffer.Position = 0; |
||
249 | UART1_rx_buffer.Locked = FALSE; |
||
250 | |||
41 | ingob | 251 | // Fill Version Info Structure |
252 | UART_VersionInfo.SWMajor = VERSION_MAJOR; |
||
253 | UART_VersionInfo.SWMinor = VERSION_MINOR; |
||
254 | UART_VersionInfo.SWPatch = VERSION_PATCH; |
||
255 | UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
||
256 | UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
||
257 | |||
89 | killagreg | 258 | NaviData.Version = NAVIDATA_VERSION; |
92 | killagreg | 259 | |
110 | killagreg | 260 | UART1_PutString("\r\nUART1 init...ok"); |
41 | ingob | 261 | } |
262 | |||
263 | |||
264 | /****************************************************************/ |
||
265 | /* USART1 receiver ISR */ |
||
266 | /****************************************************************/ |
||
267 | void UART1_IRQHandler(void) |
||
268 | { |
||
269 | static u8 abortState = 0; |
||
270 | u8 c; |
||
271 | |||
272 | if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) ) |
||
273 | { |
||
274 | // clear the pending bits |
||
275 | UART_ClearITPendingBit(UART1, UART_IT_Receive); |
||
276 | UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut); |
||
277 | // if debug UART is not UART1 |
||
278 | if (DebugUART != UART1) |
||
279 | { // forward received data to the debug UART tx buffer |
||
280 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
||
281 | { |
||
282 | // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART |
||
283 | c = UART_ReceiveData(UART1); |
||
284 | |||
285 | // check for abort condition (ESC ESC 0x55 0xAA 0x00) |
||
286 | switch (abortState) |
||
287 | { |
||
288 | case 0: if (c == 27) abortState++; |
||
289 | break; |
||
290 | case 1: if (c == 27) abortState++; else abortState = 0; |
||
291 | break; |
||
292 | case 2: if (c == 0x55) abortState++; else abortState = 0; |
||
293 | break; |
||
294 | case 3: if (c == 0xAA) abortState++; else abortState = 0; |
||
295 | break; |
||
296 | case 4: if (c == 0x00) |
||
297 | { |
||
298 | DebugUART = UART1; |
||
299 | UART0_Connect_to_MKGPS(); |
||
300 | } |
||
301 | abortState = 0; |
||
302 | break; |
||
303 | } |
||
110 | killagreg | 304 | // if the Debug uart is not UART1rederect input to the Debug UART |
305 | if (DebugUART != UART1) |
||
306 | { |
||
307 | // wait for space in the tx buffer of the DebugUART |
||
308 | while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {}; |
||
309 | // move byte to the tx fifi of the debug uart |
||
310 | UART_SendData(DebugUART, c); |
||
311 | } |
||
41 | ingob | 312 | } |
313 | } |
||
314 | else // DebugUART == UART1 (normal operation) |
||
315 | { |
||
110 | killagreg | 316 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
41 | ingob | 317 | { // some byes in the fifo and rxd buffer not locked |
318 | // get byte from fifo |
||
319 | c = UART_ReceiveData(UART1); |
||
110 | killagreg | 320 | MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c); |
41 | ingob | 321 | } // some byes in the fifo and rxd buffer not locked |
322 | } // eof DebugUart = UART1 |
||
323 | } |
||
324 | } |
||
325 | |||
326 | /**************************************************************/ |
||
327 | /* Process incomming data from debug uart */ |
||
328 | /**************************************************************/ |
||
329 | void UART1_ProcessRxData(void) |
||
330 | { |
||
110 | killagreg | 331 | SerialMsg_t SerialMsg; |
41 | ingob | 332 | // if data in the rxd buffer are not locked immediately return |
110 | killagreg | 333 | if((UART1_rx_buffer.Locked == FALSE) || (DebugUART != UART1) ) return; |
41 | ingob | 334 | Waypoint_t * pWaypoint = NULL; |
335 | |||
336 | PcAccess = 255; |
||
110 | killagreg | 337 | MKProtocol_DecodeSerialFrame(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
338 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
||
339 | switch(SerialMsg.Address) // check for Slave Address |
||
41 | ingob | 340 | { |
341 | case NC_ADDRESS: // own Slave Address |
||
110 | killagreg | 342 | switch(SerialMsg.CmdID) |
41 | ingob | 343 | { |
101 | holgerb | 344 | case 'z': // connection checker |
110 | killagreg | 345 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
346 | UART1_Request_Echo = TRUE; |
||
92 | killagreg | 347 | break; |
348 | |||
41 | ingob | 349 | case 'e': // request for the text of the error status |
110 | killagreg | 350 | UART1_Request_ErrorMessage = TRUE; |
41 | ingob | 351 | break; |
352 | |||
353 | case 's':// new target position |
||
110 | killagreg | 354 | pWaypoint = (Waypoint_t*)SerialMsg.pData; |
41 | ingob | 355 | BeepTime = 300; |
356 | if(pWaypoint->Position.Status == NEWDATA) |
||
357 | { |
||
358 | WPList_Clear(); // empty WPList |
||
359 | WPList_Append(pWaypoint); |
||
360 | GPS_pWaypoint = WPList_Begin(); |
||
361 | } |
||
362 | break; |
||
363 | |||
364 | case 'u': // redirect debug uart |
||
110 | killagreg | 365 | switch(SerialMsg.pData[0]) |
41 | ingob | 366 | { |
367 | case UART_FLIGHTCTRL: |
||
368 | UART2_Init(); // initialize UART2 to FC pins |
||
369 | DebugUART = UART2; |
||
370 | break; |
||
371 | case UART_MK3MAG: |
||
372 | if(FC.MKFlags & MKFLAG_MOTOR_RUN) break; // not if the motors are running |
||
373 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
||
374 | GPSData.Status = INVALID; |
||
375 | DebugUART = UART0; |
||
376 | break; |
||
377 | case UART_MKGPS: |
||
378 | if(FC.MKFlags & MKFLAG_MOTOR_RUN) break; // not if the motors are running |
||
379 | UART0_Connect_to_MKGPS(); // connect UART0 to MKGPS pins |
||
380 | GPSData.Status = INVALID; |
||
381 | DebugUART = UART0; |
||
382 | break; |
||
383 | } |
||
384 | break; |
||
385 | |||
92 | killagreg | 386 | case 'w':// Append Waypoint to List |
110 | killagreg | 387 | pWaypoint = (Waypoint_t*)SerialMsg.pData; |
41 | ingob | 388 | if(pWaypoint->Position.Status == INVALID) |
389 | { // clear WP List |
||
390 | WPList_Clear(); |
||
391 | GPS_pWaypoint = WPList_Begin(); |
||
110 | killagreg | 392 | //UART1_PutString("\r\nClear WP List\r\n"); |
41 | ingob | 393 | } |
394 | else if (pWaypoint->Position.Status == NEWDATA) |
||
395 | { // app current WP to the list |
||
396 | WPList_Append(pWaypoint); |
||
397 | BeepTime = 500; |
||
110 | killagreg | 398 | //UART1_PutString("\r\nAdd WP to List\r\n"); |
41 | ingob | 399 | } |
110 | killagreg | 400 | UART1_Request_NewWaypoint = TRUE; |
41 | ingob | 401 | break; |
402 | |||
92 | killagreg | 403 | case 'x':// Read Waypoint from List |
110 | killagreg | 404 | UART1_Request_ReadWaypoint = SerialMsg.pData[0]; |
92 | killagreg | 405 | break; |
406 | |||
41 | ingob | 407 | default: |
408 | // unsupported command recieved |
||
409 | break; |
||
410 | } // case NC_ADDRESS |
||
65 | killagreg | 411 | // "break;" is missing here to fall thru to the common commands |
41 | ingob | 412 | |
413 | default: // and any other Slave Address |
||
414 | |||
110 | killagreg | 415 | switch(SerialMsg.CmdID) // check CmdID |
41 | ingob | 416 | { |
417 | case 'a':// request for the labels of the analog debug outputs |
||
110 | killagreg | 418 | UART1_Request_DebugLabel = SerialMsg.pData[0]; |
419 | if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31; |
||
41 | ingob | 420 | break; |
421 | |||
422 | case 'b': // submit extern control |
||
110 | killagreg | 423 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
41 | ingob | 424 | ConfirmFrame = ExternControl.Frame; |
425 | break; |
||
426 | |||
427 | case 'd': // request for debug data; |
||
110 | killagreg | 428 | UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
429 | if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE; |
||
41 | ingob | 430 | break; |
431 | |||
63 | killagreg | 432 | case 'c': // request for 3D data; |
110 | killagreg | 433 | UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
434 | if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE; |
||
63 | killagreg | 435 | break; |
436 | |||
41 | ingob | 437 | case 'g':// request for external control data |
110 | killagreg | 438 | UART1_Request_ExternalControl = TRUE; |
41 | ingob | 439 | break; |
440 | |||
441 | case 'h':// reqest for display line |
||
110 | killagreg | 442 | RemoteKeys |= SerialMsg.pData[0]; |
41 | ingob | 443 | if(RemoteKeys != 0) DisplayLine = 0; |
110 | killagreg | 444 | UART1_Request_Display = TRUE; |
41 | ingob | 445 | break; |
446 | |||
447 | case 'l':// reqest for display columns |
||
110 | killagreg | 448 | MenuItem = SerialMsg.pData[0]; |
449 | UART1_Request_Display1 = TRUE; |
||
41 | ingob | 450 | break; |
64 | holgerb | 451 | |
452 | case 'o': // request for navigation information |
||
110 | killagreg | 453 | UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
454 | if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE; |
||
64 | holgerb | 455 | break; |
456 | |||
41 | ingob | 457 | case 'v': // request for version info |
110 | killagreg | 458 | UART1_Request_VersionInfo = TRUE; |
41 | ingob | 459 | break; |
460 | default: |
||
461 | // unsupported command recieved |
||
462 | break; |
||
463 | } |
||
464 | break; // default: |
||
465 | } |
||
466 | // unlock the rxd buffer after processing |
||
110 | killagreg | 467 | UART1_rx_buffer.Position = 0; |
468 | UART1_rx_buffer.Locked = FALSE; |
||
41 | ingob | 469 | } |
470 | |||
471 | |||
472 | /*****************************************************/ |
||
473 | /* Send a character */ |
||
474 | /*****************************************************/ |
||
110 | killagreg | 475 | s16 UART1_Putchar(char c) |
41 | ingob | 476 | { |
110 | killagreg | 477 | if (c == '\n') UART1_Putchar('\r'); |
41 | ingob | 478 | // wait until txd fifo is not full |
479 | while (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET); |
||
480 | // transmit byte |
||
481 | UART_SendData(UART1, c); |
||
482 | return (0); |
||
483 | } |
||
484 | |||
485 | /*****************************************************/ |
||
486 | /* Send a string to the debug uart */ |
||
487 | /*****************************************************/ |
||
110 | killagreg | 488 | void UART1_PutString(u8 *s) |
41 | ingob | 489 | { |
490 | if(s == NULL) return; |
||
491 | while (*s != '\0' && DebugUART == UART1) |
||
492 | { |
||
110 | killagreg | 493 | UART1_Putchar(*s); |
41 | ingob | 494 | s ++; |
495 | } |
||
496 | } |
||
497 | |||
110 | killagreg | 498 | /**************************************************************/ |
499 | /* Transmit tx buffer via debug uart */ |
||
500 | /**************************************************************/ |
||
501 | void UART1_Transmit(void) |
||
502 | { |
||
503 | u8 tmp_tx; |
||
504 | if(DebugUART != UART1) return; |
||
505 | // if something has to be send and the txd fifo is not full |
||
506 | if((UART1_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == RESET)) |
||
507 | { |
||
508 | tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer |
||
509 | UART_SendData(UART1, tmp_tx); // put character to txd fifo |
||
510 | // if terminating character or end of txd buffer reached |
||
511 | if((tmp_tx == '\r') || (UART1_tx_buffer.Position == UART1_tx_buffer.Size)) |
||
512 | { |
||
513 | UART1_tx_buffer.Position = 0; // reset txd buffer positon |
||
514 | UART1_tx_buffer.Locked = FALSE;// unlock tx buffer |
||
515 | } |
||
516 | } |
||
517 | } |
||
41 | ingob | 518 | |
519 | |||
520 | /**************************************************************/ |
||
521 | /* Send the answers to incomming commands at the debug uart */ |
||
522 | /**************************************************************/ |
||
523 | void UART1_TransmitTxData(void) |
||
524 | { |
||
110 | killagreg | 525 | if(DebugUART != UART1) return; |
526 | UART1_Transmit(); // output pending bytes in tx buffer |
||
527 | if((UART1_tx_buffer.Locked == TRUE)) return; |
||
41 | ingob | 528 | |
110 | killagreg | 529 | if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE)) |
92 | killagreg | 530 | { |
110 | killagreg | 531 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request |
92 | killagreg | 532 | Echo = 0; // reset echo value |
110 | killagreg | 533 | UART1_Request_Echo = FALSE; |
92 | killagreg | 534 | } |
110 | killagreg | 535 | if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 536 | { |
110 | killagreg | 537 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16); |
538 | UART1_Request_DebugLabel = 0xFF; |
||
41 | ingob | 539 | } |
110 | killagreg | 540 | if(ConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 541 | { |
110 | killagreg | 542 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &ConfirmFrame, sizeof(ConfirmFrame)); |
41 | ingob | 543 | ConfirmFrame = 0; |
544 | } |
||
110 | killagreg | 545 | if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 546 | { |
110 | killagreg | 547 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
548 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
||
549 | UART1_Request_DebugData = FALSE; |
||
41 | ingob | 550 | } |
61 | holgerb | 551 | |
110 | killagreg | 552 | if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE)) |
61 | holgerb | 553 | { |
110 | killagreg | 554 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
555 | UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval); |
||
556 | UART1_Request_Data3D = FALSE; |
||
61 | holgerb | 557 | } |
558 | |||
110 | killagreg | 559 | if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 560 | { |
110 | killagreg | 561 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
562 | UART1_Request_ExternalControl = FALSE; |
||
41 | ingob | 563 | } |
110 | killagreg | 564 | if(UART1_Request_Display && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 565 | { |
566 | LCD_PrintMenu(); |
||
110 | killagreg | 567 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (u8*)&DisplayBuff[DisplayLine * 20], 20); |
41 | ingob | 568 | DisplayLine++; |
569 | if(DisplayLine >= 4) DisplayLine = 0; |
||
110 | killagreg | 570 | UART1_Request_Display = FALSE; |
41 | ingob | 571 | } |
110 | killagreg | 572 | if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 573 | { |
574 | LCD_PrintMenu(); |
||
110 | killagreg | 575 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
576 | UART1_Request_Display1 = FALSE; |
||
41 | ingob | 577 | } |
110 | killagreg | 578 | if(UART1_Request_VersionInfo && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 579 | { |
110 | killagreg | 580 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
581 | UART1_Request_VersionInfo = FALSE; |
||
41 | ingob | 582 | } |
110 | killagreg | 583 | if(( (UART1_NaviData_Interval && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 584 | { |
585 | NaviData.Errorcode = ErrorCode; |
||
110 | killagreg | 586 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
587 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval); |
||
588 | UART1_Request_NaviData = FALSE; |
||
41 | ingob | 589 | } |
110 | killagreg | 590 | if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 591 | { |
110 | killagreg | 592 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
593 | UART1_Request_ErrorMessage = FALSE; |
||
41 | ingob | 594 | } |
110 | killagreg | 595 | if(UART1_Request_SendFollowMe && (UART1_tx_buffer.Locked == FALSE) && (GPSData.NumOfSats >= 4)) // sending for "Follow me" |
41 | ingob | 596 | { |
597 | GPS_CopyPosition(&(GPSData.Position),&(FollowMe.Position)); |
||
598 | FollowMe.Position.Status = NEWDATA; |
||
599 | FollowMe.Heading = -1; |
||
600 | FollowMe.ToleranceRadius = 1; |
||
601 | FollowMe.HoldTime = 60; |
||
602 | FollowMe.Event_Flag = 0; |
||
603 | FollowMe.reserve[0] = 0; // reserve |
||
604 | FollowMe.reserve[1] = 0; // reserve |
||
605 | FollowMe.reserve[2] = 0; // reserve |
||
606 | FollowMe.reserve[3] = 0; // reserve |
||
110 | killagreg | 607 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe)); |
608 | UART1_Request_SendFollowMe = FALSE; |
||
41 | ingob | 609 | } |
110 | killagreg | 610 | if(UART1_Request_NewWaypoint && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 611 | { |
612 | u8 WPNumber = WPList_GetCount(); |
||
110 | killagreg | 613 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
614 | UART1_Request_NewWaypoint = FALSE; |
||
41 | ingob | 615 | } |
110 | killagreg | 616 | if((UART1_Request_ReadWaypoint != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
92 | killagreg | 617 | { |
618 | u8 WPNumber = WPList_GetCount(); |
||
110 | killagreg | 619 | if (UART1_Request_ReadWaypoint < WPNumber) |
92 | killagreg | 620 | { |
110 | killagreg | 621 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &WPNumber, 1, &UART1_Request_ReadWaypoint, 1, WPList_GetAt(UART1_Request_ReadWaypoint), sizeof(Waypoint_t)); |
92 | killagreg | 622 | } |
623 | else |
||
624 | { |
||
110 | killagreg | 625 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
92 | killagreg | 626 | } |
110 | killagreg | 627 | UART1_Request_ReadWaypoint = 0xFF; |
92 | killagreg | 628 | } |
110 | killagreg | 629 | UART1_Transmit(); // output pending bytes in tx buffer |
41 | ingob | 630 | } |
631 |