基于AT指令开发短信程序

来源:互联网 发布:文本校对软件 编辑:程序博客网 时间:2024/04/30 03:35
 

基于AT指令开发短信程序

本人的专职工作是做手机底层软件中SMS和CBS的功能模块软件,对SMS的PDU格式可以说是比较了解,在网上查找了一下感觉目前国内公开的软件大多功能比较单一。主要特点如下: 1、支持分页短信,最大可以支持15个分页,可以一次发送超长数据。 2、文字编码不仅有7BIT和UCS2,还附上8BIT,对于一些手机可以省去解释特殊字符的烦恼。 3、支持CLASS类型的短信,如CLASS0收到就自动显示,用户看完就自动消失。 4、支持电话簿编辑功能,可以将自己的联系人输入我写的数据库中,自动用软件的下载到SIM卡中去,也可以从SIM卡中读取联系人的信息。对于备份联系人的信息非常有帮助。 5、支持短信的存储功能,可以保存到数据库或文件中。
完全掌握CNMI命令

本文摘录3gpp27005中关于CNMI的片段,充分理解此文章可以充分根据GSM-MODEM的提示功能,主动打开GSM-MODEM的新短信、状态报告,小区广播提示。

New Message Indications to TE +CNMI

Parameter Command Syntax

Command

Possible response(s)

+CNMI=[<mode>[,<mt>[,<bm>[,<ds>[,

<bfr>]]]]]

+CMS ERROR: <err>

+CNMI?

+CNMI: <mode>,<mt>,<bm>,<ds>,<bfr>

+CNMI=?

+CNMI: (list of supported <mode>s),(list of supported <mt>s),(list of supported <bm>s),(list of supported <ds>s),(list of supported <bfr>s)

Description

Set command selects the procedure, how receiving of new messages from the network is indicated to the TE when TE is active, e.g. DTR signal is ON. If TE is inactive (e.g. DTR signal is OFF), message receiving should be done as specified in 3G TS 23.038 [2].

NOTE:       When DTR signal is not available or the state of the signal is ignored (V.25ter command &D0), reliable message transfer can be assured by using +CNMA acknowledgement procedure.

<mode> controls the processing of unsolicited result codes specified within this command, <mt> sets the result code indication routing for SMS-DELIVERs, <bm> for CBMs and <ds> for SMS-STATUS-REPORTs. <bfr> defines the handling method for buffered result codes when <mode> 1, 2 or 3 is enabled. If ME does not support requested item (although TA does), final result code +CMS ERROR: <err> is returned. See chapter Message Service Failure Result Code for a list of <err> values.

Test command gives the settings supported by the TA as compound values.

NOTE:       Command Select Message Service +CSMS should be used to detect ME support of mobile terminated SMs and CBMs, and to define whether a message routed directly to TE should be acknowledged or not (refer command +CNMA).

Defined Values

<mode> (refer figure 2;

 

NOTE:       The buffering mechanism may as well be located in the ME; the setting affects only to unsolicited result codes specified within this command):

0    Buffer unsolicited result codes in the TA. If TA result code buffer is full, indications can be buffered in some other place or the oldest indications may be discarded and replaced with the new received indications.

1    Discard indication and reject new received message unsolicited result codes when TA-TE link is reserved (e.g. in on-line data mode). Otherwise forward them directly to the TE.

2    Buffer unsolicited result codes in the TA when TA-TE link is reserved (e.g. in on-line data mode) and flush them to the TE after reservation. Otherwise forward them directly to the TE.

3    Forward unsolicited result codes directly to the TE. TA-TE link specific inband technique used to embed result codes and data when TA is in on-line data mode.

NOTE:       It is possible that ME/TA result code buffer is in volatile memory. In this case messages may get lost if the power of ME/TA is switched off before codes are sent to TE. Thus, it is not recommended to use direct message routing (<mt>=2 or 3, <bm>=2 or 3, or <ds>=1) with <mode> value 0 or 2.

Figure 2: <mode> parameter

