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

📄 gsmencodepdu.c

📁 GSM短信息PDU编码程序,用于单片机控制手机模块进行编制、发送短信息
💻 C
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -