Turn a mobile phone development post (from the developer Club) _php

Source: Internet
Author: User
Keywords developer Club from post cell phone dev one info code
Code:--------------------------------------------------------------------------------
At present, the application of mobile phone messages more and more widely, the Internet to provide short messages sent to the site is more and more, but some site service is not satisfactory, often sent to the short message. The most reliable way to send is, of course, with the hands of the mobile phone, if you set a status report, it is more accurate to know whether the other party received this message. Mobile phone transmission Although reliable, but there are problems of input trouble, low efficiency. This article introduces a method, as long as the mobile phone can be connected with the computer (through the infrared port or the mobile phone data cable to connect the serial port, while the mobile phone supports GSM at instruction set), can be prepared by the short message to send software, to achieve the transmission of short messages.
Most mobile phones in the market now support the GSM at instruction set, similar to modem control, developed by manufacturers such as Nokia, Ericsson, Motorola and HP, which contains control over SMS (short Message Service).
Introduction of GSM at related instruction
The GSM at command associated with SMS is shown in table 1:

Table 1 related GSM at instructions
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 simple, and a variety of Nokia phones support this mode. Most Siemens phones only support PDU mode, PDU mode is a way to send or receive SMS messages, text messages are sent by hexadecimal encoding. Currently, PDU has replaced block mode, so this paper mainly discusses the transmission of PDU mode.
Communication between the computer and the phone
Taking Siemens S3568i as an example, this paper introduces how to realize the transmission of SMS.
Data Cable Connection
First, connect the phone to the computer serial port via the S35/25 data cable. Then, open HyperTerminal, select the direct serial port connection, the port parameter is set to 19200 rate, no check, data bit 8, stop bit 1.
Infrared connection
If you are using a computer with an infrared port, you can set up a wireless connection to your phone. First confirm that the computer infrared port is open, and the phone's infrared and fax/data functions open, docking infrared port, computer system tray should appear an infrared device Siemens S35 (if not installed infrared monitor, not shown). Then, open the HyperTerminal and select the serial port on the IrDA.
Connection test
Click the Call button on the HyperTerminal toolbar, type at and enter, if OK on the screen indicates the connection between the computer and the mobile phone is successful, then you can enter all kinds of GSM at command.
such as: query phone manufacturers, input at+cgmi= , the screen displays Siemens.
Typically, execute the test command at+cmgs=? , if returned OK, indicates that the phone supports this instruction. The full syntax format for this directive is as follows:
If PDU Mode (+cmgf=0) +cmgs= PDU is given
If the message format instruction AT+CMGF returns 0, the SMS format is PDU mode, and then the at+cmgs= is executed. <数据长度> command, the phone returns the ">" Symbol and waits for input, entering the PDU data and ending with the ^Z or ESC key.
If the message is sent successfully, it returns OK and displays the information number:
+cmgs:
If the send fails, the following information is returned:
+cms ERROR:
Analysis of PDU data format
The following is an analysis of the outgoing messages stored in the phone, which describes the data format of the SMS PDU. First, a mobile phone to write a text message, the mobile phone number is 13605696031, the message content is "Hello world!". You can read this message by executing at+cmgl=2.
The procedure is as follows (the italic character is the response message and {} is a comment):
At
Ok
at+cmgl=2 {Read no text message}
+cmgl:1,2,,24 {1 Indicates the number of messages, 2 means no messages, 24 indicates total information capacity}
683108501505f0 0B bayi 3106656930f1 0000a7 0B e8329bfd06dddf723619
Ok
The following analysis of this message:
08: SMS Center address length.
91: SMS Center number type, 91 is TON/NPI. TON/NPI adhere to the international/e.164 standard, refers to the number before the "+" number, but also can have other values, but 91 most commonly used.
683108501505F0: The SMS number is the service center address used. Due to the location of a slight processing, the actual number should be: 8613805515500 (letter F means the length minus 1), this is the author's location GSM SMS center number.
11: File header byte (header byte, is a bitmask). Here 11 refers to sending text messages normally.
00: type of information.
0B: called number length.
81: Called number type.
3106656930F1: The called number, also after the shift processing, the actual number is 13605696031.
0000A7: SMS Encoding type GSM Default Alphabet, if Chinese is 000010.
0B: Short message length.
e8329bfd06dddf723619: Short message content "Hello world!".
Coding method and programming realization of short message
Below we introduce the information encoding method of pure English and pure Chinese. Through the test we found that each message sent in the front part of the same, but the call number and text message content changes.
1. English coding
Refer to table 2 for the text message "Hello world!". The default GSM character set is 7-bit encoded, which can be simply interpreted as ASCII (ASCII value less than 80Hex, therefore, BIT8 is ignored), followed by the next 17-bit encoding successively moved to the front, forming a new 8-bit encoding, see table 2 arrow indicator. Note that the 9th line, the shift count has reached 7 bits, the code directly before adding 0. GSM does not support all ASCII character displays.
Table 2 Implementation process of English coding

Here are some of the Delphi 5 codes that implement the English encoding:
English format code, 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 counting
i:=1;j:=0;
While I<=len do
Begin
If I
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);
Special handling of shift count up to 7 bits
j:= (j+1) mod 7;if J=0 then Inc (i);
End
End
2. Chinese encoding
See table 3 for a short message with "Chinese text message". The implementation of Chinese short message is simple, just?????? The Chinese encoding to the code page is CP936 Unicode encoding.
Table 3 Implementation process of Chinese encoding

With Delphi's widestring type conversion, you can intelligently implement?????? Encoding conversion to Unicode (note that the code page is associated with the operating system). Here are some of the Delphi 5 codes that implement the Chinese encoding:
Chinese format encoding, S is 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 describes the PDU format SMS encoding. It is suggested that the information in English should not exceed 140 characters, and not more than 54 characters in Chinese. It's easier to do this if you send it using a phone that supports text. If you send "Hello world!", use the following at command:
At+cgmf=1 At+cgms= "13605696031", 129
>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.