📄 smsrecv.c
字号:
#define SMSRECV_GLOBAL
#include "includes.h"
//Added by lxo 06081111 for none-signal-region-supplement condition compile
/*#pragma ROM VERSION[]
const uchar VERSION[] ={"VER1.00"};*/
#pragma ROM TYPEINFO[]
const uchar TYPEINFO[]={"MPIP06B1"};
#pragma ROM SMSENTRYPROC[]
const PART_ENTRY_PROC far SMSENTRYPROC[] ={
{0x0141,Handle_0141Msg},
{0x0241,Handle_0241Msg},
{0x0541,Handle_0541Msg},
{0x2141,Handle_2141Msg},
{0x2241,Handle_2241Msg},
{0x2341,Handle_2341Msg},
{0x0143,Handle_0143Msg},
{0x1043,Handle_1043Msg},
{0x1143,Handle_1143Msg},
{0x1243,Handle_1243Msg},
{0x1343,Handle_1343Msg},
{0x5143,Handle_5143Msg}, //added by leon 050923 for set managenumber of card 1
{0x5243,Handle_5243Msg}, //added by leon 050923 for set messagenumber of card 1
{0x5343,Handle_5343Msg}, //added by leon 050923 for set listennumber of card 1
{0x1543,Handle_1543msg},
{0x1643,Handle_1643msg},
{0x1743,Handle_1743msg},
{0x2143,Handle_2143msg},
{0x2243,Handle_2243msg},
{0x2343,Handle_2343msg},
{0x3243,Handle_3243msg},
{0x4143,Handle_4143msg},
{0x4243,Handle_4243msg},
{0x4343,Handle_4343msg},
{0x4443,Handle_4443msg},
{0x4543,Handle_4543msg},
{0x4643,Handle_4643msg},
{0x4743,Handle_4743msg},
{0x0145,Handle_0145msg},
{0x0245,Handle_0245msg},
{0x0345,Handle_0345msg},
{0x0445,Handle_0445msg},
{0x0545,Handle_0545msg},
{0x1145,Handle_1145msg},
{0x1245,Handle_1245msg},
{0x2145,Handle_2145msg},
{0x6145,Handle_6145msg},
{0x8145,Handle_8145msg},
{0x8245,Handle_8245msg},
{0x0149,Handle_0149msg},
{0x1051,Handle_1051msg},
{0x1151,Handle_1151msg},
{0x1251,Handle_1251msg},
{0x1351,Handle_1351msg},
{0x5151,Handle_5151msg}, //added by leon 050923 for read Manage Number of Card 1
{0x5251,Handle_5251msg}, //added by leon 050923 for read Message Number of Card 1
{0x5351,Handle_5351msg}, //added by leon 050923 for read Listen Number of Card 1
{0x1551,Handle_1551msg},
{0x1751,Handle_1751msg},
{0x2151,Handle_2151msg},
{0x2251,Handle_2251msg},
{0x2351,Handle_2351msg},
{0x3251,Handle_3251msg},
{0x4151,Handle_4151msg},
{0x4251,Handle_4251msg},
{0x4351,Handle_4351msg},
{0x4451,Handle_4451msg},
{0x4551,Handle_4551msg},
{0x4651,Handle_4651msg},
{0x4751,Handle_4751msg},
{0x4851,Handle_4851msg},
{0x0347,Handle_0347msg},
{0x5145,Handle_5145msg},//add by lxo 122615
{0x0341,Handle_0341msg},//add by lxo 122623
};
#pragma ROM SMSUC[]
const uchar far SMSUC[] ={0x12,0x4F,0x60,0x59,0x7D,0xFF,0x0C,0x00,0x48,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F,0x00,0x21};
SM_PARAM Msg_Sms;
_STRUCT_CETER *Cntermsg;
TIMER *Reset_Program_Timer;
TIMER *Fix_Send_Timer;
TIMER *Future_Timer;
//TIMER *Hour24_Send_Timer;//Removed by lxo 0215030
TIMER *Send_Acc_On_Timer;
TIMER *Con_Timer;
TIMER *Custom_supervise_timer;//add by lxo;lable 122611
uchar send_ack_gprs_count=0;
TIMER *send_ack_gprs_timer;
#pragma ROM tab[]
const char far tab[]="0123456789ABCDEF";
//------------------------------------------------------------------------------------
int gsmBytes2String(LPBYTE pSrc, LPBYTE pDst, int nSrcLength)//换成ascii码字符串结束//
{
int i;
for(i=0; i<nSrcLength; i++)
{
*pDst++ = tab[*pSrc >> 4];
*pDst++ = tab[*pSrc & 0x0f];
pSrc++;
}
*pDst = '\0';
return nSrcLength * 2;
}
uint gsmString2Bytes(LPBYTE pSrc, LPBYTE pDst, uint nSrcLength)
{
uint i;
for(i=0; i<nSrcLength; i+=2)
{
if(*pSrc>='0' && *pSrc<='9')
{
*pDst = (*pSrc - '0') << 4;
}
else
{
*pDst = (*pSrc - 'A' + 10) << 4;
}
pSrc++;
if(*pSrc>='0' && *pSrc<='9')
{
*pDst |= *pSrc - '0';
}
else
{
*pDst |= *pSrc - 'A' + 10;
}
pSrc++;
pDst++;
}
return nSrcLength / 2;
}
int gsmEncodePdu(const SM_PARAM far* pSrc, LPBYTE pDst,WORD DstLength)//组帧pdu格式//
{
WORD nLength;
WORD templen;
WORD nDstLength;
/*nLength = _Strlen(pSrc->SCA,16);
pDst[0] = (uchar)( nLength + 3) / 2; //by lrx//
pDst[1] = 0x91;
nDstLength = 2;
nDstLength += gsmInvertNumbers(pSrc->SCA, &pDst[nDstLength], nLength);*/
//nDstLength = 0;
nDstLength = 0;
pDst[nDstLength++] = 0; //for sca
pDst[nDstLength++] = 0x11;
nLength = _Strlen(pSrc->TPA,16);
pDst[nDstLength++] = 0;
// pDst[nDstLength++] = 0;
pDst[nDstLength++] = (uchar)nLength;
if ((pSrc->TPA[0]=='8')&&(pSrc->TPA[1]=='6'))
{
pDst[nDstLength++] = 0x91;
}
else
{
pDst[nDstLength++] = 0xA1;
}
nDstLength += gsmInvertNumbers(pSrc->TPA, &pDst[nDstLength], nLength);
nLength=DstLength;
pDst[nDstLength++] = pSrc->TP_PID;
pDst[nDstLength++] = pSrc->TP_DCS;
//pDst[nDstLength++] = GSM_UCS2;
pDst[nDstLength++] = 0;
/*for(nLength=0; nLength<19;nLength++)
{
pDst[nDstLength++] = SMSUC[nLength];
}*/
if(pSrc->TP_DCS == GSM_7BIT)
{
// 7-bit//
pDst[nDstLength++] = (uchar)nLength;
nDstLength += gsmEncode7bit(pSrc->TP_UD, &pDst[nDstLength], nLength+1);
}
else if(pSrc->TP_DCS == GSM_UCS2)
{
// UCS2//
templen = nDstLength++;
nLength = gsmEncodeUcs2(pSrc->TP_UD, &pDst[nDstLength], nLength);
pDst[templen] = (uchar)nLength;
nDstLength += nLength;
}
else
{
// 8-bit//
templen = nDstLength++;
nLength = gsmEncode8bit(pSrc->TP_UD, &pDst[nDstLength], nLength);
pDst[templen] = (uchar)nLength;
nDstLength += nLength;
}
return nDstLength;
}
int gsmInvertNumbers(LPBYTE pSrc, LPBYTE pDst, int nSrcLength)//转换电话号码//
{
int nDstLength;//
uchar temp1;
uchar temp2;
int i;
nDstLength = (nSrcLength+1)/2;
for(i=0; i<nSrcLength;i+=2)
{
temp1 = *pSrc++;
temp2 = *pSrc++;
*pDst++ = (temp2-0x30)*16+(temp1-0x30);
}
if(nSrcLength & 1)
{
*(pDst-1) = 0xf0|(*(pSrc-2));
}
*pDst = '\0';
return nDstLength;
}
int gsmDecodeUcs2(LPBYTE pSrc, LPBYTE pDst, int nSrcLength)
{
int nDstLength;
nDstLength = WideCharToMultiByte(pSrc, nSrcLength, pDst, 160);
return nDstLength;
}
void gsmDecodePdu(LPBYTE pSrc, SM_PARAM far * pDst)
{
int nDstLength;
unsigned char tmp;
UCHAR tTP_UDHI=0;
UCHAR UDHlen;
//LPBYTE buf;
//buf=calloc(256,sizeof(BYTE));
//gsmString2Bytes(pSrc, &tmp, 2);
tmp = *pSrc-1;
pSrc += 2;
gsmSerializeNumbers(pSrc, pDst->SCA, tmp);
pSrc += tmp;
tmp = *pSrc++;
if((tmp&0x40)==0x40)
{
tTP_UDHI=1;
}
//gsmString2Bytes(pSrc, &tmp, 2);
tmp = *pSrc;
tmp = (tmp+1)/2;
pSrc += 2;
pDst->TPALEN = gsmSerializeNumbers(pSrc, pDst->TPA, tmp);
pSrc += tmp;
pDst->TP_PID = *pSrc++;
pDst->TP_DCS = *pSrc++;
//gsmString2Bytes(pSrc, (LPBYTE)&pDst->TP_PID, 2);
//gsmString2Bytes(pSrc, (LPBYTE)&pDst->TP_DCS, 2);
//pSrc += 2;
gsmSerializeNumbers(pSrc, pDst->TP_SCTS, 7); //时间//
pSrc += 7;
tmp = *pSrc++;
//gsmString2Bytes(pSrc, &tmp, 2);
//pSrc += 2;
if(tTP_UDHI>0)
{
//gsmString2Bytes(pSrc,&UDHlen,2);
UDHlen = *pSrc++;
pSrc += UDHlen;
//pSrc+=((UDHlen+1)*2);
tmp-=UDHlen;
}
if(pDst->TP_DCS == GSM_7BIT)
{
//nDstLength = gsmString2Bytes(pSrc, buf, tmp & 7 ? (int)tmp * 7 / 4 + 2 : (int)tmp * 7 / 4); // 格式转换//
//len = (tmp*7)/8;
pDst->TPUD_len = gsmDecode7bit(pSrc, pDst->TP_UD,tmp);
}
else if(pDst->TP_DCS == GSM_UCS2)
{
// nDstLength = gsmString2Bytes(pSrc, buf, tmp * 2);
// nDstLength = gsmDecodeUcs2(buf, pDst->TP_UD, nDstLength);
pDst->TPUD_len = gsmDecodeUcs2(pSrc, pDst->TP_UD, tmp);
}
else
{
pDst->TPUD_len = gsmDecode8bit(pSrc, pDst->TP_UD, tmp);
//nDstLength = gsmString2Bytes(pSrc, buf, tmp * 2);
//nDstLength = gsmDecode8bit(buf, pDst->TP_UD, nDstLength);
}
//free(buf);
//return nDstLength;
}
int gsmSerializeNumbers(LPBYTE pSrc, LPBYTE pDst, int nSrcLength)
{
int nDstLength;
char ch;
int i;
nDstLength = nSrcLength*2;
for(i=0; i<nSrcLength;i++,pSrc++)
{
*pDst++ = ((*pSrc)&0x0f)+'0';
*pDst++ = (((*pSrc)>>4)&0x0f)+'0';
}
if(*(pDst-1) == ('0'+0x0f))
{
pDst--;
nDstLength--;
}
*pDst = '\0';
return nDstLength;
}
int gsmEncode7bit(LPBYTE pSrc, LPBYTE pDst, int nSrcLength)//7位码压缩 note:长度要加一个1
{
int nSrc;
int nDst;
int nChar;
unsigned char nLeft;
nSrc = 0;
nDst = 0;
while(nSrc<nSrcLength)
{
nChar = nSrc & 7;
if(nChar == 0)
{
nLeft = *pSrc;
}
else
{
*pDst = (*pSrc << (8-nChar)) | nLeft;
nLeft = *pSrc >> nChar;
pDst++;
nDst++;
}
pSrc++;
nSrc++;
}
return nDst;
}
int gsmDecode7bit(LPBYTE pSrc, LPBYTE pDst, int nSrcLength)//7位解码//
{
int nSrc;
int nDst;
int nByte;
unsigned char nLeft;
nSrc = 0;
nDst = 0;
nByte = 0;
nLeft = 0;
while(nSrc<nSrcLength)
{
*pDst = ((*pSrc << nByte) | nLeft) & 0x7f;
nLeft = *pSrc >> (7-nByte);
pDst++;
nDst++;
nByte++;
if(nByte == 7)
{
*pDst = nLeft;
pDst++;
nDst++;
nByte = 0;
nLeft = 0;
}
pSrc++;
nSrc++;
}
return nDst;
}
int gsmEncode8bit(LPBYTE pSrc, LPBYTE pDst, int nSrcLength)//8位传输格式压缩//
{
_Memcpy(pDst, pSrc, nSrcLength);
return nSrcLength;
}
int gsmDecode8bit(LPBYTE pSrc, LPBYTE pDst, int nSrcLength)
{
_Memcpy(pDst, pSrc, nSrcLength);
return nSrcLength;
}
uint gsmEncodeUcs2(LPBYTE pSrc, LPBYTE pDst, uint nSrcLength)//gb码压缩unicode码//
{
uint nDstLength;
nDstLength = MultiByteToWideChar(pSrc, nSrcLength, pDst, 256);
return nDstLength;
}
void Assemble_Sms_Head(uint type)
{
Init_Stream();
Write_Byte_Stream('$');
Write_Byte_Stream('$');
Write_Byte_Stream('$');
Write_Byte_Stream('$');
Write_Tel_Stream(save.simcard[save.basevalue.mode.bit.simid].MyNumb,_Strlen(save.simcard[save.basevalue.mode.bit.simid].MyNumb,15),7);
Write_Word_Stream(type);
}
void Write_Gps_Data(uint type,uchar need_soshelp)
{
uint vstate[2];
uchar i;
#ifdef DEBUG_AT
// Uart1Send("the GPS Time is:");
// Uart1Word(gps_data.time.hour+8);
// Uart1Word(gps_data.time.minute);
// Uart1Word(gps_data.time.second);
#endif
if((!save.basevalue.mode.bit.private)||(type==0x0148)||(alarm_flag&0xfe53))
{
Write_Ptr_Stream(&gps_data.date.day,19);
}
else
{
Write_Ptr_Stream(&gps_data.date.day,6);
for(i=0; i<8; i++)
{
Write_Byte_Stream(0xff);
}
Write_Ptr_Stream((uchar *)&gps_data.speed,5);
}
//for vstate//
vstate[0] = 0;
vstate[1] = 0;
if(Recv_Status.doorstatus)Set_Word_Bit(vstate,0);
if(save.basevalue.mode.bit.defend)Set_Word_Bit(vstate,1);
if(!port[_ACC].status)Set_Word_Bit(vstate,2);
if(save.basevalue.mode.bit.private)Set_Word_Bit(vstate,3);
if(Get_Word_Bit(&alarm_flag,_ROP_ALM))Set_Word_Bit(vstate,4);
if(Get_Word_Bit(&alarm_flag,_GUAD_ALM))Set_Word_Bit(vstate,5);
if(need_soshelp)Set_Word_Bit(vstate,6);
//for reserve7//
//if(Get_Word_Bit(&alarm_flag,_GPSEER_ALM))Set_Word_Bit(vstate,8);
//for lcd err9//
//gprs err 10//
if(IsGpsWireOpen()&&Get_Word_Bit(&alarm_flag,_GPSEER_ALM))Set_Word_Bit(vstate,11);
if(Get_Word_Bit(&alarm_flag,_OVERAREA_ALM))Set_Word_Bit(vstate,12);
if(Get_Word_Bit(&alarm_flag,_OVERLINE_ALM))Set_Word_Bit(vstate,13);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -