bt747.model
Class Controller

java.lang.Object
  extended by bt747.model.Controller
All Implemented Interfaces:
ModelListener
Direct Known Subclasses:
AppController, J2SEController

public class Controller
extends java.lang.Object
implements ModelListener

Author:
Mario De Weerd, Florian Unger for indicated parts.

Constructor Summary
Controller()
          Currently needed because class is extended.
Controller(Model model)
           
 
Method Summary
static void addLogFile(BT747Path path)
           
 void addWayPointStyle(WayPointStyle style)
           
 void cancelGetLog()
          Cancel the log download process.
 void closeGPS()
          Close the GPS connection.
 void connectGPS()
          Connect to the GPS (open the serial connection).
 int doConvertLog(int logType)
          Convert the log given the provided parameters using other methods.
 int doConvertLog(int logOutType, GPSFileInterface gpsFile, java.lang.String ext)
           
 GPSRecord[] doConvertLogToTrackPoints()
          Convert the log into an array of trackpoints.
 TracksAndWayPoints doConvertLogToTracksAndWayPoints()
           
 void eraseLog()
          Do the actual erase.
 int getHeightReference(int logType)
           
 GPSLogConvertInterface getInputConversionInstance()
           
 GPSLogConvertInterface getInputConversionInstance(int logOutType)
           
 int getLastError()
           
 java.lang.String getLastErrorInfo()
           
 GPSFilter[] getLogFiltersToUse()
           
 Model getModel()
           
 java.lang.String getOutFileExt(int logType)
           
 GPSFile getOutFileHandler(int logType)
           
 GPSRecord[] getUserWayPoints()
           
 void gpsCmd(int cmd)
          Do a GPS command.
 void gpsCmd(int cmd, CmdParam param)
          Do a GPS command.
 void init()
          Called when the Controller starts.
 boolean isEnableStoreOK()
           
 boolean isLocationServingActive()
          Check whether location updates currently are sent out to external servers.
 void logImmediate(int value)
          Force the logger to record the current position tagged with the given log reason.
 void modelEvent(ModelEvent e)
           
 void openFreeTextPort(java.lang.String portName)
          Select a port by its 'path' (/dev/usb9 for example or /dev/com1.
 void performOperationsAfterGPSConnect()
          This does a number of operations once the GPS is effectively connected.
 void recoveryEraseLog()
          A 'recovery Erase' attempts to recover memory that was previously identified as 'bad'.
 void replyToOkToOverwrite(boolean isOkToOverwrite)
          The GpsModel is waiting for a reply to the question if the currently existing log with different data can be overwritten.
 void reqDeviceInfo()
          Request a set of device information from the GPS device that can be after specific GpsEvent events.
 void reqSettingsForStorage()
           
 void resetFilters()
           
 void restoreSetting1()
           
 void saveSettings()
          Save all the user settings to disk.
 void sendBT747Exception(BT747Exception e)
           
 void sendCmd(GpsLinkExecCommand cmd)
          Send an arbitrary GPS command.
 void setAgpsData(byte[] agpsData)
           
 void setAutoFetch(boolean isAuto)
          Some data will be constantly requested from the device to keep it up to date in the application.
 void setAutoLog(boolean enable)
           
 void setBaudRate(int baudRate)
          Sets the port's speed (baud rate).
 void setBluetooth()
          open a Bluetooth connection Calls getStatus to request initial parameters from the device.
 void setBooleanOpt(int param, boolean value)
           
 void setBTMacAddr(java.lang.String btMacAddr)
          Sets the MAC address for bluetooth (for devices that support it).
 void setChunkSize(int chunkSize)
           
 void setDatumMode(int mode)
          Set GPS's Datum mode.
 void setDebug(boolean isDebugActive)
          Set the general debugging state.
 void setDebugConn(boolean isConnDebugActive)
          Set the debugging state of the connection.
 void setDGPSMode(int mode)
          Set the DGPS mode to use when SBAS enabled.
 void setDownloadMethod(int downloadMethod)
          Set the download method.
 void setDownloadTimeOut(int timeout)
           
 void setFileNameBuilder(BT747FileName builder)
           
 void setFilterEndTime(int d)
           
 void setFilters()
           
 void setFilterStartTime(int d)
           
 void setFixInterval(int value)
           
 void setFlashUserOption(boolean lock, int updateRate, int baudRate, int periodGLL, int periodRMC, int periodVTG, int periodGSA, int periodGSV, int periodGGA, int periodZDA, int periodMCHN)
          This sets MTK specific settings into its flash.
 void setFloatOpt(int param, float value)
           
 void setGpsDecode(boolean value)
           
 void setHoluxName(java.lang.String deviceName)
          Set the textual description of the device.
 void setIncremental(boolean incrementalDownload)
          Deprecated. Use setDownloadMethod(int) instead
 void setIntOpt(int param, int value)
           
 void setLogDistanceInterval(int value)
           
 void setLogFormat(int newLogFormat)
          Sets a new log format on the device.
 void setLoggingActive(boolean on)
          Set logging status of device.
 void setLogOverwrite(boolean isOverWriteLog)
          Set log overwrite mode on the device.
 void setLogRequestAhead(int numberOfRequestsAhead)
           
 void setLogSpeedInterval(int value)
           
 void setLogTimeInterval(int value)
           
 void setModel(Model model)
           
 void setMtkDataNeeded(int dataType)
          Indicates that some data is needed from the MtkDevice.
 void setNMEADefaultPeriods()
          Sets default NMEA periods (as observed on one iBlue 747 device).
 void setNMEAPeriods(int[] periods)
          Set the NMEA period settings of the device.
 void setNMEAset(int formatNMEA)
          Sets the NMEA string types to write to the NMEA output file format.
 void setOutputFileRelPath(java.lang.String s)
          Set the output file path (including basename, no extension) relative to the BaseDirPath.
 void setPort(int port)
          open a connection on the given port number.
 void setPowerSaveEnabled(boolean set)
          Enable the power save mode on the device - this setting is untested.
 void setSBASEnabled(boolean set)
          Enable SBAS (DGPS).
 void setSBASTestEnabled(boolean isSBASTestEnabled)
          Sets the enable of SBAS (DGPS) satellites that are in test.
 void setStats(boolean b)
           
 void setStringOpt(int param, java.lang.String value)
           
 void setUsb()
          open a Usb connection Calls getStatus to request initial parameters from the device.
 void setUserWayPoints(GPSRecord[] rcrds)
           
 void setWayPointStyles(WayPointStyleSet set)
           
 void startDefaultDownload()
          Start the default log download process without taking into account the device type.
 void startDownload()
          Start the log download process.
 void startGPSPositionServing()
          If there is no LocationSender yet registered with the Model create such a LocationSender and register it with the Model so that it starts sending out position updates.
 void startWPDownload()
          Initiate the download of a 'Wonde Proud' log.
 void stopErase()
          The log is being erased - the user request to abandon waiting for the end of this operation.
 void stopGPSPositionServing()
          If there is a LocationSender currently registered as Listener with the Model of this instance then remove it from the Listeners of the Model and set registeredLocSender to null.
 void stopLogConvert()
          Stop the conversion that is ongoing.
 void storeSetting1()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Controller

public Controller(Model model)
Parameters:
model - The model to associate with this controller.

Controller

public Controller()
Currently needed because class is extended.

Method Detail

setModel

public void setModel(Model model)

getModel

public Model getModel()

modelEvent

public void modelEvent(ModelEvent e)
Specified by:
modelEvent in interface ModelListener

setAutoLog

public final void setAutoLog(boolean enable)

init

public void init()
Called when the Controller starts. Used for initialization.


gpsCmd

public void gpsCmd(int cmd)
Do a GPS command.

Parameters:
cmd -

gpsCmd

public void gpsCmd(int cmd,
                   CmdParam param)
Do a GPS command.

Parameters:
cmd -

setOutputFileRelPath

public final void setOutputFileRelPath(java.lang.String s)
Set the output file path (including basename, no extension) relative to the BaseDirPath.

Parameters:
s - The relative log file path (including basename)

setChunkSize

public final void setChunkSize(int chunkSize)
Parameters:
chunkSize - The amount of data that is requested from the device in a single command when downloading the data.

setDownloadTimeOut

public final void setDownloadTimeOut(int timeout)
Parameters:
timeout - The timeout in ms after which the lack of reply from the device will be considered as a communication failure. Depending on the operation, a recovery will be attempted.

setLogRequestAhead

public final void setLogRequestAhead(int numberOfRequestsAhead)
Parameters:
numberOfRequestsAhead - Especially when downloading using Bluetooth, downloading is slow when no request pipeline is implemented. This number defines how many 'chunk download' request will be sent to device while the first reply is still pending.

stopLogConvert

public final void stopLogConvert()
Stop the conversion that is ongoing.


setFileNameBuilder

public final void setFileNameBuilder(BT747FileName builder)

setWayPointStyles

public final void setWayPointStyles(WayPointStyleSet set)

addWayPointStyle

public final void addWayPointStyle(WayPointStyle style)

getOutFileHandler

public final GPSFile getOutFileHandler(int logType)

getOutFileExt

public java.lang.String getOutFileExt(int logType)

doConvertLog

public final int doConvertLog(int logType)
Convert the log given the provided parameters using other methods.

Parameters:
logType - Indicates the type of log that should be written. For example Model.CSV_LOGTYPE .
Returns:
0 if success, otherwise an error was encountered (error number returned and related text in getLastErrorInfo()
See Also:
Model.CSV_LOGTYPE, Model.TRK_LOGTYPE, Model.KML_LOGTYPE, Model.PLT_LOGTYPE, Model.GPX_LOGTYPE, Model.NMEA_LOGTYPE, Model.GMAP_LOGTYPE

getHeightReference

public int getHeightReference(int logType)

getInputConversionInstance

public GPSLogConvertInterface getInputConversionInstance(int logOutType)

getInputConversionInstance

public final GPSLogConvertInterface getInputConversionInstance()

getLogFiltersToUse

public final GPSFilter[] getLogFiltersToUse()

setUserWayPoints

public final void setUserWayPoints(GPSRecord[] rcrds)

getUserWayPoints

public final GPSRecord[] getUserWayPoints()

doConvertLog

public final int doConvertLog(int logOutType,
                              GPSFileInterface gpsFile,
                              java.lang.String ext)

doConvertLogToTrackPoints

public final GPSRecord[] doConvertLogToTrackPoints()
Convert the log into an array of trackpoints.

Returns:
Array of selected trackpoints.

doConvertLogToTracksAndWayPoints

public final TracksAndWayPoints doConvertLogToTracksAndWayPoints()

setIncremental

public final void setIncremental(boolean incrementalDownload)
Deprecated. Use setDownloadMethod(int) instead

Set the 'incremental download' configuration.

Parameters:
incrementalDownload - true if the log download should be incremental.

setDownloadMethod

public final void setDownloadMethod(int downloadMethod)
Set the download method.
Possible values:


cancelGetLog

public final void cancelGetLog()
Cancel the log download process.


startDownload

public final void startDownload()
Start the log download process.


startDefaultDownload

public final void startDefaultDownload()
Start the default log download process without taking into account the device type.


replyToOkToOverwrite

public final void replyToOkToOverwrite(boolean isOkToOverwrite)
                                throws BT747Exception
The GpsModel is waiting for a reply to the question if the currently existing log with different data can be overwritten. This method must be called to replay to this question which is in principle the result of a user reply to a message box.

Parameters:
isOkToOverwrite - If true, the existing log can be overwritten
Throws:
BT747Exception

stopErase

public final void stopErase()
The log is being erased - the user request to abandon waiting for the end of this operation.


startWPDownload

public final void startWPDownload()
Initiate the download of a 'Wonde Proud' log.


setLoggingActive

public final void setLoggingActive(boolean on)
Set logging status of device.

Parameters:
on - When true, logging will be turned on.

setMtkDataNeeded

public final void setMtkDataNeeded(int dataType)
Indicates that some data is needed from the MtkDevice. This will eventually issue a request to the device.

Parameters:
dataType -

setLogOverwrite

public final void setLogOverwrite(boolean isOverWriteLog)
Set log overwrite mode on the device.

Parameters:
isOverWriteLog - true - overwrite data in device when full false - stop logging when device is full

reqDeviceInfo

public final void reqDeviceInfo()
Request a set of device information from the GPS device that can be after specific GpsEvent events.


setLogFormat

public final void setLogFormat(int newLogFormat)
Sets a new log format on the device.

Parameters:
newLogFormat -
The bits in the newLogFormat can be defined using a bitwise OR of expressions like
(1<< IDX)
where IDX is one of the following:
- BT747Constants.FMT_UTC_IDX
- BT747Constants.FMT_VALID_IDX
- BT747Constants.FMT_LATITUDE_IDX
- BT747Constants.FMT_LONGITUDE_IDX
- BT747Constants.FMT_HEIGHT_IDX
- BT747Constants.FMT_SPEED_IDX
- BT747Constants.FMT_HEADING_IDX
- BT747Constants.FMT_DSTA_IDX
- BT747Constants.FMT_DAGE_IDX
- BT747Constants.FMT_PDOP_IDX
- BT747Constants.FMT_HDOP_IDX
- BT747Constants.FMT_VDOP_IDX
- BT747Constants.FMT_NSAT_IDX
- BT747Constants.FMT_SID_IDX
- BT747Constants.FMT_ELEVATION_IDX
- BT747Constants.FMT_AZIMUTH_IDX
- BT747Constants.FMT_SNR_IDX
- BT747Constants.FMT_RCR_IDX
- BT747Constants.FMT_MILLISECOND_IDX
- BT747Constants.FMT_DISTANCE_IDX
- BT747Constants.FMT_LOG_PTS_WITH_VALID_FIX_ONLY_IDX

eraseLog

public final void eraseLog()
Do the actual erase.


recoveryEraseLog

public final void recoveryEraseLog()
A 'recovery Erase' attempts to recover memory that was previously identified as 'bad'.


connectGPS

public final void connectGPS()
Connect to the GPS (open the serial connection).


closeGPS

public final void closeGPS()
Close the GPS connection.


sendCmd

public final void sendCmd(GpsLinkExecCommand cmd)
Send an arbitrary GPS command.

Parameters:
cmd - Otherwise the class must be an implementation of GpsLinkExecCommand.

setAutoFetch

public final void setAutoFetch(boolean isAuto)
Some data will be constantly requested from the device to keep it up to date in the application. When inactive the benefit is that the application fully controls what happens on the serial link.

Parameters:
isAuto - When true, the data is fetched automatically.

setBluetooth

public final void setBluetooth()
open a Bluetooth connection Calls getStatus to request initial parameters from the device. Set up the timer to regurarly poll the connection for data.


setUsb

public final void setUsb()
open a Usb connection Calls getStatus to request initial parameters from the device. Set up the timer to regurarly poll the connection for data.


setPort

public final void setPort(int port)
open a connection on the given port number. Calls getStatus to request initial parameters from the device. Set up the timer to regurarly poll the connection for data.

Parameters:
port - Port number to open

setBaudRate

public final void setBaudRate(int baudRate)
Sets the port's speed (baud rate).

Parameters:
baudRate - The baud rate to set.

openFreeTextPort

public final void openFreeTextPort(java.lang.String portName)
Select a port by its 'path' (/dev/usb9 for example or /dev/com1.

Parameters:
portName - The path to the port.

performOperationsAfterGPSConnect

public void performOperationsAfterGPSConnect()
This does a number of operations once the GPS is effectively connected. Can be extended by the application. It gets certain informations required by the application. It stores the settings related to the port (since the connection was successful) and starts of the Model to do port queries.


setDebugConn

public final void setDebugConn(boolean isConnDebugActive)
Set the debugging state of the connection.

Parameters:
isConnDebugActive - When true, the connection debug information is active.

saveSettings

public void saveSettings()
Save all the user settings to disk.


setDebug

public final void setDebug(boolean isDebugActive)
Set the general debugging state.

Parameters:
isDebugActive - If true, activate general debug.
See Also:
for other debug functionality.

resetFilters

public final void resetFilters()

setFlashUserOption

public final void setFlashUserOption(boolean lock,
                                     int updateRate,
                                     int baudRate,
                                     int periodGLL,
                                     int periodRMC,
                                     int periodVTG,
                                     int periodGSA,
                                     int periodGSV,
                                     int periodGGA,
                                     int periodZDA,
                                     int periodMCHN)
This sets MTK specific settings into its flash.
The MTK device stores a number of settings in its internal flash which is different from the log memory. These settings are restored after loss of power for example.

Parameters:
lock - When true, subsequent changes in these settings will be impossible.
updateRate - The 'fix period' of the GPS in ms. When this is 200, then the Fix is 5Hz.
baudRate - The speed of the serial communication of the MTK chipset. Be carefull - this may be the internal speed - not the external speed!
periodGLL - The period of emission of the GLL sentence (relative to the fix).
periodRMC - The period of emission of the RMC sentence (relative to the fix).
periodVTG - The period of emission of the VTG sentence (relative to the fix).
periodGSA - The period of emission of the GSA sentence (relative to the fix).
periodGSV - The period of emission of the GSV sentence (relative to the fix).
periodGGA - The period of emission of the GGA sentence (relative to the fix).
periodZDA - The period of emission of the ZDA sentence (relative to the fix).
periodMCHN - The period of emission of the MCHN sentence (relative to the fix).

setBTMacAddr

public final void setBTMacAddr(java.lang.String btMacAddr)
Sets the MAC address for bluetooth (for devices that support it).

Parameters:
btMacAddr - The Mac address to set in the following format:
00:1F:14:15:12:13.

setHoluxName

public final void setHoluxName(java.lang.String deviceName)
Set the textual description of the device. Currently supported by Holux devices.

Parameters:
deviceName - The string to set as the Device Name.

setNMEAPeriods

public final void setNMEAPeriods(int[] periods)
Set the NMEA period settings of the device.

Parameters:
periods - The array indexes are given by:
- BT747Constants.NMEA_SEN_GLL_IDX
- BT747Constants.NMEA_SEN_RMC_IDX
- BT747Constants.NMEA_SEN_VTG_IDX
- BT747Constants.NMEA_SEN_GGA_IDX
- BT747Constants.NMEA_SEN_GSA_IDX
- BT747Constants.NMEA_SEN_GSV_IDX
- BT747Constants.NMEA_SEN_GRS_IDX
- BT747Constants.NMEA_SEN_GST_IDX
- BT747Constants.NMEA_SEN_MALM_IDX
- BT747Constants.NMEA_SEN_MEPH_IDX
- BT747Constants.NMEA_SEN_MDGP_IDX
- BT747Constants.NMEA_SEN_MDBG_IDX
- BT747Constants.NMEA_SEN_ZDA_IDX
- BT747Constants.NMEA_SEN_MCHN_IDX
-

setNMEADefaultPeriods

public final void setNMEADefaultPeriods()
Sets default NMEA periods (as observed on one iBlue 747 device).


setSBASTestEnabled

public final void setSBASTestEnabled(boolean isSBASTestEnabled)
Sets the enable of SBAS (DGPS) satellites that are in test.

Parameters:
isSBASTestEnabled - When true, enable test satellites.

setSBASEnabled

public final void setSBASEnabled(boolean set)
Enable SBAS (DGPS).

Parameters:
set - When true, enables SBAS.

setDatumMode

public final void setDatumMode(int mode)
Set GPS's Datum mode.

Parameters:
mode - The datum mode to set.

setDGPSMode

public final void setDGPSMode(int mode)
Set the DGPS mode to use when SBAS enabled.

Parameters:
mode - The mode to use.

setPowerSaveEnabled

public final void setPowerSaveEnabled(boolean set)
Enable the power save mode on the device - this setting is untested.

Parameters:
set - If true, enable power save mode.

logImmediate

public final void logImmediate(int value)
Force the logger to record the current position tagged with the given log reason.

Parameters:
value - BT747Constants.RCR_TIME_MASK BT747Constants.RCR_SPEED_MASK BT747Constants.RCR_DISTANCE_MASK BT747Constants.RCR_BUTTON_MASK BT747Constants.RCR_APP0_MASK BT747Constants.RCR_APP1_MASK BT747Constants.RCR_APP2_MASK BT747Constants.RCR_APP3_MASK BT747Constants.RCR_APP4_MASK BT747Constants.RCR_APP5_MASK BT747Constants.RCR_APP6_MASK BT747Constants.RCR_APP7_MASK BT747Constants.RCR_APP8_MASK BT747Constants.RCR_APP9_MASK BT747Constants.RCR_APPY_MASK BT747Constants.RCR_APPZ_MASK BT747Constants.RCR_ALL_APP_MASK

setFixInterval

public final void setFixInterval(int value)

setLogTimeInterval

public final void setLogTimeInterval(int value)

setLogDistanceInterval

public final void setLogDistanceInterval(int value)

setLogSpeedInterval

public final void setLogSpeedInterval(int value)

isEnableStoreOK

public final boolean isEnableStoreOK()

setStats

public final void setStats(boolean b)

setGpsDecode

public final void setGpsDecode(boolean value)

setFilterEndTime

public final void setFilterEndTime(int d)

setFilterStartTime

public final void setFilterStartTime(int d)

storeSetting1

public final void storeSetting1()

restoreSetting1

public final void restoreSetting1()

reqSettingsForStorage

public final void reqSettingsForStorage()

setFilters

public final void setFilters()

setNMEAset

public final void setNMEAset(int formatNMEA)
Sets the NMEA string types to write to the NMEA output file format.

Parameters:
formatNMEA - Bit format using following bit indexes:
- BT747Constants.NMEA_SEN_GLL_IDX
- BT747Constants.NMEA_SEN_RMC_IDX
- BT747Constants.NMEA_SEN_VTG_IDX
- BT747Constants.NMEA_SEN_GGA_IDX
- BT747Constants.NMEA_SEN_GSA_IDX
- BT747Constants.NMEA_SEN_GSV_IDX
- BT747Constants.NMEA_SEN_GRS_IDX
- BT747Constants.NMEA_SEN_GST_IDX
- BT747Constants.NMEA_SEN_MALM_IDX
- BT747Constants.NMEA_SEN_MEPH_IDX
- BT747Constants.NMEA_SEN_MDGP_IDX
- BT747Constants.NMEA_SEN_MDBG_IDX
- BT747Constants.NMEA_SEN_ZDA_IDX
- BT747Constants.NMEA_SEN_MCHN_IDX

getLastError

public final int getLastError()
Returns:
the lastError

getLastErrorInfo

public final java.lang.String getLastErrorInfo()
Returns:
the lastErrorInfo

setBooleanOpt

public void setBooleanOpt(int param,
                          boolean value)

setIntOpt

public void setIntOpt(int param,
                      int value)

setFloatOpt

public void setFloatOpt(int param,
                        float value)

setStringOpt

public void setStringOpt(int param,
                         java.lang.String value)

addLogFile

public static final void addLogFile(BT747Path path)

setAgpsData

public final void setAgpsData(byte[] agpsData)

sendBT747Exception

public final void sendBT747Exception(BT747Exception e)

isLocationServingActive

public boolean isLocationServingActive()
Check whether location updates currently are sent out to external servers.

Returns:
true if the location serving is currently active, false otherwise.

startGPSPositionServing

public void startGPSPositionServing()
If there is no LocationSender yet registered with the Model create such a LocationSender and register it with the Model so that it starts sending out position updates.
As usually with Controllers this is an operation which implements the reaction of the application to some user interaction (Although this is called with other ways also). This is useful for example for a type of interaction where a user activates position sending with pressing a button.
author Florian Unger


stopGPSPositionServing

public void stopGPSPositionServing()
If there is a LocationSender currently registered as Listener with the Model of this instance then remove it from the Listeners of the Model and set registeredLocSender to null.
This is the complementing operation to startGPSPositionServing and may be used just the same way. For example the user might stop position serving by pressing a push button.
author Florian Unger