com.gtosoft.libvoyager.session
Class OBD2Session

java.lang.Object
  extended by com.gtosoft.libvoyager.session.OBD2Session

public class OBD2Session
extends java.lang.Object

- A Session layer which connects ELMBT, with a higher level class, such as PIDDecoder. - We will maintain an open line of OBD2 communication so that bluetooth commands can be sent. - When an OBD2 response is received, we'll leave the decoding up to the PIDDecoder class. - PIDDecoder will probably even request OBD data through us. - Usage: instantiate this class with an alrady -configured ELMBT, and an already-instantiated PIDDecoder. - And make sure to shut down this class by calling its shutdown() - otherwise threads will continue to live beyond our lifetime. - To get data, make a request through PIDDecoder. PIDDecoder will use a callback, which we register, to request us to get data from the bluetooth. We will in turn get that data and pass it back to PIDDecoder for decoding.


Field Summary
static int STATE_BTCONFIGURED
           
static int STATE_BTCONNECTED
           
static int STATE_OBDCONNECTED
           
static int STATE_UNINITIALIZED
           
 
Constructor Summary
OBD2Session(ELMBT e, PIDDecoder p, java.lang.String NOTUSEDnetwork, DashDB d)
          Constructor.
 
Method Summary
 boolean _suspend()
          Suspend operations by this class/session and return the network to a usable state for others.
 int getCurrentState()
           
 java.lang.String getCurrentStateByName()
           
 DashDB getDashDB()
          Returns a handle to the local DashDB instance...
 java.lang.String getOBDProtocol()
          Call this AFTER you detect that the session state is in OBDconnected state.
 GeneralStats getStats()
           
 boolean isIODoneTrying()
           
 java.lang.String obdCommand(java.lang.String obdRequest)
          Sends the specified OBD Command and obtains the response.
 void registerMessageCallback(EventCallback eventCallback)
          A means for a parent class to receive messages generated by this class.
 void registerOnStateChangedListener(EventCallback newStateChangeListener)
          Convenience method that wraps the setOnStateChangedListener.
 boolean resume()
          Resume from a suspended state - re-initialize the device in a way that ensures that it is ready for our state.
 java.lang.String sendATCommand(java.lang.String ATCommand)
          Allow the sending of AT commands...
 java.lang.String sendDTCReset()
           
 java.util.HashMap<java.lang.String,java.lang.String> sendOBDRequestByName(java.lang.String dataPointName)
          ** Intended to be called by piddecoder, not you...
 void setIOReconnectNOW()
          Will kick the I/O Layer into trying to connect again.
 void setOnStateChangedListener(EventCallback newStateChangeListener)
          Define a method that you want to be executed any time the OBD2 state changes.
 void shutdown()
          Shutdown threads and clean up.
 boolean startStateManagementThread()
          defines and starts the state management thread.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_UNINITIALIZED

public static final int STATE_UNINITIALIZED
See Also:
Constant Field Values

STATE_BTCONNECTED

public static final int STATE_BTCONNECTED
See Also:
Constant Field Values

STATE_BTCONFIGURED

public static final int STATE_BTCONFIGURED
See Also:
Constant Field Values

STATE_OBDCONNECTED

public static final int STATE_OBDCONNECTED
See Also:
Constant Field Values
Constructor Detail

OBD2Session

public OBD2Session(ELMBT e,
                   PIDDecoder p,
                   java.lang.String NOTUSEDnetwork,
                   DashDB d)
Constructor.

Parameters:
network - - defines which network we're on. This is quite important. Records in the DB are distinguished by this network ID.
e - - An instance of ELMBT which we'll use for I/O.
p - - An instance of PIDDecoder. We register ourself with this piddecoder so they can pass us requests.
Method Detail

getCurrentState

public int getCurrentState()

getCurrentStateByName

public java.lang.String getCurrentStateByName()
Returns:
- returns a string representation of the current state.

startStateManagementThread

public boolean startStateManagementThread()
defines and starts the state management thread.

Returns:
- returns true if we successfully started the thread. False if it was already running or we couldn't start it.

setOnStateChangedListener

public void setOnStateChangedListener(EventCallback newStateChangeListener)
Define a method that you want to be executed any time the OBD2 state changes.

Parameters:
newStateChangeListener - - an instance of EventCallback with onStateChange() defined (overridden).

registerOnStateChangedListener

public void registerOnStateChangedListener(EventCallback newStateChangeListener)
Convenience method that wraps the setOnStateChangedListener.

Parameters:
newStateChangeListener -

registerMessageCallback

public void registerMessageCallback(EventCallback eventCallback)
A means for a parent class to receive messages generated by this class. Very useful for debugging.

Parameters:
eventCallback - - override the newMessage() method.

shutdown

public void shutdown()
Shutdown threads and clean up.


getDashDB

public DashDB getDashDB()
Returns a handle to the local DashDB instance...

Returns:

obdCommand

public java.lang.String obdCommand(java.lang.String obdRequest)
Sends the specified OBD Command and obtains the response. This shall be the lowest level OBD commanding method available and thus it is synchronized for thread safety.

Parameters:
obdRequest - - raw request without the CR/LF.
Returns:
- returns the raw response from the device, up to the prompt character ('>').

sendATCommand

public java.lang.String sendATCommand(java.lang.String ATCommand)
Allow the sending of AT commands... if the conditions are appropriate.

Parameters:
ATCommand -
Returns:

sendOBDRequestByName

public java.util.HashMap<java.lang.String,java.lang.String> sendOBDRequestByName(java.lang.String dataPointName)
** Intended to be called by piddecoder, not you... use piddecoder's "getDataViaOBD" to get OBD2 data.

Parameters:
dataPointName - - the data point name for which we want data.
Returns:
- returns a hashmap containing all DECODED responses. K=ECU, V=(decoded) Data.

isIODoneTrying

public boolean isIODoneTrying()
Returns:
- returns true if the IO layer is done trying to reconnect.

setIOReconnectNOW

public void setIOReconnectNOW()
Will kick the I/O Layer into trying to connect again.


sendDTCReset

public java.lang.String sendDTCReset()

_suspend

public boolean _suspend()
Suspend operations by this class/session and return the network to a usable state for others. We will go to sleep as long as we're suspended.

Returns:
- true on success, false otherwise. Re-entrant: no

resume

public boolean resume()
Resume from a suspended state - re-initialize the device in a way that ensures that it is ready for our state.

Returns:
- true on success, false otherwise. Re-entrant: no

getStats

public GeneralStats getStats()

getOBDProtocol

public java.lang.String getOBDProtocol()
Call this AFTER you detect that the session state is in OBDconnected state.

Returns:
- returns the OBD protocol that was detected upon successful connection, or a blank string if none was detected.