打印

gps编程接受的数据不连续!哪位大哥给我看一下!

[复制链接]
1355|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
cheneyli|  楼主 | 2010-5-31 10:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*********************************************************************************************
* File: gps_test.c
* Author: embest
* Desc: gps function test source code
* History: R.X.Huang Program start 2005.08.16
*********************************************************************************************/
#include "2410lib.h"
#define PRINT_UART0
#define MSG_GPRMC 0
#define MSG_GPGGA 1
#define MSG_GPGSA 2
#define MSG_GPGSV 3
/*------------------------------------------------------------------------------------------*/
/*          function declare              */
/*------------------------------------------------------------------------------------------*/
void gps_test(void);
char uart_tran(void);
void gps_info(UINT32T nType, UINT8T *pPt);
int f_nUartSelect;
void gps_test(void)
{
    char cInputChar;
    char nStrBuf[200];
int  set_baud,i = 0;
uart_change_baud(UART1,4800);
while(1)
{
  cInputChar = uart_tran();
  if (f_nUartSelect == UART0)
  {
#ifdef PRINT_UART0
   uart_select(0);       // send to user
   uart_sendbyte(cInputChar);
#endif
   uart_select(1);       // send to another uart
  }
  if (f_nUartSelect == UART1)
  {
   uart_select(0);       // send to another uart
   
   if (cInputChar == '$')
   {
    if(i != 0)
    {
     if(!strncmp(nStrBuf,"$GPRMC", 6))  // Format: $GPRMC,DATA,...,DATA
     {
      gps_info(MSG_GPRMC,&nStrBuf[6]);
     }
    }
    i = 0;
   }
   nStrBuf[i] = cInputChar;
   i++;
  }
  //uart_sendbyte(cInputChar);
}
}
/* sample GPS info string:
$GPGGA,063741.998,2234.2551,N,11408.0338,E,1,08,00.9,00053.1,M,-2.1,M,,*7B
$GPGSA,A,3,06,16,14,22,25,01,30,20,,,,,01.6,00.9,01.3*0D
$GPGSV,2,1,08,06,26,075,44,16,50,227,47,14,57,097,44,22,17,169,42*73
$GPGSV,2,2,08,25,49,352,45,01,64,006,46,30,13,039,39,20,15,312,34*79
$GPRMC,063741.998,A,2234.2551,N,11408.0338,E,000.0,276.0,150805,002.1,W*7C
*/
/*********************************************************************************************
* name:  gps_info
* func:  report the info read from GPS module
* para:  nType: input, GPS info type (defined)
   pPt: input, string info pointer
* ret:  none
* modify:
* comment:  
*********************************************************************************************/
void gps_info(UINT32T nType, UINT8T *pPt)
{
int i,err,nTime,nDate,nDotNum=0;
char buf[16];

switch(nType)
{
case MSG_GPRMC:
  while(*(pPt+1) != '*')
  {
   i = 0;
   while(*++pPt != ',')
    buf[i++] = *pPt;
   buf[i] = '\0';
   
   nDotNum++;
   switch(nDotNum)
   {
    case 1:    // 格林威治,063741.998: 6时37分41.998秒
     nTime = ((buf[0]-0x30)*10+(buf[1]-0x30))<<16|\
       ((buf[2]-0x30)*10+(buf[3]-0x30))<<8|\
       (buf[4]-0x30)*10+(buf[5]-0x30);
     break;
    case 2:    // 信息有效(A)/无效(V)
     if(buf[0] != 'A')
     {
      uart_printf(" InValid Message!");
      err =1;
     }
     break;
    case 3:    // 2234.2551,N: 北纬22.342551度
     if(!err) uart_printf(" North Latitude: %s",buf);
     break;
    case 5:    // 11408.0338,E: 东经114.080338度
     if(!err) uart_printf(" East Longtitude: %s\n",buf);
     break;
    case 9:    // 150805: 2005年8月15日
     uart_printf(" 20%c%c-%c%c-%c%c", \
                   buf[4],buf[5], \
                   buf[2],buf[3], \
                   buf[0],buf[1]);
    uart_printf(" %02d:%02d:%02d\n",(nTime>>16)&0xFF,(nTime>>8)&0xFF,(nTime)&0xFF);
    default:
     break;
   }
   
  }
  break;
case MSG_GPGGA:
  // add your code here
  break;
case MSG_GPGSA:
  // add your code here
  break;
case MSG_GPGSV:
  // add your code here
default:
  break;
}
}
/*********************************************************************************************
* name:  uart_tran
* func:  Get a character from the uart
* para:  none
* ret:  get a char from uart channel
* modify:
* comment:  
*********************************************************************************************/
char uart_tran(void)
{
while(1)
{
  if(rUTRSTAT0 & 0x1)
     {
   f_nUartSelect = UART0;
   return RdURXH0();       // Receive data read
     }
     else if(rUTRSTAT1 & 0x1)
     {
   f_nUartSelect = UART1;
   return rURXH1;       // Receive data ready
  }
}
}

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

1

帖子

1

粉丝