<mt> (the rules for storing received SMs depend on its data coding scheme (refer 3G TS 23.038 [2]), preferred memory storage (+CPMS) setting and this value; refer table 1;

NOTE:       If AT command interface is acting as the only display device, the ME must support storing of class 0 messages and messages in the message waiting indication group (discard message); refer table 2):

0    No SMS-DELIVER indications are routed to the TE.

1    If SMS-DELIVER is stored into ME/TA, indication of the memory location is routed to the TE using unsolicited result code:

+CMTI: <mem>,<index>

2    SMS-DELIVERs (except class 2 messages and messages in the message waiting indication group (store message)) are routed directly to the TE using unsolicited result code:

+CMT: [<alpha>],<length><CR><LF><pdu> (PDU mode enabled)

or

+CMT: <oa>, [<alpha>],<scts>[,<tooa>,<fo>,<pid>,<dcs>,<sca>,<tosca>, <length>]<CR><LF><data> (text mode enabled; about parameters in italics, refer command Show Text Mode Parameters +CSDH)

      If ME has its own display device then class 0 messages and messages in the message waiting indication group (discard message) may be copied to both ME display and to TE. In this case, ME shall send the acknowledgement to the network (refer table 2).

      Class 2 messages and messages in the message waiting indication group (store message) result in indication as defined in <mt>=1.

3    Class 3 SMS-DELIVERs are routed directly to TE using unsolicited result codes defined in <mt>=2. Messages of other data coding schemes result in indication as defined in <mt>=1.


Table 1: <mt> parameter

<mt>

Receiving procedure for different message data coding schemes (refer 3G TS 23.038 [2])

0

no class:        as in 3G TS 23.038 [2], but use <mem3> as preferred memory

class 0:            as in 3G TS 23.038 [2], but use <mem3> as preferred memory if message is tried to be stored

class 1:            as in 3G TS 23.038 [2], but use <mem3> as preferred memory

class 2:            as in 3G TS 23.038 [2]

class 3:            as in 3G TS 23.038 [2], but use <mem3> as preferred memory

message waiting indication group (discard message): as in 3G TS 23.038 [2], but use <mem3> as preferred memory if message is tried to be stored

message waiting indication group (store message): as in 3G TS 23.038 [2], but use <mem3> as preferred memory

1

as <mt>=0 but send indication if message stored successfully

2

no class:        route message to TE

class 0:            as in 3G TS 23.038 [2], but also route message to TE and do not try to store it in memory

class 1:            route message to TE

class 2:            as <mt>=1

class 3:            route message to TE

message waiting indication group (discard message): as in 3G TS 23.038 [2], but also route message to TE and do not try to store it in memory

message waiting indication group (store message): as <mt>=1

3

class 3:            route message to TE

others:           as <mt>=1

Table 2: SMS-DELIVER result code and acknowledgement summary

<mt>

no class or class 1

class 0 or message waiting indication group (discard)

class 2 or message waiting indication group (store)

class 3

1

+CMTI

[+CMTI1)]

+CMTI

+CMTI

2

+CMT & +CNMA3)

+CMT [& +CNMA2)]

+CMTI

+CMT & +CNMA3)

3

+CMTI

[+CMTI1)]

+CMTI

+CMT & +CNMA3)

1)     result code is sent when ME does not have other display device than AT interface

2)    acknowledgement command must be sent when +CSMS <service> value equals 1 and ME does not have other display device than AT interface

3)    acknowledgement command must be sent when +CSMS <service> value equals 1

<bm> (the rules for storing received CBMs depend on its data coding scheme (refer 3G TS 23.038 [2]), the setting of Select CBM Types (+CSCB) and this value; refer table 3):

0    No CBM indications are routed to the TE.

1    If CBM is stored into ME/TA, indication of the memory location is routed to the TE using unsolicited result code:

+CBMI: <mem>,<index>

2    New CBMs are routed directly to the TE using unsolicited result code:

+CBM: <length><CR><LF><pdu> (PDU mode enabled)

or

+CBM: <sn>,<mid>,<dcs>,<page>,<pages><CR><LF><data> (text mode enabled)

     If ME supports data coding groups which define special routing also for messages other than class 3 (e.g. (U)SIM specific messages), ME may choose not to route messages of such data coding schemes into TE (indication of a stored CBM may be given as defined in <bm>=1).

