// 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