Serialio.modem
Class Modem

java.lang.Object
  extended bySerialio.modem.Modem
All Implemented Interfaces:
java.util.EventListener, Serialio.SnoopListener, Serialio.SnoopLoopListener
Direct Known Subclasses:
SerModem

public class Modem
extends java.lang.Object
implements Serialio.SnoopLoopListener, Serialio.SnoopListener

Creates a modem object.

  • Copyright (c) 1999-2003 Solutions Consulting, All Rights Reserved.

    created 1.0 28 Jul 1999


    Field Summary
    static int ABORT
               
    protected  boolean abortRequest
               
    static int CONNECT
               
    protected  java.lang.String[] controlName
               
    protected  java.util.Locale curLocale
               
    static int DIAL_BLIND
               
    static int DISCONNECT
               
    protected  java.lang.String eMsg
               
    protected  java.lang.String evMsg
               
    static int GET_CONNECT
               
    static int INITIALIZE
              The modem thread
    protected  byte[] match
               
    protected  ModemEvent me
               
    protected  ModemInterfaceProvider mip
               
    protected  java.io.InputStream mis
               
    protected  java.io.OutputStream mos
               
    protected  Serialio.modem.Modem.ModemTask mTask
               
    protected  byte[] phoneNumber
               
    protected  byte[] rdBuf
               
    protected  int rdCnt
               
    protected  java.util.ResourceBundle sMsgs
               
    protected  Serialio.SnoopLoop spy
               
    protected  ModemStatusAcceptor statusMsgNotify
               
    static int STOP
               
    static int STOP_WAIT_RING
               
    protected  boolean stopRequest
               
    protected  boolean stopWaitRing
               
    static int WAIT_DONE
               
    static int WAIT_RING
               
     
    Constructor Summary
    Modem()
              Creates a modem object
    Modem(ModemInterfaceProvider mip, java.io.OutputStream os, java.io.InputStream is)
              Creates a modem object
     
    Method Summary
     void abort()
              Abort the current request
    protected  void checkInitialized()
              Check to see if the modem is initialized.
    protected  void checkOpen()
              Check to see if the modem is 'open'.
     boolean cmdReply(byte[] snd, byte[] waitData, int tmo)
              send the dat, wait for data.
     boolean cmdReply(java.lang.String snd, java.lang.String waitData, int tmo)
              send the dat, wait for data.
     void commandMode()
              Sent the modem 'Attention' command.
     boolean contains(java.lang.String toMatch)
              Checks to see if the given String is contained in the reply buffer
     byte[] getConnectMsg()
              Get the connect message returned by the modem
     int getConnectWaitTime()
               
     ModemStatusAcceptor getModemStatusAcceptor()
              Get the object that will receive modem status msgs
     boolean getNotifyBeforeModemEvent()
               
     java.lang.String getPhoneNumber()
               
     boolean getShowModemData()
               
     boolean getShowModemStatus()
               
     boolean getShowModemStatusExpert()
               
     java.lang.String hexString()
              Creates a String from the data in the SerialData object
     boolean isInitialized()
              Returns true if the modem was initialized.
     void request(int code)
              Request modem to perform an action.
     void setConnectWaitTime(int timeInSecs)
              Set the time the modem will wait for connection after sending the dial command.
     void setDialCommand(java.lang.String cmd)
              Set the modem dial mode command string.
     void setDTR(boolean onOff)
              Set the modem DTR line
     void setInitCommand(java.lang.String cmd)
              Set the modem initialization command string.
     void setInitTime(int tmo)
              Set the modem initialization timeout value.
     void setInterfaceProvider(ModemInterfaceProvider mip)
              Set the ModemInterfaceProvider.
     void setLocale(java.util.Locale newLocale)
              Set the locale.
     void setModemStatusAcceptor(ModemStatusAcceptor viewer)
              Set the object to receive modem status msgs
     void setNotifyBeforeModemEvent(boolean s)
              Set notifyBeforeModemEvent.
     void setPhoneNumber(java.lang.String number)
              Set the phone number the modem will dial when a connect command is requted
     void setShowModemData(boolean onOff)
              When enabled this mode sends the received modem data to the registered viewer.
     void setShowModemStatus(boolean onOff)
              Set the modem status messages.
     void setShowModemStatusExpert(boolean onOff)
              Set the 'expert' modem status messages.
     void setStreams(java.io.OutputStream os, java.io.InputStream is)
              Set the streams used by the modem.
     void snoopEvent(byte[] snoopData)
              Callback for SnoopListener (contains data pattern 'snooped' for)
     void snoopLoopEvent(byte[] streamData, int cnt)
              Callback for SnoopLoopListener
     void start()
              Start the modem task.
     void statusMsg(java.lang.String msg)
              Put a msg to the assigned status area
     void statusMsgExpert(java.lang.String msg)
              Status msg for 'Experts' to the console
     void statusMsgLn(java.lang.String msg)
              Put a msg line to the assigned status area
     void stop()
              Request the modem thread to stop
     void write(byte[] data)
              Write data to the output stream
     void write(java.lang.String data)
              Write data to the output stream
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    eMsg

    protected java.lang.String eMsg

    abortRequest

    protected boolean abortRequest

    stopRequest

    protected boolean stopRequest

    stopWaitRing

    protected boolean stopWaitRing

    evMsg

    protected java.lang.String evMsg

    me

    protected ModemEvent me

    mos

    protected java.io.OutputStream mos

    mis

    protected java.io.InputStream mis

    mip

    protected ModemInterfaceProvider mip

    statusMsgNotify

    protected ModemStatusAcceptor statusMsgNotify

    curLocale

    protected java.util.Locale curLocale

    sMsgs

    protected java.util.ResourceBundle sMsgs

    spy

    protected Serialio.SnoopLoop spy

    mTask

    protected Serialio.modem.Modem.ModemTask mTask

    phoneNumber

    protected byte[] phoneNumber

    INITIALIZE

    public static final int INITIALIZE
    The modem thread

    See Also:
    Constant Field Values

    DIAL_BLIND

    public static final int DIAL_BLIND
    See Also:
    Constant Field Values

    CONNECT

    public static final int CONNECT
    See Also:
    Constant Field Values

    ABORT

    public static final int ABORT
    See Also:
    Constant Field Values

    DISCONNECT

    public static final int DISCONNECT
    See Also:
    Constant Field Values

    WAIT_DONE

    public static final int WAIT_DONE
    See Also:
    Constant Field Values

    STOP

    public static final int STOP
    See Also:
    Constant Field Values

    WAIT_RING

    public static final int WAIT_RING
    See Also:
    Constant Field Values

    GET_CONNECT

    public static final int GET_CONNECT
    See Also:
    Constant Field Values

    STOP_WAIT_RING

    public static final int STOP_WAIT_RING
    See Also:
    Constant Field Values

    rdBuf

    protected byte[] rdBuf

    match

    protected byte[] match

    rdCnt

    protected int rdCnt

    controlName

    protected java.lang.String[] controlName
    Constructor Detail

    Modem

    public Modem()
    Creates a modem object


    Modem

    public Modem(ModemInterfaceProvider mip,
                 java.io.OutputStream os,
                 java.io.InputStream is)
    Creates a modem object

    Parameters:
    mip - the object providing the interface to the modem port
    os - the output stream the modem is connected to
    is - the input stream the modem is connected to
    Method Detail

    start

    public void start()
    Start the modem task. Calling this is only required when creating a modem object without parameters.


    setLocale

    public void setLocale(java.util.Locale newLocale)
    Set the locale. This is used when modem messages are created. The default locale is en_US. CAVEAT: If you want get feedback from the class (e.g. setShowModemStatus) you must provide a Locale so the class knows what language to use.

    Parameters:
    newLocale - the desired locale. providing the interface to the modem port

    setInterfaceProvider

    public void setInterfaceProvider(ModemInterfaceProvider mip)
    Set the ModemInterfaceProvider.

    Parameters:
    mip - the ModemInterfaceProvider

    setStreams

    public void setStreams(java.io.OutputStream os,
                           java.io.InputStream is)
    Set the streams used by the modem. Note: null values are ignored (this allows only one stream to be set)

    Parameters:
    os - the output stream the modem is connected to
    is - the input stream the modem is connected to

    setInitCommand

    public void setInitCommand(java.lang.String cmd)
    Set the modem initialization command string. Note: If you override the default, don't forget the CR (e.g. "ATZ\r")

    Parameters:
    cmd - the command string

    setDialCommand

    public void setDialCommand(java.lang.String cmd)
    Set the modem dial mode command string. The default is "ATDT" for tone dialing, for most modems use "ATDP" for pulse dialing.

    Parameters:
    cmd - the command string

    setInitTime

    public void setInitTime(int tmo)
    Set the modem initialization timeout value. If the desired reply is not received within the set time, the initialize will throw an exception. The default value is 3000ms.

    Parameters:
    tmo - the timeout in millisecs

    getConnectMsg

    public byte[] getConnectMsg()
    Get the connect message returned by the modem


    isInitialized

    public boolean isInitialized()
    Returns true if the modem was initialized. The modem is initialized when it returns the expected reply when sent the initialize command.


    setModemStatusAcceptor

    public void setModemStatusAcceptor(ModemStatusAcceptor viewer)
    Set the object to receive modem status msgs


    getModemStatusAcceptor

    public ModemStatusAcceptor getModemStatusAcceptor()
    Get the object that will receive modem status msgs


    setConnectWaitTime

    public void setConnectWaitTime(int timeInSecs)
    Set the time the modem will wait for connection after sending the dial command.


    getConnectWaitTime

    public int getConnectWaitTime()

    setShowModemStatus

    public void setShowModemStatus(boolean onOff)
    Set the modem status messages. These messages are tageted for the user.

    Parameters:
    onOff - set true to enable

    getShowModemStatus

    public boolean getShowModemStatus()

    setShowModemStatusExpert

    public void setShowModemStatusExpert(boolean onOff)
    Set the 'expert' modem status messages. 'Expert' messages are targeted for a developer, or for a test mode.

    Parameters:
    onOff - set true to enable

    getShowModemStatusExpert

    public boolean getShowModemStatusExpert()

    setShowModemData

    public void setShowModemData(boolean onOff)
    When enabled this mode sends the received modem data to the registered viewer.

    Parameters:
    onOff - set true to enable

    getShowModemData

    public boolean getShowModemData()

    setPhoneNumber

    public void setPhoneNumber(java.lang.String number)
    Set the phone number the modem will dial when a connect command is requted


    getPhoneNumber

    public java.lang.String getPhoneNumber()

    setNotifyBeforeModemEvent

    public void setNotifyBeforeModemEvent(boolean s)
    Set notifyBeforeModemEvent. The default is TRUE. When set TRUE, thread notification is done BEFORE the call to modemEvent When set FALSE, thread notification is done AFTER the call to modemEvent Set to FALSE if your setting a connect state in your modemEvent Set to TRUE if your calling modem.request() from your modemEvent


    getNotifyBeforeModemEvent

    public boolean getNotifyBeforeModemEvent()

    snoopLoopEvent

    public void snoopLoopEvent(byte[] streamData,
                               int cnt)
    Callback for SnoopLoopListener

    Specified by:
    snoopLoopEvent in interface Serialio.SnoopLoopListener

    snoopEvent

    public void snoopEvent(byte[] snoopData)
    Callback for SnoopListener (contains data pattern 'snooped' for)

    Specified by:
    snoopEvent in interface Serialio.SnoopListener

    request

    public void request(int code)
    Request modem to perform an action. There is a wait block, this allows the caller to send multiple requests to the modem object without having to check for completion. If the previous request has not finished, the caller will block until it does. CAVEAT: If request() is called twice from the modemEvent() callback, the modem thread will deadlock - except when calling with STOP requests

    Parameters:
    code - the request code

    checkOpen

    protected void checkOpen()
                      throws ModemException
    Check to see if the modem is 'open'.

    Throws:
    ModemException

    checkInitialized

    protected void checkInitialized()
                             throws ModemException
    Check to see if the modem is initialized.

    Throws:
    ModemException

    commandMode

    public void commandMode()
                     throws java.io.IOException,
                            java.lang.InterruptedException
    Sent the modem 'Attention' command. This command normally puts the modem in command mode.

    Throws:
    IOException, - InterruptedException
    java.io.IOException
    java.lang.InterruptedException

    cmdReply

    public boolean cmdReply(java.lang.String snd,
                            java.lang.String waitData,
                            int tmo)
                     throws java.io.IOException,
                            java.lang.InterruptedException
    send the dat, wait for data.

    Parameters:
    snd - the data to send
    waitData - the data to wait for
    tmo - the timeout if waitData is not seen
    Throws:
    IOException, - InterruptedException
    java.io.IOException
    java.lang.InterruptedException

    cmdReply

    public boolean cmdReply(byte[] snd,
                            byte[] waitData,
                            int tmo)
                     throws java.io.IOException,
                            java.lang.InterruptedException
    send the dat, wait for data.

    Parameters:
    snd - the data to send
    waitData - the data to wait for
    tmo - the timeout if waitData is not seen
    Throws:
    IOException, - InterruptedException
    java.io.IOException
    java.lang.InterruptedException

    setDTR

    public void setDTR(boolean onOff)
                throws java.io.IOException
    Set the modem DTR line

    Throws:
    java.io.IOException

    write

    public void write(java.lang.String data)
               throws java.io.IOException
    Write data to the output stream

    Throws:
    java.io.IOException

    write

    public void write(byte[] data)
               throws java.io.IOException
    Write data to the output stream

    Throws:
    java.io.IOException

    statusMsgExpert

    public void statusMsgExpert(java.lang.String msg)
    Status msg for 'Experts' to the console


    statusMsg

    public void statusMsg(java.lang.String msg)
    Put a msg to the assigned status area


    statusMsgLn

    public void statusMsgLn(java.lang.String msg)
    Put a msg line to the assigned status area


    abort

    public void abort()
    Abort the current request


    stop

    public void stop()
    Request the modem thread to stop


    contains

    public boolean contains(java.lang.String toMatch)
    Checks to see if the given String is contained in the reply buffer

    Parameters:
    toMatch - The String to match the SerialData object

    hexString

    public java.lang.String hexString()
    Creates a String from the data in the SerialData object