123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- #include "includes.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 每次更新 进表格 存入文件系统
- /*
- 获得新的信标页
- 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;
- char start=0;
- char *Pmsg=0;
- char data[500];
- msg[17]=0;
- New_xinbiaopage.xb_CallID=htoi(msg+9);
-
- //find user name
- for(i=0;i<MAX_USER;i++){
- if(UserArr[i].id==New_xinbiaopage.xb_CallID){
- strcpy(New_xinbiaopage.xb_CallName,UserArr[i].UserName);
- }
- }
- StrAsciiToHex(msg[21],data);
- Pmsg=data;
- //456;789
- for(i=0;i<strlen(Pmsg);i++){
- if(Pmsg[i]==';'){
- Pmsg[i]=0;
- switch(j){
- case 0:
- New_xinbiaopage.xb_longitue=atoi(Pmsg+start);
- break;
- case 1:
- New_xinbiaopage.xb_latitue=atoi(Pmsg+start);
- break;
- case 2:
- New_xinbiaopage.xb_heading=atoi(Pmsg+start);
- break;
- case 3:
- New_xinbiaopage.xb_headerSpeed=atoi(Pmsg+start);
- break;
- case 4:
- New_xinbiaopage.xb_elevation=atoi(Pmsg+start);
- break;
- }
- i++;
- start=i;
- j++;
- }
- }
- }
- void PushXinbiao(SUT_XINBIAO_PAGE*NewXinbiao)
- {
- char i=0;
- for(i=0;i<sut_xinbiao_info.Max_id;i++){
- if(NewXinbiao->xb_CallID==sut_xinbiaopage[i].xb_CallID){
- memcpy(&sut_xinbiaopage[i],NewXinbiao,sizeof(SUT_XINBIAO_PAGE));
- return;
- }
- }
-
- //否,创建新页
- NewXinbiao->xb_id=sut_xinbiao_info.Max_id;
- memcpy(&sut_xinbiaopage[i+1],NewXinbiao,sizeof(SUT_XINBIAO_PAGE));
- sut_xinbiao_info.Max_id++;
-
- //处理完 清空
- memset(NewXinbiao,0,sizeof(NewXinbiao));
-
- }
- void CalcDistance(SUT_XINBIAO_PAGE*NewXinbiao)
- {
- }
- /*
- 信标协议 cmd 00 通用
- 0a 摇晕 只收不发
- a0 解除摇晕
- 0b 摇毙 不收不发
- b0 解除摇毙
- 0c 强制打开GPS
- */
- void XinbiaoPackSend(char cmd)
- {
- char temp[100]={0};
- snprintf(temp,sizeof(temp),"AT+POC=150000%08x%02x;%d;%d;%d;%d;%d;\r\n",sutPocStatus.LocalGroup.ID,cmd,sutGpsInfo.longitue\
- ,sutGpsInfo.latitue,sutGpsInfo.heading,sutGpsInfo.headerSpeed,sutGpsInfo.elevation);
- //strcpy(data,temp);
- msgAtSend(temp);
- 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<XINBIAO_NUM;i++){
- if(sut_xinbiaopage[i].xb_id==0){
- if(i!=0)sut_xinbiao_info.Max_id=sut_xinbiaopage[i-1].xb_id;
- break;
- }
- }
- }
- void WriteXbFile()
- {
- int fd;
- MSG_INFO(1,"%s save start",XINBIAO_FILE);
- fd=LSAPI_FS_Open(XINBIAO_FILE, LSAPI_FS_O_RDWR,0x0);
- if(fd<0){
- MSG_ERR(1,"%s open failed",XINBIAO_FILE);
- return;
- }
- LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
- LSAPI_FS_Write(fd, (unsigned char *)&sut_xinbiaopage, sizeof(SUT_XINBIAO_PAGE)*XINBIAO_NUM);
- LSAPI_FS_Close(fd);
- MSG_INFO(1,"%s save done", XINBIAO_FILE);
-
- }
- /*******************************************************************************************
- 下面为 首长功能
- *******************************************************************************************/
- signed char Record_Leader_CurIndex(){
- unsigned char i;
- for(i=0;i<MAX_USER;i++){
- if(leader[i].id==0)return i;//找到空白
- }
- return -1;
- }
- char Record_Leader_Scanf(int id){
- unsigned char i;
- for(i=0;i<MAX_USER;i++){
- if(leader[i].id==id)break;
- if(leader[i].id==0)break;//找到空白
- }
- if(i==MAX_USER)i=0; //覆盖第一条
- return i;
- }
- void Record_Leader_Status(char type){
- unsigned char i;
- unsigned char index;
-
- for(i=1;i<MAX_USER;i++){
- index=Record_Leader_Scanf(UserArr[i-1].id);
- leader[index].id=UserArr[i-1].id;
- if(type=0){//摇匀
- if(sut_check_box.checkstatus[i])leader[index].status=1;
- else leader[index].status=0;
- }else{
- if(sut_check_box.checkstatus[i])leader[index].status=2;
- else leader[index].status=0;
- }
- }
- }
- // ID cmd ;
- //+POC:8C00 934C0008 00 3B
- void LeaderRecv_handler(char*msg,char type)
- {
- char i;
- char start=0;
- char *Pmsg=0;
- int id=0;
- char data[250];
- StrAsciiToHex(msg[21],data);
- Pmsg=data;
- //456;789
- for(i=0;i<strlen(Pmsg);i++){
- if(Pmsg[i]==';'){
- Pmsg[i]=0;
- id=atoi(Pmsg+start);
- if(id==sutPocStatus.LocalUser.ID){
- sutPocStatus.LeaderCmd=type;
- if(sutPocStatus.spk)msgAtSend("AT+POC=0C0000\r\n");//说话状态释放话语权
- break;
- }
-
- i++;
- start=i;
- }
- }
- }
- void LeaderPackSend(char cmd)
- {
- char temp[250]={0};
- char buf[8];
- int i;
- int max;
- max=Record_Leader_CurIndex();
- if(max==-1)return;
- snprintf(temp,sizeof(temp),"AT+POC=150000%08x%02x;",sutPocStatus.LocalGroup.ID,cmd);
- for(i=0;i<max;i++){
- snprintf(buf,sizeof(buf),"%x;",leader[i].id);
- strcat(temp,buf);
- }
- strcat(temp,"\r\n");
- msgAtSend(temp);
- MSG_INFO(1,temp);
- }
- //LEADER leader[XINBIAO_NUM];
- void ReadLeaderFile()
- {
- int fd,i=0;
- fd=LSAPI_FS_Open(LEADER_FILE, LSAPI_FS_O_RDWR,0);
- if(fd<0){
- MSG_ERR(1,"%s open read failed", LEADER_FILE);
- return;
- }
- LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
- LSAPI_FS_Read(fd, (unsigned char *)&leader, sizeof(LEADER)*XINBIAO_NUM);
-
- }
- void WriteLeaderFile()
- {
- int fd;
- MSG_INFO(1,"%s save start",LEADER_FILE);
- fd=LSAPI_FS_Open(LEADER_FILE, LSAPI_FS_O_RDWR,0x0);
- if(fd<0){
- MSG_ERR(1,"%s open failed",LEADER_FILE);
- return;
- }
- LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
- LSAPI_FS_Write(fd, (unsigned char *)&leader, sizeof(LEADER)*XINBIAO_NUM);
- LSAPI_FS_Close(fd);
- MSG_INFO(1,"%s save done", LEADER_FILE);
-
- }
|