#include "includes.h" #include "math.h" SUT_XINBIAO_PAGE sut_xinbiaopage[XINBIAO_NUM]; SUT_XINBIAO_PAGE New_xinbiaopage; SUT_XINBIAO_INFO sut_xinbiao_info; USERARR UserArr[MAX_USER]; //临时存储当前所有成员 //每次 86 都需要更新 LEADER leader[XINBIAO_NUM]; //根据 UserArr 每次更新 进表格 存入文件系统 void PushXinbiao(SUT_XINBIAO_PAGE*NewXinbiao); /* 获得新的信标页 callID //是, 更新页 //否,创建新页 */ //+POC=8C00%08x%02x;%d;%d;%d;%d;%d;\r\n" //+POC:8C00 934C0008 00 3B void Recv_PackNewxinbiaopage(char*msg) { char i,j=0,z=0; char start=0; char *Pmsg=0; char data[500]={0}; msg[17]=0; //处理完 清空 memset(&New_xinbiaopage,0,sizeof(New_xinbiaopage)); New_xinbiaopage.xb_CallID=htoi(msg+9); MSG_INFO(1,"xb_CallID===%x",New_xinbiaopage.xb_CallID); //find user name for(i=0;ixb_longitue; double destLat=NewXinbiao->xb_latitue; srcLon/=1000000; srcLat/=1000000; destLon/=1000000; destLat/=1000000; MSG_INFO(1,"srcLon==%lf,srcLat====%lf,destLon====%lf,destLat===%lf",srcLon,srcLat,destLon,destLat); NewXinbiao->xb_distance=GetDirectDistance(srcLon,srcLat,destLon,destLat); MSG_INFO(1,"xb_distance===%lf",NewXinbiao->xb_distance); } //根据角度计算弧度 double rad(double d) { //const double PI = 3.1415926535898; double num=0; num=d * PI/180.0; MSG_INFO(1,"num===%lf",num); return num; } //根据弧度计算角度 double Angle(double r) { // const double PI = 3.1415926535898; return r * 180/PI; } //计算方位角 double GetBearing(double lat1, double lng1, double lat2, double lng2) { double d = 0; double radLat1 = rad(lat1);//根据角度计算弧度 double radLat2 = rad(lat2); double radLng1 = rad(lng1); double radLng2 = rad(lng2); d = sin(radLat1)*sin(radLat2)+cos(radLat1)*cos(radLat2)*cos(radLng2-radLng1); d = sqrt(1-d*d); d = cos(radLat2)*sin(radLng2-radLng1)/d; d = Angle(asin(d)); return d;//返回方位角 } void PushXinbiao(SUT_XINBIAO_PAGE*NewXinbiao) { char i=0; double srcLon=sutGpsInfo.longitue; double srcLat=sutGpsInfo.latitue; double destLon=NewXinbiao->xb_longitue; double destLat=NewXinbiao->xb_latitue; srcLat/=1000000; srcLon/=1000000; destLat/=1000000; destLon/=1000000; NewXinbiao->xb_dir=GetBearing(srcLat,srcLon,destLat,destLon); MSG_INFO(1,"xb_dir=======%d",NewXinbiao->xb_dir); CalcDistance(NewXinbiao); for(i=0;ixb_CallID==sut_xinbiaopage[i].xb_CallID){ NewXinbiao->xb_id=sut_xinbiaopage[i].xb_id; memcpy(&sut_xinbiaopage[i],NewXinbiao,sizeof(SUT_XINBIAO_PAGE)); return; } } //否,创建新页 sut_xinbiao_info.Max_id++; NewXinbiao->xb_id=sut_xinbiao_info.Max_id; memcpy(&sut_xinbiaopage[i],NewXinbiao,sizeof(SUT_XINBIAO_PAGE)); // } // /* 信标协议 cmd 00 通用 0a 摇晕 只收不发 a0 解除摇晕 0b 摇毙 不收不发 b0 解除摇毙 0c 强制打开GPS */ //AT+POC=150000 000be4e300 void XinbiaoPackSend(char cmd) { char temp[100]={0}; char buf[50]; /* snprintf(buf,sizeof(buf),"AT+POC=150000%08x%02x",sutPocStatus.LocalGroup.ID); msgAtSend(buf); snprintf(buf,sizeof(buf),"%d;%d;%d;%d;%d;",cmd,sutGpsInfo.longitue\ ,sutGpsInfo.latitue,sutGpsInfo.aspect,sutGpsInfo.speed,sutGpsInfo.hight); */ snprintf(buf,sizeof(buf),"AT+POC=150000%08x%02x",sutPocStatus.LocalGroup.ID,cmd); msgAtSend(buf); snprintf(buf,sizeof(buf),"%s;%d;%d;%d;%d;%d;",sutApp.UserInfo.Firm_CallID,sutGpsInfo.longitue\ ,sutGpsInfo.latitue,sutGpsInfo.aspect,sutGpsInfo.speed,sutGpsInfo.hight); AscStrTurnHexStr(buf,temp); msgAtSend(temp); msgAtSend("\r\n"); MSG_INFO(1,temp); } //定时发送信标 void Xinbiao_handler(unsigned int interval){ static unsigned short cnt=0; //char Packdata[100]={0}; if(sutApp.gtMode!=0) return; if(newPara.Xinbiao_SendMode==0)return; if(newPara.gpsEnable==0)return; if(++cnt<((newPara.Xinbiao_Time+1)*5*1000/interval) && gpsCheckCnt==0) return; cnt=0; gpsCheckCnt=0; if(sutGpsInfo.isGpsValid){ XinbiaoPackSend(NULLCMD); } } void ReadXbFile() { int fd,i=0; fd=LSAPI_FS_Open(XINBIAO_FILE, LSAPI_FS_O_RDWR,0); if(fd<0){ MSG_ERR(1,"%s open read failed", XINBIAO_FILE); return; } LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET); LSAPI_FS_Read(fd, (unsigned char *)&sut_xinbiaopage, sizeof(SUT_XINBIAO_PAGE)*XINBIAO_NUM); for(i=0;i