gsmencodepdu.c
来自「GSM短信息PDU编码程序,用于单片机控制手机模块进行编制、发送短信息」· C语言 代码 · 共 56 行
C
56 行
#include <my.h>
typedef struct{
uchar SCA[16];
uchar TPA[16];
uchar TP_PID;
uchar TP_DCS;
uchar TP_SCTS[16];
uchar TP_UD[16];
uchar index;
} SM_PARAM;
//PDU编码,用于编制、发送短信息
//pSrc:源PDU参数指针
//pDst:目标PDU串指针
//返回:目标PDU串长度
uint gsmEncodePdu(const SM_PARAM *pSrc,uchar *pDst)
{
uint nLength;
uint nDstLength;
uchar buf[256];
nLength=strlen(pSrc->SCA);
buf[0]=(uchar)((nLength&1)==0?nLength:nLength+1)/2+1;
buf[1]=0x91;
nDstLength=gsmBytes2String(buf,pDst,2);
nDstLength+=gsmInvertNumber(pSrc->SCA,&pDst{nDstLength],nLength);
nLength=strlen(pSrc->TPA);
buf[0]=0x11;
buf[1]=0;
buf[2]=(uchar)nLength;
buf[3]=0x91;
nDstLength+=gsmBytes2String(buf,&pDst[nDstLength],4);
nDstLength+=gsmInvertNumbers(pSrc->TPA,&pDst[nDstLength],nLength);
nLength=strlen(pSrc->TPA,&pDst[nDstLength],nLength);
nLength=strlen(pSrc->TP_UD);
buf[0]=pSrc->TP_PID;
buf[1]=pSrc->TP_DCS;
buf[2]=0;
if(pSrc->TP_DCS==GSM_7BIT)
{
buf[3]=nLength;
nLength=gsmEncode7bit(pSrc->TP_UD,&buf[4],nLength+1)+4;
}
else if(pSrc->TP_DCS==GSM_UCS2)
{
buf[3]=gsmEncodeUcs2(pSrc->TP_UD,&buf[4],nLength);
nLength=buf[3]+4;
}
else
{
buf[3]=gsmEncode8bit(pSrc->TP_UD,&buf[4],nLength);
nLength=buf[3]+4;
}
nDstLength+=gsmByte2String(buf,&pDst[nDstLength],nLength);
return nDstLength;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?