⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nokia_sms.cpp

📁 PDU解码
💻 CPP
字号:
// Nokia_SMS.cpp: implementation of the Nokia_SMS class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SMS.h"
#include "Nokia_SMS.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Nokia_SMS::Nokia_SMS()
{
	SMS_Length=0;

}

Nokia_SMS::~Nokia_SMS()
{

}


char Nokia_SMS::CheckSum(char *buf, int count)
{
	char Sum=0;
	char *Ptr=buf;
	for(int i=0;i<count;i++)
	{
		Sum^=*Ptr++;
	}
	return Sum;
}

char* Nokia_SMS::Pack7(char *Dest, CString Src)
{
    char *Ptr=Dest;
	int Src_len=Src.GetLength();
    int Dest_len=(Src_len*8)/7;
	for(int i=0;i<Dest_len;i++)
	{
		*Ptr++=0;
	}
	Ptr=Dest;
	unsigned int shift=0;
	char tmp;
	for(i=0;i<Src_len;i++)
	{
        tmp=Src.GetAt(i)&0x7f;
		tmp<<=shift;
		*Ptr|=tmp;
		shift+=7;
		if(shift>8)
		{
			shift&=0x07;
			Ptr++;
			tmp=Src.GetAt(i)&0x7f;
			tmp>>=(7-shift);
			*Ptr=tmp;
		}
	}
	return Ptr+1;
}

char * Nokia_SMS::Num2bcd(char *Dest, CString Src,bool byte)
{
   char *Ptr=Dest;
   for(int i=0;i<12;i++)
   {
	   *Ptr++=0;
   }
   Ptr=Dest;
   Ptr++;
   int Index=0;
   if(Src.GetAt(Index++)=='+')
   {
	   *Ptr++=(char)0x91;
   }
   else
   {
	   *Ptr++=(char)0x81;
   }
   for(;Index<Src.GetLength();)
   {
	   char tmp=Src.GetAt(Index++)-'0';
	   if(Index<Src.GetLength())
	   {
		   tmp|=(Src.GetAt(Index++)-'0')<<4;
	   }
	   else
	   {
		   tmp|=0xf0;
	   }
	   *Ptr++=tmp;
   }
   if(byte==true)
   {
	   *Dest=Ptr-Dest-1;
   }
   else
   {
	   *Dest=Src.GetLength()-1;
   }
   return Dest+12;
}

void Nokia_SMS::MsgPack(CString DestNum,CString ServerNum, CString Msg)
{
    char *Ptr=SMS_Buffer;
	//standard frame data header
	*Ptr++=0x00;
	*Ptr++=0x01;
	*Ptr++=0x00;

	//send sms
	*Ptr++=0x01;
	*Ptr++=0x02;
	*Ptr++=0x00;

	//Server number
	Ptr=Num2bcd(Ptr,ServerNum,true);

	//TPDU
    *Ptr++=0x11;

	//Misc
	*Ptr++=0x00;
	*Ptr++=0x00;
	*Ptr++=0x00;
	
	//Message size
	*Ptr++=Msg.GetLength();

	//Dest Number
	Ptr=Num2bcd(Ptr,DestNum,false);

	//validity period
	*Ptr++=(char)0xad;

	//filler
	*Ptr++=0;
	*Ptr++=0;
	*Ptr++=0;
	*Ptr++=0;
	*Ptr++=0;
	*Ptr++=0;

	//Message body
	Ptr=Pack7(Ptr,Msg);

	SMS_Length=Ptr-SMS_Buffer;



	
}

void Nokia_SMS::FramePack(char DestDev, char SrcDev, char MsgType, char SeqNo)
{
	char Buf[1024];
	for(int i=0;i<SMS_Length;i++)
	{
		Buf[i]=SMS_Buffer[i];
	}
	char *Ptr=SMS_Buffer;
	*Ptr++=0x1f;
	*Ptr++=DestDev;
	*Ptr++=SrcDev;
	*Ptr++=MsgType;
	*Ptr++=SMS_Length>>8;
	*Ptr++=SMS_Length;
	for(i=0;i<SMS_Length;i++)
	{
		*Ptr++=Buf[i];
	}
	*Ptr++=SeqNo;
	SMS_Length=Ptr-SMS_Buffer;
	*Ptr=CheckSum(SMS_Buffer,SMS_Length);
	SMS_Length++;

}

int Nokia_SMS::GetLength()
{
    return SMS_Length;
}

char Nokia_SMS::GetAt(int i)
{
   return SMS_Buffer[i];
}

void Nokia_SMS::SetAt(int i, char ch)
{
    SMS_Buffer[i]=ch;
}

void Nokia_SMS::GetMsg(char location)
{
    char *Ptr=SMS_Buffer;
	//standard header
	*Ptr++=0x00;
	*Ptr++=0x01;
	*Ptr++=0x00;
	//get sms
	*Ptr++=0x07;
	*Ptr++=0x02;
	*Ptr++=location;
	*Ptr++=0x01;
	*Ptr++=0x64;
	SMS_Length=Ptr-SMS_Buffer;
}

void Nokia_SMS::GetIMEI()
{
	char *Ptr=SMS_Buffer;
	//standard header
	*Ptr++=0x00;
	*Ptr++=0x01;
	//*Ptr++=0x00;
	//get sms
	*Ptr++=0xce;
	*Ptr++=0x1d;
	*Ptr++=0xfe;
	*Ptr++=0x23;
	*Ptr++=0x0;
	*Ptr++=0x0;
	SMS_Length=Ptr-SMS_Buffer;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -