GPS.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. //on_off : 0, 拉低IO
  13. //on_off : 1, 拉高IO
  14. void GPS_RFPwrCtrl(char on_off)
  15. {
  16. static unsigned char firstIn=0;
  17. char buf[20];
  18. unsigned char status=0;
  19. if(on_off) status=1;
  20. if(firstIn==0)
  21. {
  22. firstIn++;
  23. os_dly_wait(10);
  24. ModemSendAT("AT^GPIOINIT=1\r\n");//初始化GPIO驱动
  25. os_dly_wait(10);
  26. ModemSendAT("AT^GPIOCFG=1,3,1\r\n");//使能GPS_RFPWR_EN [PIN56]
  27. }
  28. os_dly_wait(10);
  29. sprintf(buf, "AT^GPIOSET=3,%d\r\n",status);
  30. ModemSendAT(buf);
  31. }
  32. /**********************************************************************************
  33. GPSInit
  34. ***********************************************************************************/
  35. void GPSInit(void)
  36. {
  37. GPIO_InitTypeDef GPIO_InitStructure;
  38. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  39. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  40. GPIO_InitStructure.GPIO_Pin = GPS_PWR_PIN;
  41. GPIO_Init(GPS_PWR_PORT, &GPIO_InitStructure);
  42. GPS_PWR_ON;
  43. }
  44. void GPSRestart(void)
  45. {
  46. g_usRx3Len=0;
  47. rx3_ct=0;
  48. }
  49. /************************************
  50. GPSGetGPRMC
  51. 从NEMA数据流中提取$GPRMC行并返回
  52. ************************************/
  53. char* GPSGetGPRMC(char *msg)
  54. {
  55. /************************************
  56. $GPGGA,235957.003,,,,,0,0,,,M,,M,,*44
  57. $GPGSA,A,1,,,,,,,,,,,,,,,*1E
  58. $GPGSV,1,1,00*79
  59. $GPRMC,235957.003,V,,,,,0.00,0.00,050180,,,N*4D
  60. ************************************/
  61. char *p=msg;
  62. char ch1,ch2;
  63. ch1=*p;
  64. while(ch1){
  65. ch2=ch1;
  66. ch1=*p++;
  67. if(ch2==0xD && ch1==0x0A){
  68. if(p[0]=='$' && p[3]=='R' && p[5]=='C'){ //$GPRMC
  69. return p;
  70. }
  71. }
  72. }
  73. return 0;
  74. }
  75. /***********************************************************************************/