3    Class 3 CBMs are routed directly to TE using unsolicited result codes defined in <bm>=2. If CBM storage is supported, messages of other classes result in indication as defined in <bm>=1.

Table 3: <bm> parameter

<bm>

Receiving procedure for different message data coding schemes (refer 3G TS 23.038 [2])

0

all schemes: as in 3G TS 23.038 [2]; if CBM storage is supported, store message to "BM" (or some manufacturer or data coding scheme specific memory)

1

all schemes: as <bm>=0 but send indication if message stored successfully

2

all schemes: route message to TE unless ME has detected a special routing to somewhere else (e.g. to (U)SIM; an indication may be sent if message stored successfully)

3

class 3:            route message to TE

others:     as <bm>=1 (if CBM memory storage is supported)

<ds>:

0    No SMS-STATUS-REPORTs are routed to the TE.

1    SMS-STATUS-REPORTs are routed to the TE using unsolicited result code:

+CDS: <length><CR><LF><pdu> (PDU mode enabled)

or

+CDS: <fo>,<mr>,[<ra>],[<tora>],<scts>,<dt>,<st> (text mode enabled)

2    If SMS-STATUS-REPORT is stored into ME/TA, indication of the memory location is routed to the TE using unsolicited result code:

+CDSI: <mem>,<index>

Table 4: SMS-STATUS-REPORT result code and acknowledgement summary

<ds>

result codes and commands

1

+CDS & +CNMA1)

2

+CDSI

1)    acknowledgement command must be sent when +CSMS <service> value equals 1

<bfr>:

0    TA buffer of unsolicited result codes defined within this command is flushed to the TE when <mode> 1...3 is entered (OK response shall be given before flushing the codes).

1    TA buffer of unsolicited result codes defined within this command is cleared when <mode> 1...3 is entered.

Implementation

Mandatory when any of the new message indications implemented

发表于 @ 2005年11月12日 3:01 PM | 评论 (0)

详解如何利用AT指令发送CLASS分类短信

本文详细介绍如何利用AT指令和GSM-MODEM模块发送CLASS2的信息,其它CLASS信息类同。

目的手机:13911792320。

发送内容:TestForClass Type sms!,this is class 2!

要求状态报告和直接应答,按UCS2编码格式进行发送。

AT发送命令为:

AT+CMGS=93

>

00B1000D91683119712923F0001AFF4E00540065007300740046006F0072

0043006C0061007300730020005400790070006500200073006D00730021

002C007400680069007300200069007300200063006C006100730073002000320021

+CMGS: 114

OK

以上述发送内容中:B1说明要求状态报告和直接应答,也就是第二个字节的内容。

                                    DCS=0x1A,说明编码类型为UCS2,CLASS为CLASS2。

在我们开发短信过程中,可以根据DCS的组合不同实现不同类型的短信类型。如果要开发出其它功能的短信,如EMS,串联短信,还要在加上用户信息(UDHI)。

发表于 @ 2005年11月12日 2:50 PM | 评论 (0)

基于AT开发短信

基于AT指令集开发短信应用,我认为至少要参考如下文档:

   1。http://www.3gpp.org/中的24.005。

   2、http://www.3gpp.org/中的23.040。

如果把这两个文档看仔细了,再强大的短信也可以开发出来。如果有做这方面的开发人员希望能仔细看这二个文档,而不是到处找现在的代码可以使用。要知道目前见网上或市场上的很多软件功能特别少。我把我的短信软件功能列举如下:

    1、支持超长分页短信,最大15分页,可以一次性发送较长的内容。

    2、支持CLASS分类短信,如CLASS0要求立即显示,CLASS2要求存储到SIM卡等。

  3、支持替换短信,用于发布信息和监控报警等非常有用。

  4、支持电话簿管理,可以备份到数据库。

  5、支持短信保存到指定文件,方便短信的管理。

当然,如果你在开发过程中有较大的问题,也可以和我联系。

发表于 @ 2005年11月03日 3:41 PM | 评论 (1)
原创粉丝点击