设为首页 加入收藏

TOP

C++之AT指令与GPRS通信(五)
2015-07-24 07:26:43 来源: 作者: 【 】 浏览:480
Tags:指令 GPRS 通信
uccess); //for debug } if(BInit) { //int ITmp=strRecv.find(+CSCA: +86, false); int ITmp=strRecv.indexOf(+CSCA: +86, 0,Qt::CaseSensitive); //CSCA -----messege Center address( 0 --->end number) === INIT if(ITmp>0 ) //read mobilephone number ,then show in HostNUmText; { BInit=FALSE; strServerNumber=strRecv.mid(ITmp+sizeof(+CSCA: +86)-1,11); //get Center number ui->Txt_State->setPlainText( Init success+strServerNumber); ui->Txt_HostNum->setText(strServerNumber); BInit=0; } else ui->Txt_State->setPlainText(Init fail); } if(BSend) //send ready encode string { BSend=0; const char *sendata=strEncodeMsg.toLatin1(); int len=strlen(sendata); if(fd>0) MySerial::nwrite(fd,sendata,len); ui->Txt_State->setPlainText(send success); strEncodeMsg=; } // if(strRecv.find(+CMTI,false)>=0) if(strRecv.indexOf(+CMTI,0)>=0) //CMTI ---- new messege arrive { int index=strRecv.indexOf(,); QString msgIndex=strRecv.mid(index+1,2); BRead=TRUE; ui->Txt_State->insertPlainText(New Message arrive ); // BNew=TRUE; ReadMessage(msgIndex); } return ; //if(strRecv.find(RING,false)>=0) if(strRecv.indexOf(RING,0)>=0) //RING ---- yes or no to call { if(BRing==1) return; BRing=1; if(0==QMessageBox::information(this, New call,Do you want to answer? ,ok,no,0,0,1 )) { MySerial::nwrite(fd,ATA ,sizeof(ATA ) ); } else MySerial::nwrite(fd,ATH ,sizeof(ATH ) ); BRing=0; } } /************************************************************************/ void Gprs::ReadMessage(QString strMsgIndex) { if(fd>0) { BRead=1; const char *chCmd; QString strCmdRead=AT+CMGR=+strMsgIndex; //CMGR---->read messege strCmdRead+= ; // chCmd=strCmdRead.latin1(); chCmd=strCmdRead.toLatin1(); //ui->Txt_TargetMsg->setText(chCmd); //ui->Txt_HostMsg->setText(chCmd); int len=::strlen(chCmd); MySerial::nwrite( fd, chCmd, len); } } /************************************************************************/ QString Gprs::ProcessMessage(QString strMsg,QString &strClientNum) //encode 7bit and PUD encode { char *strdd=Time: ; char *strcontent=Content: ; QString ctrlouttmp; QString strupper; int n, nPDULength, i, len ; QString strData,strSrc,strDes,nType,strPDULength; QString strnumber , strdate, strnumtmp, strdatetmp; const char *charPDULength; QString messagecontent; n = strMsg.lastIndexOf(','); strPDULength = strMsg.mid(n+1,2); charPDULength=strPDULength.toLatin1(); nPDULength=(*charPDULength-48)*10; nPDULength+=*(charPDULength+1)-48; strData = strMsg.mid(n+23,nPDULength*2); // get the TPDU content strnumber=strData.mid(6,14); //modify 6,12 // get the mobile phone number len=strnumber.length(); // decode the mobile phone number for(i=0;i 4)&&(i<10)) strdatetmp+=:; } messagecontent+=QString( strdd+strdatetmp+ ); // 2. add the decoded date & time into the message content nType=strData.mid(22,2);//20,2 strSrc = strData.mid(40,(nPDULength-19)*2); // get the content string if(nType.indexOf(00,0)>=0) strDes=Bit7Decode(strSrc); // 7 bits decoding else strDes=DecToUnicode(strSrc); // PDU decoding ( it's what we use in this contest ) strDes=strDes.toLower(); messagecontent+=QString(strcontent+strDes+ ); // 3. add the decoded date & time into the message content return messagecontent; //return strDes; } /************************************************************************/ QString Gprs::DecToUnicode(QString strSrc) { int strlength; QString strMsgtmp,str0; bool ok; QString strMsgout; ushort num; strlength=strSrc.length(); const ushort *data; for(int i=0;i > (7-nByte); pDst++; nDst++; nByte++; if(nByte == 7) { *pDst = nLeft ; pDst++; nDst++; nByte = 0; nLeft = 0; } pSrc++; nSrc++; } *pDst = 0; retu
首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇UVA 12508 - Triangles in the Gr.. 下一篇HDU2577dp基础

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: