gpsCtl.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "includes.h"
  2. SUT_MESS sutMess;
  3. GPS_DEF gpsInfo;
  4. const unsigned short GPS_TimeTable[GPS_TABLE_NUM]={0,5,10,15,30,60,120,300};
  5. void gpsDataInit(void){
  6. memset((unsigned char *)&sutMess, 0, sizeof(SUT_MESS));
  7. memset((unsigned char *)&gpsInfo, 0, sizeof(GPS_DEF));
  8. }
  9. unsigned short getGPSTimeValue(unsigned char index){
  10. return GPS_TimeTable[index];
  11. }
  12. static unsigned char gpsCheckCnt=1;//默认开机查询一次
  13. void gpsCheckInfo(void){//查询GPS信息
  14. gpsCheckCnt++;
  15. }
  16. /*控制查询GPS状态
  17. dly:接口被调用的频率,单位ms*/
  18. void gpsProCtl(int dly){
  19. static unsigned short cnt=0;
  20. if(sutApp.gtMode!=0) return;//GT模式后不再查询
  21. if(getAppObjStatus(ASLEEP_POC)==0) return;//POC休眠时,不发指令
  22. if(++cnt<(5*1000/dly) && gpsCheckCnt==0) return;
  23. cnt=0;
  24. //以下5秒操作一次
  25. msgAtSend("AT+CGPS\r\n");
  26. gpsCheckCnt=0;
  27. }
  28. /*
  29. +CGPS:bf,ba,gf,[Lat],[Long]
  30. bf:0 部标关闭 1 部标打开
  31. ba:0 部标未鉴权 1 部标已鉴权
  32. gf:0 GPS关闭 1 GPS打开
  33. Lat: 已定位才有,定位纬度 度.度(已放大1000000)
  34. Long: 已定位才有,定位经度 度.度(已放大1000000)
  35. msg=bf,ba,gf,[Lat],[Long]
  36. */
  37. void proGpsMsg(char *msg){
  38. int i;
  39. unsigned char needCloseGps=0;
  40. unsigned char needOpenGps=0;
  41. unsigned char dotNum=0,lach=0;
  42. unsigned char bblF=0,bbAuth=0,gpsF=0;
  43. unsigned int Lat=0,Long=0;
  44. //获取部标开关状态
  45. bblF=atoi(msg);
  46. for(i=0;i<strlen(msg);i++){
  47. if(msg[i]==',') dotNum++;
  48. if(lach==','){
  49. if(dotNum==1) bbAuth=atoi(&msg[i]);
  50. else if(dotNum==2) gpsF=atoi(&msg[i]);
  51. else if(dotNum==3) Lat=atoi(&msg[i]);
  52. else if(dotNum==4) Long=atoi(&msg[i]);
  53. }
  54. lach=msg[i];
  55. }
  56. //优先根据gpsEnable打开或关闭GPS
  57. if(newPara.gpsEnable==0){
  58. needCloseGps=1;
  59. }else{
  60. //根据GPS上传间隔,打开/关闭GPS
  61. if(newPara.gpsTimeIndex<GPS_TABLE_NUM){
  62. if(GPS_TimeTable[newPara.gpsTimeIndex]==0) needCloseGps=1;
  63. else needOpenGps=1;
  64. }
  65. }
  66. if(needCloseGps!=0 && gpsF!=0){
  67. MSG_INFO(1, "Shut GPS");
  68. msgAtSend("AT+SGPS=0\r\n");
  69. gpsCheckInfo();//检查下是否成功
  70. }
  71. if(needOpenGps!=0 && gpsF==0){
  72. MSG_INFO(1, "Open GPS");
  73. msgAtSend("AT+SGPS=1\r\n");
  74. gpsCheckInfo();//检查下是否成功
  75. }
  76. //根据bubiaoEnable打开或关闭GPS
  77. if(newPara.bubiaoEnable==0){
  78. if(bblF!=0){
  79. MSG_INFO(1, "Shut BUBIAO");
  80. msgAtSend("AT+BUBIAO=0\r\n");
  81. gpsCheckInfo();//检查下是否成功
  82. }
  83. }else{
  84. if(bblF==0){
  85. MSG_INFO(1, "Open BUBIAO");
  86. msgAtSend("AT+BUBIAO=1\r\n");
  87. gpsCheckInfo();//检查下是否成功
  88. }
  89. }
  90. //更新值
  91. gpsInfo.bblF=bblF;
  92. gpsInfo.bbAuth=bbAuth;
  93. gpsInfo.Lat=Lat;
  94. gpsInfo.Long=Long;
  95. gpsInfo.update++;
  96. if(Lat==0 && Long==0) gpsInfo.gpsLocated=0;
  97. else gpsInfo.gpsLocated=1;
  98. }