qjs412_51 发表于 2012-1-6 14:00:04

无需短信中心号码的PDU编码(内有实例)

一般PDU编码都是要有短信中心号码,
近来发现一种无需短信中心号码的编码方式

0011000D9168+接收手机号码(处理过的)+000800+发送字符串长度/2+发送的字符串的内容+(ctrl+Z)

其中000800也可以是0008A7,其中原因,我也不知

这种方式发送短信,可以成功,我已经试过,但是具体原理不知道,还求高人解释!

例子:发送短信内容“内部测试”
测试环境:TC35i

1.发送 AT+CMGS=23(别忘了回车结束)
回应 : >
2.发送 :0011000D91685158505319F200080008518590E86D4B8BD5(别忘了ctrl+Z和回车结束)

chenqi 发表于 2012-1-6 14:34:27

貌似现在的手机卡都不用短信中心号码了,发短信时候编码里面的短信中心号码可以省掉

qjs412_51 发表于 2012-1-6 14:37:05

网上查的PDU编码,都是需要中心号码的,

难道大家发送PDU格式的短信都不要中心号码?

me out?

chenqi 发表于 2012-1-6 14:56:15

第一个字节是消息中心地址长度,当为00时候,表示使用sim卡内部的设置值。那个A7是信息有效期

qjs412_51 发表于 2012-1-6 15:24:13

回复【3楼】chenqi
-----------------------------------------------------------------------

哦,原来如此,谢谢了

huangqi412 发表于 2012-1-6 16:18:42

mark

comway 发表于 2012-1-9 10:37:06

无需PDU编码的短信岂不更简单

warmonkey 发表于 2012-1-9 10:38:12

我试过这种方式,不成功,于是只好先读取SMSC地址

qjs412_51 发表于 2012-1-9 14:16:04

回复【6楼】comway 移动狗
-----------------------------------------------------------------------

中文不需要PDU?

回复【7楼】warmonkey
-----------------------------------------------------------------------

我试过,是可以发出来短信的,并且换了一个地方的卡也能用

EM_MG_MC 发表于 2012-1-9 14:35:58

我也测试了不成功啊

yuzr 发表于 2012-1-9 14:43:04

mark

lysoft 发表于 2012-1-9 14:47:12

ASCII码是不需要PDU的

qjs412_51 发表于 2012-1-9 14:51:49

短信发送格式设置成PDU格式:AT+CMGF=0
其他的相关的命令就没有了

comway 发表于 2012-1-9 16:51:28

回复【8楼】qjs412_51
-----------------------------------------------------------------------

中文不需要PDU
http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=4008925&bbs_page_no=1&bbs_id=3045

ahong2hao 发表于 2012-1-9 17:22:51

回复【13楼】comway 移动狗
-----------------------------------------------------------------------

中文不需要PDU ?????
这个只是针对这个型号的GSM模块,木有通用性。
采用标准AT的GSM还是得用PUD模式。

AT+CMGS=019
返回 > 发送 0011000D91683165304843F5000801044F60597D<ctrl+z>
{解释:
00 //SMSC长度,此处省略SMSC(本机号码)
11 //FO基本参数(TP-MTI/VFP)
00 //消息基准值TP-MR
0D //目的电话号码长度
91 //Type of Address
68 //中国的国际区号
3165304843F5 //<手机号码编码> 实际号码为13560384345
00 //PID
08 //编码模式:08为Unicode编码,00为Bit7编码,15为Bit8编码
01 //有效期
04 //信息长度
4F60597D //“你好”的 unicode 编码
这个不用设置短信中心号码。

qjs412_51 发表于 2012-1-9 17:35:24

回复【14楼】ahong2hao
-----------------------------------------------------------------------

厉害,受教,谢谢

comway 发表于 2012-1-10 08:53:36

回复【14楼】ahong2hao
-----------------------------------------------------------------------

通用有用吗?怎么没有同时上intel和AMD cpu的主板?真不通用

skype 发表于 2012-1-10 16:27:16

中英文短信都不用短信中心号码

------------------------------------------------------------------------------------------------------------------------
#include "main.h"
#include "SysTick.h"
#include "Serial.h"
#include "Delay.h"
#include "Watchdog.h"
#include "eeprom.h"
#include "GSM_V1.h"
#include "Ex_Isr.h"
#include "Sms.h"

const unsigned char code *SCA_FO_MR_DA = "0011000D9168";
const unsigned char code *SMS_parameter = "0008FF";
const char code Ctrl_z[] = {0x1A, 0x00};

const unsigned char code ASIIC[]=
{       
        '0', '1', '2', '3',
        '4', '5', '6', '7',
        '8', '9', 'A', 'B',
        'C', 'D', 'E', 'F'
};

// 正常顺序的字符串转换为两两颠倒的字符串,若长度为奇数,补'F'凑成偶数
// 如:"8613851872468" --> "683158812764F8"
// pSrc:                 待转换的源字符串指针
// pDst:                 转换后的目标字符串指针
// nSrcLength:         等转换的源字符串长度
// 返回:                 转换后的目标字符串长度,包含了字符串结束符'\0'的长度
unsigned char GsmInvertNumbers(unsigned char *pSrc, unsigned char *pDst, unsigned char nSrcLength)
{
    unsigned char nDstLength;                           // 目标字符串长度
    unsigned char ch;                                  // 用于保存一个字符
        unsigned char i;
   
        nDstLength = nSrcLength;                // 复制串长度
   
        for (i=0; i<nSrcLength; i+=2)        // 两两颠倒
        {
      ch = *pSrc++;                      // 保存先出现的字符
      *pDst++ = *pSrc++;                   // 复制后出现的字符
      *pDst++ = ch;                      // 复制先出现的字符
        }
   
    if (nSrcLength & 1)                        // 源串长度是奇数吗?
    {
      *(pDst-2) = 'F';           // 补'F'
      nDstLength++;              // 目标串长度加1
    }
   
    *pDst = '\0';                                // 输出字符串加个结束符
        return nDstLength;                        // 返回目标字符串长度,加上了'\0'的长度
}
   
/*
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// 测试ok
// 字节数据转换为可打印字符串
// 如:{0xC8, 0x32, 0x9B, 0xFD, 0x0E, 0x01} --> "C8329BFD0E01"
// pSrc:                 待转换的源数据指针
// pDst:                 转换后存放目标字符串指针
// nSrcLength:         待转换的源数据长度,数据长度不能大于256个字节,从1开始
// 返回:                 转换后的目标字符串长度 <=0xffff,带字符串结束符'\0'。
unsigned char GsmBytes2String(const unsigned char *pSrc, unsigned char *pDst, unsigned char nSrcLength)
{
        unsigned char i;
    const unsigned char code tab[] = "0123456789ABCDEF";            // 0x0-0xf的字符查找表
        for (i=0; i<nSrcLength; i++)
        {       
                *pDst = tab >> 4];                                        // 输出高4位
                pDst++;
                *pDst = tab & 0x0f];                                // 输出低4位
                pDst++;                                                                                // 转换下一个十六进制字节
    }
        pDst++;
        *pDst = '\0';                                                                        // 输出字符串加个结束符
        return (nSrcLength * 2 + 1);                                        // 返回目标字符串长度,带字符串结束符'\0'
}
*/


/*------------------------------------------------------------------------------------------*-
* 函数名称: SendSMS()
* 参    数: pSMS_data 要发送的字符串
* 返    回: xx
* 函数功能: 发送SMS
*            
* 说    明:
*
* 当前版本: V1.0               * 取代版本:
* 作   者: wsl                 * 修    改:
* 版本信息: 2010-10-10         * 修改信息:
-*-------------------------------------------------------------------------------------------*/
void SendPduSms(unsigned char *pSMS_data, unsigned char *phone)
{
        unsigned char xdata SMS_Buffer;
        unsigned char idata PhoneNumber;
        unsigned char idata tmp = {0};
        unsigned char i;

        if ((phone==0xFF) || (phone==0))
        {
                return;//当传递的号码不空时返回
        }
        memset(SMS_Buffer, 0, 340);                                                                                                // 清缓冲区
        memset(PhoneNumber, 0, 15);       
        GsmInvertNumbers(phone, PhoneNumber, strlen((const char*)phone));                //号码转换       
       
        //信息头
        strncpy((char*)SMS_Buffer, (const char*)SCA_FO_MR_DA, strlen((const char*)SCA_FO_MR_DA));
        //增加目标手机号码
        strcat((char*)SMS_Buffer, (const char*)PhoneNumber);
        //参数
        strcat((char*)SMS_Buffer, (const char*)SMS_parameter);
       
       
        //信息数据长度
        i = strlen((char const*)pSMS_data)/2;
        memset(tmp, 0, 4);       
        tmp = ASIIC;
        tmp = ASIIC;
        strcat((char*)SMS_Buffer, (const char*)tmp);
        //信息数据
        strcat((char*)SMS_Buffer, (const char*)pSMS_data);
        //ctrl+z
        strcat((char*)SMS_Buffer, Ctrl_z);
       
        memset(tmp, 0, 4);       
        //计算
        i = (strlen((const char*)SMS_Buffer) - 2) / 2;
        tmp = i / 100 + 0x30;
        i = i % 100;
        tmp = i / 10 + 0x30;
        tmp = i % 10 + 0x30;

        bSentSuccessfully = 0;
        i = 0;
        while ((!bSentSuccessfully) && (++i <= 8))
        {
                SendString("ATH\r\n", 0);                                                               
                GetGsmResponseValue(0, 1, "OK");

                SendString("AT+CMGF=0\r\n", 0);                                        //短信息设置为PDU格式
                GetGsmResponseValue(0, 1, "OK");
                SendString("AT+CSCS=\"UCS2\"\r\n", 0);                        //PDU字符集       
                GetGsmResponseValue(0, 1, "OK");

                SendString("AT+CMGS=", 0);               
                SendString(tmp, 0);       
                SendString("\r\n", 0);       
                GetGsmResponseValue(0, 1, "OK");                                //在此处串口收到的有可能是+CMS ERROR而不是>
                SendString(SMS_Buffer, 0);                                       
                GetGsmResponseValue(1, 10, "OK");
        }
        SendString("ATH\r\n", 0);                                                               
        GetGsmResponseValue(0, 1, "OK");
}
/*------------------------------------------------------------------------------------------*-
* 函数名称: Send_SMS()
* 参    数: pSMS_data 要发送的字符串
* 返    回: xx
* 函数功能: 发送SMS
*            
* 说    明:
*
* 当前版本: V1.0               * 取代版本:
* 作   者: wsl                 * 修    改:
* 版本信息: 2010-10-10         * 修改信息:
-*-------------------------------------------------------------------------------------------*/
void SendTxtSms(unsigned char *pNumber, unsigned char *pSMS_data)
{
        unsigned char i=0;
        bSentSuccessfully = 0;
        i = 0;
        while ((!bSentSuccessfully) && (++i <= 8))
        {
                SendString("ATH\r\n", 0);                                                //挂机
                GetGsmResponseValue(0, 1, "OK");
               
               SendString("AT+CMGF=1\r\n", 0);                       
                GetGsmResponseValue(0, 1, "OK");
                SendString("AT+CSCS=\"GSM\"\r\n", 0);                       
                GetGsmResponseValue(0, 1, "OK");
               
                SendString("AT+CMGS=", 0);               
                SendString(pNumber, 0);       
                SendCharacter(';');
                SendString("\r\n", 0);       
                GetGsmResponseValue(0, 1, "OK");
               
                SendString(pSMS_data, 0);
                SendCharacter(0x1A);
                GetGsmResponseValue(1, 10, "OK");
        }
        SendString("ATH\r\n", 0);                                                               
        GetGsmResponseValue(0, 1, "OK");
}

comway 发表于 2012-1-10 17:05:23

回复【17楼】skype
-----------------------------------------------------------------------

顶一个
有没有发彩信的源码?求分享

pinocchio 发表于 2012-2-29 23:52:59

如果这样的话,用单片机可以省去编码部分了,找个机会试试

ycwjl728 发表于 2012-3-1 07:19:53

Mark!
页: [1]
查看完整版本: 无需短信中心号码的PDU编码(内有实例)