📄 mainfrm.cpp
字号:
}
if(remainder==4){
char test;
char temp=poctet[0];
char high=temp&0x80;
temp=poctet[0];
char low=temp&0x7f;
pseptet[0]=low;
test=pseptet[0];
temp=poctet[1];
low=temp&0x3f;
WORD x,y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<1;
x=x>>8;
pseptet[1]=x;
test=pseptet[1];
temp=poctet[1];
high=temp&0xc0;
temp=poctet[2];
low=temp&0x1f;
x,y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<2;
x=x>>8;
pseptet[2]=x;
temp=poctet[2];
high=temp&0xe0;
temp=poctet[3];
low=temp&0x0f;
x=0;
y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<3;
x=x>>8;
pseptet[3]=x;
pseptet[4]='\0';
}
if(remainder==5){
char test;
char temp=poctet[0];
char high=temp&0x80;
temp=poctet[0];
char low=temp&0x7f;
pseptet[0]=low;
test=pseptet[0];
temp=poctet[1];
low=temp&0x3f;
WORD x,y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<1;
x=x>>8;
pseptet[1]=x;
test=pseptet[1];
temp=poctet[1];
high=temp&0xc0;
temp=poctet[2];
low=temp&0x1f;
x=0;
y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<2;
x=x>>8;
pseptet[2]=x;
temp=poctet[2];
high=temp&0xe0;
temp=poctet[3];
low=temp&0x0f;
x=0;
y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<3;
x=x>>8;
pseptet[3]=x;
temp=poctet[3];
high=temp&0xf0;
temp=poctet[4];
low=temp&0x07;
x=0;
y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<4;
x=x>>8;
pseptet[4]=x;
pseptet[5]='\0';
}
if(remainder==6){
char test;
char temp=poctet[0];
char high=temp&0x80;
temp=poctet[0];
char low=temp&0x7f;
pseptet[0]=low;
test=pseptet[0];
temp=poctet[1];
low=temp&0x3f;
WORD x,y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<1;
x=x>>8;
pseptet[1]=x;
test=pseptet[1];
temp=poctet[1];
high=temp&0xc0;
temp=poctet[2];
low=temp&0x1f;
x=0;
y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<2;
x=x>>8;
pseptet[2]=x;
temp=poctet[2];
high=temp&0xe0;
temp=poctet[3];
low=temp&0x0f;
x=0;
y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<3;
x=x>>8;
pseptet[3]=x;
temp=poctet[3];
high=temp&0xf0;
temp=poctet[4];
low=temp&0x07;
x=0;
y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<4;
x=x>>8;
pseptet[4]=x;
temp=poctet[4];
high=temp&0xf8;
temp=poctet[5];
low=temp&0x03;
x=0;
y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<5;
x=x>>8;
pseptet[5]=x;
pseptet[6]='\0';
}
if(remainder==7){
char test;
char temp=poctet[0];
char high=temp&0x80;
temp=poctet[0];
char low=temp&0x7f;
pseptet[0]=low;
test=pseptet[0];
temp=poctet[1];
low=temp&0x3f;
WORD x,y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<1;
x=x>>8;
pseptet[1]=x;
test=pseptet[1];
temp=poctet[1];
high=temp&0xc0;
temp=poctet[2];
low=temp&0x1f;
x=0;
y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<2;
x=x>>8;
pseptet[2]=x;
temp=poctet[2];
high=temp&0xe0;
temp=poctet[3];
low=temp&0x0f;
x=0;
y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<3;
x=x>>8;
pseptet[3]=x;
temp=poctet[3];
high=temp&0xf0;
temp=poctet[4];
low=temp&0x07;
x=0;
y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<4;
x=x>>8;
pseptet[4]=x;
temp=poctet[4];
high=temp&0xf8;
temp=poctet[5];
low=temp&0x03;
x=0;
y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<5;
x=x>>8;
pseptet[5]=x;
temp=poctet[5];
high=temp&0xfc;
temp=poctet[6];
low=temp&0x01;
x=0;
y=0;
x=low;
x=x<<8;
y=y|high;
y=y&0x00ff;
x=x|y;
x=x<<6;
x=x>>8;
pseptet[6]=x;
pseptet[7]='\0';
}
}
void CMainFrame::EncodePdu(CString sstring, CString &dstring)
{
int i,j,len;
char cur;
dstring=_T("");
len=sstring.GetLength();
i=1;
j=0;
while(i<len)
{
if(i<len)
cur=(sstring.GetAt(i) >> j) | ((sstring.GetAt(i+1) << (7-j)) & 0xff);
else
cur=(sstring.GetAt(i) >> j) & 0x7f;
dstring.Insert(dstring.GetLength()+1,cur);
i++;
j=(j+1) % 7;
if(j==0)
i++;
}
}
void CMainFrame::GetSumString(int sum, CString &string)
{
int ge,shi,bai;
char ch;
ge=sum % 10;
sum=sum / 10;
shi=sum % 10;
sum=sum / 10;
bai=bai % 10;
ch=0x30+bai;
string.Insert(string.GetLength()+1,ch);
ch=0x30+shi;
string.Insert(string.GetLength()+1,ch);
ch=0x30+ge;
string.Insert(string.GetLength()+1,ch);
}
void CMainFrame::TransAdd(CString sadd, CString &dadd,int ntype)
{
char weishu,ctype,ch,chh,chl;
char hbyte,lbyte;
ctype=0x91;
if(ntype==SERVERCENTERADD)
weishu=(sadd.GetLength()+3)/2;
else
weishu=sadd.GetLength();
dadd.Insert(1,weishu);
dadd.Insert(2,ctype);
int i,len;
len=sadd.GetLength();
i=0;
while(i<len-1)
{
chh=sadd.GetAt(i++);
chl=sadd.GetAt(i++);
hbyte=chl-0x30;
lbyte=chh-0x30;
ch=hbyte*0x10+lbyte;
dadd.Insert(dadd.GetLength()+1,ch);
}
chh=sadd.GetAt(i);
lbyte=chh-0x30;
hbyte=0x0f;
ch=hbyte*0x10+lbyte;
dadd.Insert(dadd.GetLength()+1,ch);
}
void CMainFrame::GetSendOrderData(char nbuffertext[], CStringArray* ar)
{
int len,i;
len=nbuffertext[0];
i=0;
messagetext.Empty();
dialnumar.RemoveAll();
while(i<len)
{
messagetext.Insert(i+1,nbuffertext[i+1]);
i++;
}
dialnumar.Append(*ar);
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//m_ComPort.
CFrameWnd::OnTimer(nIDEvent);
}
BOOL CMainFrame::GetMessage(CString sstring, CString &sendnum, CString &recnum, CString ×tr, CString &usertext)
{
int snumlen,rnumlen;
CString snumstr,rnumstr;
GetSubStr(sstring,5,6,snumstr);
snumlen=atoi(snumstr);
GetSubStr(sstring,9,9+snumlen*2-3,snumstr);
return(TRUE);
}
void CMainFrame::IntToCString(int num, CString &numstr)
{
int d,e;
d=num /10;
e=num % 10;
while((d!=0)||(e!=0))
{
char ch;
ch=e+0x30;
numstr.Insert(numstr.GetLength(),ch);
d=num /10;
e=num % 10;
}
}
void CMainFrame::TransPhoneNum(CString &str)
{
CString temp;
int len,i;
char chone,chtwo;
len=str.GetLength();
i=0;
while(i+1<len)
{
chone=str.GetAt(i++);
chtwo=str.GetAt(i++);
}
}
void CMainFrame::AnsiToUni(CString ans, CString &uni)
{
char ch[2];
unsigned char cha,chb;
int i,len,re;
len=ans.GetLength();
i=0;
while(i<len)
{
WCHAR wch;
cha=ans.GetAt(i++);
if(cha<0x80)
{
chb=0x00;
}
else
{
ch[0]=cha;
cha=ans.GetAt(i++);
ch[1]=cha;
int re=MultiByteToWideChar(CP_ACP,0,ch,2,&wch,1);
cha=wch % 0x100;
chb=wch / 0x100;
}
uni.Insert(uni.GetLength()+1,chb);
uni.Insert(uni.GetLength()+1,cha);
}
}
void CMainFrame::TransToAscii(CString sstr, CString &dstr)
{
int i,len;
unsigned char ch,cha,chb;
i=0;
len=sstr.GetLength();
while(i<len)
{
ch=sstr.GetAt(i++);
cha=ch % 0x10;
chb=ch / 0x10;
if(cha<10)
cha+=0x30;
else
cha+=0x37;
if(chb<10)
chb+=0x30;
else
chb+=0x37;
dstr.Insert(dstr.GetLength(),chb);
dstr.Insert(dstr.GetLength(),cha);
}
}
BOOL CMainFrame::GetRecSMData(CString recstr, CString flagstr, recsmdata& smdata)
{
CString astr,substr;
int pos,readflag,numlen,dcs;
astr=recstr;
pos=astr.Find(flagstr);
GetSubStr(astr,pos+7,pos+9,substr);
readflag=atoi(substr);
if(readflag==0)
smdata.readflag=FALSE;
else
smdata.readflag=TRUE;
astr.Delete(0,pos+10);
char ch;
ch=0x0a;
pos=astr.Find(ch);
substr.Empty();
GetSubStr(astr,pos+1,pos+2,substr);
numlen=hextoi(substr);
astr.Delete(0,pos+5);
astr.Delete(0,numlen*2);
substr.Empty();
GetSubStr(astr,0,1,substr);
numlen=hextoi(substr);
substr.Empty();
GetSubStr(astr,4,4+numlen,substr);
CString phonenum;
decodedialnum(substr,phonenum);
smdata.senddialnum=phonenum;
astr.Delete(0,numlen+5);
substr.Empty();
GetSubStr(astr,2,3,substr);
dcs=hextoi(substr);
substr.Empty();
GetSubStr(astr,4,17,substr);
CString timestr;
GetTimeStr(substr,timestr);
smdata.timestr=timestr;
astr.Delete(0,18);
substr.Empty();
GetSubStr(astr,0,1,substr);
numlen=hextoi(substr);
substr.Empty();
GetSubStr(astr,2,numlen*2+1,substr);
//根据dcs显示文本
CString pdutext;
switch(dcs)
{
//纯英文格式,pdu经过移位处理
case 2:
Decode(substr,pdutext);
smdata.smtext=pdutext;
break;
//纯中文格式,unicode码
case 8:
DeCodeUni(substr,pdutext);
smdata.smtext=pdutext;
break;
//中英文混合格式,unicode码
case 10:
DeCodeUni(substr,pdutext);
smdata.smtext=pdutext;
break;
//其它格式,暂时无法处理
default:
smdata.smtext=_T("文本格式不能识别!");
break;
}
return(TRUE);
}
int CMainFrame::hextoi(CString hexstr)
{
int len,i,sum,t;
char ch;
sum=0;
len=hexstr.GetLength();
i=0;
while(i<len)
{
ch=hexstr.GetAt(i++);
if((ch>=0x30)&&(ch<=0x39))
t=ch-0x30;
else
t=ch-55;
sum=sum*16+t;
}
return(sum);
}
void CMainFrame::decodedialnum(CString sdialnum, CString &ddialnum)
{
int i,len;
char cha,chb;
len=sdialnum.GetLength();
i=0;
while(i<len)
{
chb=sdialnum.GetAt(i++);
cha=sdialnum.GetAt(i++);
ddialnum.Insert(ddialnum.GetLength(),cha);
ddialnum.Insert(ddialnum.GetLength(),chb);
}
ddialnum.Delete(ddialnum.GetLength()-1,1);
}
void CMainFrame::GetTimeStr(CString sstr, CString ×tr)
{
char cha,chb;
timestr=_T("20");
cha=sstr.GetAt(0);
chb=sstr.GetAt(1);
timestr.Insert(100,chb);
timestr.Insert(100,cha);
timestr+=_T("年");
cha=sstr.GetAt(2);
chb=sstr.GetAt(3);
timestr.Insert(100,chb);
timestr.Insert(100,cha);
timestr+=_T("月");
cha=sstr.GetAt(4);
chb=sstr.GetAt(5);
timestr.Insert(100,chb);
timestr.Insert(100,cha);
timestr+=_T("日 ");
cha=sstr.GetAt(6);
chb=sstr.GetAt(7);
timestr.Insert(100,chb);
timestr.Insert(100,cha);
timestr+=_T("时");
cha=sstr.GetAt(8);
chb=sstr.GetAt(9);
timestr.Insert(100,chb);
timestr.Insert(100,cha);
timestr+=_T("分");
cha=sstr.GetAt(10);
chb=sstr.GetAt(11);
timestr.Insert(100,chb);
timestr.Insert(100,cha);
timestr+=_T("秒 时差:");
cha=sstr.GetAt(12);
chb=sstr.GetAt(13);
timestr.Insert(100,chb);
timestr.Insert(100,cha);
}
void CMainFrame::DeCodeUni(CString sstr, CString &dstr)
{
CFile gfile;
CFileException e;
if( !gfile.Open( "e:/smsinterface/unitoansi.dit", CFile::modeRead|CFile::typeBinary, &e ) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
return;
}
WCHAR wch;
UINT result;
WORD tempch,ansistr;
unsigned char cha,chb;
int len,i;
i=0;
len=sstr.GetLength();
while(i<len)
{
CString unistr;
GetSubStr(sstr,i,i+3,unistr);
wch=hextoi(unistr);
if(wch>=0x100)
{
result=1;
gfile.Seek(0,CFile::begin);
ansistr=0;
while(result)
{
result=gfile.Read(&tempch,2);
if(result)
if(tempch==wch)
{
gfile.Read(&tempch,2);
ansistr=tempch;
break;
}
else
result=gfile.Read(&tempch,2);
}
if(!result)
ansistr=0xB0A1;
char ch;
ch=ansistr / 0x100;
dstr.Insert(dstr.GetLength(),ch);
ch=ansistr % 0x100;
dstr.Insert(dstr.GetLength(),ch);
}
else
{
char chansi;
chansi=wch % 0x100;
dstr.Insert(dstr.GetLength(),chansi);
}
i+=4;
}
gfile.Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -