|
IM Profile | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.siemens.icm.io.ATCommand
The ATCommand class supports the execution of AT commands on the same way, as it would be done through a serial interface. It provides a simple manner to send strings directly to the AT-Interpreters of the device.
Because the device might provide more than one AT-Interpreter at the same time, instances of this class can be connected to the several AT-Channels of the device. Because the instances of this ATCommand class are connected directly to the different AT parsers inside the module, there are only exactly as much instances possible as the number of provided AT interpreters. Trying to cre-ate more instances of this class will cause the constructor to fail.
Because the different AT-Channels of the device might have different capabilities, these capabili-ties can be queried (Fax, Data-Transfers). It might be possible (or better be probable) that there is e.g. only one instance with CSD capabilities available.
Additionally, a callback class for unsolicited AT-Events (URCs) can be registered.
Please be aware that corresponding to the setting made by the "AT+CSCS" command the string parameters of several AT commands has to be passed in the GSM or UCS2 character set and the responses might contain strings in that character set as well. The ATCommand class does no string conversion at all which means that all converting between Java strings and GSM respectively UCS2 strings has to be done by the application itself in both directions. For easy conversion be-tween the different character sets the class ATStringConversion can be used.
To be able to deal with data connections created by this class e.g. by using the ATD command there are member variables for input and output streaming from and to data connections which are accessible via the getDataOutputStream() and getDataInputStream() functions. If the module is in transparent data mode (a data connection is active) the call of the send functions is forbidden and will cause an IllegalStateException.
For performance reasons there is no synchronization done in this class. If an instance of this class has to be accessed from different threads, it has to be ensured that the send() functions, the re-lease() function, the cancelCommand() function and the breakConnection() function are synchro-nized in the user implementation. There is only a minimal synchronisation, which prohibits sending or reading data when another thread has an ongoing data transfer. Trying to break the connection of another thread is as well not possible. An IOException will be thrown.
Currently the maximal possible length of AT commands passed via the send() methods is 815 characters, including the line feed.
ATCommandListener
,
ATCommandResponseListener
,
ATStringConverter
Constructor Summary | |
ATCommand(boolean csdSupport)
Creates a new instance of the ATCommand class. |
|
ATCommand(boolean csdSupport,
boolean atEvents,
boolean ring,
boolean dcd,
boolean dsr,
boolean conn)
Creates a new instance of the ATCommand class starting only the required listeners. |
Method Summary | |
void |
addListener(ATCommandListener listener)
Registers listeners to receive unsolicited AT-Events (URCs). |
String |
breakConnection()
This function switches the module, when in CSD data call, back from transparent data mode to AT command mode. |
void |
cancelCommand()
Cancel a running AT command. |
boolean |
csdSupported()
Get information if the connected AT-Interpreter is able to handle CSD connections. |
boolean |
getCONN()
Get the state of a data connection of the devices AT channel. |
InputStream |
getDataInputStream()
This function returns the input stream for data connections. |
OutputStream |
getDataOutputStream()
This function returns the output stream for data connections. |
boolean |
getDCD()
Get the state of the DCD (Data Carrier Detect) signal of the devices AT channel. |
boolean |
getDSR()
Get the state of the DSR (Data Set Ready) signal of the devices AT channel. |
boolean |
getRING()
Get the state of the RING signal of the devices AT channel. |
void |
release()
Release resources locked by the ATCommand class. |
void |
removeListener(ATCommandListener listener)
Removes a listener object which has been previously added from the internal list table of listener objects. |
String |
send(String ATCmd)
Send an AT command to the device. |
void |
send(String ATCmd,
ATCommandResponseListener response)
Send an AT command to the device. |
void |
setDTR(boolean SignalState)
Set the state of the DTR (Data Terminal Ready) signal of the devices AT channel. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ATCommand(boolean csdSupport) throws ATCommandFailedException, IllegalStateException
csdSupport
- A flag indicating if the instance of this class should have CSD support
or not. It might be possible that there is an instance with CSD support created,
even if it wasn't requested if there are only instances with CSD support available.
But it can never happen that there is CSD support requested and an instance without
created. If CSD support is requested and there is no instance with CSD available an
IllegalStateException will be thrown.
IllegalStateException
- if there isn't any instance of the AT interpreter with the
requested capabilities available.
ATCommandFailedException
- if the connection to the AT-Interpreter
fails because of some internal reasons (e.g. because the virtual COM port cannot be
opened in the PC emulator).ATCommandListener
public ATCommand(boolean csdSupport, boolean atEvents, boolean ring, boolean dcd, boolean dsr, boolean conn) throws ATCommandFailedException, IllegalStateException
csdSupport
- A flag indicating if the instance of this class should have CSD support
or not. It might be possible that there is an instance with CSD support created,
even if it wasn't requested if there are only instances with CSD support available.
But it can never happen that there is CSD support requested and an instance without
created. If CSD support is requested and there is no instance with CSD available an
IllegalStateException will be thrown.atEvents
- listener for unsolicited AT-Events (URCs)ring
- listener for changes of the serial interface signal RINGdcd
- listener for changes of the serial interface signal DCD (Data Carrier Detect)dsr
- listener for changes of the serial interface signal DSR (Data Set Ready)conn
- listener for changes of the state of a data connection
IllegalStateException
- if there isn't any instance of the AT interpreter with the
requested capabilities available.
ATCommandFailedException
- if the connection to the AT-Interpreter
fails because of some internal reasons (e.g. because the virtual COM port cannot be
opened in the PC emulator).ATCommandListener
Method Detail |
public void release() throws ATCommandFailedException
ATCommandFailedException
- if releasing locked resources fails because of:
public String send(String ATCmd) throws ATCommandFailedException, IllegalStateException, IllegalArgumentException
Currently there are 1024 bytes reserved to temporary store the response internal inside the virtual machine. Some AT commands return responses which might be longer (e.g. reading a phone book or the provider list at once). In this case an ATCommandFailedException will be thrown. To avoid this an application should use the possible problematic commands in their format returning only single entries.
Attention:
If there are strings sent to the AT command interpreter by this method which are
not valid AT commands because they don't start with "AT" they will be ignored by
the AT command interpreter, no response will be sent and this method is blocking
infinitely! The application should protect itself of sending wrong AT commands or
call the method cancelCommand() if the blocking method send() does not return.
ATCmd
- The command to send.
ATCommandFailedException
- if sending of the command fails because:
IllegalStateException
- if sending of the command not possible because:
IllegalArgumentException
- if the command is invalid because:
send(String ATCmd, ATCommandResponseListener response)
public void send(String ATCmd, ATCommandResponseListener response) throws ATCommandFailedException, IllegalStateException, IllegalArgumentException
Currently there are 1024 bytes reserved to temporary store the response internal inside the virtual machine. Some AT commands return responses which might be longer (e.g. reading a phone book or the provider list at once). In this case an ATCommandFailedException will be printed out (not thrown) and the callback class is called passing a null to the listener function. To avoid this an application should use the possible problematic commands in their format returning only single entries. Also if anything else went wrong the response listener is called with a null as parameter to indicate the problem. If already this send function throws an exception the listener is not called anymore.
Attention:
If there are strings sent to the AT command interpreter by this method which are
not valid AT commands because they don't start with "AT" they will be ignored by
the AT command interpreter, no response will be sent and the waiting listener will
never be called! If an invalid AT command is cancelled with the cancelCommand()
function the waiting response listener will be called with an "ERROR" as
response.
ATCmd
- The command to send.response
- Instance of the callback class which will receive the response to
the command.
ATCommandFailedException
- if sending of the command fails because
of some internal reasons
IllegalStateException
- if sending of the command not possible because:
IllegalArgumentException
- if the command is invalid because:
send(String ATCmd)
,
cancelCommand()
public void cancelCommand() throws ATCommandFailedException, IllegalStateException
ATCommandFailedException
- if canceling command fails because
of some internal reasons.
IllegalStateException
- if canceling command fails because:
send(String ATCmd, ATCommandResponseListener response)
public void setDTR(boolean SignalState) throws ATCommandFailedException
SignalState
- The new state of the DTR signal.
ATCommandFailedException
- if setting of the DTR signal failed
because of some internal reasons.public boolean getRING() throws ATCommandFailedException
ATCommandFailedException
- if reading of the RING signal fails
because of some internal reasons.ATCommandListener
,
addListener(com.siemens.icm.io.ATCommandListener)
public boolean getDCD() throws ATCommandFailedException
ATCommandFailedException
- if reading of the DCD signal fails
because of some internal reasons.ATCommandListener
,
addListener(com.siemens.icm.io.ATCommandListener)
public boolean getDSR() throws ATCommandFailedException
ATCommandFailedException
- if reading of the DSR signal fails
because of some internal reasons.ATCommandListener
,
addListener(com.siemens.icm.io.ATCommandListener)
public boolean getCONN() throws ATCommandFailedException
ATCommandFailedException
- if getting the state fails
because of some internal reasons.ATCommandListener
,
addListener(com.siemens.icm.io.ATCommandListener)
public boolean csdSupported()
public void addListener(ATCommandListener listener)
listener
- The ATCommandListener object to be registered.ATCommandListener
,
removeListener(com.siemens.icm.io.ATCommandListener)
public void removeListener(ATCommandListener listener)
listener
- The ATCommandListener object to be removed from the list.ATCommandListener
,
addListener(com.siemens.icm.io.ATCommandListener)
public String breakConnection() throws IOException
Before it is switched back to AT command mode the output buffer of the OutputStream will be flushed automatically. Possible pending read operations via the InputStream stream will return after the data connection has been closed.
Calling breakConnection() to stop an ongoing data transfer of another thread provokes an IOException.
This method is exclusive for CSD data calls. It cannot be called for other procedures using the data stream mode like I2C or RSA, which have their own way to change to AT command mode.
IOException
- if there is no open data connection available, the stream has
been closed before or an IO error occurs.getDataInputStream()
,
getDataOutputStream()
public OutputStream getDataOutputStream()
If there are data connections created with the ATCommand class (typically with "ATD" or "AT^SSPI") this stream is used to send output data to the data connection. It is already open but accepts only data if the module is in transparanet data mode (an open data connection exists). If the module is in AT command mode calling of any function of this stream causes an IOException. The stream remains open until the release function of the ATCommand class is called. This means that the close() function of this stream hasn't any consequence. All write() functions return immediately if there is enough place in the send buffer. Only if not all data can be written in the out buffer they will block until there is enough place in the buffer again. The flush() function will block until all buffered data has been sent out. The write() and flush() functions are only able to access the internal used primary buffers. If data has left these primary buffers it might be possible that the data is still stored in lower buffers. These buffers cannot be accesed by the high level Java classes any more. So it might be possible that data in these lower buffers is lost when a data connection is closed even if the flush() function has been called and has successfully returned.
For performance reasons there is no synchronization done in this stream class. If an instance of this class has to be accessed from different threads it has to be ensured that the write() functions and the flush() function are synchronized in the user implementation.
OutputStream
,
release()
public InputStream getDataInputStream()
If there are data connections created with the ATCommand class (typically with "ATD" or "AT^SSPI") this stream is used to read input data from the data connection. It is already open but can only be used if the module is in transparanet data mode (an open data connection exists). If the module is in AT command mode calling of any function of this stream causes an IOException. The stream remains open until the release function of the ATCommand class is called. This means that the close() function of this stream hasn't any consequence. Possible pending write() or skip() functions of this stream will return with the already read or skipped data or -1 in case of the single byte read() if the data connection is interrupted by calling the breakConnection() function. The mark feature of the InputStream class is not supported.
For performance reasons there is no synchronization done in this class. If an instance of this class has to be accessed from different threads it has to be ensured that the read() functions, the skip() function and the available() function are synchronized in the user implementation.
InputStream
,
breakConnection()
|
IM Profile | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |