首页  编辑  

GPRS 时间解码

Tags: /超级猛料/Date.Time.时间和日期/   Date Created:

GPRS GMM 信令中解码时间

typedef struct TimeAndTimeZoneParameter

{

unsigned char validTimeAndTimeZone;//valid 为1时有效

unsigned char Year;

unsigned char Month;

unsigned char Day;

unsigned char Hour;

unsigned char Minute;

unsigned char Second;

unsigned char TimeZone;

}TIMEANDZONEPARAM;

TimeAndTimeZoneParameter* GetGSM_GPRSMM_GMM_Information_TimeAndTimeZoneParameter(int  count,  unsigned char* szSrc)

{

unsigned char Temp1,Temp2,TMP;

unsigned short test;

TimeAndTimeZoneParameter *pTimeAndTimeZoneParameter=NULL;

unsigned short CurPos=0;

if((pTimeAndTimeZoneParameter=(TimeAndTimeZoneParameter *)malloc(sizeof(TimeAndTimeZoneParameter)))==NULL)

return NULL;//内存分配失败

memset(pTimeAndTimeZoneParameter,0,sizeof(TimeAndTimeZoneParameter));

//pTimeAndTimeZoneParameter->flag=((szSrc[0]&0xf)<<8)|szSrc[1];

//pMMCMServiceRequest->bUL=bUL;

CurPos=CurPos+2;

int MessageSize=count;//取得信令长度

if(szSrc[CurPos]==0x43)//取结构GPRSMM_Network_Name

{

CurPos++;

if(CurPos+1>MessageSize)

return pTimeAndTimeZoneParameter;

if(CurPos+szSrc[CurPos]+1>MessageSize)

       return pTimeAndTimeZoneParameter;

CurPos+=szSrc[CurPos]+1;

}

if(szSrc[CurPos]==0x45)//取结构GPRSMM_Network_Name

{

CurPos++;

if(CurPos+1>MessageSize)

return pTimeAndTimeZoneParameter;

if(CurPos+szSrc[CurPos]+1>MessageSize)

CurPos+=szSrc[CurPos]+1;

}

if(szSrc[CurPos]==0x46)//取结构TimeZoneParameter

{

CurPos++;

if(CurPos+1>MessageSize)

return pTimeAndTimeZoneParameter;

CurPos++;

}

if(szSrc[CurPos]==0x47)//取结构TimeAndTimeZoneParameter

{

CurPos++;

if(CurPos+7>MessageSize)

return pTimeAndTimeZoneParameter;

unsigned char TempByte;

pTimeAndTimeZoneParameter->validTimeAndTimeZone=1;

TempByte = szSrc[CurPos];

pTimeAndTimeZoneParameter->Year=((TempByte&0xF)<<4) | ((TempByte&0xF0)>> 4);

TempByte = szSrc[CurPos+1];

pTimeAndTimeZoneParameter->Month=((TempByte&0xF)<<4) | ((TempByte&0xF0)>> 4);

TempByte = szSrc[CurPos+2];

pTimeAndTimeZoneParameter->Day=((TempByte&0xF)<<4) | ((TempByte&0xF0)>> 4);

TempByte = szSrc[CurPos+3];

pTimeAndTimeZoneParameter->Hour=((TempByte&0xF)<<4) | ((TempByte&0xF0)>> 4);

TempByte = szSrc[CurPos+4];

pTimeAndTimeZoneParameter->Minute=((TempByte&0xF)<<4) | ((TempByte&0xF0)>> 4);

TempByte = szSrc[CurPos+5];

pTimeAndTimeZoneParameter->Second=((TempByte&0xF)<<4) | ((TempByte&0xF0)>> 4);

TempByte = szSrc[CurPos+6];

pTimeAndTimeZoneParameter->TimeZone=((TempByte&0xF)<<4) | ((TempByte&0xF0)>> 4);

CurPos=CurPos+7;

//将参数转化为正确的形式

//pTimeAndTimeZoneParameter->Year=(pTimeAndTimeZoneParameter->Year>>4)*10+pTimeAndTimeZoneParameter->Year&0x0f;

TMP = pTimeAndTimeZoneParameter->Year;

Temp1 = (TMP>>4)*10;

Temp2 = TMP&0x0f;

TMP = Temp1+ Temp2;

pTimeAndTimeZoneParameter->Year= TMP;

//pTimeAndTimeZoneParameter->Month=(pTimeAndTimeZoneParameter->Month>>4)*10+pTimeAndTimeZoneParameter->Month&0x0f;

TMP = pTimeAndTimeZoneParameter->Month;

Temp1 = (TMP>>4)*10;

Temp2 = TMP&0x0f;

TMP = Temp1+ Temp2;

pTimeAndTimeZoneParameter->Month= TMP;

//pTimeAndTimeZoneParameter->Day=(pTimeAndTimeZoneParameter->Day>>4)*10+pTimeAndTimeZoneParameter->Day&0x0f;

TMP = pTimeAndTimeZoneParameter->Day;

Temp1 = (TMP>>4)*10;

Temp2 = TMP&0x0f;

TMP = Temp1+ Temp2;

pTimeAndTimeZoneParameter->Day= TMP;

/*pTimeAndTimeZoneParameter->Hour=(pTimeAndTimeZoneParameter->Hour>>4)*10+pTimeAndTimeZoneParameter->Hour&0x0f;*/

//pTimeAndTimeZoneParameter->Hour = (pTimeAndTimeZoneParameter->Hour + 8) % 24;

TMP = pTimeAndTimeZoneParameter->Hour;

Temp1 = (TMP>>4)*10;

Temp2 = TMP&0x0f;

TMP = Temp1+ Temp2;

pTimeAndTimeZoneParameter->Hour= TMP;

TMP = pTimeAndTimeZoneParameter->Minute;

Temp1 = (TMP>>4)*10;

Temp2 = TMP&0x0f;

TMP = Temp1+ Temp2;

pTimeAndTimeZoneParameter->Minute= TMP;

TMP = pTimeAndTimeZoneParameter->Second;

Temp1 =(TMP>>4)*10;

Temp2 = TMP&0x0f;

TMP = Temp1+ Temp2;

pTimeAndTimeZoneParameter->Second=TMP;

}

   //.....其他结构

return pTimeAndTimeZoneParameter;

//此函数不能释放pTimeAndTimeZoneParameter内存

}