#include "includes.h" SUT_POC_STATUS sutPocStatus; OS_TID idPocTask=0; //U64 stkPocTask[POC_TASK_STK_SIZE]; unsigned long g_ulGroupID; unsigned char g_ucSelect=0; int g_iModemVer=0; char g_iPocVer[15]={0}; /***************************************** numb:取第几个&后的字段 string:返回的字段 return: 返回当前所处位置 ******************************************/ unsigned char StringCatByNumb(char *msg,char numb,char *string) { short i=0; short j=0; char flag=0; short Indexcnt=0; while(*msg!=0x0d && *msg!=0x0a) //0d { if(*msg=='&') { i++; if(i>numb){ break; } } if(i==numb){ if(flag==0){ j++; Indexcnt=j; flag=1; msg++; } *string++=*msg; } msg++; j++; } *string++=0; //printf("i===%d,j====%d,numb===%d,index====%d\r\n",i,j,numb,Indexcnt); if(i200&用户ID&缺省群组ID&用户账号有效期&用户名称 StringCatByNumb(msg,1,name); sutPocStatus.LocalUser.ID=atoi(name); Index=StringCatByNumb(msg,3,name); ValidDate=atoi(name); snprintf(Stracebuf,sizeof(Stracebuf),"有效日期为:%d.......",ValidDate); SlwTrace(INF,Stracebuf,1); Index=StringCatByNumb(msg,4,name); //printf("MSLEN===%d,index===%d\r\n",MsgLen,Index); SlwTrace(INF,name,1); // //memcpy(sutPocStatus.LocalUser.name,name,MsgLen-Index-3); strcpy(sutPocStatus.LocalUser.name,name); //SlwTrace(INF,name,1); // ModemSendAT("AT+POC=508\r\n"); return 0; } int GetGroupInfo(char *msg,int MsgLen) { char name[POC_USER_NAME_LEN*2+1]; unsigned long id; unsigned short index; char Stracebuf[50]; //>201&群组ID&在线状态&群组名称 index=StringCatByNumb(msg,1,name); //SlwTrace(INF,"GROUP-----------------",1); SlwTrace(INF,name,1); sutPocStatus.LocalGroup.ID=atoi(name); //printf("groupID===============%d\r\n",sutPocStatus.LocalGroup.ID); StringCatByNumb(msg,2,name); sutPocStatus.Logined=atoi(name); // 判断是否登录 sutPocStatus.FirstLogined=1; index=StringCatByNumb(msg,3,name); SlwTrace(INF,name,1); memset(sutPocStatus.LocalGroup.name,0,sizeof(sutPocStatus.LocalGroup.name)); //memcpy(sutPocStatus.LocalGroup.name,name,MsgLen-index-3); strcpy(sutPocStatus.LocalGroup.name,name); //对讲状态初始化 sutPocStatus.Speaker=0; sutPocStatus.PPTpress=0; SlwTrace(INF, "login ok",1); snprintf(Stracebuf,sizeof(Stracebuf),"AT+POC=522&%d&%d\r\n",(Vbat-340)*100/(430-340),g_iCSQ); sutLcdParam.OnTimeCt=0; ModemSendAT(Stracebuf); os_dly_wait(10); //获取模块时间 ModemSendAT("AT+POC=509\r\n"); return 0; } int GetGroupInfoBy129(char *msg,int MsgLen) { char name[POC_USER_NAME_LEN*2+1]; unsigned long id; unsigned short index; char Stracebuf[50]; //>129&入群结果&群组ID&群组名称 index=StringCatByNumb(msg,2,name); SlwTrace(INF,name,1); sutPocStatus.LocalGroup.ID=atoi(name); index=StringCatByNumb(msg,1,name); sutPocStatus.Logined=atoi(name); // 判断是否登录 index=StringCatByNumb(msg,3,name); SlwTrace(INF,name,1); memset(sutPocStatus.LocalGroup.name,0,sizeof(sutPocStatus.LocalGroup.name)); strcpy(sutPocStatus.LocalGroup.name,name); //对讲状态初始化 sutPocStatus.Speaker=0; sutPocStatus.PPTpress=0; return 0; } int GetMcuSpeakerInfo(char *msg,int MsgLen) { char name[POC_USER_NAME_LEN*2+1]; unsigned long id; unsigned short index; char Stracebuf[50]; //206&组呼&状态&主叫ID&被叫ID&主叫 用户名&被叫用户名 //判断开始或结束 StringCatByNumb(msg,2,name); if(atoi(name)==1){ sutPocStatus.Speaker=1; if(sutUIstatus.Status!=UIS_STANDBY) sutPocStatus.PocingCnt=1; SlwTrace(INF,"开始说话----\r\n",0); //先判断类型 StringCatByNumb(msg,1,name); if(atoi(name)==4)sutPocStatus.SOS_Flag=1; }else if(atoi(name)==2){ StringCatByNumb(msg,1,name); if(atoi(name)==1)sutPocStatus.SOS_Flag=0; if(sutPocStatus.SOS_Flag==0)sutPocStatus.Speaker=0; sutPocStatus.PocingCnt=0; SlwTrace(INF,"结束说话----\r\n",0); //memset(sutPocStatus.Callname,0,sizeof(sutPocStatus.Callname)); return 0; } //获取主叫ID StringCatByNumb(msg,3,name); sutPocStatus.CallID=atoi(name); //获取主叫用户名 index=StringCatByNumb(msg,5,name); memset(sutPocStatus.Callname,0,sizeof(sutPocStatus.Callname)); strcpy(sutPocStatus.Callname,name); return 0; } char ZXPocHandle(char *msg,int MsgLen) { char i,j; char cmd[4]; unsigned long id; unsigned short index; char Tempbuf[100]; char tempbuf[6]; unsigned short cmdnum; USER_RTC_DEF temptime; if(*msg=='>'){ for(i=0;i<3;i++) { cmd[i]=msg[i+1]; } }else { for(i=0;i<3;i++) { cmd[i]=msg[i]; } } cmd[3]=0; cmdnum=atoi(cmd); //printf("cmd====%d\r\n",cmdnum); switch(cmdnum){ case MCU_R_APP_START_STR: //APP登录 snprintf(Tempbuf,sizeof(Tempbuf),"AT+POC=504&%s&%s&%s&%s&%s&%s&%d&%d&%s\r\n",sutProductPara.PIP,sutProductPara.APNApn,sutProductPara.Net_Mode \ ,sutProductPara.Language,sutProductPara.Local,sutProductPara.Channel,sutProductPara.SendToneEnadble,sutProductPara.PromptToneEnable,sutProductPara.IMEI); SlwTrace(INF,Tempbuf,1); ModemSendAT(Tempbuf); break; case MCU_R_AMP_ON_STR: sutPocStatus.TTS=1; SpeakerEnable(); break; case MCU_R_AMP_OFF_STR: sutPocStatus.TTS=0;// 测试用 SpeakerDisable(); break; case MCU_R_GET_BATVOL_STR: if(Vbat>435)snprintf(Tempbuf,sizeof(Tempbuf),"AT+POC=522&%d&%d\r\n",100,g_iCSQ); else if(Vbat>330)snprintf(Tempbuf,sizeof(Tempbuf),"AT+POC=522&%d&%d\r\n",(Vbat-340)*100/(430-340),g_iCSQ); ModemSendAT(Tempbuf); break; case MCU_R_PUSH_SELF_INFO_STR: // 200 用户自己的信息 //>200&用户ID&缺省群组ID&用户账号有效期&用户名称 GetUserInfo(msg,MsgLen); break; case MCU_R_PUSH_ONOFFLINE_STR: //201 群组,及是否在线 GetGroupInfo(msg,MsgLen); break; case MCU_R_JION_RET_STR://129 入群指令 GetGroupInfoBy129(msg,MsgLen); break; case MCU_R_PUSH_US_STATE_STR: //204 //推送好友状态变化 break; case MCU_R_PUSH_PTT_RES_STR: //205 推送PTT说话状态 StringCatByNumb(msg,1,Tempbuf); if(atoi(Tempbuf)==1){ if(g_usSOSCnt==3){ sutPocStatus.SOS_Flag=1; } sutPocStatus.PPTpress=1; sutPocStatus.Speaker=0; } else{ Pttfreeflag=0; sutPocStatus.SOS_Flag=0; sutPocStatus.PPTpress=0; } //>205&类型&被叫ID&被叫名称&状态 break; case MCU_R_PUSH_SPEAK_STR: //206 //推送被叫 说话状态 //206&1&1&5219878&6920&4&用户 //206&组呼&状态&主叫ID&被叫ID&主叫 用户名&被叫用户名 LCDTimeOut(0); //LcdSendCommand(0x29); // LCD_BL_HIGH; // LcdSleepFlag=0; sutLcdParam.OnTimeCt=0; GetMcuSpeakerInfo(msg,MsgLen); break; case MCU_R_PUSH_P2PCALL_STR : // 207 //推送单呼 主叫状态 //>207&状态&被叫ID&被叫name //状态 0失败 1成功 2等待 3对方拒接 4结束 index=StringCatByNumb(msg,1,Tempbuf); if(atoi(Tempbuf)==1){ sutPocStatus.danHunStatus=2; UISetNextStatus(UIS_STANDBY); } else if(atoi(Tempbuf)==2){ //等待 // sutPocStatus.danHunStatus=1; // GuiClearRect(0,110,160,128); } else if(atoi(Tempbuf)==0){ sutPocStatus.danHunStatus=0;//单呼失败 if(0==strcmp(sutProductPara.Language,"cn"))snprintf(Tempbuf,sizeof(Tempbuf),"呼叫失败"); else snprintf(Tempbuf,sizeof(Tempbuf),"call failed!"); ShowMessageBox(Tempbuf); UISetNextStatus(UIS_STANDBY); } else if(atoi(Tempbuf)==3){ sutPocStatus.danHunStatus=0;//单呼失败 if(0==strcmp(sutProductPara.Language,"cn"))snprintf(Tempbuf,sizeof(Tempbuf),"对方拒绝接通"); else snprintf(Tempbuf,sizeof(Tempbuf),"refuse!"); ShowMessageBox(Tempbuf); UISetNextStatus(UIS_STANDBY); } else if(atoi(Tempbuf)==4){ sutPocStatus.Speaker=0; sutPocStatus.PPTpress=0; sutPocStatus.danHunStatus=0;//单呼结束 sutPocStatus.PocingCnt=0; UISetNextStatus(UIS_STANDBY); } break; case MCU_R_PUSH_P2PBCALL_STR : //208 //推送单呼 被叫状态 //>208&状态&被叫ID&被叫name //状态 1开始 2接通 3对方拒接 4结束 LCDTimeOut(0); sutLcdParam.OnTimeCt=0; index=StringCatByNumb(msg,1,Tempbuf); if(atoi(Tempbuf)==2){ sutPocStatus.danHunStatus=2;//单呼成功 /////////1 StringCatByNumb(msg,3,Tempbuf); memset(sutPocStatus.Callname,0,sizeof(sutPocStatus.Callname)); strcpy(sutPocStatus.Callname,Tempbuf); if(sutUIstatus.Status!=UIS_STANDBY) sutPocStatus.PocingCnt=1; } if(atoi(Tempbuf)==4){ sutPocStatus.danHunStatus=0;//单呼结束 sutPocStatus.Speaker=0; sutPocStatus.PocingCnt=0;//1 if(sutUIstatus.Status==UIS_STANDBY)GuiClearAreaFixColor(100,111,60,18,OrangeColorId); } break; case MCU_R_GET_UNUM_STR: //135 //获取在线用户数量 //>135&7 StringCatByNumb(msg,1,Tempbuf); sutPocStatus.UserOnLineNum=atoi(Tempbuf); sutPocStatus.UserNum_Update=1; snprintf(Tempbuf, sizeof(Tempbuf), "oneLine:%d",sutPocStatus.UserOnLineNum); SlwTrace(INF,Tempbuf,1); break; case MCU_R_GET_GNUM_STR : //132 //群组数量 StringCatByNumb(msg,1,Tempbuf); sutPocStatus.GroupOnLineNum=atoi(Tempbuf); sutPocStatus.GroupNum_Update=1; snprintf(Tempbuf, sizeof(Tempbuf), "onLine:%d",sutPocStatus.GroupOnLineNum); SlwTrace(INF,Tempbuf,1); break; case MCU_R_GET_REC_NUM_STR: //150 录音记录个数 //>150&6805&10 recordID StringCatByNumb(msg,1,Tempbuf); id=atoi(Tempbuf); if(sutPocStatus.recordID==id){ StringCatByNumb(msg,2,Tempbuf); sutPocStatus.VoiceOnLineNum=atoi(Tempbuf); sutPocStatus.VoiceNum_Update=1; snprintf(Tempbuf, sizeof(Tempbuf), "vioce onLine:%d",sutPocStatus.VoiceOnLineNum); SlwTrace(INF,Tempbuf,1); } break; case MCU_R_GET_GP_LIST_STR: //134 //群组列表 //>134&个数&起始序列号&GID&名称&GID&名称 //>134&1 & N &UID&Uname if(strlen(msg)<10){ //规避异常 break; } memset(sutPocStatus.AllGroups[sutPocStatus.FillGroupIndex].name,0,POC_GROUP_NAME_LEN); index=StringCatByNumb(msg,4,Tempbuf); //memcpy(sutPocStatus.AllGroups[sutPocStatus.FillGroupIndex].name,Tempbuf,MsgLen-index-3); //strcpy(sutPocStatus.AllGroups[sutPocStatus.FillGroupIndex].name,Tempbuf); strncpy(sutPocStatus.AllGroups[sutPocStatus.FillGroupIndex].name,Tempbuf,POC_USER_NAME_LEN); StringCatByNumb(msg,3,Tempbuf); sutPocStatus.AllGroups[sutPocStatus.FillGroupIndex].ID=atoi(Tempbuf); //sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].status=3; sutPocStatus.GetOneGroupFlag=1; break; case MCU_R_GET_LUS_LIST_STR: // 137 在线用户列表 //>137&个数&起始序列号&UID&名称&UID&名称 //>137&1 & N &UID&Uname if(strlen(msg)<10){ //规避异常 break; } memset(sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].name,0,POC_USER_NAME_LEN); memset(Tempbuf,0,sizeof(Tempbuf)); index=StringCatByNumb(msg,4,Tempbuf); if(Tempbuf==0){ strncpy(sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].name,"空",POC_USER_NAME_LEN); }else strncpy(sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].name,Tempbuf,POC_USER_NAME_LEN); //memcpy(sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].name,Tempbuf,MsgLen-index-3); //strcpy(sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].name,Tempbuf); StringCatByNumb(msg,3,Tempbuf); sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].ID=atoi(Tempbuf); sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].status=3; sutPocStatus.GetOneUserFlag=1; break; case MCU_R_GET_REC_LIST_STR: // 151 录音文件列表 if(strlen(msg)<10||sutPocStatus.FillVoiceIndex>4){ //规避异常 break; } //>151&个数&起始序列&类型&时长&名字 //类型 0:呼出 1呼入 memset(sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].name,0,POC_USER_NAME_LEN); index=StringCatByNumb(msg,5,Tempbuf); //7 //memcpy(sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].name,Tempbuf,MsgLen-index-3); //strcpy(sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].name,Tempbuf); printf("==========FillVoiceIndex====%d======\r\n",sutPocStatus.FillVoiceIndex); strncpy(sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].name,Tempbuf,POC_USER_NAME_LEN); StringCatByNumb(msg,2,Tempbuf); sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].ID=atoi(Tempbuf); StringCatByNumb(msg,3,Tempbuf); sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].type=atoi(Tempbuf); StringCatByNumb(msg,4,Tempbuf); if(atoi(Tempbuf)/1000==0) sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].time=1; else sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].time=atoi(Tempbuf)/1000; //sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].status=3; sutPocStatus.GetOneVoiceFlag=1; break; case MCU_R_TIME_STR: //140 //网络时间 //>140&2019&5&23&9&51&31 StringCatByNumb(msg,4,Tempbuf); temptime.hour=atoi(Tempbuf); //+8 StringCatByNumb(msg,5,Tempbuf); temptime.min=atoi(Tempbuf); StringCatByNumb(msg,6,Tempbuf); temptime.second=atoi(Tempbuf); RTC_UserSetTime(temptime); break; case MCU_R_ENABLE_GPS_STR: // 117使能GPS 获取GPS 上传间隔 ///>117&5000 5000MS StringCatByNumb(msg,1,Tempbuf); sutGpsInfo.GPS_UploadTime=atoi(Tempbuf)/1000; if(sutGpsInfo.GPS_UploadTime<=0) sutGpsInfo.GPS_UploadTime=15; /// 测试用 sutGpsInfo.Updata=1; g_uiGpsStat=1; break; case MCU_R_DISABLE_GPS_STR : // 118 关闭GPS sutGpsInfo.Updata=1; g_uiGpsStat=0; break; // case MCU_R_VERSION_STR_STR: //获取POC 版本 // index=StringCatByNumb(msg,1,Tempbuf); // SlwTrace(INF,Tempbuf,1); // break; case MCU_R_TRANS_AT_CMD_STR: //modem 要求MCU 发送AT strcpy(Tempbuf,&msg[5]); ModemSendAT(Tempbuf); break; //sutPocStatus case MCU_R_PLAY_REC_STR: StringCatByNumb(msg,2,Tempbuf); sutPocStatus.TTS= atoi(Tempbuf); //0 失败 1 正在播放 2播放结束 break; default: break; } } void LoginPocInfo() { char Tempbuf[100]; snprintf(Tempbuf,sizeof(Tempbuf),"AT+POC=504&%s&%s&%s&%s&%s&%s&%d&%d&%d&%s\r\n",sutProductPara.PIP,sutProductPara.APNApn,sutProductPara.Net_Mode \ ,sutProductPara.Language,sutProductPara.Local,sutProductPara.Channel,sutProductPara.SendToneEnadble,sutProductPara.RecvToneEnadble,sutProductPara.PromptToneEnable,sutProductPara.IMEI); SlwTrace(INF,Tempbuf,1); ModemSendAT(Tempbuf); // os_dly_wait(20); // ModemSendAT(Tempbuf); }