#include "includes.h" POC_DEF sutPocStatus; void pocDataInit(void){ memset((unsigned char *)&sutPocStatus, 0, sizeof(POC_DEF)); } /*控制查询POC设置状态 dly:接口被调用的频率,单位ms*/ void pocProCtl(int dly){ //3秒查询一次 static unsigned short cnt=0; if(sutApp.gtMode!=0) return;//GT模式后不再查询 if(++cnt<(5*1000/dly)) return; cnt=0; if(getAppObjStatus(ASLEEP_POC)==0) return;//POC休眠时,不发指令 if(sutApp.pocParaDone==0) msgAtSend("AT+POC=020000\r\n");//用于检测并设置POC参数 msgAtSend("AT$MYSYSINFO\r\n");//查询当前网络制式 msgAtSend("AT+UDP?\r\n");//查询功耗状态 msgAtSend("AT+CSQ\r\n");//查询信号强度 msgAtSend("AT+GPIP?\r\nAT+GGIP?\r\n");//查询PIP,GIP //msgAtSend("AT+HEAP\r\n"); } static void micPro(int mic); static void spkPro(int spk); static void pocStartMsg(void); static void pro80Msg(char *msg); static void pro81Msg(char *msg); static void pro82Msg(char *msg); static void pro83Msg(char *msg); static void pro84Msg(char *msg); static void pro86Msg(char *msg); static void pro3dMsg(char *msg); static void pro3eMsg(char *msg); static void pro0eMsg(char *msg); static void pro1eMsg(char *msg); static void pro1dMsg(char *msg); static void pocGetVer(char *msg); static void pocGetPpp(char *msg); static void proGauthMsg(char *msg); static void proNoteMsg(char *msg); static void proNetMode(char *msg); static void proSimMode(char *msg); static void proPwrMode(char *msg); static void proFotaMsg(char *msg); static void proGmrMsg(char *msg); static void proSmsMsg(char *msg); static void proAlarmMsg(void); static void proPendMsg(void); static void proToneMsg(char *msg); static void proGPIPMsg(char *msg); static void proGGIPMsg(char *msg); static void proCsqMsg(char *msg); static void proMicSpk(int mic, int spk); void cmdsProcess(char *msg, int len){//已去掉回车换行 static char firstTTSEnd=1; int i; char *p,taddr[30],buf[100]; if(sutApp.pocInitStatus==0) sutApp.pocInitStatus=1; if(sutApp.gtMode==0){ appSleepCtl(ASLEEP_POC, 1); tryWakeupApp(); MSG_INFO(1,"POC:%s",msg); if(msgCmp(msg, "+POC:SLEEP")){//POC休眠了 appSleepCtl(ASLEEP_POC, 0); }else if(msgCmp(msg, "+POC:WAKEUP")){//POC唤醒了 }else if(msgCmp(msg, "+POC:8B")){ buf[0]=msg[7];buf[1]=msg[8];buf[2]=0; i=atoi(buf); buf[0]=msg[9];buf[1]=msg[10];buf[2]=0; proMicSpk(i, atoi(buf)); //micPro(atoi(buf)); //buf[0]=msg[9];buf[1]=msg[10];buf[2]=0; //spkPro(atoi(buf)); }else if(msgCmp(msg, "+HTTS: END")){ sutPocStatus.TTS=0; if(firstTTSEnd==1){ firstTTSEnd=0; msgAtSend("AT+HTTSSPEED=1282,3000\r\n");//设置TTS音量 } }else if(msgCmp(msg, "+HTTS: START")){ paControl(true); sutPocStatus.TTS=1; }else if(msgCmp(msg, "+CGPS:")) proGpsMsg(msg+6); else if(msgCmp(msg, "$MYSYSINFO:")) proNetMode(msg+12); else if(msgCmp(msg, "+TONE:")) proToneMsg(msg+6); else if(msgCmp(msg, "+UDP:")) proPwrMode(msg+5); else if(msgCmp(msg, "+CSQ: ")) proCsqMsg(msg+6); else if(msgCmp(msg, "+POC:82")) pro82Msg(msg+7); else if(msgCmp(msg, "+POC:3D")) pro3dMsg(msg+7); else if(msgCmp(msg, "+POC:3E")) pro3eMsg(msg+7); else if(msgCmp(msg, "+POC:80")) pro80Msg(msg+7); else if(msgCmp(msg, "+POC:1E")) pro1eMsg(msg+7); else if(msgCmp(msg, "+POC:86")) pro86Msg(msg+7); else if(msgCmp(msg, "+POC:83")) pro83Msg(msg+7); else if(msgCmp(msg, "+POC:84")) pro84Msg(msg+7); else if(msgCmp(msg, "+POC:0E")) pro0eMsg(msg+7); else if(msgCmp(msg, "+POC:1D")) pro1dMsg(msg+7); else if(msgCmp(msg, "+POC:START")) pocStartMsg(); else if(msgCmp(msg, "+POC_VER:")) pocGetVer(msg+9); else if(msgCmp(msg, "+POC_PPP:")) pocGetPpp(msg+9); else if(msgCmp(msg, "+POC:02000000")) setPocPara(msg+13,len-13); else if(msgCmp(msg, "+GAUTH:")) proGauthMsg(msg+7); else if(msgCmp(msg, "+NOTE:")) proNoteMsg(msg+6); else if(msgCmp(msg, "+RSIM:")) proSimMode(msg+6); else if(msgCmp(msg, "+FOTA:")) proFotaMsg(msg+6); else if(msgCmp(msg, "+CGPS:")) proGpsMsg(msg+6); else if(msgCmp(msg, "+GPIP:")) proGPIPMsg(msg+6); else if(msgCmp(msg, "+GGIP:")) proGGIPMsg(msg+6); else if(msgCmp(msg, "+GMR:")) proGmrMsg(msg+5); else if(msgCmp(msg, "+SMS:")) proSmsMsg(msg+5); else if(msgCmp(msg, "+ALARM")) proAlarmMsg(); else if(msgCmp(msg, "+POC:PEND")) proPendMsg(); else if(msgCmp(msg, "+CPIN: READY")) sutApp.cardStatus=1; else MSG_INFO(1, "skip:%d,%s", len,msg); } } //处理POC模块信息 void pocCmdHandler(unsigned char *msg, int len){ //有消息进来,如果不是+POC:SLEEP,POC都唤醒了 static char tmp[300],ch; static int k=0; unsigned int j; if(sutApp.authReady==0) return; if(sutApp.gtMode !=0 && sutApp.gtTMode != 0){ nwy_usb_serial_send(msg, len);//TM模式下直接透传 return; } for(j=0;j=sizeof(tmp)) k=0; tmp[k++]=msg[j]; if(ch=='\r' && msg[j]=='\n'){ if(k!=2){ //处理 k -=2;tmp[k]=0;//去掉回车换行 cmdsProcess(tmp,k); } k=0; } ch=msg[j]; } } static void proMicSpk(int mic, int spk){ if(mic==0 && spk==0){//0000 if(newPara.KeySound!=0) pttBeepStart(false); sutPocStatus.spk=0; sutPocStatus.mic=0; }else if(mic==1 && spk==0){//0100 if(newPara.KeySound!=0) pttBeepStart(false); sutPocStatus.mic=1; }else if(mic==0 && spk==1){//0001 if(newPara.KeySound!=0) pttBeepStart(false); paControl(true); sutPocStatus.spk=1; sutPocStatus.mic=0; }else if(mic==0 && spk==13){//0013 if(newPara.KeySound!=0) beepStart(TONE_SPECIAL); } } static void micPro(int mic){ switch(mic){ case 0://关闭mic sutPocStatus.mic=0; break; case 1://打开mic if(newPara.KeySound!=0) beepStart(TONE_NORMAL); sutPocStatus.mic=1; //sutPocStatus.spk=0; break; } } static void spkPro(int spk){ switch(spk){ case 0://tone音后关闭spk if(newPara.KeySound!=0) beepStart(TONE_NORMAL); sutPocStatus.spk=0; break; case 1://tone音后保持spk打开 if(newPara.KeySound!=0) beepStart(TONE_NORMAL); paControl(true); sutPocStatus.spk=1; sutPocStatus.mic=0; break; case 2://播放TTS paControl(true); sutPocStatus.TTS=1; break; case 13://抢麦失败,可以tone特殊音 if(newPara.KeySound!=0) beepStart(TONE_SPECIAL); break; } } /*POC已启动成功*/ static void pocStartMsg(void){ sutApp.pocInitStatus=1; } /*当前账号所属群组列表信息,一次性获取所有 不同应用采用不同需求指令 从不在线到登录会主动上报一次列表 发AT+POC=0D0000也会上报一次列表 msg:000000,iiii(组列表索引),dddddddd(组ID),nnnn(组成员数),mmmmmm(组名称)*/ static void pro80Msg(char *msg){ } /*所在组成员信息列表 发AT+POC=0E0000xxxxxxxx查询 msg:010000,iiii(成员列表索引),dddddddd(成员ID),mmmmmmmm(成员名称)*/ static void pro81Msg(char *msg){ } /*登录状态信息 msg:ss(00未登录,02已登录),dddddddd(成员id),mmmmmmmm(状态信息内容) 00 CEDECDF8C2E7C1ACBDD3 表示不在线,输出信息为 无网络连接(拨号没 成功) 00 CEDEB7A8C1ACBDD3 表示不在线,输出信息为 无法连接(IP 不对或定 向卡) 00 C3BBD3D0B7FECEF1 表示不在线,输出信息为 没有服务(没注册) 00 B5C7C2BDCAA7B0DC 表示不在线,输出信息为 登陆失败(账号错误) 00 0D5CBBAC5D0C5CFA2B4EDCEF3 账号信息错误 02 0001A750 B2E2CAD431BAC5(测试 1 号),*/ static void pro82Msg(char *msg){ char buf[3],*pName; int type,len; char Username[POC_GROUP_USER_NAME_LEN*2]; buf[0]=msg[0];buf[1]=msg[1];buf[2]=0; type=atoi(buf); switch(type){ case 0: sutPocStatus.logined=0; if(0==memcmp(msg+10, "CEDECDF8C2E7C1ACBDD3",20)) sutPocStatus.PocLineOffReason=1; else if(0==memcmp(msg+10, "CEDEB7A8C1ACBDD3",16)) sutPocStatus.PocLineOffReason=2; else if(0==memcmp(msg+10, "C3BBD3D0B7FECEF1",16)) sutPocStatus.PocLineOffReason=3; else if(0==memcmp(msg+10, "B5C7C2BDCAA7B0DC",16)) sutPocStatus.PocLineOffReason=4; break; case 2: sutPocStatus.PocLineOffReason=0; len=strlen(msg+10); if(len>POC_GROUP_USER_NAME_LEN) len=POC_GROUP_USER_NAME_LEN; memcpy(Username, msg+10,len); Username[len]=0; StrAsciiToHex(Username, sutPocStatus.LocalUser.name); msg[10]=0; sutPocStatus.LocalUser.ID=strtol(&msg[2], &pName, 16); MSG_INFO(1, "Login ok"); sutPocStatus.loginResult=3; break; } } /*有人说话 msg:00,dddddddd(成员id),nnnnnnnn(成员名称)*/ static void pro83Msg(char *msg){ int len; char callerName[POC_GROUP_USER_NAME_LEN*2]; backLightReset();//鏀跺埌鏈変汉璇磋瘽 len=strlen(msg+10); if(len>POC_GROUP_USER_NAME_LEN) len=POC_GROUP_USER_NAME_LEN; memcpy(callerName, msg+10,len); callerName[len]=0; if(0!=memcmp(callerName, sutPocStatus.CallName,len)) StrAsciiToHex(callerName, sutPocStatus.CallName); } /*单呼响应信息 msg:00,mmmmmmmmmm(单呼结果信息) BAF4BDD0B3C9B9A6 表示 呼叫成功 BAF4BDD0CAA7B0DC 表示 呼叫失败 CDCBB3F6C1D9CAB1BAF4BDD0 表示 退出临时呼叫 C1D9CAB1BAF4BDD031BAC5BBFA 表示 临时呼叫 1 号机*/ static void pro84Msg(char *msg){ //unsigned char danhureport[POC_GROUP_USER_NAME_LEN+1]; //StrAsciiToHex(msg+2, danhureport); ttsPlay(ENCODE_USER_GBK, msg+2); if(0==memcmp(msg+2, "C1D9CAB1", 8)) sutPocStatus.danHuStatus=1; else if(0==memcmp(msg+2, "CDCBB3F6", 8)) sutPocStatus.danHuStatus=0; else if(0==memcmp(msg+2, "BAF4BDD0B3C9B9A6", 16)) sutPocStatus.danHuStatus=1; } /*切换群组完成指令(表示已登录) msg:00,dddddddd(组id),nnnnnnnn(组名称)*/ static void pro86Msg(char *msg){ char buf[POC_GROUP_USER_NAME_LEN*4+40],*pName; int len,i; char GroupName[POC_GROUP_USER_NAME_LEN*2]; char tmp[POC_GROUP_USER_NAME_LEN*2+20]; char needTTs=0; sutPocStatus.logined=1; len=strlen(msg+10); if(len>POC_GROUP_USER_NAME_LEN) len=POC_GROUP_USER_NAME_LEN; memcpy(GroupName, msg+10,len); GroupName[len]=0; msg[10]=0; sutPocStatus.LocalGroup.ID=strtol(msg+2, &pName,16); StrAsciiToHex(GroupName, sutPocStatus.LocalGroup.name); if(sutPocStatus.firstLogin==0){ snprintf(tmp, sizeof(tmp), "%s,已登陆,%s", sutPocStatus.LocalUser.name,sutPocStatus.LocalGroup.name); backLightReset();//第一次登录时,保持屏亮起来 needTTs=1; }else{ snprintf(tmp, sizeof(tmp), "进入,%s",sutPocStatus.LocalGroup.name); if(sutApp.groupTTSEnable!=0){ needTTs=1; sutApp.groupTTSEnable=0; } } if(needTTs!=0){ memset(buf, 0, sizeof(buf)); for(i=0;i= POC_GROUP_USER_NAME_LEN*2) len = POC_GROUP_USER_NAME_LEN*2; memcpy(name, &msg[18], len); name[len]=0; msg[18]=0; id=strtol(&msg[10],&pTemp,16); sutPocStatus.AllUsers[sutPocStatus.ListFillIndex].ID=id; if(name[0]==0){ sutPocStatus.AllUsers[sutPocStatus.ListFillIndex].name[0]=' '; sutPocStatus.AllUsers[sutPocStatus.ListFillIndex].name[1]=0; }else StrAsciiToHex(name, sutPocStatus.AllUsers[sutPocStatus.ListFillIndex].name); sutPocStatus.ListFillIndex++; if(sutPocStatus.ListFillIndex==sutPocStatus.ExceptionReadNum){ sutPocStatus.ListGetOneFlag=1; sutPocStatus.ListDetailValid=1; } } /*定时查询所属组信息 发AT+POC=1D0000xxxxx获得 msg:000000,iiii(组列表索引),dddddddd(组ID),nnnn(成员个数),mmmmmmmmm(名称)*/ static void pro1dMsg(char *msg){ unsigned short num; char name[POC_GROUP_USER_NAME_LEN*2+1]; unsigned long id; unsigned short index; char *pTemp; int len; if(!uiAssist.status)return ; len = strlen(&msg[22]);//已去掉回车换行 if(len >= POC_GROUP_USER_NAME_LEN*2) len = POC_GROUP_USER_NAME_LEN*2; memcpy(name, &msg[22], len); name[len]=0; msg[22]=0; num=strtol(&msg[18],&pTemp,16); msg[18]=0; id=strtol(&msg[10],&pTemp,16); sutPocStatus.AllGroups[sutPocStatus.ListFillIndex].ID=id; sutPocStatus.AllGroups[sutPocStatus.ListFillIndex].usernum=num; if(name[0]==0){ sutPocStatus.AllGroups[sutPocStatus.ListFillIndex].name[0]=' '; sutPocStatus.AllGroups[sutPocStatus.ListFillIndex].name[1]=0; }else StrAsciiToHex(name, sutPocStatus.AllGroups[sutPocStatus.ListFillIndex].name); sutPocStatus.ListFillIndex++; if(sutPocStatus.ListFillIndex==sutPocStatus.ExceptionReadNum){ sutPocStatus.ListGetOneFlag=1; sutPocStatus.ListDetailValid=1; } } /* +POC_VER:01027 msg=01027 */ static void pocGetVer(char *msg){ snprintf(sutApp.pocVersion, sizeof(sutApp.pocVersion), "%s",msg); } static void pocGetPpp(char *msg){ if(msg[0]=='1') sutApp.pocPpp=1; else{ sutApp.pocPpp=0; learnUserInfoClear(); } } /* +GAUTH:AD86EBCCECC4 msg=AD86EBCCECC4+回车 */ static void proGauthMsg(char *msg){ #if 1 unsigned char newAuthTable[10]={0x50,0x28,0xaf,0x6d,0x08,0x9c,0x1b,0xe4,0x23,0x77}; unsigned char randBuf[100]; char buf[3]; int len,i,j; len=0; for(i=0;isizeof(imei)){ MSG_ERR(1, "imei buffer overflow:%d",i); return; } memcpy(imei, imeiPtr,i);//得到IMEI数据:长度为i的imei //组织协议数据 memset(tmp, 0,sizeof(tmp)); memcpy(tmp,FACTORY_MARK,strlen(FACTORY_MARK)); memcpy(tmp+16, MODULE_MARK,strlen(MODULE_MARK)); tmp[32]=i; memcpy(tmp+33,imei,i); i=32+1+i; //使用长度为len的randBuf加密串对长度为i的tmp进行加密 extCodeBuffer(randBuf, len, tmp, i); //将长度为i的tmp内存以十六进制串打包发送 for(j=0;j'9') return; netModeValue=msg[0]-0x30; netshowvalue=netModeValue; } /* +RSIM:1 msg=1/2 */ static void proSimMode(char *msg){ unsigned char tmpSim; tmpSim=msg[0]-0x31; if(tmpSim!=0 && tmpSim!=1) return; sutApp.simSel=tmpSim; } /* +UDP:0,5,30 msg=0,5,30 */ static void proPwrMode(char *msg){ int seg1,seg2; short i; char buf[15]; for(i=2;i