GPS.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**********************************************************************************
  2. * File Name: GPS.c
  3. * Function Describe:device for GPS
  4. * Relate Module:
  5. * Explain: the GPS should be using ublox
  6. * Writer: ShiLiangWen
  7. * Date: 2015.1.26
  8. ***********************************************************************************/
  9. #define THIS_FILE_ID 9
  10. //------------------------------------------------------------------------------------
  11. #include "includes.h"
  12. /**********************************************************************************
  13. GPSInit
  14. ***********************************************************************************/
  15. int GPSInit(void)
  16. {
  17. GPIO_InitTypeDef GPIO_InitStructure;
  18. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  19. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  20. GPIO_InitStructure.GPIO_Pin = GPS_PWREN_PIN;
  21. GPIO_Init(GPS_PWREN_PORT, &GPIO_InitStructure);
  22. SlwTrace(INF,"[13]GPSInit...",1);
  23. GPS_PWREN_LOW;
  24. os_dly_wait(50);
  25. GPS_PWREN_HIGH;
  26. sutGpsInfo.isGpsWork=0;
  27. sutGpsInfo.isGpsValid=0;
  28. sutGpsInfo.GpsInactiveCt=0;
  29. return 0;
  30. }
  31. /************************************
  32. GPSGetGPRMC
  33. 从NEMA数据流中提取$GPRMC行并返回
  34. ************************************/
  35. char* GPSGetGPRMC(char *msg)
  36. {
  37. /************************************
  38. $GPGGA,235957.003,,,,,0,0,,,M,,M,,*44
  39. $GPGSA,A,1,,,,,,,,,,,,,,,*1E
  40. $GPGSV,1,1,00*79
  41. $GPRMC,235957.003,V,,,,,0.00,0.00,050180,,,N*4D
  42. ************************************/
  43. char *p=msg;
  44. char ch1,ch2;
  45. ch1=*p;
  46. while(ch1){
  47. ch2=ch1;
  48. ch1=*p++;
  49. if(ch2==0xD && ch1==0x0A){
  50. if(p[0]=='$' && p[3]=='R' && p[5]=='C'){ //$GPRMC
  51. return p;
  52. }
  53. }
  54. }
  55. return 0;
  56. }
  57. /***********************************************************************************/