?? sms.java
字號(hào):
// SMS Transceiver// SMS Transceiver is a tool for sending and receiving SMS via a// serial connection between PC and a mobile phone. It establish// on the basis of a serial line (or IrDA) connection a AT command based// communication for sending and receiving SMS and SMS-based e-Mails.//// file: SMS.java// uses: SMSTools.java, Msg.java, Port.java//// This program uses the javax.comm Service from Sun to transfer data via the// serial PC port. Tested with JBuilder 6, JDK 1.3.1 on Windows 2000 and// with Nokia 6210 on port COM 1 in German D1 GSM net. Tested also via IrDA// connection with IrCOMM2k and Siemens SL55 (some of the features are not// available on the SL55).//// Third party tested with Siemens ME45 and Siemens S45, Windows XP and Unix.//// The AT commands for mobile telephone are specified in the ETSI standards:// TS 27.005 Data Circuit terminating Equipment (DTE - DCE) interface for// Short Message Service (SMS) and Cell Broadcast Service (CBS)// TS 07.07 AT command set for GSM Mobile Equipment (ME)// TS 27.007 AT command set for 3G User Equipment (UE)// TS 23.040 coding of PDUs//// Remarks: * Before starting this programm you have to adopt SMSDIALNO, EMAILDIALNO,// EMAILADR to your personal values.// * On some GSM networks you have to switch on the SMS to email option first.// This could be (on some networks) done with a SMS including the command OPEN to the SMSC.// * It is a good practice to test all AT command to a mobile first with a terminal programm.// * This tool works only with data coding scheme = 00 (=standard GSM Alphabet).// * Some SMSC uses non ETSI conform codings or unusual coding parameters,// this could cause problems with the decoding of the PDUs.// * SMS Transceifer work in PDU mode of the mobile phone not in text mode. By// the way text mode is quite simple, but there are many phone which don't// support it, because its an optional feature.// * Useful tool for PDU analysing : pduspy.exe (use e.g. Google for retrieving it)// * Some GSM networks supports for SMS a confirmation of receive. In the// German D1 GSM net this could be done by *T# at the beginning of the SMS.// * Statements for debuging are marked by "for debuging".// * For SMS only you don't need EMAILDIALNO and EMAILADR. This email stuff should// demonstrate the possibility to send Internet emails from a SMS device.// * The timing for sending and receiving data over the RS232 is on some// PC or Unix hardware sometimes quite critical. There are also some mobile phones// who sends the individual bytes of the response quite irregular, sometimes with// quite big breks between the individual bytes. The critical places for this// data communication are marked with [Timing].// * The "create PDUs functionality" can be used to generate predefined PDU which can// be send via a simple microcontroller application with AT-commands to a mobile phone.//// Ideas for the next versions: * UCS2 support (difficult, quite much work)// * MMS support (only if a AT command interface is specified by ETSI)// * version for PIC microcontrollers (much work, difficult interoperability))//// Warning: This programm deletes all the SMS stored in the mobile phone.//// Release Procedure: 1. find and solve all critical points marked by "???"// 2. Test all separate SMS Transceiver functionalities from GUI// 3. Anonymisize moile phone number and email adress// 4. Build HTML source code file// 5. Build source code file in ZIP package with JavaDoc files//// This source code is under GNU General Public License (see www.opensource.org for details).// Please send corrections and ideas for extensions to Wolfgang Rankl (www.wrankl.de).// Copyright 2003-2004 by Wolfgang Rankl, Munich//// 26. July 2004 - V 10, rw: clarification concerning type of address (TOA),// add create PDUs functionality, new method: convertCharArray2String// 5th published version// 4. June 2004 - V 9, rw: fix minor bugs in "read SMS" and "invest runtime",// add some console output about port activity for debugging,// put all hardware dependant methods into Port.java,// add some hints and clarifications for the serial communication,// increase robustness of the serial communication,// 4th published version// 25. May 2004 - V 8, rw: improved GUI, add parse SMS functionality,// simplify constructor of SMSTools, fix bug in deleteAllSMS()// add a open() method to class Msg (serial connection// is now only open during data transmission)// test connection via IrDA with IrCOMM2k and Siemens SL55// fix bug in parse-functionality// 3rd published version// 4. Feb. 2004 - V 7, rw: fix some bugs, clarify some ambiguous documentation,// add getIndexOfSMS, add testConnection, add getLongTime// add getSignalQuality, add getBatteryStatus,// add decodeAddressField, adoped deleteSMS, add deleteAllSMS,// add GUI, new package Msg.java, improve read() method,// rebuild to a more object oriented programm,// 2nd published version// 28. May 2003 - V 6, rw: source simplifed and reviewed, 1st published version// 15. May 2003 - V 5, rw: improved documentation and clarifications// 24. April 2003 - V 4, rw: code review, optimisation of read(), improved documentation// 9. Jan. 2003 - V 3, rw: add method sendAT(...)// 20. Dec. 2002 - V 2, rw: improved documentation// 19. Dec. 2002 - V 1, rw: initial runnable version//---------------------------------------------------------------------------------------package smspack;import java.awt.*;import java.awt.event.*;import java.util.*;import java.text.*;import javax.swing.*;public class SMS extends JFrame implements ActionListener { // TOA = type of address (= type of number || numbering plan identifier) // it is a national dialing number format (0x81, e.g. short number format for net internal calls) static final boolean TOA_NATIONAL = true; // TOA = type of address (= type of number || numbering plan identifier) // it is a international dialing number format (0x91, e.g. usual number format for normal calls) static final boolean TOA_INTERNATIONAL = false; static final String SMSTEXTSIGN = ">"; // sign for the begin of the SMS text static final int TIMEOUT = 2*60*1000; // timeout [ms] for SMS run time measurement static final int MAXNOSIMSMS = 20; // maximal number of stored SMS in SIM static final String SMSDIALNO = "0175108xxxx"; // dialing number for SMS transmission, this is the number of the phone you want to send the SMS static final String EMAILDIALNO = "8000"; // dialing number for eMail transmission, this is the number you have to dial if you want to convert a SMS into a e-Mail static final String EMAILADR = "wolfgang.rankl@xx.xx-xx.de"; // eMail adress static final String COMPORT = "COM1"; // used COM port for data transmission public static JTextArea ta = new JTextArea(40, 100); /** build the GUI with all it components */ SMS() { //----- create text area with scroll pane ta.setTabSize(4); ta.setFont(new Font("Monospaced", 0, 12)); // Courier, 12 point size ta.setBackground(new Color( 0, 0, 0)); // black blue ta.setForeground(new Color(200, 255, 100)); // yellowgreen getContentPane().add(new JScrollPane(ta), BorderLayout.CENTER); //----- create panel with buttons JPanel buttonPanel = new JPanel(new GridLayout(25, 1)); JButton button1 = new JButton("decode PDUs"); button1.addActionListener(this); buttonPanel.add(button1); JButton button8 = new JButton("create PDUs"); button8.addActionListener(this); buttonPanel.add(button8); JButton button2 = new JButton("read SMS"); button2.addActionListener(this); buttonPanel.add(button2); JButton button3 = new JButton("read ME Info"); button3.addActionListener(this); buttonPanel.add(button3); JButton button4 = new JButton("send SMS"); button4.addActionListener(this); buttonPanel.add(button4); JButton button5 = new JButton("invest Runtime"); button5.addActionListener(this); buttonPanel.add(button5); JButton button6 = new JButton("AT Cmd."); button6.addActionListener(this); buttonPanel.add(button6); JButton button7 = new JButton("Parse"); button7.addActionListener(this); buttonPanel.add(button7); JButton button9 = new JButton("Exit"); button9.addActionListener(this); buttonPanel.add(button9); getContentPane().add(buttonPanel, BorderLayout.EAST); } // SMS /** creates a Windows conform formated date and time string * @return: data and time string */ public static String getFormatedDateTime() { String s; Date t = new Date(); t.getTime(); s = DateFormat.getDateTimeInstance().format(t); return s; } // getFormatedDateTime /** creates a long value for the time * @return: number of milliseconds since January 1, 1970, */ public static long getLongTime() { long l; Date time = new Date(); l = time.getTime(); return l; } // getLongTime /** show text in the text window * @param text text string to show on the display */ public static void showText(String text) { ta.setText(ta.getText() + text); } // showText /** show text in the text window * @param text char array to show on the display */ public static void showText(char[] text) { ta.setText(ta.getText() + text); } // showText /** dispatcher which the main parts of the programm * @param event event button which is pressed */ public void actionPerformed(ActionEvent event) { boolean loopbreak; int n, i; int[] index; long sendtime, starttime, receivetime, deltatime; String s, pdu, sendtext, receivetext, originateno; showText("\n-------------------------------------------\n"); String cmd = event.getActionCommand(); if (cmd.equals("decode PDUs")) { showText("decode some PDUs for demonstration and test\n\n"); pdu = "0791198968004544040C911989684385620000408002804532800FEB721E145E97F331507D5DCEC700"; showText(SMSTools.getSMSText(pdu)+ "\n"); pdu = "0791947101670000040485080039004010313131604020D737DB7C0EBBCF2E69D8BD6603C865D739DD22975DE3771B442DCFE9"; showText(SMSTools.getSMSText(pdu)+ "\n"); pdu = "0791947101670000040C9194617011078800004010023112914016D737DB7C0EBBCF2069D8BD66B340CDBA3B3D4603\n"; showText(SMSTools.getSMSText(pdu) + "\n"); pdu = "0791448720900253040C9144775425208800003021620274900018C2B0B80C22A7C9A03A485D9F83C661361BD42EFF40";
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -