123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503 |
- #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;
- int g_iPocVer=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(i<numb) return 0;
-
- return Indexcnt;
- }
- int GetUserInfo(char *msg,int MsgLen)
- {
- char name[POC_USER_NAME_LEN*2+1];
- unsigned int Index;
- unsigned short ValidDate;
- unsigned int id;
- char Stracebuf[50];
-
- //>200&用户ID&缺省群组ID&用户账号有效期&用户名称
- StringCatByNumb(msg,1,name);
-
- sutPocStatus.LocalUser.ID=atoi(name);
- Index=StringCatByNumb(msg,3,name);
-
- //printf("INDEX111111======%d\r\n",Index);
- //SlwTrace(INF,"/*******日期*********/",1);
- //SlwTrace(INF,name,1);////////////////////
-
- 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);
- 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);
- ModemSendAT(Stracebuf);
- os_dly_wait(10);
- //获取模块时间
- ModemSendAT("AT+POC=509\r\n");
- 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;
- 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:
- //AT+POC=522&80&12
- //ModemSendAT("AT+POC=522&80&12\r\n");
- 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_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;//单呼失败
- snprintf(Tempbuf,sizeof(Tempbuf),"呼叫失败");
- ShowMessageBox(Tempbuf);
- UISetNextStatus(UIS_STANDBY);
- }
-
- else if(atoi(Tempbuf)==3){
- sutPocStatus.danHunStatus=0;//单呼失败
- snprintf(Tempbuf,sizeof(Tempbuf),"对方拒绝接通");
- 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);
- g_usModeHTime=atoi(Tempbuf); //+8
- StringCatByNumb(msg,5,Tempbuf);
- g_usModeMTime=atoi(Tempbuf);
- StringCatByNumb(msg,6,Tempbuf);
- g_usModeSTime=atoi(Tempbuf);
- SetTime(g_usModeHTime, g_usModeMTime, g_usModeSTime);
- break;
-
- case MCU_R_ENABLE_GPS_STR: // 117使能GPS 获取GPS 上传间隔
- // sutGpsInfo.GPS_UploadTime
- ///>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_LED_STR: //set LED 110
- // //>110&red_mode&red_offtime&red_ontime&greed_mode&green_offtime&green_ontim
- //
- // StringCatByNumb(msg,1,Tempbuf); //red 长亮或长灭
- //
- // if(atoi(Tempbuf)==1) {
- // sucRedLedSleep=0;
- // sucRedLedFlash=1;
- //
- // }
- // else if(atoi(Tempbuf)==2) {
- // sucRedLedFlash=0;
- // sucRedLedSleep=1;
- // }
- // else {
- // StringCatByNumb(msg,2,Tempbuf);
- // sucRedLedSleep=atoi(Tempbuf)/100;
- //
- // StringCatByNumb(msg,2,Tempbuf);
- // sucRedLedFlash=atoi(Tempbuf)/100;
- // }
- // StringCatByNumb(msg,4,Tempbuf); //green
- //
- // if(atoi(Tempbuf)==1) {
- // sucBlueLedSleep=0;
- // sucBlueLedFlash=1;
- // }
- // else if(atoi(Tempbuf)==2){
- // sucBlueLedFlash=0;
- // sucBlueLedSleep=1;
- // }
- // else {
- // StringCatByNumb(msg,5,Tempbuf);
- // sucBlueLedSleep=atoi(Tempbuf)/100;
- // StringCatByNumb(msg,6,Tempbuf);
- // sucBlueLedFlash=atoi(Tempbuf)/100;
- // }
- // break;
- case MCU_R_VERSION_STR_STR: //获取POC 版本
- index=StringCatByNumb(msg,1,Tempbuf);
- SlwTrace(INF,Tempbuf,1);
- g_iPocVer=atoi(Tempbuf);
- 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&%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);
- os_dly_wait(20);
- ModemSendAT(Tempbuf);
- }
|