123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029 |
- /**********************************************************************************
- * File Name: TSGpsProcess.c
- * Function Describe:device for Gps Process for TS/T808
- * Relate Module:
- * Explain: 采用TCP或UDP格式传输
- * Writer: wuzhao
- * Date: 2015.12.14
- *外设类型:0x01,
- *命令类型:0x05
- ***********************************************************************************/
- #define THIS_FILE_ID 24
- //-------------------------------------------------------------------------------------------
- #include "includes.h"
- SUT_GPS_SEND_DATA sutGpsSendData;
- //SUT_PRODUCT_PARA TSsutProductPara;
- REGISTRATION Regist;
- AVL_MSG_BODY_ATTRIB msgBodyAttrib;
- MSG_HEAD msghead;
- MSG_PACKET msgPacket;
- AUTH auth;
- SIM SimData;
- unsigned int a;
- unsigned int b;
- char GPSDataBuf[8];
- char GPSDataBuf1[8];
- //*p_buf -- *m_data size -- m_size
- /**********************************************************************************
- GpsSendHead
- ***********************************************************************************/
- void TSGpsServerConect(void)
- {
- // int len;
- // unsigned char buf[100];
- // unsigned char temp[5];
- // SUTDS ds;
- // SlwTrace(INF, "Device ACK",1);
- // memcpy(temp, (unsigned char*)&sutFeed.feedliushuiID,2);
- // ds.Data.usData=sutFeed.feedID;
- // temp[2] = ds.Data.ucData.b2;
- // temp[3] = ds.Data.ucData.b1;
- // temp[4] = sutFeed.result;
- // len=TSGpsPacket(buf,sutProductPara.PSN,TS_TERMINAL_UNIVERSAL_ANSWER,temp,sizeof(temp));
- // MC8332ModemSendTcpData(GPS_DATA_SOCKET,buf,len);
- }
- //从厂商编号到用户数据依次累加的累加和,取累加的档�8位作为校验码
- unsigned char TSGetCheckSum(unsigned char *pData,int len)
- {
- int i;
- unsigned char sum= pData[1]; //sum=0;
- for(i=1;i<len-1;i++){
- sum=sum^pData[i+1];
- }
- return sum;
- }
- /*************************************************************************************
- *
- **************************************************************************************/
- // replace 0x7d 0x01 with 0x7d and 0x7d 0x02 with 0x7e 接收
- //长度不会变大,只会变小或不变
- int reduce(unsigned char *pData,int DataLen)
- {
- unsigned char *p = pData;
- int data_len=0;
- int i;
-
- if(DataLen==0) return 0;
- for(i=0;i<DataLen-1;i++)
- {
- if(pData[i] == 0x7d && pData[i+1] == 0x01)
- {
- *p++ = 0x7d;i++;
- }else if(pData[i] == 0x7d && pData[i+1] == 0x02)
- {
- *p++ = 0x7e;i++;
- }else *p++=pData[i];
- data_len++;
- }
-
- return data_len;
- }
- // loop every character, replace 0x7d with 0x7d 0x01 and 0x7e with 0x7d 0x02 发送
- int escapse(unsigned char *pData,int DataLen) {
-
- unsigned char *p= (unsigned char *)malloc(DataLen * 2);
- unsigned char * q = p;
- int data_len = 0;
- int i;
- if (DataLen == 0) {
- return 0;
- }
-
- memset(p, 0, DataLen * 2);
-
- for (i = 0; i < DataLen; i ++) {
- if (pData[i] == 0x7d) {
- *q ++ = 0x7d;
- *q ++ = 0x01;
- data_len += 2;
- } else if (pData[i] == 0x7e) {
- *q ++ = 0x7d;
- *q ++ = 0x02;
- data_len += 2;
- } else {
- *q ++ = pData[i];
- data_len += 1;
- }
- }
- memcpy(pData, p, data_len);
- free(p);
- DataLen = data_len;
- //free(p);
- return DataLen;
- }
- /******************************************************/
- int* TenToTwo(int Datalen)
- {
- static int c[10]={0};
- int i=0;
- do {
- c[i++]=Datalen%2;
- Datalen/=2;
- } while(Datalen!=0);
-
- return c;
- }
- /**********************
- **消息头12字节,消息体属性2个字节,这两个字节的16位。低10位是消息体长度
- 因此消息消息最长小于1024字节,Bit13是分包标志,看终端发到平台一个消息,可能很长,一个消息体发不完,分包发出去那么
- Bit12置为1,消息头长度变成16字节,消息头的后4个字节为消息包分装项内容,总共
- 有多少个包,这次发送的消息包是分包中的第几个消息包
- sutProductPara.APN
- **************************/
- int TSGpsPacket(unsigned char *Buffer,unsigned long PSN,unsigned short ID,unsigned char *pData,int DataLen)
- {
- static unsigned short liushiID=0;
- unsigned char *pBuf=Buffer,sum;
- int j,flag = 0,i=0;
- int talpage=1,MSnum = 0;
- char Psnsv[12];
- static unsigned short snum = 1;
- unsigned short Len=DataLen+6;
- unsigned short pageItem=DataLen+12;
- snprintf(Psnsv, sizeof(Psnsv),"%010u",(unsigned int)PSN);
- pBuf[i++]=0x7e;
-
- pBuf[i++]=(ID>>8)&0xff;
- pBuf[i++]=ID&0xff;
- //消息体属性
- msgBodyAttrib.EncrypType=NO_ENCRYP;//NO_ENCRYP;
- msgBodyAttrib.msgBodyLength=(DataLen);
- pBuf[i++]=msgBodyAttrib.EncrypType;
- pBuf[i++]=msgBodyAttrib.msgBodyLength;
- //SIM卡号
- for(j=0;j<6;j++){
- pBuf[i++]=SimData.SIM[j];
- }
- //消息流水号
- pBuf[i++] = (liushiID>>8)&0xff;
- pBuf[i++] = liushiID&0xff;
- liushiID++;
-
- if(pData!=NULL)
- {
- //snum++;
- //消息包封装项
- //msgPacket.msgPacketID=0x30;
- //msgPacket.msgTotalCount=0x30;
- //pBuf[i++] = msgPacket.msgPacketID;
- //pBuf[i++] = msgPacket.msgTotalCount;
- //MSnum++;
- //包封装项 4
- for(j=0;j<DataLen;j++)
- {//0
- pBuf[i++]= pData[j];
- }
- }
- sum = TSGetCheckSum(pBuf,i);
-
- pBuf[i++] = sum;
- //对整体数据,除sum进行转义
- i=escapse(&pBuf[1],i-1);//头的7E不转义
- i++;
- pBuf[i++] = 0x7e;
- return i;
- }
- /************************************************************
- 位置信息汇报
- *************************************************************/
- /**********************************************************************************
- GpsSendPosition
- 发送位置数据
- Head(2) Cmd(2) Len(2) PSN(4) GpsData(34) Check(1) End(1)
- Cmd=0x0200
- 总长度=2+2+2+40=46
- ***********************************************************************************/
- void TSGpsSendPosition(void)
- {
- M_RESULT r;
- int i;
- int len;
- char tmp[5];
- char buf[150];
- unsigned char GpsBuf[50];
- sutGpsSendData.Acpect=0x12;
- //114.03524
- sutGpsSendData.JJJJ[0]=0x11;
- sutGpsSendData.JJJJ[1]=0x40;
- sutGpsSendData.JJJJ[2]=0x35;
- sutGpsSendData.JJJJ[3]=0x24;
- //22.62082
- sutGpsSendData.WWWW[0]=0x02;
- sutGpsSendData.WWWW[1]=0x26;
- sutGpsSendData.WWWW[2]=0x20;
- sutGpsSendData.WWWW[3]=0x82;
-
- sutGpsSendData.Mileag=0x34;
- sutGpsSendData.SSFF=0x56;
- sutGpsSendData.status=0x01;
-
- len=TSGpsPacket(GpsBuf,0x123456,0x0200,(unsigned char *)&sutGpsSendData,sizeof(SUT_GPS_SEND_DATA));
-
- SlwTrace(DEBUG,"SendGpsD>>");
- for(i=0;i<len;i++){
- snprintf(tmp, sizeof(tmp),"%02x ",GpsBuf[i]);
- SlwTrace(DEBUG,tmp);
- }
- SlwTrace(DEBUG,"\r\n");
-
- r=ModemSendToSocket(0,GpsBuf,len);
- if(r==SUCCEED){
- SlwTrace(DEBUG,"Send OK!\r\n");
- }else if(r==FAIL){
- SlwTrace(DEBUG,"Send Fail!\r\n");
- }else{
- SlwTrace(DEBUG,"Send Timeout!\r\n");
- }
-
- }
- /*******************************************************
- GPRMC信息,与,之间的子信息处理,存储到相应的结构体中元素中
- *******************************************************/
- void TSGPS_GPRMC_Handle(unsigned char *ch,unsigned char ch1) //1处
- {
- // unsigned char x,y;
- //// send_byte('d');
- // switch(ch1)
- // {
- // case 0: //时间
- // for(x=0,y=0;x<8;x++)
- // {
- // if(x==2||x==5){ sutGpsInfo.Time[x]=0x3a;}
- // else sutGpsInfo.Time[x]=ch[y++];
- // }
- // // send_byte(time[7]);
- // break;
- // case 1: //状态
- // sutGpsInfo.Status=ch[0];
- // break;
- // case 2: //纬度
- // for(x=10,y=0;x<17;x++)
- // {
- // if(x==12||x==15) {}
- // else sutGpsInfo.Location[x]=ch[y++];
- // }
- // break;
- // case 3: //南北纬
- // sutGpsInfo.Location[9]=ch[0];
- // break;
- // case 4: //经度
- // for(x=1,y=0;x<8;x++){
- // if(x==4||x==7){}
- // else sutGpsInfo.Location[x]=ch[y++];
- // }
- // break;
- // case 5: //东西经
- // sutGpsInfo.Location[0]=ch[0];
- // break;
- // case 6: //航速
- // for(x=0;x<6;x++){
- // sutGpsInfo.Speed[x+1]=ch[x];
- // }
- // sutGpsInfo.Speed[6]=0x20;
- // sutGpsInfo.Speed[7]=0x20;
- // break;
- // case 7: //信息自己定义
- // break;
- // case 8: //信息自己定义
- // break;
- // case 9: //信息自己定义
- // break;
- // case 10: //信息自己定义
- // break;
- // case 11: //信息自己定义
- // break;
- // default:break;
- // }
- }
- /*******************************************************
- 处理GPRMC信息
- *******************************************************/
- void TSGPS_GPRMC_Alysis(char *RMC_Data) //2处
- {
- unsigned char i,j,k;
- unsigned char count;
- unsigned char temp[10];
- //send_byte('a');
- for(i=0;i<strlen(RMC_Data);)
- {
- switch(RMC_Data[i])
- {
- case '$':
- j=i++; //标记$的起始位置
- while(RMC_Data[i]!=',') //RMC_Data[i]==','时结束循环。
- {i++;}
- // uart1_sendbytes(GPRMC[RMC_Count].RMC_ID);
- break;
- case ',':
- j=i++; //标记,的起始位置
- while((RMC_Data[i]!=',')&&(RMC_Data[i]!='*')) //RMC_Data[i]==','或者=='*'时结束循环。
- {i++;}
- if(j+1!=i)
- {
-
- for(j=j+1,k=0;j<i;j++)
- {
- temp[k++]=RMC_Data[j];
- }
- temp[k]='\0';
- // send_byte(temp[0]);
- }
- else temp[0]='\0';
- // send_byte('c');
- TSGPS_GPRMC_Handle(temp,count++);
- break;
- case '*':
- i=strlen(RMC_Data); //处理完成,软件结束。
- break;
- default:break;
-
- }
- }
- // send_byte('e');
- }
- void TSGpsDataInit(void)
- {
- // unsigned char *p;
- // char buf2[20];
- // p=(unsigned char *)&sutGpsSendData;
- // memset(p, 0, sizeof(SUT_GPS_SEND_DATA));
- // p=(unsigned char *)&sutGpsInfo;
- // memset(p, 0, sizeof(SUT_GPS_INF));
- //
- // #if 1
- // //sutGpsInfo.SendTime = sutProductPara.m_GPS_SendTime;
- // sutGpsInfo.GPS_UploadTime = GPS_TimeTable[sutProductPara.m_GPS_TimeIndex];
- // snprintf(buf2, sizeof(buf2), "Gpstime=%d",sutGpsInfo.GPS_UploadTime);
- // SlwTrace(INF, buf2,1);
- // #else
- // sutGpsInfo.SendTime=10;//默认主动上报时间间隔 单位为15秒
- // sutGpsInfo.GPSSendTime=10;
- // #endif
- //
- // sutGpsInfo.isGpsAuthOk = 0;//未鉴权
- }
- /*************************************************************************
- *检查GPS 服务器发过来的数据包是否正确
- 非法 返回0
- 合法 返回命令码
- **************************************************************************/
- //"7e8300 000c 000009771810000001 4130313233343536373839 b87e"
- unsigned char TSGpsServerCheckPack(unsigned char *data,unsigned short DataLen)//3处
- {
- unsigned char cmd;
- unsigned short len;
- unsigned long PSN;
-
- //判断数据包的包头是否正确
- // escapse(data,DataLen);
- if(data[0]!=TSGPS_PACK_HEAD)return 0;
- //判断数据包的校验是否正确
- if(data[DataLen-2] != TSGetCheckSum(data,DataLen-2))
- return 255;
- //判断数据包的结尾是否正确
- if(data[DataLen-1] != TSGPS_PACK_END)
- return 255;
- //获取数据包的长度 并判断长度是否正确
- len=(unsigned short)data[3]*256+data[4];
- if(DataLen!=(len+5))return 255;
- // //判断终端编号是否正确
- // PSN=(unsigned long)data[5]<<24;
- // PSN+=(unsigned long)data[6]<<16;
- // PSN+=(unsigned long)data[7]<<8;
- // PSN+=(unsigned long)data[8];
- // if(PSN!=sutNetPara.PSN) return 0;
- //解析当前命令
- cmd = data[2];
- //sutGpsInfo.HostCmd = cmd;
- return cmd;
- }
- /**************************************************************************************************
- * // TS_PROID 440000
- // TS_CITYID 440300
- 车牌D4C1423738583134
- ***************************************************************************************************/
- void TSMakeSendData(void)
- {
- int i,len;
- // static int Table[20]={0};
- static int Table1[20]={0};
- static int Temp[8];
- static int Temp1[4];
- const unsigned char acTemp[]={
- 0x34,0x31,0x30,0x30,0x30,//制造商ID Regist.Manufacturers
- //32 30 31 34 30 34 00 00 00 00 00 00 00 00 00 00 00 00 00 00
- 0x32,0x30,0x31,0x34,0x30,0x34,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //终端型号Regist.TerMod
- 0x65,0x30,0x30,0x72, //终端IDRegist.TerID
- };
- const unsigned char TSacTemp[]={
- 0xD4,0xC1,0x42,0x37,0x38,0x58,0x31,0x34,
- };
- // len = strlen(sutProductPara.REG);
- // if(!len){
- // Regist.CityID = ((TS_CITYID>>8)&0xffff);
- // Regist.CityID = (TS_CITYID&0xffff);
- // Regist.CityID = ((TS_CITYID>>24)&0xffff);
- // Regist.CityID = ((TS_CITYID>>16)&0xffff);
- //
- // Regist.proID =((TS_PROID>>8)&0xff);
- // Regist.proID =(TS_PROID&0xff);
- //
- // for(i = 0; i < 5; i++){
- // Regist.Manufacturers[i] = acTemp[i];
- // }
- // for(i = 0; i < 20; i++){
- // Regist.TerMod[i]= acTemp[i+5];
- // }
- // for(i = 0; i < 4; i++){
- // Regist.TerID[i]= acTemp[i+25];
- // }
- //
- // Regist.PlateColor=0x01;//未上牌取值为0
- // // 车牌颜色为0 表示车辆VIN
- // for(i = 0; i < 8; i++){//7会返回
- // Regist.Plate[i] = TSacTemp[i];
- // }
- // }else{
- // Regist.proID =((sutProductPara.proID>>8)&0xff);
- // Regist.proID =(sutProductPara.proID&0xff);
- //
- // Regist.CityID = ((sutProductPara.CityID>>24)&0xffff);
- // Regist.CityID = ((sutProductPara.CityID>>16)&0xffff);
- // Regist.CityID = ((sutProductPara.CityID>>8)&0xffff);
- // Regist.CityID = (sutProductPara.CityID&0xffff);
- //
- // for(i = 0; i < 5; i++){
- // Regist.Manufacturers[i] = sutProductPara.Manufacturers[i];
- // }
- //
- // for(i = 0; i < 20; i++){
- // //sscanf(sutProductPara.TerMod+2*i,"%2x",&Table1[i]);
- // if((i<20)&&(sutProductPara.TerMod[i]!='0')){
- // //sscanf(sutProductPara.TerMod+2*i,"%2x",&Table1[i]);
- // Regist.TerMod[i]= sutProductPara.TerMod[i];
- // }else{
- // Regist.TerMod[i]=0x00;
- // }
- //
- // }
- // for(i = 0; i < 4; i++){
- // sscanf(sutProductPara.TerID+2*i,"%2x",&Temp1[i]);
- // Regist.TerID[i]= Temp1[i];
- // }
- // Regist.PlateColor=sutProductPara.PlateColor;//
- // for(i = 0; i < 8; i++){
- // sscanf(sutProductPara.Plate+2*i,"%2x",&Temp[i]);
- // Regist.Plate[i] = Temp[i];
- //
- // }
- // }
- }
- /************************************************************
- 终端注册、注销
- *3431303030制作商ID
- 3230313430340000000000000000000000000000终端型号
- 30303030313131 终端ID
- *************************************************************/
- uint32_t Process_TSRegistration(char* buf, uint32_t len)
- {
- // unsigned char SendBuf[100];
- // unsigned short PacketLen;
- //
- // if(g_ucSelect==1){
- // TSMakeSendData();
- // }else{
- // TSRegData();
- // }
- // //REGISTRATION Regist;
- // PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_TERMINAL_REGISTRATION,(unsigned char *)&Regist,sizeof(REGISTRATION));
- // MC8332ModemSendTcpData(0,SendBuf,PacketLen);
- // return len;
-
- }
- void Registration(void)
- {
- // SlwTrace(INF,"Try-Reg!",1);
- // if(sutProductPara.SIMFlag){SIMReg();}
- //#if 0
- // if(sutProductPara.Select==1) TSMakeSendStrData(); // 串口注册
- // else TSRegData(sutProductPara.PSN);
- //#else
- // TSRegData();
- //#endif
- }
- void RegistrationLogout(void)
- {
- unsigned char SendBuf[100];
- unsigned short PacketLen;
-
- unsigned char *data=NULL;
- PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_TERMINAL_CANCELLATION,data,0);
- //MC8332ModemSendTcpData(0,SendBuf,PacketLen);
- }
- /************************************************************
- 终端鉴权
- *************************************************************/
- void Authentication(void)
- {
- // unsigned char SendBuf[100];
- // unsigned short PacketLen;
- // SlwTrace(INF,"Re-Authentication!",1);
- // PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_TERMINAL_AUTHENTICATION,(unsigned char *)&sutProductPara.AutH,sizeof(AUTH));//实际是返回的鉴权信息
- // MC8332ModemSendTcpData(GPS_DATA_SOCKET,SendBuf,PacketLen);
- //}
- ////以下
- //uint32_t Process_TSAuthentication(char* buf, uint32_t len)
- //{
- // unsigned char SendBuf[100];
- // unsigned short PacketLen;
- //
- // TSMakeGpsSendData();
- // PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_TERMINAL_AUTHENTICATION,(unsigned char *)&auth,sizeof(AUTH));
- // MC8332ModemSendTcpData(0,SendBuf,PacketLen);
- // return len;
- }
- /************************************************************
- 位置信息查询
- *************************************************************/
- uint32_t Process_TSCenterGetPos_rsp(unsigned char* buf, unsigned short len)
- {
- unsigned char SendBuf[100];
- unsigned short PacketLen;
- TSMakeGpsSendData();
- PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_LOCATION_INFORMATION_INQUIRY,(unsigned char *)&sutGpsSendData,sizeof(SUT_GPS_SEND_DATA));
- //MC8332ModemSendTcpData(0,SendBuf,PacketLen);
- return 0;
- }
- uint32_t Process_TSClient_rsp(char* buf, unsigned short len)
- {
- // if(!sutGpsInfo.isServerLogin){
- // sutGpsInfo.isServerLogin=1;
- // SlwTrace(INF,"[Gps Logined]",1);
- // }
- // return 0;
- }
- /**************************************************************************************************
- *看下 如果一直发注册信息会如何
- ***************************************************************************************************/
- void TSGpsTimingSendPos(void)
- {
- // unsigned char SendBuf[100];
- // unsigned short PacketLen;
- // SlwTrace(INF,"TSGpsTimingSendPos",1);
- // TSMakeGpsSendData();
- // PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_LOCATION_INFORMATION_REPORTING,(unsigned char *)&sutGpsSendData,sizeof(SUT_GPS_SEND_DATA));
- // MC8332ModemSendTcpData(GPS_DATA_SOCKET,SendBuf,PacketLen);
- // return ;
- }
- /***********************************************************************************
- *服务器设置主动上报时间
- *数据格式
- HEAD1 HEAD2 CMD LEN1 LEN2 PSN1 PSN2 PSN3 PSN4 X1 X2 CHECK END
- 29 29 34 00 08 PSN[4] X1 X2 CHECK 0D
- time=X1*256+X2
- ***********************************************************************************/
- uint32_t Process_TSCenterGetPosTimerout(char* buf, uint32_t len)
- {
- // char SendBuf[100];
- // unsigned short t;
- // unsigned short PacketLen;
- // //跳过终端序列号4 bytes
- //
- // //获取时间
- // sutGpsInfo.GPS_UploadTime =((unsigned short)buf[9]&0xff<<8) + (unsigned short)buf[10]&0xff ;
- // snprintf(SendBuf, sizeof(SendBuf),"[GpsTime=%d]",sutGpsInfo.GPS_UploadTime);
- // SlwTrace(INF,SendBuf,1);
- // TSMakeGpsSendData();
- // PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_EVENT_REPORT,(unsigned char *)&sutGpsSendData,sizeof(SUT_GPS_SEND_DATA));
- // MC8332ModemSendTcpData(0,SendBuf,PacketLen);
- // return len;
- }
- /************************************************************
- 建立好连接后,向平台发送终端鉴权消息进行鉴权、建立链接
- *************************************************************/
- /************************************************************
- 连接建立和终端鉴权成功后,终端周期性向平台发送终端心跳信息,拼图收到后
- 向终端发送平台通用应答消息,发送周期由终端参数指定、链接维持
- *************************************************************/
- uint32_t Process_TSPlatformAnswer(char* buf, uint32_t len)
- {
- unsigned char SendBuf[100];
- unsigned short PacketLen;
- TSMakeGpsSendData();
- PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_PLATFORM_UNIVERSAL_ANSWER,(unsigned char *)&sutGpsSendData,sizeof(SUT_GPS_SEND_DATA));
- //MC8332ModemSendTcpData(0,SendBuf,PacketLen);
- return 0;
- }
- uint32_t Process_TSTerminalHeartbeat(char* buf, uint32_t len)
- {
- unsigned char SendBuf[100];
- unsigned short PacketLen;
- TSMakeGpsSendData();
- PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_TERMINAL_HEARTBEAT,(unsigned char *)&sutGpsSendData,sizeof(SUT_GPS_SEND_DATA));
- //MC8332ModemSendTcpData(0,SendBuf,PacketLen);
- return 0;
- }
- void TS_SendHeartTick(void)
- {
- // unsigned char SendBuf[100];
- // unsigned short PacketLen;
- // SlwTrace(INF, "HeartTick",1);
- // PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_TERMINAL_HEARTBEAT,0,0);
- // MC8332ModemSendTcpData(GPS_DATA_SOCKET,SendBuf,PacketLen);
- }
- void TS_SendSOSMessage(void)
- {
- // unsigned char SendBuf[100];
- // unsigned short PacketLen;
- // SlwTrace(INF, "SOS Send",1);
- // PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_SEND_SOS_SMS,0,0);
- // MC8332ModemSendTcpData(GPS_DATA_SOCKET,SendBuf,PacketLen);
- }
- void TS_ReqRealTime(void)
- {
- // unsigned char SendBuf[100];
- // unsigned short PacketLen;
- // SlwTrace(INF, "ReqRealTime",1);
- // PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_TERMINAL_REQTIME,0,0);
- // MC8332ModemSendTcpData(GPS_DATA_SOCKET,SendBuf,PacketLen);
- }
- /************************************************************
- 平台主发消息,终端主发消息
- *************************************************************/
- /******************************************************************************
- *目前服务器只做了:注册,取消注册,位置信息,鉴权消息
- *******************************************************************************/
- TSCmd_struct TSCmd_info[] =
- {
- // {TS_TERMINAL_REGISTRATION, Process_TSRegistration},//终端注册
- // {TS_TERMINAL_REGISTRATION_REPLY, Process_TSRegistrationReply},//终端注册应答
- // {TS_TERMINAL_AUTHENTICATION, Process_TSAuthentication},//鉴权
- // {TS_SETTING_TERMINAL_PARAMETERS, Process_TSParametersSet},
- {TS_LOCATION_INFORMATION_INQUIRY, Process_TSCenterGetPos_rsp},//位置查询
- // {XINGAN_PACKET_CENTER_CMD_GET_STAT, Process_XinganCenterGetStat_rsp},
- // {XINGAN_PACKET_CENTER_CMD_RESET, Process_XinganCenterReset_rsp},
- // {XINGAN_PACKET_CENTER_CMD_DEFAULT_SET, Process_XinganCenterDefaultSet_rsp},
- // {TS_TERMINAL_HEARTBEAT, Process_TSCenterGetPosTimerout},
- // {XINGAN_PACKET_CENTER_CMD_GET_POS_LENOUT, Process_XinganCenterGetPosLenout},
- // {XINGAN_PACKET_CENTER_CMD_CLOSE_WARNING, Process_XinganCenterCloseWarning_rsp},
- // {XINGAN_PACKET_CENTER_CMD_OPEN_OIL_WAY, Process_XinganCenterOpenOilWay_rsp},
- // {XINGAN_PACKET_CENTER_CMD_CLOSE_OIL_WAY, Process_XinganCenterCloseOilWay_rsp},
- // {XINGAN_PACKET_CENTER_CMD_GET_VER, Process_XinganCenterGetVer_rsp},
- // {XINGAN_PACKET_CENTER_CMD_DIAL_CALL, Process_XinganCenterDialCall_rsp} ,
- // {XINGAN_PACKET_CENTER_CMD_HIGH_SPEED_WARNING, Process_XinganCenterHighSpeedWarning_rsp},
- // {XINGAN_PACKET_CENTER_CMD_STATISTICS_MILE, Process_XinganCenterStatisticsMile_rsp},
- // {XINGAN_PACKET_CENTER_CMD_UDP_IPPORT, Process_XinganCenterIPport_rsp},
- // {XINGAN_PACKET_CENTER_CMD_APN, Process_XinganCenterApn_rsp},
- //
- // {TS_EVENT_REPORT, Process_TSClient_rsp},
- //
- // {XINGAN_PACKET_CLIENT_CMD_CONNECT, Process_XinganClientConnectReq},
- // {XINGAN_PACKET_CLIENT_SEND_POS_DATA, Process_XinganClientSendPosData},
- // {XINGAN_PACKET_CLIENT_CMD_SEND_WARNING_DATA, Process_XinganClientSendWarnData},
- //{TS_QUERY_TERMINAL_PARAMETERS, Process_TSParametersQuery},
- //{TS_TERMINAL_CONTROL, Process_TSTerminalContrl},
- // {TS_PLATFORM_UNIVERSAL_ANSWER, Process_TSPlatformAnswer},
- // {TS_TERMINAL_HEARTBEAT, Process_TSTerminalHeartbeat},
- };
- TSGPS_process_packet GetTSProcessFun(uint32_t Cmd)
- {
- // uint32_t j;
- // for(j=0;j<sizeof(TSCmd_info)/sizeof(TSCmd_struct);j++)
- // {
- // if(Cmd == TSCmd_info[j].cmd)
- // {
- // return TSCmd_info[j].process_packet;
- // }
- // }
- // return NULL;
- }
- /***************************************************************
- 处理GPS服务器发过来的信息
- 返回:
- 无效消息 不处理 返回0
- 否则返回命令码
- ****************************************************************/
- unsigned char TSGpsServerProcess(unsigned char *data, unsigned short DataLen)//4处
- {
- unsigned char cmd;
- TSGPS_process_packet ProcessFun;
- cmd=TSGpsServerCheckPack(data,DataLen);
- if(255 == cmd) return 0;
- ProcessFun = GetTSProcessFun(cmd);
- if(ProcessFun !=NULL)
- {
- ProcessFun(data, DataLen);
- }
- return cmd;
- }
- /*********************************************************
- *************************************************************/
- unsigned long power(int base, int times)
- {
- int i;
- unsigned long rslt = 1;
- for(i=0; i<times; i++){
- rslt *= base;
- }
- return rslt;
- }
- /********************************************************
- BCD转10进制
- ********************************************************/
- unsigned long BCDtoDec(const unsigned char *bcd, int length)
- {
- int i, tmp;
- unsigned long dec = 0;
- for(i=0; i<length; i++)
- {
- tmp = ((bcd[i]>>4)&0x0F)*10 + (bcd[i]&0x0F);
- dec += tmp * power(100, length-1-i);
- }
- return dec;
- }
- /********************************************************
- 10进制转BCD
- ********************************************************/
- int DectoBCD(int Dec, unsigned char *Bcd, int length)
- {
- int i;
- int temp;
- for(i=length-1; i>=0; i--)
- {
- temp = Dec%100;
- Bcd[i] = ((temp/10)<<4) + ((temp%10) & 0x0F);
- Dec /= 100;
- }
- return 0;
- }
- //#define GPS_DEBUG_GPS_SEND_DATA
- /***************************************************************************
- *MakeGpsSendData
- 根据sutGpsInfo生成sutGpsSendData
- ****************************************************************************/
- void TSMakeGpsSendData(void)//5处
- {
- char sv[17];
- char data[3];
- char buf[10];
- int buf1[3];
- int j,temp,num;
- char *pTemp;
- char WWWW[5];
- static int Table[4]={0};
- static int Table1[4]={0};
- sutGpsSendData.Time[0] = sutGpsInfo.year;
- sutGpsSendData.Time[1] = sutGpsInfo.month;
- sutGpsSendData.Time[2] = sutGpsInfo.day;
- sutGpsSendData.Time[3] = sutGpsInfo.hour;
- sutGpsSendData.Time[4] = sutGpsInfo.minu;
- sutGpsSendData.Time[5] = sutGpsInfo.sec;
- sutGpsSendData.St=0x00;
- #if 0
- if(sutGpsInfo.isGpsValid)
- {//wjl 1121
- sutGpsSendData.status |=(0x01<<24);//ACC
- sutGpsSendData.status |=(0x01<<25);//定位标志
- sutGpsSendData.status |=(0x01<<28);//运营状态
- }else sutGpsSendData.status=0;
- #else
- sutGpsSendData.status=0;
- if(sutGpsInfo.isGpsValid)
- {
- // sutGpsSendData.status |=(1<<24);//b0 1 acc
- // sutGpsSendData.status |=(1<<25);//b1 1 定位
- // if(sutGpsInfo.NSFlag=='S')
- // sutGpsSendData.status |=(1<<26);//b2 1 南纬
- // if(sutGpsInfo.EWFlag=='W')
- // sutGpsSendData.status |=(1<<27);//b3 1 西经
- // sutGpsSendData.status |=(1<<28);//b4 1 运营
- //sutGpsSendData.status |=(1<<29);//b5 1 经纬度已加密
- //sutGpsSendData.status |=(1<<30);//b6 保留
- //sutGpsSendData.status |=(1<<31);//b7 保留
-
- //sutGpsSendData.status |=(1<<16);//b8 载状态-1
- //sutGpsSendData.status |=(1<<17);//b9 载状态-0
- //sutGpsSendData.status |=(1<<18);//b10 车辆油状态
- //sutGpsSendData.status |=(1<<19);//b11 车辆电路状态
- //sutGpsSendData.status |=(1<<20);//b12 车锁状态
- //sutGpsSendData.status |=(1<<21);//b13 门1状态
- //sutGpsSendData.status |=(1<<22);//b14 门2状态
- //sutGpsSendData.status |=(1<<23);//b15 门3状态
-
- //sutGpsSendData.status |=(1<<8);//b16 门4状态
- //sutGpsSendData.status |=(1<<9);//b17 门5状态
- //sutGpsSendData.status |=(1<<10);//b18 是否使用GPS卫星定位
- //sutGpsSendData.status |=(1<<11);//b19 是否使用北斗卫星定位
- //sutGpsSendData.status |=(1<<12);//b20 是否使用GLONASS卫星定位
- //sutGpsSendData.status |=(1<<13);//b21 是否使用Galileo卫星定位
- }
- #endif
- // sutGpsSendData.Mileag=((sutGpsInfo.StatisticsMile>>8)&0xFF)|(((sutGpsInfo.StatisticsMile)&0xFF)<<8);
- // sutGpsSendData.SSFF=((sutGpsInfo.speed>>8)&0xFF)|(((sutGpsInfo.speed)&0xFF)<<8);
- // sutGpsSendData.Acpect=sutGpsInfo.aspect;
- //
- // GetCoordinates(1);
- // sutGpsSendData.WWWW[0] = sutGpsInfo.testWD>>24;
- // sutGpsSendData.WWWW[1] = sutGpsInfo.testWD>>16;
- // sutGpsSendData.WWWW[2] = sutGpsInfo.testWD>>8;
- // sutGpsSendData.WWWW[3] = sutGpsInfo.testWD;
- // sutGpsSendData.JJJJ[0] = sutGpsInfo.testJD>>24;
- // sutGpsSendData.JJJJ[1] = sutGpsInfo.testJD>>16;
- // sutGpsSendData.JJJJ[2] = sutGpsInfo.testJD>>8;
- // sutGpsSendData.JJJJ[3] = sutGpsInfo.testJD;
- }
- void AscStrTurnHexStr(char *AscStr, char *HexStr)
- {
- char *pAscStr=AscStr;
- int i=4;
- unsigned char d,h,l;
- while(i){
- d=(unsigned char)*pAscStr++;
- l=d&0x0f;
- h=d>>4;
- *HexStr++=AscToHex(h);
- *HexStr++=AscToHex(l);
- i--;
- }
- *HexStr=0;
- }
- void getData(void)
- {
- // char buf[10];
- // char buf1[8];
- // char buf2[4]={0};
- // char temp[3];
- // char temp1[3];
- // char temp2[5];
- // char temp3[5];
- // char data[6];
- // char data1[6];
- // char data2[6];
- // int i,num,num1,j,w,Gdata,k;
- // double Jnum1,Jnum2,Jnum3;//有小数位 8位有效
- // double Wnum1,Wnum2,Wnum3;//有小数位 8位有效
- // char b[]="0123456789ABCDEF";
- // MakeGpsSendData();
- //// AscStrToHexStr((char *)sutLcdGpsSendData.JJJJ,buf1);
- // AscStrTurnHexStr((char *)sutLcdGpsSendData.JJJJ,buf1);
- // memset(temp, 0, sizeof(temp));
- // for(i=0;i<3;i++){
- // temp[i]=buf1[i];
- // }
- // j=atoi(temp);
- // memset(temp2, 0, sizeof(temp2));
- // for(i=0;i<6;i++){
- // temp2[i]=buf1[i+3];
- // }
- // num=atoi(temp2);
- // Jnum1=num/1000;
- // Jnum1 /=60;
- // Jnum2 = (num%1000)*60;
- // Jnum2 /=3600000;
- // Jnum3=Jnum1+Jnum2;
- //
- // //sutLcdGpsSendData.j=j*1000000+Jnum3*1000000;
- // sutLcdGpsSendData.j = (j+Jnum3)*1000000;
- // sprintf(buf,",%d,",sutLcdGpsSendData.j);
- // SlwTrace(INF,buf);
- // i =0;
- // k=6;
- // memset(data, 0, sizeof(data));
- // while(sutLcdGpsSendData.j>0){
- // data[i]=sutLcdGpsSendData.j%16;
- // GPSDataBuf[k]=b[data[i]];//data1
- // sutLcdGpsSendData.j=sutLcdGpsSendData.j/16;
- // k--;
- // i++;
- // }
- // SlwTrace(INF,GPSDataBuf);
- //// AscStrToHexStr((char *)sutLcdGpsSendData.WWWW,buf2);
- // AscStrTurnHexStr((char *)sutLcdGpsSendData.WWWW,buf2);
- // for(i=0;i<3;i++){
- // temp1[i]=buf2[i];
- // }
- // w=atoi(temp1);
- // for(i=0;i<6;i++){//5
- // temp3[i]=buf2[i+3];
- // }
- // num1=atoi(temp3);
- // Wnum1=num1/1000;
- // Wnum1 /=60;
- // Wnum2 = (num1%1000)*60;
- // Wnum2 /=3600000;
- // Wnum3=Wnum1+Wnum2;
- //
- // //sutLcdGpsSendData.W=w*1000000+Wnum3*1000000;
- // sutLcdGpsSendData.W=(w+Wnum3)*1000000;
- // buf[0]=0;
- // sprintf(buf,"%d",sutLcdGpsSendData.W);
- // SlwTrace(INF,buf);
- // i =0;
- // k=6;
- // data1[0]=0;
- // while(sutLcdGpsSendData.W>0){
- // data1[i]=sutLcdGpsSendData.W%16;
- // GPSDataBuf1[k]=b[data1[i]];//data1
- // sutLcdGpsSendData.W=sutLcdGpsSendData.W/16;
- // k--;
- // i++;
- // }
- // SlwTrace(INF,GPSDataBuf1);
-
- // buf[0]=0;
- // sprintf(buf,"%d",sutLcdGpsSendData.j);
- // SlwTrace(INF,buf);
- // buf[0]=0;
- // sprintf(buf,"%d",sutLcdGpsSendData.W);
- // SlwTrace(INF,buf);
- }
- void TSRegData(void){
- // int i;
- // static int Temp1[7];
- // static int Table1[20]={0};
- // static int Temp[8];
- // unsigned char SendBuf[100],len;
- // unsigned short PacketLen,data1,data2,data3,data4;
- // unsigned int PSN;
- // PSN=sutProductPara.PSN;
- //
- // Regist.proID=0;
- // Regist.CityID=0;
- // for(i = 0; i < 5; i++) Regist.Manufacturers[i] = 0;
- // for(i = 0; i < 20; i++) Regist.TerMod[i]= 0x00;
- // Regist.TerID[0]=(unsigned char)((PSN>>24)&0xff);//没出来显示乱码
- // Regist.TerID[1]=(unsigned char)((PSN>>16)&0xff);
- // Regist.TerID[2]=(unsigned char)((PSN>>8)&0xff);
- // Regist.TerID[3]=(unsigned char)(PSN&0xff);
- // for(i = 0; i < 3; i++) Regist.TerID[i+4]= 0x00;
- //
- // Regist.PlateColor=0;
- // for(i = 0; i < 8; i++) Regist.Plate[i] = 0x00;
- // PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_TERMINAL_REGISTRATION,(unsigned char *)&Regist,sizeof(REGISTRATION));
- // MC8332ModemSendTcpData(GPS_DATA_SOCKET,SendBuf,PacketLen);
- }
- void SIMReg(void)
- {
- // int i;
- // static int Table1[6]={0};
- // for(i = 0; i < 6; i++){
- // sscanf(sutProductPara.SIM+2*i,"%2x",&Table1[i]);
- // SimData.SIM[i]= Table1[i];
- // }
- }
|