frog.plugin.spot
Class SpotPlugin

java.lang.Object
  extended by frog.plugin.spot.SpotPlugin
All Implemented Interfaces:
Plugin, Frog_Spot_Constants

public class SpotPlugin
extends Object
implements Plugin, Frog_Spot_Constants

Plugin for the FROG system allowing the use of Sun Microsystem's SPOTs as a device.

Please see http://brazos.cs.tcu.edu for more documentation.

Author:
Team Better Recognize
See Also:
SpotConnection

Field Summary
static String[] availFilters
          Filters that the SPOT is capable of performing.
protected static HashSet<Short> availPorts
          A HashSet allows constant time look-up and addition.
protected static Hashtable<String,SpotConnection> connections
          SpotConnections are Sun SPOTs that are connected and have DeviceListeners attached to them.
static String type
          Applied to any Device object we create.
 
Fields inherited from interface frog.plugin.spot.Frog_Spot_Constants
CORRUPT_DATA, END_OF_DATA, INT_CORRUPT_DATA, INT_END_OF_DATA, MSG_ACK, MSG_ADD_FILTER, MSG_ALIVE, MSG_DISCONNECT, MSG_DISCOVER, MSG_END_OF_DATA, MSG_ERROR, MSG_GESTURE, MSG_REMOVE_FILTERS, MSG_RESEND, MSG_SAMPLE_RATE, PORT_BCAST, PORT_MAX, PORT_REPLY, PORT_START, SPOT1, SPOT1_PORT, SPOT2, SPOT2_PORT, SPOT3, SPOT3_PORT, SPOT4, SPOT4_PORT, SPOT5, SPOT5_PORT, SPOT6, SPOT6_PORT, SPOT7, SPOT7_PORT, SPOT8, SPOT8_PORT, SPOTB1, SPOTB1_PORT, SPOTB2, SPOTB2_PORT, SPOTB3, SPOTB3_PORT, SPOTB4, SPOTB4_PORT
 
Constructor Summary
SpotPlugin()
          Creates a single SpotPlugin object.
 
Method Summary
 void addFilter(Device device, int id, String arg)
          \ |*** ***| |*** Inherited Methods ***| |*** ***| \
 void calibrate(Device device)
          Calibrates the accelerometers of the target device.
 void connect(Device device)
          Formally connect to a specified device.
 void disconnect(Device device)
          Disconnect a connected device.
 void disconnectAll()
          Disconnect from all devices known to this Plugin.
 void discover(Vector<Device> deviceList)
          A non-blocking method for finding nearby discoverable devices.
 String[] getActiveFilters(Device device)
          Returns a list of filters currently active on the device.
 String[] getAvailFilters()
          Returns a list of available filters that this device supports.
static SpotPlugin getInstance()
          Retrieves the singleton object of SpotPlugin.
 int getSampleRate(Device device)
          Gets the current sampling rate of this Device in hertz.
 void removeFilter(Device device, int index)
          Removes a filter from the list of active filters on the Device.
 void resetFilters(Device device)
          Removes any filters currently active on the Device.
 void setSampleRate(Device device, int rate)
          Instructs this device to sample at a given rate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

type

public static final String type
Applied to any Device object we create.

See Also:
Constant Field Values

connections

protected static final Hashtable<String,SpotConnection> connections
SpotConnections are Sun SPOTs that are connected and have DeviceListeners attached to them. In the event they are disconnected, unexpectedly or not, they should be remove from this list. This Hashtable starts out with 4 slots as, at least initially, FROG's GUI only supports 4 connected devices.


availPorts

protected static final HashSet<Short> availPorts
A HashSet allows constant time look-up and addition. We want that because we only want one instance of each port to exist in the set.

HashMaps are not thread-safe so the methods here that use them are synchronized.


availFilters

public static final String[] availFilters
Filters that the SPOT is capable of performing.

Constructor Detail

SpotPlugin

public SpotPlugin()
           throws Throwable
Creates a single SpotPlugin object. Attempts to call this constructor more than once will generate an Exception.

Throws:
Throwable
Method Detail

getInstance

public static SpotPlugin getInstance()
Retrieves the singleton object of SpotPlugin.

Returns:
SpotPlugin's singleton object

addFilter

public void addFilter(Device device,
                      int id,
                      String arg)
               throws IOException
\ |*** ***| |*** Inherited Methods ***| |*** ***| \

Specified by:
addFilter in interface Plugin
Parameters:
device - the device to send the new filter information to
id - the filter desired. This should be the index from the array of filters.
arg - the argument String for this filter
Throws:
IOException - if any communication error occurs
See Also:
Plugin.getAvailFilters(), Device.addFilter(int, String)

calibrate

public void calibrate(Device device)
               throws IOException
Description copied from interface: Plugin
Calibrates the accelerometers of the target device. If the device requires calibration or any adjustment before use, this method can be called to provide a custom GUI instructing the user on how to set up their device (such as setting it flat on a table or throwing it out a window).

