Rev 163 | Rev 171 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 163 | Rev 165 | ||
---|---|---|---|
Line 181... | Line 181... | ||
181 | GPIO_InitTypeDef GPIO_InitStructure; |
181 | GPIO_InitTypeDef GPIO_InitStructure; |
182 | UART_InitTypeDef UART_InitStructure; |
182 | UART_InitTypeDef UART_InitStructure; |
Line 183... | Line 183... | ||
183 | 183 | ||
184 | // initialize txd buffer |
184 | // initialize txd buffer |
185 | Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN); |
185 | Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN); |
186 | 186 | ||
187 | // initialize rxd buffer |
187 | // initialize rxd buffer |
Line 188... | Line 188... | ||
188 | Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN); |
188 | Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN); |
189 | 189 | ||
Line 229... | Line 229... | ||
229 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
229 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
230 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
230 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
231 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
231 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
Line 232... | Line 232... | ||
232 | 232 | ||
233 | UART_DeInit(UART1); // reset uart 1 to default |
233 | UART_DeInit(UART1); // reset uart 1 to default |
234 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
234 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
235 | // enable uart 1 interrupts selective |
235 | // enable uart 1 interrupts selective |
236 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
236 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
237 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
237 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
238 | // configure the uart 1 interupt line |
238 | // configure the uart 1 interupt line |
Line 279... | Line 279... | ||
279 | c = UART_ReceiveData(UART1); |
279 | c = UART_ReceiveData(UART1); |
Line 280... | Line 280... | ||
280 | 280 | ||
281 | // check for abort condition (ESC ESC 0x55 0xAA 0x00) |
281 | // check for abort condition (ESC ESC 0x55 0xAA 0x00) |
282 | switch (abortState) |
282 | switch (abortState) |
283 | { |
283 | { |
284 | case 0: |
284 | case 0: |
285 | if (c == 27) abortState++; |
285 | if (c == 27) abortState++; |
286 | break; |
286 | break; |
287 | case 1: |
287 | case 1: |
288 | if (c == 27) abortState++; |
288 | if (c == 27) abortState++; |
289 | else abortState = 0; |
289 | else abortState = 0; |
290 | break; |
290 | break; |
291 | case 2: |
291 | case 2: |
292 | if (c == 0x55) abortState++; |
292 | if (c == 0x55) abortState++; |
293 | else abortState = 0; |
293 | else abortState = 0; |
294 | break; |
294 | break; |
295 | case 3: |
295 | case 3: |
296 | if (c == 0xAA) abortState++; |
296 | if (c == 0xAA) abortState++; |
297 | else abortState = 0; |
297 | else abortState = 0; |
298 | break; |
298 | break; |
299 | case 4: |
299 | case 4: |
300 | if (c == 0x00) |
300 | if (c == 0x00) |
301 | { |
301 | { |
302 | if(DebugUART == UART0) |
302 | if(DebugUART == UART0) |
303 | { |
303 | { |
304 | UART0_Connect_to_MKGPS(); |
304 | UART0_Connect_to_MKGPS(); |
305 | TIMER2_Init(); // enbable servo outputs |
305 | TIMER2_Init(); // enbable servo outputs |
306 | fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer |
306 | fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer |
307 | } |
307 | } |
308 | DebugUART = UART1; |
308 | DebugUART = UART1; |
309 | } |
309 | } |
310 | abortState = 0; |
310 | abortState = 0; |
311 | break; |
311 | break; |
312 | } // end switch abort state |
312 | } // end switch abort state |
313 | // if the Debug uart is not UART1, redirect input to the Debug UART |
313 | // if the Debug uart is not UART1, redirect input to the Debug UART |
Line 341... | Line 341... | ||
341 | /**************************************************************/ |
341 | /**************************************************************/ |
342 | void UART1_ProcessRxData(void) |
342 | void UART1_ProcessRxData(void) |
343 | { |
343 | { |
344 | // return on forwarding uart or unlocked rx buffer |
344 | // return on forwarding uart or unlocked rx buffer |
345 | if(DebugUART != UART1) return; |
345 | if(DebugUART != UART1) return; |
346 | 346 | ||
347 | u8 c; |
347 | u8 c; |
348 | // if rx buffer is not locked |
348 | // if rx buffer is not locked |
349 | if(UART1_rx_buffer.Locked == FALSE) |
349 | if(UART1_rx_buffer.Locked == FALSE) |
350 | { //collect data from primary rx fifo |
350 | { //collect data from primary rx fifo |
351 | while(fifo_get(&UART1_rx_fifo, &c)) |
351 | while(fifo_get(&UART1_rx_fifo, &c)) |
352 | { // break if complete frame is collected |
352 | { // break if complete frame is collected |
353 | if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break; |
353 | if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break; |
354 | } |
354 | } |
355 | } |
355 | } |
Line 412... | Line 412... | ||
412 | break; |
412 | break; |
413 | } |
413 | } |
414 | break; |
414 | break; |
Line 415... | Line 415... | ||
415 | 415 | ||
416 | case 'w':// Append Waypoint to List |
416 | case 'w':// Append Waypoint to List |
417 | { |
417 | { |
418 | static u8 oldIndex = 0x00; |
418 | static u8 oldIndex = 0x00; |
419 | 419 | ||
420 | pWaypoint = (Waypoint_t*)SerialMsg.pData; |
420 | pWaypoint = (Waypoint_t*)SerialMsg.pData; |
421 | if(pWaypoint->Position.Status == INVALID) |
421 | if(pWaypoint->Position.Status == INVALID) |
422 | { // clear WP List |
422 | { // clear WP List |
423 | WPList_Clear(); |
423 | WPList_Clear(); |
424 | oldIndex = 0x00; |
424 | oldIndex = 0x00; |
425 | GPS_pWaypoint = WPList_Begin(); |
- | |
426 | //UART1_PutString("\r\nClear WP List\r\n"); |
425 | GPS_pWaypoint = WPList_Begin(); |
427 | UART1_Request_NewWaypoint = TRUE; |
426 | UART1_Request_NewWaypoint = TRUE; |
428 | } |
427 | } |
429 | else if (pWaypoint->Position.Status == NEWDATA) |
428 | else if (pWaypoint->Position.Status == NEWDATA) |
430 | { // app current WP to the list |
- | |
431 | sprintf(text, "\r\nAdd WP: Index= %d, oldIndex = %d\r\n", pWaypoint->Index, oldIndex); |
- | |
432 | UART1_PutString(text); |
- | |
433 | 429 | { // app current WP to the list |
|
434 | if (pWaypoint->Index == oldIndex + 1) |
430 | if (pWaypoint->Index == oldIndex + 1) |
435 | { |
431 | { |
436 | WPList_Append(pWaypoint); |
432 | WPList_Append(pWaypoint); |
437 | BeepTime = 500; |
433 | BeepTime = 500; |
438 | oldIndex = pWaypoint->Index; |
434 | oldIndex = pWaypoint->Index; |
439 | UART1_Request_NewWaypoint = TRUE; |
435 | UART1_Request_NewWaypoint = TRUE; |
440 | } |
- | |
441 | 436 | } |
|
442 | 437 | } |
|
443 | } |
- | |
444 | } |
438 | } |
Line 445... | Line 439... | ||
445 | break; |
439 | break; |
446 | 440 | ||
447 | case 'x':// Read Waypoint from List |
441 | case 'x':// Read Waypoint from List |
Line 451... | Line 445... | ||
451 | case 'j':// Set/Get NC-Parameter |
445 | case 'j':// Set/Get NC-Parameter |
452 | switch(SerialMsg.pData[0]) |
446 | switch(SerialMsg.pData[0]) |
453 | { |
447 | { |
454 | case 0: // get |
448 | case 0: // get |
455 | break; |
449 | break; |
456 | 450 | ||
457 | case 1: // set |
451 | case 1: // set |
458 | { |
452 | { |
459 | s16 value; |
453 | s16 value; |
460 | value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100; |
454 | value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100; |
461 | NCParams_SetValue(SerialMsg.pData[1], &value); |
455 | NCParams_SetValue(SerialMsg.pData[1], &value); |
462 | } |
456 | } |
463 | break; |
457 | break; |
Line 464... | Line 458... | ||
464 | 458 | ||
465 | default: |
459 | default: |
466 | break; |
460 | break; |
467 | } |
461 | } |
468 | UART1_Request_ParameterId = SerialMsg.pData[1]; |
462 | UART1_Request_ParameterId = SerialMsg.pData[1]; |
469 | UART1_Request_Parameter = TRUE; |
463 | UART1_Request_Parameter = TRUE; |
470 | break; |
464 | break; |