GPS.c
上传用户:buddy3
上传日期:2022-06-12
资源大小:100k
文件大小:8k
- #include "..config.h"
- struct GPSGPRMC GPS_GPRMC; //GPS数据结构体
- char GPS_Time = 0; //GPS计数器
- char GPSState = 0; //GPS状态
- const char GPS_V = 0; //没定到位的状态
- const char GPS_A = 1; //定到位的状态
- //$HZQJ,$GPRMC,064528,A,3002.6166,N,12053.053,E,14.9,276.3,260407,,,ARM_V2.29TEST,5750106008,01001208,0,
- const int GPSData_Buf_Len = 130; //上发的GPS数据长度
- char GPSData_Buf[130] = {0}; //上发的GPS协议数据
- char GPSState_ChangeFlag = 0; //GPS状态改变系数
- //GPS数据接收保护,循环里每次减一
- //每收到GPRMC数据的时候 GPSData_Protect = GPSData_ProtectMAX ,
- //当 GPSData_Protect = 0的时候,GSM,GPS掉电重启动
- const int GPSData_ProtectMAX = 10;
- int GPSData_Protect = 10;
- /*
- **********************************************************************
- 函数:GPS_0183
- 参数:*p GPS接收的数据
- 返回:无
- 功能:GPS数据处理
- **********************************************************************
- */
- void GPS_0183(char *p)
- {
- int i;
- char GPRMC_Buf[100] = {0};
- char *p1;
- if(strstr(p,"$GPRMC"))
- {
- char *GPRMC_P;
- GPRMC_P = GPRMC_Buf;
- for(i=0;i<100;i++)
- {
- if(*p == 'r') break;
- GPRMC_Buf[i] = *p++;
- }
-
- GPS_Time++; //GPS计数器
-
- GPSData_Protect = GPSData_ProtectMAX;
-
- //UART0_SendStr_char(GPRMC_Buf);
-
- if(strstr(GPRMC_Buf,",A,")) //GPS定到位
- {
- GPSState = GPS_A; //设置LED状态标志
- State[1] = '0'; //修改系统GPS状态位 0 表示定到位
- //GPS时间
- p1 = strchr(GPRMC_P,',');
- p1++;
- memset(GPS_GPRMC.GPS3_Time,0,GPS_TD);
- strncpy(GPS_GPRMC.GPS3_Time,p1,(GPS_TD-1));
- GPS_GPRMC.GPS3_Time[GPS_TD-1] = 0;
- //UART0_SendStr_char("rnGPS3_Time==");
- //UART0_SendStr_char(GPS_GPRMC.GPS3_Time);
- //UART0_SendStr_char("==rn");
- //GPS有效位
- p1 = strchr(p1,',');
- p1++;
- memset(GPS_GPRMC.GPS4_A,0,GPS_ANE);
- strncpy(GPS_GPRMC.GPS4_A,p1,(GPS_ANE-1));
- GPS_GPRMC.GPS4_A[GPS_ANE-1] = 0;
- //UART0_SendStr_char("rnGPS4_A==");
- //UART0_SendStr_char(GPS_GPRMC.GPS4_A);
- //UART0_SendStr_char("==rn");
- //GPS纬度
- p1 = strchr(p1,',');
- p1++;
- memset(GPS_GPRMC.GPS5_weidu,0,GPS_wjfLen);
- for(i=0;i<GPS_wjfLen;i++)
- {
- if(*p1 == ',') break;
- GPS_GPRMC.GPS5_weidu[i] = *p1++;
- }
- GPS_GPRMC.GPS5_weidu[GPS_wjfLen-1] = 0;
- //UART0_SendStr_char("rnGPS5_weidu==");
- //UART0_SendStr_char(GPS_GPRMC.GPS5_weidu);
- //UART0_SendStr_char("==rn");
- //GPS南北半球
- p1 = strchr(p1,',');
- p1++;
- memset(GPS_GPRMC.GPS6_NS,0,GPS_ANE);
- strncpy(GPS_GPRMC.GPS6_NS,p1,(GPS_ANE-1));
- GPS_GPRMC.GPS6_NS[GPS_ANE-1] = 0;
- //UART0_SendStr_char("rnGPS6_NS==");
- //UART0_SendStr_char(GPS_GPRMC.GPS6_NS);
- //UART0_SendStr_char("==rn");
- //GPS经度
- p1 = strchr(p1,',');
- p1++;
- memset(GPS_GPRMC.GPS7_jingdu,0,GPS_wjfLen);
- for(i=0;i<GPS_wjfLen;i++)
- {
- if(*p1 == ',') break;
- GPS_GPRMC.GPS7_jingdu[i] = *p1++;
- }
- GPS_GPRMC.GPS7_jingdu[GPS_wjfLen-1] = 0;
- //UART0_SendStr_char("rnGPS7_jingdu==");
- //UART0_SendStr_char(GPS_GPRMC.GPS7_jingdu);
- //UART0_SendStr_char("==rn");
- //GPS东西半球
- p1 = strchr(p1,',');
- p1++;
- memset(GPS_GPRMC.GPS8_EW,0,GPS_ANE);
- strncpy(GPS_GPRMC.GPS8_EW,p1,(GPS_ANE-1));
- GPS_GPRMC.GPS8_EW[GPS_ANE-1] = 0;
- //UART0_SendStr_char("rnGPS8_EW==");
- //UART0_SendStr_char(GPS_GPRMC.GPS8_EW);
- //UART0_SendStr_char("==rn");
- //GPS速率
- p1 = strchr(p1,',');
- p1++;
- memset(GPS_GPRMC.GPS9_Velocity,0,GPS_wjfLen);
- for(i=0;i<GPS_wjfLen;i++)
- {
- if(*p1 == ',') break;
- GPS_GPRMC.GPS9_Velocity[i] = *p1++;
- }
- GPS_GPRMC.GPS9_Velocity[GPS_wjfLen-1] = 0;
- //UART0_SendStr_char("rnGPS9_Velocity==");
- //UART0_SendStr_char(GPS_GPRMC.GPS9_Velocity);
- //UART0_SendStr_char("==rn");
- //GPS方位角
- p1 = strchr(p1,',');
- p1++;
- memset(GPS_GPRMC.GPS10_FWJ,0,GPS_wjfLen);
- for(i=0;i<GPS_wjfLen;i++)
- {
- if(*p1 == ',') break;
- GPS_GPRMC.GPS10_FWJ[i] = *p1++;
- }
- GPS_GPRMC.GPS10_FWJ[GPS_wjfLen-1] = 0;
- //UART0_SendStr_char("rnGPS10_FWJ==");
- //UART0_SendStr_char(GPS_GPRMC.GPS10_FWJ);
- //UART0_SendStr_char("==rn");
- //GPS日期
- p1 = strchr(p1,',');
- p1++;
- memset(GPS_GPRMC.GPS11_Date,0,GPS_TD);
- strncpy(GPS_GPRMC.GPS11_Date,p1,(GPS_TD-1));
- GPS_GPRMC.GPS11_Date[GPS_TD-1] = 0;
- //UART0_SendStr_char("rnGPS11_Date==");
- //UART0_SendStr_char(GPS_GPRMC.GPS11_Date);
- //UART0_SendStr_char("==rn");
-
- memset(GPS_GPRMC.GPS12_wuxiao1,0,GPS_ANE);
-
- memset(GPS_GPRMC.GPS13_wuxiao2,0,GPS_ANE);
-
- memset(GPS_GPRMC.GPS14_V,0,Edition_Len);
- strncpy(GPS_GPRMC.GPS14_V,Edition,(Edition_Len-1));
- GPS_GPRMC.GPS14_V[Edition_Len-1] = 0;
-
- memset(GPS_GPRMC.GPS15_ID,0,TNumber_Len);
- strncpy(GPS_GPRMC.GPS15_ID,TerminalNumber,(TNumber_Len-1));
- GPS_GPRMC.GPS15_ID[TNumber_Len-1] = 0;
-
- memset(GPS_GPRMC.GPS16_State,0,State_Len);
- strncpy(GPS_GPRMC.GPS16_State,State,(State_Len-1));
- GPS_GPRMC.GPS16_State[State_Len-1] = 0;
-
- GPS_GPRMC.GPS17_Return[0] = '0';
-
- memset(GPSData_Buf,0,GPSData_Buf_Len); //清GPS数据缓存
-
- strcat(GPSData_Buf,GPS_GPRMC.GPS1_Head);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS2_Command);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS3_Time);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS4_A);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS5_weidu);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS6_NS);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS7_jingdu);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS8_EW);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS9_Velocity);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS10_FWJ);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS11_Date);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS12_wuxiao1);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS13_wuxiao2);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS14_V);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS15_ID);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS16_State);
- strcat(GPSData_Buf,",");
- strcat(GPSData_Buf,GPS_GPRMC.GPS17_Return);
- strcat(GPSData_Buf,",");
-
- GPSData_Buf[GPSData_Buf_Len-1] = 0;
-
- GPSState_ChangeFlag = 1;//GPSData_Buf缓存里的数据有更新,GPSState_ChangeFlag的值为1
-
- }
-
- else if(strstr(GPRMC_Buf,",V,"))
- {
- GPSState = GPS_V;
- State[1] = '1'; //修改系统GPS状态位 1 表示没定到位
- }
- }
- }
- /*
- **********************************************************************
- 函数:SendGPSData
- 参数:无
- 返回:无
- 功能:GPS定位的时候发送GPS数据,没定位的时候发送心跳信
- **********************************************************************
- */
- char SendGPSData_Time = 0;
- void SendGPSData(void)
- {
- if(GSMState == GPRS)
- {
- if(GPS_Time >=30)
- {
- char XinTiaoCon[100] = {0};
- strcat(XinTiaoCon,"$HZQJ,00,");
- strcat(XinTiaoCon,TerminalNumber);
- strcat(XinTiaoCon,",");
- strcat(XinTiaoCon,State);
- strcat(XinTiaoCon,",");
- strcat(XinTiaoCon,Edition);
- strcat(XinTiaoCon,",");
-
- GPS_Time = 0;
-
- if(GPSState == GPS_A)
- UART0_SendStr_char(GPSData_Buf);
- else
- {
- if(GPSState_ChangeFlag == 1) UART0_SendStr_char(GPSData_Buf); //当GPS数据有更新,发送最新的GPS数据
- else UART0_SendStr_char(XinTiaoCon);
- }
-
- GPSState_ChangeFlag = 0; //发送完GPS数据后状态改变系数清零
-
- if((SendGPSData_Time++) >= 5)
- {
- SendGPSData_Time = 0;
- GSMGPS_Reset(); //5次没有返回$HZQJ,01模块掉电重启
- }
- }
- }
- }