com.gtosoft.libvoyager.db
Class DashDB

java.lang.Object
  extended by SQLiteOpenHelper
      extended by com.gtosoft.libvoyager.db.DashDB

public class DashDB
extends SQLiteOpenHelper

A Class to facilitate Dash related database queries. This class will be responsible` for fetching data from the database if necessary and caching it locally in hashmaps. Upon fetching an item from the DB, assume it won't chnage and read from hashmap. Include a method to reload hashmaps (invalidate all cached data) The DB will get overwritten on upgrade or reinstall. we're assuming no persistently needed data will be stored here.


Field Summary
static java.lang.String DB_NAME
           
static int DB_VERSION
           
static int DPS_FIELD_DPN
           
static int DPS_FIELD_FORMULA
           
static int DPS_FIELD_SIGBYTES
           
static int OBD_CACHEFIELD_DATASHORTNAME
           
static int OBD_CACHEFIELD_DESCRIPTION
           
static int OBD_CACHEFIELD_DPN
           
static int OBD_CACHEFIELD_FORMULA
           
static int OBD_CACHEFIELD_MAXVALUE
           
static int OBD_CACHEFIELD_MINVALUE
           
static int OBD_CACHEFIELD_REQUEST
           
static java.lang.String SCHEMA_ASSET_FILE_NAME
           
 
Constructor Summary
DashDB(Context context)
          Main constructor.
 
Method Summary
 boolean addMonitorRecord(java.lang.String sessionID, java.lang.String timeStamp, java.lang.String header, java.lang.String oldData, java.lang.String newData, long numChanges, long changeRate, long transmitRate, long numTransmits)
           
 boolean backupDB(java.lang.String optionalName)
           
 void clearCachedNetworkIDData()
          Clear any cached data based on NetworkID.
 void dbMsg(java.lang.String msg)
           
 java.util.Set<java.lang.String> getAllDPNNetIDs()
           
 Cursor getAllPassiveDPNs()
          Returns a list of ACTIVE (scannable) obd request records.
 java.util.Set<java.lang.String> getColumnSet(java.lang.String SQLQuery)
          This method builds a hashset containing the value of column 0 of each record, if that record contains something.
 java.lang.String getCommandByName(java.lang.String commandName)
          Given a command name, we assume networkID 01 (SWCAN) We do a lookup and return the command(s) to send for this command.
 Cursor getCommandRecords()
           
 Cursor getConvBaselineRecords()
          For use in baseline testing.
 java.util.Set<java.lang.String> getDataPointNamesSet(java.lang.String whichNetwork)
          Returns a set containing all the datapoint names in the database for the given network.
 java.util.Set<java.lang.String> getDPNCANIDsForNetworkID(java.lang.String networkID)
           
 java.lang.String[][] getDPSForHDR(java.lang.String networkID, java.lang.String HDR)
          This method will look up the given header in the dataPoint table of the database.
 java.lang.String getFormula(java.lang.String network, java.lang.String dataPointName)
          Returns the formula for the given datapoint name.
 java.lang.String getHeaderWithSigBytes(java.lang.String network, java.lang.String dataPointName)
          This method will be used when the calling class wants to search its data for the given data point but their data is arranged by header+sig.
 java.lang.String getHeaderWithSigBytes(java.lang.String network, java.lang.String header, java.lang.String data)
          To know how many data bytes to append, we look up the pid in the database
 java.lang.String getNextMonitorSessionID(java.lang.String startTime)
          Get the next monitor session ID in the DB.
 Cursor getOBDActiveRequests()
          Returns a list of ACTIVE (scannable) obd request records.
 java.util.Set<java.lang.String> getOBDDatapoints()
          returns a Set containing all the datapoints defined for OBD.
 java.lang.String getOBDFormulaByName(java.lang.String DPN)
           
 double getOBDMaxValue(java.lang.String DPN)
           
 double getOBDMinValue(java.lang.String DPN)
           
 java.lang.String getOBDRequestByName(java.lang.String DPN)
           
 java.lang.String getOBDShortName(java.lang.String DPN)
           
 java.lang.String getProfileValue(java.lang.String proType, java.lang.String proSubType, java.lang.String proKey)
           
 int getSigByteCount(java.lang.String network, java.lang.String header)
           
 GeneralStats getStats()
           
 boolean isDBReady()
           
 boolean mkdir(java.lang.String directory)
          Create the specified directory (the last part of the path only, not the whole tree).
 void onCreate(SQLiteDatabase db)
           
 void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
           
static void safeSleep(int numSeconds)
           
static double safeStringToDouble(java.lang.String doublestring)
           
 boolean setMonitorSessionStopTime(java.lang.String sessionID, java.lang.String stopTime)
           
 boolean setProfileValue(java.lang.String proType, java.lang.String proSubType, java.lang.String proKey, java.lang.String proValue)
           
 void setUSUnits(boolean trueIfConvertToUS)
           
 void shutdown()
           
 java.lang.String X_getOBDFieldByName(java.lang.String fieldName, java.lang.String dataPointName)
          Returns the string value of a specified field, as identified by its datapointname.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCHEMA_ASSET_FILE_NAME

public static final java.lang.String SCHEMA_ASSET_FILE_NAME
See Also:
Constant Field Values

OBD_CACHEFIELD_DPN

public static final int OBD_CACHEFIELD_DPN
See Also:
Constant Field Values

OBD_CACHEFIELD_DATASHORTNAME

public static final int OBD_CACHEFIELD_DATASHORTNAME
See Also:
Constant Field Values

OBD_CACHEFIELD_REQUEST

public static final int OBD_CACHEFIELD_REQUEST
See Also:
Constant Field Values

OBD_CACHEFIELD_FORMULA

public static final int OBD_CACHEFIELD_FORMULA
See Also:
Constant Field Values

OBD_CACHEFIELD_DESCRIPTION

public static final int OBD_CACHEFIELD_DESCRIPTION
See Also:
Constant Field Values

OBD_CACHEFIELD_MINVALUE

public static final int OBD_CACHEFIELD_MINVALUE
See Also:
Constant Field Values

OBD_CACHEFIELD_MAXVALUE

public static final int OBD_CACHEFIELD_MAXVALUE
See Also:
Constant Field Values

DB_NAME

public static final java.lang.String DB_NAME
See Also:
Constant Field Values

DB_VERSION

public static final int DB_VERSION
See Also:
Constant Field Values

DPS_FIELD_SIGBYTES

public static final int DPS_FIELD_SIGBYTES
See Also:
Constant Field Values

DPS_FIELD_DPN

public static final int DPS_FIELD_DPN
See Also:
Constant Field Values

DPS_FIELD_FORMULA

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

DashDB

public DashDB(Context context)
Main constructor.

Parameters:
context -
Method Detail

safeSleep

public static void safeSleep(int numSeconds)

getSigByteCount

public int getSigByteCount(java.lang.String network,
                           java.lang.String header)
Returns:
- the number of data bytes, starting from the first, leftmost one, which need to be appended to the header to make the data unique. In other words, some PIDs contain two or more different data points even though they come from the same PID. This method scans the dataPoint table for the given network and header and returns the longest sigBytes legnth.

getFormula

public java.lang.String getFormula(java.lang.String network,
                                   java.lang.String dataPointName)
Returns the formula for the given datapoint name.

Parameters:
network - - the network from network table. 01 = SWCAN.
dataPointName - - datapointname
Returns:
- returns the formula, such as: 33-63,ONSTAR_LAT or 32-32,BIT

getHeaderWithSigBytes

public java.lang.String getHeaderWithSigBytes(java.lang.String network,
                                              java.lang.String header,
                                              java.lang.String data)
To know how many data bytes to append, we look up the pid in the database

Parameters:
header -
data -
Returns:

getHeaderWithSigBytes

public java.lang.String getHeaderWithSigBytes(java.lang.String network,
                                              java.lang.String dataPointName)
This method will be used when the calling class wants to search its data for the given data point but their data is arranged by header+sig.

Parameters:
dataPointName -
Returns:

getDataPointNamesSet

public java.util.Set<java.lang.String> getDataPointNamesSet(java.lang.String whichNetwork)
Returns a set containing all the datapoint names in the database for the given network.

Returns:

backupDB

public boolean backupDB(java.lang.String optionalName)

dbMsg

public void dbMsg(java.lang.String msg)

isDBReady

public boolean isDBReady()
Returns:
- true if DB ready for use, false otherwise.

onCreate

public void onCreate(SQLiteDatabase db)

onUpgrade

public void onUpgrade(SQLiteDatabase db,
                      int oldVersion,
                      int newVersion)

mkdir

public boolean mkdir(java.lang.String directory)
Create the specified directory (the last part of the path only, not the whole tree).

Parameters:
directory - - directory, for example: /sdcard/Dash
Returns:
- returns true on success, false otherwise.

getOBDRequestByName

public java.lang.String getOBDRequestByName(java.lang.String DPN)

getOBDFormulaByName

public java.lang.String getOBDFormulaByName(java.lang.String DPN)

getOBDShortName

public java.lang.String getOBDShortName(java.lang.String DPN)

getOBDMinValue

public double getOBDMinValue(java.lang.String DPN)

getOBDMaxValue

public double getOBDMaxValue(java.lang.String DPN)

setUSUnits

public void setUSUnits(boolean trueIfConvertToUS)

safeStringToDouble

public static double safeStringToDouble(java.lang.String doublestring)
Parameters:
doublestring -
Returns:

getConvBaselineRecords

public Cursor getConvBaselineRecords()
For use in baseline testing.

Returns:
- returns a cursor containing all fields and all records of the convBaseline table. The return value will be null in the event of an error.

shutdown

public void shutdown()

getOBDDatapoints

public java.util.Set<java.lang.String> getOBDDatapoints()
returns a Set containing all the datapoints defined for OBD.

Returns:

getCommandByName

public java.lang.String getCommandByName(java.lang.String commandName)
Given a command name, we assume networkID 01 (SWCAN) We do a lookup and return the command(s) to send for this command.


getCommandRecords

public Cursor getCommandRecords()

getNextMonitorSessionID

public java.lang.String getNextMonitorSessionID(java.lang.String startTime)
Get the next monitor session ID in the DB. That means create one.


addMonitorRecord

public boolean addMonitorRecord(java.lang.String sessionID,
                                java.lang.String timeStamp,
                                java.lang.String header,
                                java.lang.String oldData,
                                java.lang.String newData,
                                long numChanges,
                                long changeRate,
                                long transmitRate,
                                long numTransmits)

setMonitorSessionStopTime

public boolean setMonitorSessionStopTime(java.lang.String sessionID,
                                         java.lang.String stopTime)

setProfileValue

public boolean setProfileValue(java.lang.String proType,
                               java.lang.String proSubType,
                               java.lang.String proKey,
                               java.lang.String proValue)

getProfileValue

public java.lang.String getProfileValue(java.lang.String proType,
                                        java.lang.String proSubType,
                                        java.lang.String proKey)

X_getOBDFieldByName

public java.lang.String X_getOBDFieldByName(java.lang.String fieldName,
                                            java.lang.String dataPointName)
Returns the string value of a specified field, as identified by its datapointname.

Parameters:
fieldName -
dataPointName -
Returns:

getColumnSet

public java.util.Set<java.lang.String> getColumnSet(java.lang.String SQLQuery)
This method builds a hashset containing the value of column 0 of each record, if that record contains something.

Parameters:
SQLQuery -
Returns:
- always returns a set. That set may contain zero or more elements.

getOBDActiveRequests

public Cursor getOBDActiveRequests()
Returns a list of ACTIVE (scannable) obd request records.

Returns:
- returns a cursor covering those records. fields: id, dataPointName, request, description. Used by the preferences dialog to display a list of available OBD2 datapoints.

getAllPassiveDPNs

public Cursor getAllPassiveDPNs()
Returns a list of ACTIVE (scannable) obd request records.

Returns:
- returns a cursor covering those records. fields: id, dataPointName, request, description.

getDPSForHDR

public java.lang.String[][] getDPSForHDR(java.lang.String networkID,
                                         java.lang.String HDR)
This method will look up the given header in the dataPoint table of the database. It will return a 2-dimensional (say X and Y) string array: X = zero or more instances of block Y to be searched for the given PID. Y = Sigbytes, DPN (Datapoint Name), Formula - The String array indices will be defined in DashDB.DPS_FIELD_XXXX - This will be used by the PIDDecoder class to extract data points from data packets.

Parameters:
HDR - - the 29 or 11-bit CAN header such as "10 00 20 40" or "199"...
Returns:
- - Returns a reference to the string array containing key information necessary for decoding/identifying the datapoint. - Returns null if there are no DPNs for the given header.

clearCachedNetworkIDData

public void clearCachedNetworkIDData()
Clear any cached data based on NetworkID. This will be called by parent if the network ID changes.


getStats

public GeneralStats getStats()

getAllDPNNetIDs

public java.util.Set<java.lang.String> getAllDPNNetIDs()
Returns:
- returns a set containing all network IDs present in the dataPoint table.

getDPNCANIDsForNetworkID

public java.util.Set<java.lang.String> getDPNCANIDsForNetworkID(java.lang.String networkID)
Parameters:
networkID - - the NetworkID for which you want all the known CAN IDs as seen in the dataPoint table of the database.
Returns:
- returns a distinct Set containing zero or more elements corresponding to all CAN IDs known for that Network ID.