Rev 110 | Rev 113 | 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 | // + 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 | |
110 | killagreg | 78 | u8 UART1_Request_VersionInfo = FALSE; |
79 | u8 UART1_Request_SendFollowMe = FALSE; |
||
80 | u8 UART1_Request_ExternalControl= FALSE; |
||
81 | u8 UART1_Request_Display = FALSE; |
||
82 | u8 UART1_Request_Display1 = FALSE; |
||
83 | u8 UART1_Request_DebugData = FALSE; |
||
84 | u8 UART1_Request_DebugLabel = 255; |
||
85 | u8 UART1_Request_NaviData = FALSE; |
||
86 | u8 UART1_Request_ErrorMessage = FALSE; |
||
87 | u8 UART1_Request_NewWaypoint = FALSE; |
||
88 | u8 UART1_Request_ReadWaypoint = 255; |
||
89 | u8 UART1_Request_Data3D = FALSE; |
||
90 | u8 UART1_Request_Echo = FALSE; |
||
112 | killagreg | 91 | u8 UART1_DisplayLine = 0; |
92 | u8 UART1_ConfirmFrame = 0; |
||
41 | ingob | 93 | |
94 | UART_TypeDef *DebugUART = UART1; |
||
95 | |||
110 | killagreg | 96 | #define UART1_BAUD_RATE 57600 //Baud Rate for the serial interfaces |
97 | |||
98 | // the tx buffer |
||
99 | #define UART1_TX_BUFFER_LEN 150 |
||
100 | u8 UART1_tbuffer[UART1_TX_BUFFER_LEN]; |
||
101 | Buffer_t UART1_tx_buffer; |
||
102 | |||
103 | // the rx buffer |
||
104 | #define UART1_RX_BUFFER_LEN 150 |
||
105 | u8 UART1_rbuffer[UART1_RX_BUFFER_LEN]; |
||
106 | Buffer_t UART1_rx_buffer; |
||
107 | |||
92 | killagreg | 108 | volatile u8 SerialLinkOkay = 0; |
41 | ingob | 109 | |
110 | u8 text[100]; |
||
111 | |||
112 | const u8 ANALOG_LABEL[32][16] = |
||
113 | { |
||
90 | killagreg | 114 | //1234567890123456 |
41 | ingob | 115 | "AngleNick ", //0 |
116 | "AngleRoll ", |
||
117 | "AccNick ", |
||
118 | "AccRoll ", |
||
119 | " ", |
||
75 | holgerb | 120 | "MK-Flags ", //5 |
95 | killagreg | 121 | "NC-Flags ", |
41 | ingob | 122 | " ", |
123 | " ", |
||
124 | "GPS Data ", |
||
61 | holgerb | 125 | "CompassHeading ", //10 |
126 | "GyroHeading ", |
||
41 | ingob | 127 | "SPI Error ", |
128 | "SPI Okay ", |
||
129 | "I2C Error ", |
||
130 | "I2C Okay ", //15 |
||
131 | " ",// "FC_Kalman_K ", |
||
132 | "ACC_Speed_N ", |
||
133 | "ACC_Speed_E ", |
||
134 | " ",// "GPS ACC ", |
||
135 | " ",// "MAXDrift ", //20 |
||
136 | "N_Speed ", |
||
137 | "E_Speed ", |
||
99 | killagreg | 138 | "P-Part ", |
139 | "I-Part ", |
||
140 | "D-Part ",//25 |
||
141 | "PID-Part ", |
||
41 | ingob | 142 | "Distance N ", |
143 | "Distance E ", |
||
144 | "GPS_Nick ", |
||
145 | "GPS_Roll ", //30 |
||
146 | "Used_Sats " |
||
147 | }; |
||
148 | |||
112 | killagreg | 149 | DebugOut_t DebugOut; |
150 | ExternControl_t ExternControl; |
||
151 | UART_VersionInfo_t UART_VersionInfo; |
||
152 | NaviData_t NaviData; |
||
153 | Waypoint_t FollowMe; |
||
154 | Data3D_t Data3D; |
||
155 | u16 Echo; // 2 bytes recieved will be sent back as echo |
||
41 | ingob | 156 | |
112 | killagreg | 157 | u32 UART1_DebugData_Timer; |
158 | u32 UART1_DebugData_Interval = 5000; // in ms |
||
159 | u32 UART1_NaviData_Timer; |
||
160 | u32 UART1_NaviData_Interval = 5000; // in ms |
||
161 | u32 UART1_Data3D_Timer = 0; // in ms |
||
162 | u32 UART1_Data3D_Interval = 0; |
||
163 | |||
41 | ingob | 164 | /********************************************************/ |
165 | /* Initialization the UART1 */ |
||
166 | /********************************************************/ |
||
167 | void UART1_Init (void) |
||
168 | { |
||
169 | GPIO_InitTypeDef GPIO_InitStructure; |
||
170 | UART_InitTypeDef UART_InitStructure; |
||
171 | |||
172 | SCU_APBPeriphClockConfig(__UART1, ENABLE); // Enable the UART1 Clock |
||
173 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
||
174 | |||
175 | /*Configure UART1_Rx pin GPIO3.2*/ |
||
176 | GPIO_StructInit(&GPIO_InitStructure); |
||
177 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
||
178 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
||
179 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
||
180 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
||
181 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART1_RxD |
||
182 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
||
183 | |||
184 | /*Configure UART1_Tx pin GPIO3.3*/ |
||
185 | GPIO_StructInit(&GPIO_InitStructure); |
||
186 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
||
187 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
||
188 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
||
189 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART1_TX |
||
190 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
||
191 | |||
192 | /* UART1 configured as follow: |
||
193 | - Word Length = 8 Bits |
||
194 | - One Stop Bit |
||
195 | - No parity |
||
196 | - BaudRate = 57600 baud |
||
197 | - Hardware flow control Disabled |
||
198 | - Receive and transmit enabled |
||
199 | - Receive and transmit FIFOs are Disabled |
||
200 | */ |
||
201 | UART_StructInit(&UART_InitStructure); |
||
202 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
||
203 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
||
204 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
||
110 | killagreg | 205 | UART_InitStructure.UART_BaudRate = UART1_BAUD_RATE; |
41 | ingob | 206 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
207 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
||
208 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
||
209 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
||
210 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
||
211 | |||
212 | UART_DeInit(UART1); // reset uart 1 to default |
||
213 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
||
214 | // enable uart 1 interrupts selective |
||
215 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
||
216 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
||
217 | // configure the uart 1 interupt line as an IRQ with priority 4 (0 is highest) |
||
218 | VIC_Config(UART1_ITLine, VIC_IRQ, 4); |
||
219 | // enable the uart 1 IRQ |
||
220 | VIC_ITCmd(UART1_ITLine, ENABLE); |
||
221 | // initialize the debug timer |
||
110 | killagreg | 222 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
223 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500; |
||
224 | |||
225 | // initialize txd buffer |
||
112 | killagreg | 226 | Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN); |
110 | killagreg | 227 | |
228 | // initialize rxd buffer |
||
112 | killagreg | 229 | Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN); |
110 | killagreg | 230 | |
41 | ingob | 231 | // Fill Version Info Structure |
232 | UART_VersionInfo.SWMajor = VERSION_MAJOR; |
||
233 | UART_VersionInfo.SWMinor = VERSION_MINOR; |
||
234 | UART_VersionInfo.SWPatch = VERSION_PATCH; |
||
235 | UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
||
236 | UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
||
237 | |||
89 | killagreg | 238 | NaviData.Version = NAVIDATA_VERSION; |
92 | killagreg | 239 | |
110 | killagreg | 240 | UART1_PutString("\r\nUART1 init...ok"); |
41 | ingob | 241 | } |
242 | |||
243 | |||
244 | /****************************************************************/ |
||
245 | /* USART1 receiver ISR */ |
||
246 | /****************************************************************/ |
||
247 | void UART1_IRQHandler(void) |
||
248 | { |
||
249 | static u8 abortState = 0; |
||
250 | u8 c; |
||
251 | |||
252 | if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) ) |
||
253 | { |
||
254 | // clear the pending bits |
||
255 | UART_ClearITPendingBit(UART1, UART_IT_Receive); |
||
256 | UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut); |
||
257 | // if debug UART is not UART1 |
||
258 | if (DebugUART != UART1) |
||
259 | { // forward received data to the debug UART tx buffer |
||
260 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
||
261 | { |
||
262 | // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART |
||
263 | c = UART_ReceiveData(UART1); |
||
264 | |||
265 | // check for abort condition (ESC ESC 0x55 0xAA 0x00) |
||
266 | switch (abortState) |
||
267 | { |
||
268 | case 0: if (c == 27) abortState++; |
||
269 | break; |
||
270 | case 1: if (c == 27) abortState++; else abortState = 0; |
||
271 | break; |
||
272 | case 2: if (c == 0x55) abortState++; else abortState = 0; |
||
273 | break; |
||
274 | case 3: if (c == 0xAA) abortState++; else abortState = 0; |
||
275 | break; |
||
276 | case 4: if (c == 0x00) |
||
277 | { |
||
278 | DebugUART = UART1; |
||
279 | UART0_Connect_to_MKGPS(); |
||
280 | } |
||
281 | abortState = 0; |
||
282 | break; |
||
283 | } |
||
110 | killagreg | 284 | // if the Debug uart is not UART1rederect input to the Debug UART |
285 | if (DebugUART != UART1) |
||
286 | { |
||
287 | // wait for space in the tx buffer of the DebugUART |
||
288 | while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {}; |
||
289 | // move byte to the tx fifi of the debug uart |
||
290 | UART_SendData(DebugUART, c); |
||
291 | } |
||
41 | ingob | 292 | } |
293 | } |
||
294 | else // DebugUART == UART1 (normal operation) |
||
295 | { |
||
110 | killagreg | 296 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
41 | ingob | 297 | { // some byes in the fifo and rxd buffer not locked |
298 | // get byte from fifo |
||
299 | c = UART_ReceiveData(UART1); |
||
110 | killagreg | 300 | MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c); |
41 | ingob | 301 | } // some byes in the fifo and rxd buffer not locked |
302 | } // eof DebugUart = UART1 |
||
303 | } |
||
304 | } |
||
305 | |||
306 | /**************************************************************/ |
||
307 | /* Process incomming data from debug uart */ |
||
308 | /**************************************************************/ |
||
309 | void UART1_ProcessRxData(void) |
||
310 | { |
||
110 | killagreg | 311 | SerialMsg_t SerialMsg; |
41 | ingob | 312 | // if data in the rxd buffer are not locked immediately return |
110 | killagreg | 313 | if((UART1_rx_buffer.Locked == FALSE) || (DebugUART != UART1) ) return; |
41 | ingob | 314 | Waypoint_t * pWaypoint = NULL; |
315 | |||
110 | killagreg | 316 | MKProtocol_DecodeSerialFrame(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
317 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
||
318 | switch(SerialMsg.Address) // check for Slave Address |
||
41 | ingob | 319 | { |
320 | case NC_ADDRESS: // own Slave Address |
||
110 | killagreg | 321 | switch(SerialMsg.CmdID) |
41 | ingob | 322 | { |
101 | holgerb | 323 | case 'z': // connection checker |
110 | killagreg | 324 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
325 | UART1_Request_Echo = TRUE; |
||
92 | killagreg | 326 | break; |
327 | |||
41 | ingob | 328 | case 'e': // request for the text of the error status |
110 | killagreg | 329 | UART1_Request_ErrorMessage = TRUE; |
41 | ingob | 330 | break; |
331 | |||
332 | case 's':// new target position |
||
110 | killagreg | 333 | pWaypoint = (Waypoint_t*)SerialMsg.pData; |
41 | ingob | 334 | BeepTime = 300; |
335 | if(pWaypoint->Position.Status == NEWDATA) |
||
336 | { |
||
337 | WPList_Clear(); // empty WPList |
||
338 | WPList_Append(pWaypoint); |
||
339 | GPS_pWaypoint = WPList_Begin(); |
||
340 | } |
||
341 | break; |
||
342 | |||
343 | case 'u': // redirect debug uart |
||
110 | killagreg | 344 | switch(SerialMsg.pData[0]) |
41 | ingob | 345 | { |
346 | case UART_FLIGHTCTRL: |
||
347 | UART2_Init(); // initialize UART2 to FC pins |
||
348 | DebugUART = UART2; |
||
349 | break; |
||
350 | case UART_MK3MAG: |
||
351 | if(FC.MKFlags & MKFLAG_MOTOR_RUN) break; // not if the motors are running |
||
352 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
||
353 | GPSData.Status = INVALID; |
||
354 | DebugUART = UART0; |
||
355 | break; |
||
356 | case UART_MKGPS: |
||
357 | if(FC.MKFlags & MKFLAG_MOTOR_RUN) break; // not if the motors are running |
||
358 | UART0_Connect_to_MKGPS(); // connect UART0 to MKGPS pins |
||
359 | GPSData.Status = INVALID; |
||
360 | DebugUART = UART0; |
||
361 | break; |
||
362 | } |
||
363 | break; |
||
364 | |||
92 | killagreg | 365 | case 'w':// Append Waypoint to List |
110 | killagreg | 366 | pWaypoint = (Waypoint_t*)SerialMsg.pData; |
41 | ingob | 367 | if(pWaypoint->Position.Status == INVALID) |
368 | { // clear WP List |
||
369 | WPList_Clear(); |
||
370 | GPS_pWaypoint = WPList_Begin(); |
||
110 | killagreg | 371 | //UART1_PutString("\r\nClear WP List\r\n"); |
41 | ingob | 372 | } |
373 | else if (pWaypoint->Position.Status == NEWDATA) |
||
374 | { // app current WP to the list |
||
375 | WPList_Append(pWaypoint); |
||
376 | BeepTime = 500; |
||
110 | killagreg | 377 | //UART1_PutString("\r\nAdd WP to List\r\n"); |
41 | ingob | 378 | } |
110 | killagreg | 379 | UART1_Request_NewWaypoint = TRUE; |
41 | ingob | 380 | break; |
381 | |||
92 | killagreg | 382 | case 'x':// Read Waypoint from List |
110 | killagreg | 383 | UART1_Request_ReadWaypoint = SerialMsg.pData[0]; |
92 | killagreg | 384 | break; |
385 | |||
41 | ingob | 386 | default: |
387 | // unsupported command recieved |
||
388 | break; |
||
389 | } // case NC_ADDRESS |
||
65 | killagreg | 390 | // "break;" is missing here to fall thru to the common commands |
41 | ingob | 391 | |
392 | default: // and any other Slave Address |
||
393 | |||
110 | killagreg | 394 | switch(SerialMsg.CmdID) // check CmdID |
41 | ingob | 395 | { |
396 | case 'a':// request for the labels of the analog debug outputs |
||
110 | killagreg | 397 | UART1_Request_DebugLabel = SerialMsg.pData[0]; |
398 | if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31; |
||
41 | ingob | 399 | break; |
400 | |||
401 | case 'b': // submit extern control |
||
110 | killagreg | 402 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
112 | killagreg | 403 | UART1_ConfirmFrame = ExternControl.Frame; |
41 | ingob | 404 | break; |
405 | |||
406 | case 'd': // request for debug data; |
||
110 | killagreg | 407 | UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
408 | if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE; |
||
41 | ingob | 409 | break; |
410 | |||
63 | killagreg | 411 | case 'c': // request for 3D data; |
110 | killagreg | 412 | UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
413 | if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE; |
||
63 | killagreg | 414 | break; |
415 | |||
41 | ingob | 416 | case 'g':// request for external control data |
110 | killagreg | 417 | UART1_Request_ExternalControl = TRUE; |
41 | ingob | 418 | break; |
419 | |||
420 | case 'h':// reqest for display line |
||
110 | killagreg | 421 | RemoteKeys |= SerialMsg.pData[0]; |
112 | killagreg | 422 | if(RemoteKeys != 0) UART1_DisplayLine = 0; |
110 | killagreg | 423 | UART1_Request_Display = TRUE; |
41 | ingob | 424 | break; |
425 | |||
426 | case 'l':// reqest for display columns |
||
110 | killagreg | 427 | MenuItem = SerialMsg.pData[0]; |
428 | UART1_Request_Display1 = TRUE; |
||
41 | ingob | 429 | break; |
64 | holgerb | 430 | |
431 | case 'o': // request for navigation information |
||
110 | killagreg | 432 | UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
433 | if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE; |
||
64 | holgerb | 434 | break; |
435 | |||
41 | ingob | 436 | case 'v': // request for version info |
110 | killagreg | 437 | UART1_Request_VersionInfo = TRUE; |
41 | ingob | 438 | break; |
439 | default: |
||
440 | // unsupported command recieved |
||
441 | break; |
||
442 | } |
||
443 | break; // default: |
||
444 | } |
||
112 | killagreg | 445 | Buffer_Clear(&UART1_rx_buffer); |
41 | ingob | 446 | } |
447 | |||
448 | |||
449 | /*****************************************************/ |
||
450 | /* Send a character */ |
||
451 | /*****************************************************/ |
||
110 | killagreg | 452 | s16 UART1_Putchar(char c) |
41 | ingob | 453 | { |
110 | killagreg | 454 | if (c == '\n') UART1_Putchar('\r'); |
41 | ingob | 455 | // wait until txd fifo is not full |
456 | while (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET); |
||
457 | // transmit byte |
||
458 | UART_SendData(UART1, c); |
||
459 | return (0); |
||
460 | } |
||
461 | |||
462 | /*****************************************************/ |
||
463 | /* Send a string to the debug uart */ |
||
464 | /*****************************************************/ |
||
110 | killagreg | 465 | void UART1_PutString(u8 *s) |
41 | ingob | 466 | { |
467 | if(s == NULL) return; |
||
468 | while (*s != '\0' && DebugUART == UART1) |
||
469 | { |
||
110 | killagreg | 470 | UART1_Putchar(*s); |
41 | ingob | 471 | s ++; |
472 | } |
||
473 | } |
||
474 | |||
110 | killagreg | 475 | /**************************************************************/ |
476 | /* Transmit tx buffer via debug uart */ |
||
477 | /**************************************************************/ |
||
478 | void UART1_Transmit(void) |
||
479 | { |
||
480 | u8 tmp_tx; |
||
481 | if(DebugUART != UART1) return; |
||
482 | // if something has to be send and the txd fifo is not full |
||
483 | if((UART1_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == RESET)) |
||
484 | { |
||
485 | tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer |
||
486 | UART_SendData(UART1, tmp_tx); // put character to txd fifo |
||
487 | // if terminating character or end of txd buffer reached |
||
112 | killagreg | 488 | if((tmp_tx == '\r') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes)) |
110 | killagreg | 489 | { |
112 | killagreg | 490 | Buffer_Clear(&UART1_tx_buffer); |
110 | killagreg | 491 | } |
492 | } |
||
493 | } |
||
41 | ingob | 494 | |
495 | |||
496 | /**************************************************************/ |
||
497 | /* Send the answers to incomming commands at the debug uart */ |
||
498 | /**************************************************************/ |
||
499 | void UART1_TransmitTxData(void) |
||
500 | { |
||
110 | killagreg | 501 | if(DebugUART != UART1) return; |
502 | UART1_Transmit(); // output pending bytes in tx buffer |
||
503 | if((UART1_tx_buffer.Locked == TRUE)) return; |
||
41 | ingob | 504 | |
110 | killagreg | 505 | if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE)) |
92 | killagreg | 506 | { |
110 | killagreg | 507 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request |
92 | killagreg | 508 | Echo = 0; // reset echo value |
110 | killagreg | 509 | UART1_Request_Echo = FALSE; |
92 | killagreg | 510 | } |
110 | killagreg | 511 | if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 512 | { |
110 | killagreg | 513 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16); |
514 | UART1_Request_DebugLabel = 0xFF; |
||
41 | ingob | 515 | } |
112 | killagreg | 516 | if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 517 | { |
112 | killagreg | 518 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame)); |
519 | UART1_ConfirmFrame = 0; |
||
41 | ingob | 520 | } |
110 | killagreg | 521 | if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 522 | { |
110 | killagreg | 523 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
524 | UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval); |
||
525 | UART1_Request_DebugData = FALSE; |
||
41 | ingob | 526 | } |
61 | holgerb | 527 | |
110 | killagreg | 528 | if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE)) |
61 | holgerb | 529 | { |
110 | killagreg | 530 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
531 | UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval); |
||
532 | UART1_Request_Data3D = FALSE; |
||
61 | holgerb | 533 | } |
534 | |||
110 | killagreg | 535 | if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 536 | { |
110 | killagreg | 537 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
538 | UART1_Request_ExternalControl = FALSE; |
||
41 | ingob | 539 | } |
110 | killagreg | 540 | if(UART1_Request_Display && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 541 | { |
542 | LCD_PrintMenu(); |
||
112 | killagreg | 543 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&DisplayBuff[UART1_DisplayLine * 20], 20); |
544 | UART1_DisplayLine++; |
||
545 | if(UART1_DisplayLine >= 4) UART1_DisplayLine = 0; |
||
110 | killagreg | 546 | UART1_Request_Display = FALSE; |
41 | ingob | 547 | } |
110 | killagreg | 548 | if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 549 | { |
550 | LCD_PrintMenu(); |
||
110 | killagreg | 551 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
552 | UART1_Request_Display1 = FALSE; |
||
41 | ingob | 553 | } |
110 | killagreg | 554 | if(UART1_Request_VersionInfo && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 555 | { |
110 | killagreg | 556 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
557 | UART1_Request_VersionInfo = FALSE; |
||
41 | ingob | 558 | } |
110 | killagreg | 559 | if(( (UART1_NaviData_Interval && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 560 | { |
561 | NaviData.Errorcode = ErrorCode; |
||
110 | killagreg | 562 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
563 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval); |
||
564 | UART1_Request_NaviData = FALSE; |
||
41 | ingob | 565 | } |
110 | killagreg | 566 | if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 567 | { |
110 | killagreg | 568 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
569 | UART1_Request_ErrorMessage = FALSE; |
||
41 | ingob | 570 | } |
110 | killagreg | 571 | if(UART1_Request_SendFollowMe && (UART1_tx_buffer.Locked == FALSE) && (GPSData.NumOfSats >= 4)) // sending for "Follow me" |
41 | ingob | 572 | { |
573 | GPS_CopyPosition(&(GPSData.Position),&(FollowMe.Position)); |
||
574 | FollowMe.Position.Status = NEWDATA; |
||
575 | FollowMe.Heading = -1; |
||
576 | FollowMe.ToleranceRadius = 1; |
||
577 | FollowMe.HoldTime = 60; |
||
578 | FollowMe.Event_Flag = 0; |
||
579 | FollowMe.reserve[0] = 0; // reserve |
||
580 | FollowMe.reserve[1] = 0; // reserve |
||
581 | FollowMe.reserve[2] = 0; // reserve |
||
582 | FollowMe.reserve[3] = 0; // reserve |
||
110 | killagreg | 583 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe)); |
584 | UART1_Request_SendFollowMe = FALSE; |
||
41 | ingob | 585 | } |
110 | killagreg | 586 | if(UART1_Request_NewWaypoint && (UART1_tx_buffer.Locked == FALSE)) |
41 | ingob | 587 | { |
588 | u8 WPNumber = WPList_GetCount(); |
||
110 | killagreg | 589 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
590 | UART1_Request_NewWaypoint = FALSE; |
||
41 | ingob | 591 | } |
110 | killagreg | 592 | if((UART1_Request_ReadWaypoint != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
92 | killagreg | 593 | { |
594 | u8 WPNumber = WPList_GetCount(); |
||
110 | killagreg | 595 | if (UART1_Request_ReadWaypoint < WPNumber) |
92 | killagreg | 596 | { |
110 | killagreg | 597 | 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 | 598 | } |
599 | else |
||
600 | { |
||
110 | killagreg | 601 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
92 | killagreg | 602 | } |
110 | killagreg | 603 | UART1_Request_ReadWaypoint = 0xFF; |
92 | killagreg | 604 | } |
110 | killagreg | 605 | UART1_Transmit(); // output pending bytes in tx buffer |
41 | ingob | 606 | } |
607 |