123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- /********************************************************************************
- * File Name: GpsTask.c
- * Function Describe:The GpsTask for the system
- * Relate Module:
- * Explain: Hardware version is HS110C
- * Writer: ShiLiangWen
- * Date: 2015.4.12
- *******************************************************************************/
- #define THIS_FILE_ID 16
- //--------------------------------------------------------------------------------
- #include "includes.h"
- //OS_TID idGpsTask=0;
- //U64 stkGpsTask[GPS_TASK_STK_SIZE];
- SUT_GPS_STATUS sutGpsStatus;
- SUT_MESS sutMess;
- int g_iCSQ=-1;
- //const unsigned char GPS_TimeTable[]={0,5,10,15,30,60};
- const unsigned char GPS_TimeTable[]={5,10,15,30,60};
- //======================================
- static STATUE GpsServerStatus=CLOSE;
- unsigned char TimeFlag=1;//获取服务器时间标记
- unsigned char sucGpsSentTcpCt=0;//从启动发送到收到计数器
- /*******************************************************************************
- 校验
- *******************************************************************************/
- unsigned char GetCheck(unsigned char *data, unsigned short datalen)
- {
- unsigned char ck=0;
- int i;
- for(i=0;i<datalen;i++){
- ck^=data[i];
- }
- return ck;
- }
- /*****************************************************************************
- *发送数据封包
- format: 0x29 0x29 CMD Len PSN[4] Data Check 0x0D
- Len=DataLen+6
- ******************************************************************************/
- int SendBufPack(char *pBuf,unsigned char cmd,unsigned short DataLen,unsigned char *data)
- {
- SUTDS ds;
- SUTDL dl;
- int i,j;
- if(DataLen>UART3_TX_BUFFER_SIZE)return 0;
- //包头
- pBuf[0]=0x29;//Head
- pBuf[1]=0x29;//Head
- pBuf[2]=cmd;//CMD
- //DataLen
- ds.Data.usData=DataLen+6;
- pBuf[3]=ds.Data.ucData.b2;
- pBuf[4]=ds.Data.ucData.b1;
- //PSN
- dl.Data.ulData=sutProductPara.PSN;
- pBuf[5]=dl.Data.ucData.b4;
- pBuf[6]=dl.Data.ucData.b3;
- pBuf[7]=dl.Data.ucData.b2;
- pBuf[8]=dl.Data.ucData.b1;
- //Data
- j=9;
- for(i=0;i<DataLen;i++){
- pBuf[j++]=data[i];
- }
- //check
- pBuf[j++]= GetCheck(TxBuffer3,(DataLen+6));
- pBuf[j++]=0x0D;
- return j;
- }
- /*******************************************************************
- *GetCSQ
- ********************************************************************/
- int GetCSQ(char* msg)
- {//+CSQ: 29,56
- return atoi(&msg[6]);
- }
- int GetCCSQ(char* msg)
- {//+CCSQ: 29,56
- return atoi(&msg[7]);
- }
- /*******************************************************************
- *GetIPStatus
- ********************************************************************/
- STATUE GetIPStatus(char *msg)
- {
- //if(ModemStrCmp(msg,"+ZIPSTATUS:")){ //+ZIPSTATUS: xxxx
- if(msg[12]=='E' && msg[14]=='T' && msg[22]=='D'){//+ZIPSTATUS: ESTABLISHED
- // if(TimeFlag==0){
- // ModeGetTime();//获取时间 文工说只有IP通了 才正确
- // TimeFlag+=1;
- // }
- return OPEN;
- }else if(msg[12]=='S' && msg[14]=='N' && msg[19]=='T'){//+ZIPSTATUS: SYN_SENT
- return SYN_SENT;
- }else{
- return CLOSE;
- }
- //}else return INVALID;
- }
- /*******************************************************************
- *GetIPStatusu
- ********************************************************************/
- STATUE GetIPStatusu(char *msg)
- {
- //if(ModemStrCmp(msg,"+ZIPSTATUSU:")){ //+ZIPSTATUSU: ESTABLISHED
- if(msg[13]=='E' && msg[15]=='T' && msg[23]=='D'){
- return OPEN;
- }else if(msg[13]=='S' && msg[15]=='N' && msg[20]=='T'){
- return SYN_SENT;
- }else{
- return CLOSE;
- }
- //}else return INVALID;
- }
- /*******************************************************************
- *GetIPStatus
- 返回:0--未获取 1--获取成功
- 00
- ********************************************************************/
- void StartFeedBack(void)
- {
- if(sutFeed.feedBackStart==0) return;
- TSGpsServerConect();
- sutFeed.feedBackStart=0;
- }
- /***********************************************************
- *控制发送位置信息
- 此函数每秒执行一次
- ************************************************************/
- void GpsCtrlSendPos(void)
- {
- static unsigned char authTryTime=0;//发起鉴权次数,也代表连续失败多少次
- static unsigned short SendTime=0;
- static unsigned char suctt;
- static unsigned short realTimeSecond=0xff00;
- char packetHadSend=0;
- uint32_t AvgSpeed;
- int i;
- static unsigned int susGpsTimingSendCt=0;//控制按时间发送
- char buf[30];
-
-
- //计算平均速度
- sutGpsInfo.speedbuf[4]=sutGpsInfo.speedbuf[3];
- sutGpsInfo.speedbuf[3]=sutGpsInfo.speedbuf[2];
- sutGpsInfo.speedbuf[2]=sutGpsInfo.speedbuf[1];
- sutGpsInfo.speedbuf[1]=sutGpsInfo.speedbuf[0];
- sutGpsInfo.speedbuf[0]=sutGpsInfo.speed;
- for(i=0;i<5;i++){
- AvgSpeed=sutGpsInfo.speedbuf[i];
- }
- AvgSpeed/=5;
- sutGpsInfo.AvgSpeed=AvgSpeed;
- //---控制按时间间隔发送GPS位置
-
- sutGpsInfo.GPS_SecondCnt++;
-
- if(sutGpsInfo.isGpsValid && g_uiGpsStat) //GPS是打开的。
- {//可以发位置包,检测时间是否到了
- if(sutGpsInfo.GPS_SecondCnt>=sutGpsInfo.GPS_UploadTime) //
- {
- sutGpsInfo.GPS_SecondCnt=0;
-
- //GetCoordinates(1);
- TSGpsTimingSendPos(); //向模块发送 GPS 数据
- packetHadSend=1;//已发了数据包
- }
- }
- if(++suctt >= 30)
- {
- suctt = 0;
- if(!g_uiGpsStat) SlwTrace(INF, "GPS close",1);
- }
- }
- STATUE GetIPNewStatus(char *msg, unsigned char socketNum)
- {//+TCPSTATUS:x:s [socket: status]
- //+TCPSTATUS:1:1
- //+TCPSTATUS:ERROR!
- STATUE sta=CLOSE;
- unsigned char thisSocket;
-
- thisSocket = atoi(&msg[11]);
- if(msg[13] == '1') sta = OPEN;
- else if(msg[13] == '0')sta = CLOSE;
-
- if(thisSocket == socketNum) return sta;
- else return INVALID;
- }
|