com.gtosoft.libvoyager.util
Class PIDDecoder

java.lang.Object
  extended by com.gtosoft.libvoyager.util.PIDDecoder

public class PIDDecoder
extends java.lang.Object

Author:
brad

Constructor Summary
PIDDecoder(DashDB d)
          A simple constructor.
 
Method Summary
 boolean decodeOneMessage(java.lang.String m)
          Process a single sniffed PID message.
 java.util.HashMap<java.lang.String,java.lang.String> getAllDatapoints()
           
 java.lang.String getCachedDataByName(java.lang.String dataPointName)
          Goes to the local cache and looks for the specified datapoint name.
 java.lang.String getDataViaOBD_singleNode(java.lang.String DPN)
          Convenience method to make a request, and if we get a response from multiple ECUs, we just return the first.
 java.lang.String getDataViaOBD(java.lang.String dataPointName)
          Contacts the OBD2 layer, asks it to send an OBD request, and get the response.
 java.lang.String getMoniNetFingerprint()
          You must be in CAN monitor/passive mode, collecting data.
 NetworkStats getNetworkStats()
          Public interface to our stats calculation logic.
 java.lang.String getPIDDataByName(java.lang.String dataPointName)
          Convenience method that just calls getCachedDataByName.
 GeneralStats getStats()
          Passes a reference to our stats class up to a calling class.
 boolean injectTestData()
          Inject test data into the stream of PIDs we're supposedly reading from the device.
 void registerNewDataArrivedHandler(EventCallback ecb)
           
 void registerNewMessageHandler(EventCallback ecb)
           
 void registerOBD2SessionLayer(OBD2Session o)
           
 void registerOnDPArrivedCallback(EventCallback newDPArrivedHandler)
          Define an eventCallback with the onDPArrived method overridden to receive a callback every time a datapoint is decoded.
 void reset()
          Reset things like the PID hashmap for a new use.
 boolean sendOBDRequestByName(java.lang.String dataPointName)
          Send an OBD2 PID request.
 void setNetworkID(java.lang.String newNetworkID)
          Change the network ID at runtime.
 void shutdown()
          call this method to initiate a stop/shutdown of all threads and running tasks owned by this class instance.
 void stopInjectingTestData()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PIDDecoder

public PIDDecoder(DashDB d)
A simple constructor.

Parameters:
d - - An existing DashDB instance.
Method Detail

reset

public void reset()
Reset things like the PID hashmap for a new use. also resets stats.


setNetworkID

public void setNetworkID(java.lang.String newNetworkID)
Change the network ID at runtime.

Parameters:
newNetworkID -

decodeOneMessage

public boolean decodeOneMessage(java.lang.String m)
Process a single sniffed PID message. This is the entry-point into the class for new sniffed data.

Parameters:
m - - the message as sniffed.
Returns:
- returns true unless there was a problem processing the message.

registerOBD2SessionLayer

public void registerOBD2SessionLayer(OBD2Session o)

registerNewMessageHandler

public void registerNewMessageHandler(EventCallback ecb)

registerNewDataArrivedHandler

public void registerNewDataArrivedHandler(EventCallback ecb)

shutdown

public void shutdown()
call this method to initiate a stop/shutdown of all threads and running tasks owned by this class instance. The class will no longer be usable after a shutdown - re-instantiate it for use after a shutdown.


getDataViaOBD

public java.lang.String getDataViaOBD(java.lang.String dataPointName)
Contacts the OBD2 layer, asks it to send an OBD request, and get the response. We will then decode the response and return it as a string.

Returns:

getCachedDataByName

public java.lang.String getCachedDataByName(java.lang.String dataPointName)
Goes to the local cache and looks for the specified datapoint name. If found, it is returned right out of the cache. Note that the cache could be any age, we're not checking.


getPIDDataByName

public java.lang.String getPIDDataByName(java.lang.String dataPointName)
Convenience method that just calls getCachedDataByName. So that we have a get/set for DataByName.

Parameters:
dataPointName -
Returns:

sendOBDRequestByName

public boolean sendOBDRequestByName(java.lang.String dataPointName)
Send an OBD2 PID request. The response will be propagated through the event system. In other words, to get the data, Register/Subscribe to the DPArrived event.

Parameters:
dataPointName -
Returns:

getAllDatapoints

public java.util.HashMap<java.lang.String,java.lang.String> getAllDatapoints()

registerOnDPArrivedCallback

public void registerOnDPArrivedCallback(EventCallback newDPArrivedHandler)
Define an eventCallback with the onDPArrived method overridden to receive a callback every time a datapoint is decoded.

Parameters:
newDPArrivedHandler -

injectTestData

public boolean injectTestData()
Inject test data into the stream of PIDs we're supposedly reading from the device. We will read that test data from a file on the device called /sdcard/Dash/replaylog This file is NOT distributed with Voyager.


stopInjectingTestData

public void stopInjectingTestData()

getNetworkStats

public NetworkStats getNetworkStats()
Public interface to our stats calculation logic.

Returns:

getStats

public GeneralStats getStats()
Passes a reference to our stats class up to a calling class.

Returns:
- returns a collection of our stats and those collected from our children.

getMoniNetFingerprint

public java.lang.String getMoniNetFingerprint()
You must be in CAN monitor/passive mode, collecting data. This method blocks for a while - possibly 60 seconds, to wait for the network to settle. Returns a "fingerprint" of the network. The finterprint should be sufficiently unique to uniquely identify the protocol (GM/Toyota/Ford, etc) in use on the network.

Returns:
- blank string ("") on error, or a string describing the network... (the "fingerprint")

getDataViaOBD_singleNode

public java.lang.String getDataViaOBD_singleNode(java.lang.String DPN)
Convenience method to make a request, and if we get a response from multiple ECUs, we just return the first.

Parameters:
DPN - (data point name)
Returns:
- returns the response from the first ECU. Could be different ECU across multiple requets for the same DPN.