/********************************************************************************** * 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; REGISTRATION Regist; AVL_MSG_BODY_ATTRIB msgBodyAttrib; MSG_HEAD msghead; MSG_PACKET msgPacket; AUTH auth; SIM SimData; SUT_LCDGPS_SEND_DATA sutLcdGpsSendData; //´Ó³§É̱àºÅµ½Óû§Êý¾ÝÒÀ´ÎÀÛ¼ÓµÄÀۼӺͣ¬È¡ÀۼӵĵµÍ8λ×÷ΪУÑéÂë unsigned char TSGetCheckSum(unsigned char *pData,int len) { int i; unsigned char sum= pData[1]; for(i=1;i>8)&0xff; pBuf[i++]=ID&0xff; //ÏûÏ¢ÌåÊôÐÔ msgBodyAttrib.EncrypType=NO_ENCRYP;//NO_ENCRYP; msgBodyAttrib.msgBodyLength=(DataLen); pBuf[i++]=msgBodyAttrib.EncrypType; pBuf[i++]=msgBodyAttrib.msgBodyLength; //SIM¿¨ºÅ if(sutNewSegmentPara.SIMFlag!=1){ pBuf[i++]=0; // for (j=0;j<10;j+=2) { pBuf[i++]=(Psnsv[j]<<4)|(Psnsv[j+1]&0x0F); } }else{ 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>8)&0xff); Regist.proID =(sutNewSegmentPara.proID&0xff); Regist.CityID = ((sutNewSegmentPara.CityID>>24)&0xffff); Regist.CityID = ((sutNewSegmentPara.CityID>>16)&0xffff); Regist.CityID = ((sutNewSegmentPara.CityID>>8)&0xffff); Regist.CityID = (sutNewSegmentPara.CityID&0xffff); for(i = 0; i < 5; i++) Regist.Manufacturers[i] = sutNewSegmentPara.Manufacturers[i]; for(i = 0; i < 20; i++) { if((i<20)&&(sutNewSegmentPara.TerMod[i]!='0')) Regist.TerMod[i]= sutNewSegmentPara.TerMod[i]; else Regist.TerMod[i]=0x00; } for(i = 0; i < 4; i++) { sscanf(sutNewSegmentPara.TerID+2*i,"%2x",&Temp1[i]); Regist.TerID[i]= Temp1[i]; } Regist.PlateColor=sutNewSegmentPara.PlateColor;// for(i = 0; i < 8; i++) { sscanf(sutNewSegmentPara.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(sutNewSegmentPara.Select==1) TSMakeSendData(); else TSRegData(sutProductPara.PSN); //REGISTRATION Regist; PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_TERMINAL_REGISTRATION,(unsigned char *)&Regist,sizeof(REGISTRATION)); MC8332ModemSendTcpData(GPS_DATA_SOCKET,SendBuf,PacketLen); return len; } void Registration(void) { SlwTrace(INF, "Registration",1); if(sutNewSegmentPara.SIMFlag){SIMReg();} TSRegData(sutProductPara.PSN); } 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(GPS_DATA_SOCKET,SendBuf,PacketLen); } /************************************************************ Öն˼øÈ¨ *************************************************************/ void Authentication(void) { unsigned char SendBuf[100]; unsigned short PacketLen; unsigned char temp[27]; SlwTrace(INF, "Authentication!",1); memset(temp,0,sizeof(temp)); memcpy(temp,(unsigned char *)&sutNewSegmentPara.AutH,sizeof(sutNewSegmentPara.AutH)); memcpy(&temp[sizeof(sutNewSegmentPara.AutH)],CCID,sizeof(CCID)); PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_TERMINAL_AUTHENTICATION,temp,sizeof(temp));//ʵ¼ÊÊÇ·µ»ØµÄ¼øÈ¨ÐÅÏ¢ 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(GPS_DATA_SOCKET,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(GPS_DATA_SOCKET,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; TSMakeGpsSendData(); PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_LOCATION_INFORMATION_REPORTING,(unsigned char *)&sutGpsSendData,sizeof(SUT_GPS_SEND_DATA)); MC8332ModemSendTcpData(GPS_DATA_SOCKET,SendBuf,PacketLen); } /*********************************************************************************** *·þÎñÆ÷ÉèÖÃÖ÷¶¯Éϱ¨Ê±¼ä *Êý¾Ý¸ñʽ 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) { 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(GPS_DATA_SOCKET,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(GPS_DATA_SOCKET,SendBuf,PacketLen); return 0; } void TS_SendHeartTick(void) { unsigned char SendBuf[100]; unsigned short PacketLen; PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_TERMINAL_HEARTBEAT,0,0); MC8332ModemSendTcpData(GPS_DATA_SOCKET,SendBuf,PacketLen); } /********************************************************* *************************************************************/ unsigned long power(int base, int times) { int i; unsigned long rslt = 1; for(i=0; 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; } 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 MakeGpsSendData(void) { char buf[12]; unsigned char *data=(unsigned char *)&sutLcdGpsSendData; memset(data, 0, sizeof(SUT_LCDGPS_SEND_DATA)); data[0] = (sutGpsInfo.latitue>>24)&0xFF; data[1] = (sutGpsInfo.latitue>>16)&0xFF; data[2] = (sutGpsInfo.latitue>>8)&0xFF; data[3] = (sutGpsInfo.latitue)&0xFF; data[4] = (sutGpsInfo.longitue>>24)&0xFF; data[5] = (sutGpsInfo.longitue>>16)&0xFF; data[6] = (sutGpsInfo.longitue>>8)&0xFF; data[7] = (sutGpsInfo.longitue)&0xFF; // sprintf(buf,"%d",sutGpsInfo.latitue); // SlwTrace(INF,buf,1); // buf[0]=0; // sprintf(buf,"%d",sutGpsInfo.longitue); // SlwTrace(INF,buf,1); } /***************************************************** ÉîÛÚ±±Î³22.33 ¶«¾­114.07 ¾­¹ýÊÔÑéÊý¾Ý±È½Ï׼ȷ£¬µ«ÊǶ«Î÷Äϱ±²»ÖªµÀ ******************************************************/ void GetCoordinates(unsigned char type) { //type 0 UIʱµ÷Óà // 1 ÉÏ´«Ê±µ÷Óà char buf[10]; char buf0[10]={0}; char buf1[8]; char buf2[4]={0}; char temp[3]; char temp1[3]; char temp2[5]; char temp3[5]; int i,num,num1,w,j; double Jnum1,Jnum2,Jnum3;//ÓÐСÊýλ 8λÓÐЧ double Wnum1,Wnum2,Wnum3;//ÓÐСÊýλ 8λÓÐЧ MakeGpsSendData(); 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; sutGpsInfo.testJD = j*1000000+Jnum3*1000000;//ÉÏ´«Ê±Ê¹Óà AscStrTurnHexStr((char *)sutLcdGpsSendData.WWWW,buf2); for(i=0;i<3;i++) temp1[i]=buf2[i]; w=atoi(temp1); for(i=0;i<6;i++) temp3[i]=buf2[i+3]; num1=atoi(temp3); Wnum1=num1/1000; Wnum1 /=60; Wnum2 = (num1%1000)*60; Wnum2 /=3600000; Wnum3=Wnum1+Wnum2; sutGpsInfo.testWD = w*1000000+Wnum3*1000000; } //#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(sutGpsInfo.isGpsValid) {//wjl 1121 sutGpsSendData.status |=(0x01<<24);//ACC sutGpsSendData.status |=(0x01<<25);//¶¨Î»±êÖ¾ sutGpsSendData.status |=(0x01<<28);//ÔËӪ״̬ }else sutGpsSendData.status=0; 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 TSRegData(unsigned long PSN){ int i; static int Temp1[7]; static int Table1[20]={0}; static int Temp[8]; unsigned char SendBuf[100]; unsigned short PacketLen,data1,data2,data3,data4; 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(sutNewSegmentPara.SIM+2*i,"%2x",&Table1[i]); SimData.SIM[i]= Table1[i]; } }