none
ppc2003上的GPS问题 RRS feed

  • 問題


  • 我的程序是采用单独线程轮询串口获取数据的方式。

    刚开始可以正常获取$GPGGA、 $GPGSV、 $GPRMC等GPS数据。

    后来莫名其妙的就获取不到了。得到的全是$PGLOR,RID,PPC,BTL.....

    很晕。网上搜了,说不是设备原因,是程序的原因。

    望高手帮忙解答

     

    2008年9月15日 上午 09:51

解答

  • 如你所說的一樣,6515所用的是AGPS,不是SiRF III. 所以會出現$PGLOR這類的訊息.
    或許這篇文章能給你一些答案

    參考 : http://www.gpspassion.com/fr/articles.asp?id=166

    2008年9月18日 上午 08:14

所有回覆

  • 請貼上收資料有關資料收集部分的程式碼

    2008年9月15日 上午 10:07
    版主
  • Code Snippet

    //读取串口数据线程
    UINT PortReadThread(LPVOID lpvoid)

        DWORD dwCommModemStatus;
     
        // Specify a set of events to be monitored for the port.
        SetCommMask (m_hPort, EV_RXCHAR | EV_CTS | EV_DSR | EV_RLSD | EV_RING);
     //=============================
     int ReadFalge=0,ReadCount=0;
     
        while (m_hPort != INVALID_HANDLE_VALUE)
     {
      // Wait for an event to occur for the port.
      WaitCommEvent (m_hPort, &dwCommModemStatus, 0);
      
      // Re-specify the set of events to be monitored for the port.
      SetCommMask (m_hPort, EV_RXCHAR | EV_CTS | EV_DSR | EV_RING);
      
      if (dwCommModemStatus & EV_RXCHAR)
      {
       // Loop for waiting for the data.
       int  K;
       BYTE bText[MAXLENGTH];
       
       K  = 0;
       
       for(;;)
       {
        DWORD nLength;
        COMSTAT ComStat;
        DWORD dwErrorFlags;
        BYTE bBuffer[MAXLENGTH];
        
        ClearCommError(m_hPort,&dwErrorFlags,&ComStat);
        
        nLength = 1;         //每次只读一个字节
        ReadFile(m_hPort,bBuffer,nLength,&nLength,NULL);
        
        if(bBuffer[0] == '\n')
        { 
         bText[K] = 0;
         
         if ((bText[0] == '$') & (bText[1] == 'G') & (bText[2] == 'P') &
          (bText[3] == 'G') & (bText[4] == 'G') & (bText[5] == 'A') )
         {
          WriteGGAToFile(bText);
         }
         else if ((bText[0] == '$') & (bText[1] == 'G') & (bText[2] == 'P') &
          (bText[3] == 'G') & (bText[4] == 'S') & (bText[5] == 'V') )
         {
          WriteGSVToFile(bText);
         }
         else if ((bText[0] == '$') & (bText[1] == 'G') & (bText[2] == 'P') &
          (bText[3] == 'R') & (bText[4] == 'M') & (bText[5] == 'C') )
         {
          WriteRMCToFile(bText);
         }

         K   = 0;

        }
        else if(bBuffer[0] == '$')
        {
         K   = 0;
         bText[K] = bBuffer[0];
         K++;
        }
        else
        {
         bText[K] = bBuffer[0];
         K++;
        }
        Sleep(1);
       }
      }

     }
     
     return true;
    }

     

     

     

    2008年9月16日 上午 12:43
  • Code Snippet
    //打开串口
    BOOL OpenPort(UINT portNo,UINT baud,UINT parity,UINT databits,UINT stopbits)
    {
     // if the port is already opened: close it
     if (m_hPort != NULL)
     {  
      CloseHandle(m_hPort);
      m_hPort = NULL;
     }
     
     ///////////////////////////////////////////
     //PortInitialize
     DCB    PortDCB;
     COMMTIMEOUTS CommTimeouts;
     
     //////////////////////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////////////////////
     //打开串口
     CString temp;
     TCHAR szPort[10];
     
     temp.Format(_T("COM%d:"), portNo);
     wcscpy(szPort,temp);
     
     m_hPort = CreateFile(szPort,      // communication port string (COMX)
      GENERIC_READ,     // read/write types
      0,        // comm devices must be opened with exclusive access
      NULL,       // no security attributes
      OPEN_EXISTING,     // comm devices must use OPEN_EXISTING
      FILE_ATTRIBUTE_NORMAL,   // Async I/O
      NULL);       // template must be 0 for comm devices
     
     // If it fails to open the port, return FALSE.
     if ( m_hPort == INVALID_HANDLE_VALUE )
     {
      //ProcessErrorMessage(_T("CreateFile()"));
      
      //MessageBox(_T("打开串口错误!!!"),_T("提示信息"),MB_ICONEXCLAMATION  | MB_OK);
      
      CloseHandle(m_hPort);
      m_hPort = NULL;
      
      return FALSE;
     }
     
     SetupComm(m_hPort,512,512);
     //////////////////////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////////////////////
     
     
     //配置串口
     ZeroMemory(&PortDCB, sizeof(DCB));
     PortDCB.DCBlength = sizeof (DCB);  
     
     // Get the default port setting information.
     GetCommState (m_hPort, &PortDCB);
     if (GetCommState (m_hPort, &PortDCB) == FALSE)
     {  
      //ProcessErrorMessage(_T("GetCommState()"));
      
      //MessageBox(_T("配置串口错误!!!"),_T("提示信息"),MB_ICONEXCLAMATION  | MB_OK);
      
      CloseHandle(m_hPort);
      m_hPort = NULL;
      
      return FALSE;
     }
     
     // Change the DCB structure settings.
     PortDCB.BaudRate   = baud;     // Current baud
     PortDCB.fBinary    = TRUE;     // Binary mode; no EOF check
     PortDCB.fParity    = TRUE;     // Enable parity checking.
     PortDCB.fOutxCtsFlow  = FALSE;    // No CTS output flow control
     PortDCB.fOutxDsrFlow  = FALSE;    // No DSR output flow control
     PortDCB.fDtrControl   = DTR_CONTROL_ENABLE;
     // DTR flow control type
     PortDCB.fDsrSensitivity  = FALSE;    // DSR sensitivity
     PortDCB.fTXContinueOnXoff = TRUE;     // XOFF continues Tx
     PortDCB.fOutX    = FALSE;                // No XON/XOFF out flow control
     PortDCB.fInX    = FALSE;                // No XON/XOFF in flow control
     PortDCB.fErrorChar   = FALSE;    // Disable error replacement.
     PortDCB.fNull    = FALSE;                // Disable null stripping.
     PortDCB.fRtsControl   = RTS_CONTROL_ENABLE;
     // RTS flow control
     PortDCB.fAbortOnError  = FALSE;    // Do not abort reads/writes on
     // error.
     PortDCB.ByteSize   = databits;     // Number of bits/bytes, 4-8
     PortDCB.Parity    = NOPARITY;    // 0-4=no,odd,even,mark,space
     PortDCB.StopBits   = stopbits;    // 0,1,2 = 1, 1.5, 2
     
     // Configure the port according to the specifications of the DCB structure.
     if (SetCommState (m_hPort, &PortDCB) == FALSE)
     { 
      // Could not create the read thread.
      //ProcessErrorMessage(_T("SetCommState()"));
      
      //MessageBox(_T("DCB结构错误!!!"),_T("提示信息"),MB_ICONEXCLAMATION  | MB_OK);
      
      CloseHandle(m_hPort);
      m_hPort = NULL;
      
      return FALSE;
     }
     //////////////////////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////////////////////
     
     //设置延时
     // Retrieve the time-out parameters for all read and write operations
     // on the port.
     ZeroMemory(&CommTimeouts, sizeof(COMMTIMEOUTS));
     if (GetCommTimeouts (m_hPort, &CommTimeouts) == FALSE)
     {  
      
      //MessageBox(_T("设置延时错误!!!"),_T("提示信息"),MB_ICONEXCLAMATION  | MB_OK);
      
      CloseHandle(m_hPort);
      m_hPort = NULL;
      
      return FALSE;
     }
     
     // Change the COMMTIMEOUTS structure settings.
     CommTimeouts.ReadIntervalTimeout   = 2000; 
     CommTimeouts.ReadTotalTimeoutMultiplier  = 0; 
     CommTimeouts.ReadTotalTimeoutConstant  = 0;   
     CommTimeouts.WriteTotalTimeoutMultiplier = 50; 
     CommTimeouts.WriteTotalTimeoutConstant  = 1000;   
     
     // Set the time-out parameters for all read and write operations
     // on the port.
     if (!SetCommTimeouts (m_hPort, &CommTimeouts))
     {   
      // Could not create the read thread.
      
      //MessageBox(_T("COMMTIMEOUTS结构错误!!!"),_T("提示信息"),MB_ICONEXCLAMATION  | MB_OK);
      
      CloseHandle(m_hPort);
      m_hPort = NULL;
      
      return FALSE;
     }
     
     // Direct the port to perform extended functions SETDTR and SETRTS.
     // SETDTR: Sends the DTR (data-terminal-ready) signal.
     // SETRTS: Sends the RTS (request-to-send) signal.
     EscapeCommFunction (m_hPort, SETDTR);
     EscapeCommFunction (m_hPort, SETRTS);
     
     // flush the port
     //if(!PurgeComm(m_hPort, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT))
     //{
     // ProcessErrorMessage(_T("PurgeComm()"));
     // return false;
     //}
     TRACE(_T("串口打开成功"));
     
     return TRUE;
    }

     

     

     

    2008年9月16日 上午 12:50
  •  

    怎么没人回答呢!急!
    2008年9月18日 上午 02:05
  • 建議你先不要去做 GPS的Parse

    先Dump GPS output 看看會不會發生你說的現象

    不管會或是不會

    你應該都有方向找到 Bug 在那了

    底下是一個 demo + dummy GPS output

    GetGPSLine 後你在去做 Parse 比較容易

     

    Code Snippet

    typedef enum { FALSE=0, TRUE } BOOL;

     

    static char dummyGPS(void)
    {
     static int i = 0;
     static char dummy[] = "TQWAGEAQe" // test fail sequenc
      "$GPGSA,A,3,01,05,08,,,21,23,25,29,,,,1.9,1.9,1.0*31\n"
      "$GPGSV,3,1,10,01,73,344,36,05,26,071,30,08,48,054,35,09,13,045,00*74\n"
      "$GPGSV,3,2,10,15,21,314,00,21,72,135,36,23,36,129,30,25,34,215,39*7D\n"
      "$GPGSV,3,3,10,29,54,291,33,30,28,115,30,,,,,,,,*77\n"
      "$PGRME,24.5,M,16.6,M,31.5,M*1B\n"
      "$GPGLL,4157.356,N,08340.213,W,223706,A*32\n"
      "$PGRMZ,547,f,3*1D\n"
      "$PGRMM,WGS 84*06\n"
      "$GPBOD,,T,,M,,*47\n"
      "$GPRTE,1,1,c,0*07\n"
      "$GPRMC,223707,A,4157.356,N,08340.213,W,001.3,344.7,160898,006.2,W*71\n"
      "$GPRMB,A,,,,,,,,,,,,V*71\n"
      "$GPGGA,223708,4157.356,N,08340.213,W,1,07,1.9,166.7,M,-34.3,M,,*74\n"
      "$GPGSA,A,3,01,05,08,,,21,23,25,29,,,,1.9,1.9,1.0*31\n"
      "$GPGSV,3,1,10,01,73,344,34,05,26,071,30,08,48,054,35,09,13,045,00*76\n"
      "$GPGSV,3,2,10,15,21,314,00,21,72,135,35,23,36,129,30,25,34,215,38*7F\n"
      "$GPGSV,3,3,10,29,54,291,32,30,28,115,30,,,,,,,,*76\n"
      "$PGRME,24.6,M,20.8,M,34.7,M*14\n"
      "$GPGLL,4157.356,N,08340.213,W,223708,A*3C\n"
      "$PGRMZ,542,f,3*18\n"
      "$PGRMM,WGS 84*06\n"
      "$GPBOD,,T,,M,,*47\n"
      "$GPRTE,1,1,c,0*07\n"
      "$GPRMC,223710,A,4157.357,N,08340.213,W,001.2,344.7,160898,006.2,W*77\n"
      "$GPRMB,A,,,,,,,,,,,,V*71\n"
      "$GPGGA,223710,4157.357,N,08340.213,W,1,07,1.7,164.9,M,-34.3,M,,*7E\n"
      "$GPGSA,A,3,01,05,08,,,21,23,25,29,,,,2.6,1.7,1.8*3B\n"
      "$GPGSV,3,1,10,01,73,344,34,05,26,071,30,08,48,054,35,09,13,045,00*76\n"
      "$GPGSV,3,2,10,15,21,314,00,21,72,135,36,23,36,129,30,25,34,215,37*73\n"
      "$GPGSV,3,3,10,29,54,291,31,30,28,115,30,,,,,,,,*75\n"
      "$PGRME,25.3,M,24.8,M,38.1,M*1E\n"
      "$GPGLL,4157.358,N,08340.213,W,223710,A*3B\n"
      "$PGRMZ,540,f,3*1A\n"
      "$PGRMM,WGS 84*06\n"
      "$GPBOD,,T,,M,,*47\n"
      "$GPRTE,1,1,c,0*07\n"
      "$GPRMC,223712,A,4157.358,N,08340.214,W,001.2,344.7,160898,006.2,W*7D\n"
      "$GPRMB,A,,,,,,,,,,,,V*71\n"
      "$GPGGA,223712,4157.358,N,08340.214,W,1,07,1.8,163.9,M,-34.3,M,,*7C\n"
      "$GPGSA,A,3,01,,08,,,21,23,25,29,,,,2.8,1.8,1.3*34\n"
      "$GPGSV,3,1,10,01,73,344,34,05,26,071,30,08,48,054,35,09,13,045,00*76\n"
      "$GPGSV,3,2,10,15,21,314,00,21,72,135,36,23,36,129,30,25,34,215,36*72\n"
      "$GPGSV,3,3,10,29,54,291,31,30,28,115,30,,,,,,,,*75\n"
      "$PGRME,25.3,M,24.8,M,38.1,M*1E\n"
      "$GPGLL,4157.358,N,08340.214,W,223712,A*3E\n"
      "$PGRMZ,538,f,3*15\n"
      "$PGRMM,WGS 84*06\n"
      "$GPBOD,,T,,M,,*47\n"
      "$GPRTE,1,1,c,0*07\n"
      "$GPRMC,223714,A,4157.359,N,08340.214,W,001.2,344.7,160898,006.2,W*7A\n"
      "$GPRMB,A,,,,,,,,,,,,V*71\n"
      "$GPGGA,223714,4157.359,N,08340.214,W,1,06,1.9,163.4,M,-34.3,M,,*76\n"
      "$GPGSA,A,3,01,,08,,,21,23,25,29,,,,3.0,1.9,1.5*3A\n"
      "$GPGSV,3,1,10,01,73,344,34,05,26,071,30,08,48,054,36,09,13,045,00*75\n"
      "$GPGSV,3,2,10,15,21,314,00,21,72,135,36,23,36,129,30,25,34,215,36*72\n"
      "$GPGSV,3,3,10,29,54,291,32,30,28,115,30,,,,,,,,*76\n"
      "$PGRME,25.3,M,24.8,M,38.1,M*1E\n"
      "$GPGLL,4157.360,N,08340.214,W,223714,A*33\n"
      "$PGRMZ,537,f,3*1A\n"
      "$PGRMM,WGS 84*06\n"
      "$GPBOD,,T,,M,,*47\n"
      "$GPRTE,1,1,c,0*07\n"
      "$GPRMC,223716,A,4157.360,N,08340.215,W,001.2,344.7,160898,006.2,W*73\n"
      "$GPRMB,A,,,,,,,,,,,,V*71\n"
      "$GPGGA,223716,4157.360,N,08340.215,W,1,06,1.9,163.8,M,-34.3,M,,*73\n"
      "$GPGSA,A,3,01,,08,,,21,23,25,29,,,,3.0,1.9,1.5*3A\n"
      "$GPGSV,3,1,10,01,73,344,34,05,26,071,30,08,48,054,35,09,13,045,00*76\n"
      "$GPGSV,3,2,10,15,21,314,00,21,72,135,36,23,36,129,30,25,34,215,36*72\n"
      "$GPGSV,3,3,10,29,54,291,31,30,28,115,30,,,,,,,,*75\n"
      "$PGRME,25.3,M,24.8,M,38.1,M*1E\n"
      "$GPGLL,4157.361,N,08340.215,W,223716,A*31\n"
      "$PGRMZ,538,f,3*15\n";

      if ( i >= sizeof(dummy))
      {
       i = 0; // reset i
      }
      return dummy[i++];
    }

    static char getGPSChar(void)
    {
     return dummyGPS();
    }

    static BOOL getGPSLine(char* buff, int size)
    {
     char tmp[256];
     char rx;
     int  len = 0;
     BOOL begin = FALSE;

     do
     {
      rx = getGPSChar();

      if ('$' == rx)
      {
       begin = TRUE;
       len = 0;
      }

      if (TRUE == begin)
      {
       tmp[len++] = rx;
      }
     } while(rx != '\n');

     tmp[len] = '\0'; // put terminate char

     if ((size > len) && (len > 4))
     {
      strcpy(buff,tmp);
      return TRUE;
     }

     return FALSE;
    }

    int _tmain(int argc, _TCHAR* argv[])
    {
     char test[100];
     int i;
     
     for (i = 0; i < 500; i++)
     {
      if (TRUE == getGPSLine(test,sizeof(test)))
      {
       printf("%s", test);
      }
     }
     return 0;
    }

     

     

    2008年9月18日 上午 02:28
  • 谢谢!

     

    我把获取的所有以$开头GPS data写在一个txt文件中。内容都是$PGLOR,RID,PPC,BTL,1.24.2041.0.123.4.98*05

     

    hp iPAQ hw6515的定位采取的是A-GPS。我猜想可能和这一点有关系。

     

    我猜想,$PGLOR   这一条语句是用来从GSM网络中的服务器获取定位信息。

     

    还有待证实。

    2008年9月18日 上午 07:52
  • 如你所說的一樣,6515所用的是AGPS,不是SiRF III. 所以會出現$PGLOR這類的訊息.
    或許這篇文章能給你一些答案

    參考 : http://www.gpspassion.com/fr/articles.asp?id=166

    2008年9月18日 上午 08:14
  •  

    谢谢!
    2008年9月19日 上午 02:09