Specified by:
calibrate in interface Plugin
Parameters:
device - the device to be calibrated
Throws:
IOException - if any communication error occurs
See Also:
Device.calibrate()

connect

public void connect(Device device)
             throws IOException
Description copied from interface: Plugin
Formally connect to a specified device. After the user has been presented with a list of discovered devices, the one they pick must be connected to so that a formal connection (and probably a new Thread) can be established and they can begin using the device.

Specified by:
connect in interface Plugin
Parameters:
device - the device to connect to
Throws:
IOException - if any communication error occurs. It should be assumed that if this exception is thrown, the device is NOT connected.
See Also:
Device.connect(DeviceListener)

disconnect

public void disconnect(Device device)
                throws IOException
Description copied from interface: Plugin
Disconnect a connected device. This method should tear down any facilities that were set up to support the device. This should be called by the user when they wish to disconnect the device.

Unlike unexpected disconnects (disconnects resulting from battery or communication failure), the disconnect() method should not notify DeviceListeners of anything. A call to this method means the disconnect is deliberate and expected.

Specified by:
disconnect in interface Plugin
Parameters:
device - the device to disconnect from
Throws:
IOException - if the device cannot be sent a disconnect signal. Regardless, a best attempt must be made to tear down any local resources tied to this device.
See Also:
Device.disconnect()

disconnectAll

public void disconnectAll()
                   throws IOException
Description copied from interface: Plugin
Disconnect from all devices known to this Plugin. Convenience method for FROG. Most likely to be called when FROG is in the process of shutting down.

Specified by:
disconnectAll in interface Plugin
Throws:
IOException - if any of the connected devices could not be sent a disconnect message. Regardless, FROG is probably shutting down and any local resources should be freed.

discover

public void discover(Vector<Device> deviceList)
              throws IOException
Description copied from interface: Plugin
A non-blocking method for finding nearby discoverable devices. Ideally this Plugin should broadcast a message looking for nearby devices. As devices are found, they should be placed on the deviceList. Implementing classes are encouraged to try and make the discovery of devices within 10 seconds. Devices that are found should not be connected to, but rather added to the given Vector<Device> so that the caller can view devices as they become available.

This method is expected to be non-blocking. That is, a Plugin should launch the discovery process in a separate Thread to allow other Plugins to perform their respective discoveries simultaneously.

Specified by:
discover in interface Plugin
Throws:
IOException - any catastrophic errors occur. Should ideally be thrown if the radio or other hardware is missing. Communication errors between the plugin and a device are not a sufficient cause to throw this exception.

getActiveFilters

public String[] getActiveFilters(Device device)
                          throws IOException
Description copied from interface: Plugin
Returns a list of filters currently active on the device. If the Device does not support on-device filtering, a null or empty array may be returned.

Specified by:
getActiveFilters in interface Plugin
Returns:
the list of currently active filters on the device in the order in which they were instantiated
Throws:
IOException - if a list of active filters could not be obtained from the Device.
See Also:
Device.getActiveFilters()

getAvailFilters

public String[] getAvailFilters()
Description copied from interface: Plugin
Returns a list of available filters that this device supports. The array of strings returned by this method should be in a specific order as the index of the array will be used to communicate with the device later.

Specified by:
getAvailFilters in interface Plugin
Returns:
a list of Strings containing the names of the filters supported
See Also:
Device.getAvailFilters()

getSampleRate

public int getSampleRate(Device device)
                  throws IOException
Description copied from interface: Plugin
Gets the current sampling rate of this Device in hertz.

Specified by:
getSampleRate in interface Plugin
Returns:
the sampling rate of this device in hertz
Throws:
IOException - if the current sample rate could not be obtained from the Device
See Also:
Device.getSampleRate()

removeFilter

public void removeFilter(Device device,
                         int index)
                  throws IOException
Description copied from interface: Plugin
Removes a filter from the list of active filters on the Device. This method does nothing at all if on-device filtering is not supported.

Specified by:
removeFilter in interface Plugin
Parameters:
device - the Device to delete a filter from
index - the position on the Device's active filters list to remove
Throws:
IOException - if the filter on the Device could not be removed

resetFilters

public void resetFilters(Device device)
                  throws IOException
Description copied from interface: Plugin
Removes any filters currently active on the Device. This method makes it possible for the user to edit or remove filters the Device is performing. This method does nothing if on-device filtering cannot be done by this type of Device.

Specified by:
resetFilters in interface Plugin
Parameters:
device - the Device to clear the filters on
Throws:
IOException - if any communication error occurs
See Also:
Plugin.addFilter(Device, int, String), Device.resetFilters()

setSampleRate

public void setSampleRate(Device device,
                          int rate)
                   throws IOException
Description copied from interface: Plugin
Instructs this device to sample at a given rate. If this device is incompatible with setting a different sampling rate, this method does nothing.

Specified by:
setSampleRate in interface Plugin
rate - the rate to sample at in hertz
Throws:
IOException - if any communication error occurs