Switch to a mobile phone development post (from the developer Club)

Source: Internet
Author: User
Tags format character set count end header integer ord string
Code:--------------------------------------------------------------------------------
At present, the application of mobile phone messages more and more widely, the Internet to provide short message sent to the site is also more and more, but some sites are not satisfactory service, often sent to the short message. The most reliable way to send is, of course, with the hands of the mobile phone, if set a status report, more accurate to know whether the other party received this message. Mobile phone delivery, although more reliable, but there are input problems, inefficient. This article describes a method, as long as the mobile phone can be connected to the computer (through the infrared port or the mobile phone data line to connect the serial port, while the mobile phone support GSM at instruction set), it can be compiled by the text of the message to send software to achieve the delivery of short messages.
Most mobile phones in the market now support the GSM at instruction set, similar to modem control, which is developed by Nokia, Ericsson, Motorola and HP manufacturers, including the control of SMS (short message Service).
Introduction of GSM at related instruction
SMS-related GSM at directives are shown in table 1:

Table 1 related GSM at Directives
There are three ways to implement SMS control:
Block Mode;
Text Mode based on at command;
PDU Mode based on at command.
Text mode is relatively simple, a variety of Nokia phones support the model. Most of Siemens mobile phones only support PDU mode, PDU mode is a way to send or receive SMS information of mobile phone, SMS text is transmitted after hexadecimal encoding. Currently, PDU has replaced block mode, so this article mainly discusses the PDU mode of sending.
The communication between computer and mobile phone
Taking Siemens S3568i as an example, this paper introduces how to realize the sending of short message.
Data Cable Connection
First, the phone is connected to the computer serial port via the S35/25 data line. Then, open HyperTerminal, select Direct serial port connection, port parameter set to 19200 rate, no checksum, data bit 8, stop bit 1.
Infrared connection
If you use a computer with an infrared port, you can set up a wireless connection to your phone. First make sure that your computer's infrared port is turned on, and that the infrared and fax/data features of your phone are turned on, that you have an infrared device on your computer's tray, Siemens S35 (not shown if you do not have an infrared monitor installed). Then, turn on HyperTerminal and select the serial port on the IrDA.
Connection test
Click on the Super Terminal toolbar Call button, input at and enter, if the screen appears OK will indicate that the computer and mobile phone connection is successful, then you can enter all kinds of GSM at instructions.
Such as: Search mobile phone manufacturers, input at+cgmi=<cr&gt, screen display Siemens.
Normally, execute the test command at+cmgs=?<cr> If you return OK, the phone supports this instruction. The complete syntax format for the directive is as follows:
If PDU Mode (+cmgf=0) +CMGS=&LT;LENGTH&GT;&LT;CR&GT;PDU is given <ctrl-Z/ESC>
If message format instruction AT+CMGF returns 0, SMS format is PDU mode, then at+cmgs=< data length > command, the phone returns ">" Symbol and waits for input, input PDU data and end with ^Z or ESC key.
If the message is sent successfully, it returns OK and displays the message number:
+cmgs: <mr>
If the send fails, the following message is returned:
+cms ERROR: <err>
Analysis of PDU data format
The data format of the SMS PDU is described below by analyzing the outgoing information stored in the phone. First of all, write a short message with the mobile phone, send the mobile phone number 13605696031, the information content is "Hello world!". You can read this message by executing at+cmgl=2.
The procedure is as follows (italic character is response information, {} is a comment):
At
Ok
at+cmgl=2 {Read not sent SMS}
+cmgl:1,2,,24 {1 Indicates the number of messages, 2 indicates no information, and 24 indicates total information capacity}
683108501505f0 0B bayi 3106656930f1 0000a7 0B e8329bfd06dddf723619
Ok
This message is analyzed below:
08: Short Message Center address length.
91: Short Message Center number type, 91 is TON/NPI. TON/NPI comply with the international/e.164 standard, refers to the number before the need to add ' + ' number, in addition to other values, but 91 most commonly used.
683108501505F0: Short message number, is the service center address used. Due to the location of a slightly processed, the actual number should be: 8613805515500 (the letter F means length minus 1), this is the author's location GSM short Message Center number.
11: File header byte (header byte, is a bitmask). Here 11 refers to the normal sending of short messages.
00: Information type.
0B: called number length.
81: Called number type.
3106656930F1: Called number, also through the shift processing, the actual number is 13605696031.
0000A7: SMS encoding type GSM Default alphabet, if Chinese is 000010.
0B: Short message length.
e8329bfd06dddf723619: SMS Content "Hello world!".
Coding method and programming implementation of short message
Below we introduce the information coding method of pure English and pure Chinese. By testing, we found that each message sent in front of the same, only the number of calls and SMS content changes.
1. English code
See table 2 for the text message "Hello world!". The default GSM character set is 7-bit encoding, which can be simply interpreted as ASCII (ASCII value is less than 80Hex, so the BIT8 is ignored), sequentially moving the next 17-bit encoded to the front to form a new 8-bit encoding, see table 2 arrow instructions. Note that the 9th line, the shift count has reached 7 digits, then directly add this code before 0. GSM does not support all ASCII character displays.
Table 2 The implementation process of English coding

The following is the implementation of the English Code part of Delphi 5 codes:
Encoded in English format, S is string
function Encode1 (var s:string): String;
Var
I,j,len:integer;
Cur:integer;
t:string;
Begin
Result:= ';
Len:=length (s);
J for Shift Count
i:=1;j:=0;
While I<=len do
Begin
If I<len Then
Data transformation
Cur:= (Ord (S[i]) shr j) or ((Ord (s[i+1)) SHL (7-j)) and $FF)
Else
Cur:= (Ord (S[i]) shr j) and $7f;
Fmtstr (t, '%2.2x ', [cur]);
Result:=result+t;
Inc (I);
The shift count reaches 7-bit special treatment
j:= (j+1) mod 7;if J=0 then Inc (i);
End
End
2. Chinese code
See table 3 for the text message "Chinese short message". The implementation of Chinese short message is simpler, just?????? The Chinese encoding is converted to the Unicode encoding of the code page as CP936.
Table 3 The implementation process of Chinese encoding

Through the Widestring type conversion of Delphi, we can skillfully realize the?????? encoded conversions to Unicode (note that code pages are associated with the operating system). The following is a partial Delphi 5 code that implements the Chinese encoding:
Encoded in Chinese format, S is a Unicode String
function Encode2 (var s:widestring): String;
Var
I,len:integer;
Cur:integer;
t:string;
Begin
Result:= ';
Len:=length (s);
I:=1;
While I<=len do
Begin
Cur:=ord (S[i]);
BCD Conversion
Fmtstr (t, '%4.4x ', [cur]);
Result:=result+t;
Inc (I);
End
End
Summary
The above introduces the PDU format short message code. It is suggested that English information should not exceed 140 characters in length and not more than 54 Chinese characters. It's easier to do this if you use a mobile phone that supports text. If you send "Hello world!", use the following at command:
at+cgmf=1<cr>at+cgms= "13605696031",129<cr>
>hello world!<^z>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.