public class GsmSmsService extends AbstractSmsService implements SmsService
Before the service can be used, it has to be initalized with the proper configuration settings. The configuration must be passed as Properties to the init() method.
For incoming messages, the GsmSmsService provides the originating SMSC number as aMessage property
with the key SMSC_ADDR_PROPERTY
. The SMSC address returned is an instance of
the GsmAddress
class.
Consult the jSMS Users Guide for examples how to use this class.
Modifier and Type | Class and Description |
---|---|
class |
GsmSmsService.MessageReader |
class |
GsmSmsService.MessageReaderPolling |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CONFIG_GSM_CHECK_ON_SEND
CONFIG_GSM_CHECK_ON_SEND is the name of the constant holding the value "sms.gsm.checkonsend".
|
static java.lang.String |
CONFIG_GSM_CONNECTOR
CONFIG_GSM_CONNECTOR is the name of the constant holding the value "sms.gsm.connector".
|
static java.lang.String |
CONFIG_GSM_CPIN_ETSI
CONFIG_GSM_CPIN_ETSI is the name of the constant holding the value "sms.gsm.cpin.etsi".
|
static java.lang.String |
CONFIG_GSM_GET_UNREAD_MSG
CONFIG_GSM_GET_UNREAD_MSG is the name of the constant holding the value "sms.gsm.receive.unreadmsg".
|
static java.lang.String |
CONFIG_GSM_GPRS
CONFIG_GSM_GPRS is the name of the constant holding the value "sms.gprs".
|
static java.lang.String |
CONFIG_GSM_INITSTRING
CONFIG_GSM_INITSTRING is the name of the constant holding the value "sms.gsm.initstring".
|
static java.lang.String |
CONFIG_GSM_INITTIME
CONFIG_GSM_INITTIME is the name of the constant holding the value "sms.gsm.inittime".
|
static java.lang.String |
CONFIG_GSM_NMI_MODE
CONFIG_GSM_NMI_MODE is the name of the constant holding the value "sms.gsm.nmi".
|
static java.lang.String |
CONFIG_GSM_STORAGE
CONFIG_GSM_STORAGE is the name of the constant holding the value "sms.gsm.storage".
|
static java.lang.String |
CONFIG_GSM_WAITFORNET
CONFIG_GSM_WAITFORNET is the name of the constant holding the value "sms.gsm.waitfornet".
|
static java.lang.String |
CONFIG_GSM_WAITFORNET_INTERVAL
CONFIG_GSM_WAITFORNET_INTERVAL is the name of the constant holding the value "sms.gsm.waitfornet.interval".
|
static java.lang.String |
CONFIG_PIN
CONFIG_PIN is the name of the constant holding the value "sms.pin".
|
static java.lang.String |
CONFIG_POLL_INTERVAL
CONFIG_POLL_INTERVAL is the name of the constant holding the value "sms.receive.poll_interval".
|
static java.lang.String |
CONFIG_PUK
CONFIG_PUK is the name of the constant holding the value "sms.puk".
|
static java.lang.String |
SMSC_ADDR_PROPERTY
SMSC_ADDR_PROPERTY is the name of the constant holding the value "gsm.smsc.addr".
|
VERSION
Constructor and Description |
---|
GsmSmsService()
Creates a new GsmSmsService.
|
Modifier and Type | Method and Description |
---|---|
void |
connect()
Connect to the GSM device or SMS gateway.
|
void |
deleteAllMessages()
Delete all messages currently stored on the GSM device.
|
void |
deleteMessage(int msgNr)
Delete a specific message from the GSM device.
|
void |
destroy()
Destroy this service.
|
void |
disconnect()
Disconnect from the SMS gateway.
|
java.lang.String |
getManufacturer()
Returns the Manufacturer of the GSM device in use (e.g.
|
Message |
getMessage(int msgNr)
Get a specific Message from the GSM device.
|
Message |
getMessage(int msgNr,
boolean delete)
Get a specific Message from the GSM device.
|
java.util.Vector |
getMessages()
Returns a list of all messages currently stored in the GSM device.
|
java.util.Vector |
getMessages(boolean delete)
Returns a list of all messages currently stored in the GSM device.
|
java.lang.String |
getModel()
Returns the Model of the GSM device in use (e.g.
|
int |
getNetworkRegistration()
Returns the status of the network registration (AT+CREG).
|
java.lang.String |
getRevision()
Returns the GSM device revision
|
java.lang.String |
getServiceCentreAddress()
Return the Service Centre Address as configured on the Phone GSM device.
|
java.lang.String |
getServiceName()
Gets the name of the service.
|
int[] |
getSignalQuality()
Get the quality of the radiosignal between the GSM device and the base station.
|
java.lang.String[] |
getSubscriberNumber()
Returns the MSISDNs related to the subscriber (this information can be stored in the SIM or in the ME).
|
boolean |
hasCapability(Capability capability)
The GsmSmsService supports the following capabilities:
Capability.RECEIVE
Capability.SEND
|
void |
init(java.util.Properties props)
Initialize the service.
|
void |
resetDevice()
Reset the GSM device by sending the command "AT+CFUN=1,1".
|
AtReply |
sendATCommand(java.lang.String cmd)
Send an AT-command to the GSM modem.
|
void |
sendMessage(Message message)
Send a message to a GSM recipient.
|
void |
sendMessage(Message message,
java.lang.String smsc)
Send a message to a GSM recipient using a specific SMSC address.
|
void |
startReceiving()
Start receiving Messages.
|
void |
stopReceiving()
Stop receiving Messages.
|
boolean |
supportDeleteMessage()
Deprecated.
since jSMS 2.1.8
|
boolean |
supportReadMessage()
Deprecated.
since jSMS 2.1.8, use
hasCapability(Capability.RECEIVE)
instead. |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addMessageEventListener, cancel, getKeepAliveInterval, getLastIsAliveTime, getProperties, init, init, isAlive, isConnected, isInitialized, isKeepAliveActive, isReceiving, query, removeMessageEventListener, replace, setKeepAliveInterval
public static final java.lang.String CONFIG_PIN
public static final java.lang.String CONFIG_PUK
public static final java.lang.String CONFIG_GSM_CONNECTOR
public static final java.lang.String CONFIG_POLL_INTERVAL
public static final java.lang.String CONFIG_GSM_STORAGE
public static final java.lang.String CONFIG_GSM_NMI_MODE
public static final java.lang.String CONFIG_GSM_GET_UNREAD_MSG
public static final java.lang.String CONFIG_GSM_INITTIME
public static final java.lang.String CONFIG_GSM_WAITFORNET
public static final java.lang.String CONFIG_GSM_WAITFORNET_INTERVAL
public static final java.lang.String CONFIG_GSM_GPRS
public static final java.lang.String CONFIG_GSM_INITSTRING
public static final java.lang.String CONFIG_GSM_CPIN_ETSI
public static final java.lang.String CONFIG_GSM_CHECK_ON_SEND
public static final java.lang.String SMSC_ADDR_PROPERTY
public GsmSmsService()
init(Properties)
public final java.lang.String getServiceName()
getServiceName
in interface SmsService
public void sendMessage(Message message) throws MessageException, GsmException, TimeoutException
sendMessage
in interface SmsService
message
- the message to send.GsmException
- if the message could not be sent.TimeoutException
- if the communication with the device timed out.MessageException
- if the message could not be sent.public void sendMessage(Message message, java.lang.String smsc) throws MessageException, GsmException, TimeoutException
message
- the message to send.smsc
- the address (phone number) of the SMSC to useGsmException
- if the message could not be sent.TimeoutException
- if the communication with the device timed out.MessageException
- if the message could not be sent.public java.util.Vector getMessages() throws MessageException
MessageException
public java.util.Vector getMessages(boolean delete) throws MessageException
delete
- if 'true', the messages will be removed from the device.MessageException
public Message getMessage(int msgNr) throws MessageException
msgNr
- the storage location (index) of the message to fetch.MessageException
public Message getMessage(int msgNr, boolean delete) throws MessageException
msgNr
- the storage location (index) of the message to fetch.delete
- if 'true', the messages will be removed from the device.MessageException
public void deleteMessage(int msgNr) throws MessageException
msgNr
- the storage location (index) of the message to erase.MessageException
public void deleteAllMessages() throws MessageException
MessageException
public boolean supportReadMessage()
hasCapability(Capability.RECEIVE)
instead.SmsService
supportReadMessage
in interface SmsService
public boolean supportDeleteMessage()
SmsService
supportDeleteMessage
in interface SmsService
public void connect() throws MessageException
SmsService
MessageEvent.DEVICE_READY
event to all registered
MessageEventListeners.connect
in interface SmsService
MessageException
MessageEvent
,
MessageEventListener
public void disconnect() throws MessageException
disconnect
in interface SmsService
MessageException
MessageEvent
,
MessageEventListener
public void init(java.util.Properties props) throws MessageException
sms.gsm.connector | The connector to use ("SERIAL" or "IP") |
sms.pin | The PIN code (Personal Identification Number) used to activate the SIM card |
sms.puk | THE PUK (Personal UnlocK) code used to unlock a barred SIM card |
sms.receive.poll_interval | Polling Intervall in milliseconds (for devices not supporting asynchronous receiving) |
sms.gsm.storage | Prefered message store for incoming messages ("SM" (SIM memory), "ME", (Phone memory)) |
sms.gsm.receive.unreadmsg | If this property is set to "true", jSMS will try to read unread messages from the device when startReceiving is called. Defaults to true. |
sms.gsm.inittime | Number of seconds to wait for GSM device to become ready. Defaults to 1 second. Try increasing this parameter if calls to init() fail. |
sms.gsm.waitfornet | Make sure that the GSM device is registered to the network when initializing the Service. Allowed values are either true or false. Defaults to false. |
sms.gsm.waitfornet.interval | Network registration check interval in milliseconds. Only applies if sms.gsm.waitfornet is enabled. Defaults to 1000. |
sms.gsm.gprs | If this property is set to "true", jSMS will try to use the GPRS network for transmitting SMS. Defaults to false. |
connector.serial.port | Name of the serial port to use, e.g. COM1 (if sms.gsm.connector is set to "SERIAL") |
connector.serial.bps | Port speed (default: 9600) |
connector.serial.databits | Number of data bits (5,6,7,8) |
connector.serial.parity | Parity ("N" (none)," E" (even), "O" (odd), "M" (mark), "S" (pace) |
connector.serial.stopbits | Number of stop bits (1, 15 (1.5), 2) |
connector.serial.flowctrl |
Flow control. It can be a combination of the following (separated by spaces or commas):
|
connector.serial.DTR | Sets or clears the DTR (Data Terminal Ready) bit in the UART, if supported by the underlying implementation of the java COMMUNICATION API. |
connector.serial.RTS | Sets or clears the RTS (Request To Send) bit in the UART, if supported by the underlying implementation of the java COMMUNICATION API. |
connector.tcp.host | host name or IP adress of the terminal server where the GSM device is connected |
connector.tcp.port | port number of terminal server at which the GSM device can be reached |
sms.connector.timeout | Communication timeout of the connector in milliseconds. Defaults to 10'000 |
sms.gsm.cpin.etsi | set this property to "true" if the response from your GSM device on the command "AT+CPIN?" does NOT contain a final "OK". If unset, jSMS uses the GSM vendor identification to determine the behaviour of the device. |
sms.gsm.checkonsend | Setting this property to "true" results in jSMS checking the connection
to the GSM device before sending a SMS. Checking is done by calling the
isAlive() method. If the check fails, the GsmSmsService will either broadcast
a DEVICE_NOT_RESPONDING event
to all registered event handlers (if the init property "keepalive.disconnects"
is false) or disconnect itself from the device by calling disconnect()
(if the init property "keepalive.disconnects" is true). Please note that
enabling this feature increases the time it takes for sending a SMS.
Defaults to false.
|
init
in interface SmsService
MessageException
- if jSMS is unable to communicate with your
GSM device or the GSM device doesn't support SMSSmsService.init()
,
SmsService.init(java.io.File)
public void destroy()
destroy
in interface SmsService
public int[] getSignalQuality()
On successful query, this method will return a int[] with size 2. The Received Signal Strength Indication (RSSI) will be returned at position 0 in the array. The channel Bit Error Rate (BER) ist returned at position 1.
0 | -113 dBm or less |
---|---|
1 | -111 dBm |
2...30 | -109... -53 dBm |
31 -51 | dBm or greater |
99 | not known or not detectable |
0 | Less than 0.1 % |
---|---|
1 | 0.26 % to 0.30 % |
2 | 0.51 % to 0.64 % |
3 | 1.0 % to 1.3 % |
4 | 1.9 % to 2.7 % |
5 | 3.8 % to 5.4 % |
6 | 7.6 % to 11.0 % |
7 | Greater than 15.0 % |
99 | 99 not known or not detectable |
public java.lang.String getServiceCentreAddress() throws MessageException
MessageException
- if service is not initialized, not connected or
the device does not support querying the SMSC addresspublic int getNetworkRegistration()
Possible return values are:
0
: not registered, ME is not currently searching a new operator to register to1
: registered, home network2
: not registered, but ME is currently searching a new operator to register to3
: registration denied4
: unknown5
: registered, roamingpublic void resetDevice()
public AtReply sendATCommand(java.lang.String cmd) throws MessageException, TimeoutException, java.io.IOException
The following example demonstrates how to query the TA serial number:
GsmSmsService service = new GsmSmsService(); service.init(configFile); service.connect(); AtReply reply = service.sendATCommand("AT+CGSN"); if( !reply.isError() ) { String serial = reply.getReply(); System.out.println("TA Serial-Number: "+serial); }
cmd
- the AT-CommandMessageException
- if the service is not connected.TimeoutException
- if the communication with the GSM device timed outjava.io.IOException
- if an I/O error occurspublic java.lang.String getManufacturer()
public java.lang.String getModel()
public java.lang.String getRevision()
public boolean hasCapability(Capability capability)
hasCapability
in interface SmsService
capability
- one of the Constants in the Capability
class.public void startReceiving() throws java.io.IOException, java.lang.IllegalStateException
MessageEventListener
with the Service. After receiving
has started, the service will broadcast a MessageEvent of type
RECEIVING_STARTED
to all registered
MessageEvent listeners.
The GSM SmsService will first retrieve all unread messages stored on the
GSM device . For each unread message,
a MESSAGE_RECEIVED
event will be
broadcasted to the registered listeners. The messages will then be deleted
from the phone. Further receiving will be done by either using asynchronous
receiving (if the device supports this) or by polling for incoming messages.
startReceiving
in interface SmsService
java.io.IOException
- if the communication with the SMS gateway/device failsjava.lang.IllegalStateException
- if the service isn't initialized and in connected
state or there are no registered Message Event Listeners.SmsService.addMessageEventListener(MessageEventListener)
public void stopReceiving()
SmsService
MessageEvent.RECEIVING_STOPPED
to all registered MessageEvent listeners.stopReceiving
in interface SmsService
public java.lang.String[] getSubscriberNumber() throws MessageException, GsmException, TimeoutException
MessageException
- if the service is not connected
.GsmException
- if the GSM device doesn't support querying the subscriber numbersTimeoutException
- if the communication with the GSM device times outobject XP, Inc. © 2000-2013. All rights reserved object XP