Class FakeDrinkMachine

java.lang.Object
  extended byBasicDrinkMachine
      extended byFakeDrinkMachine
All Implemented Interfaces:
DrinkMachineSpec

public class FakeDrinkMachine
extends BasicDrinkMachine

A DrinkMachineSpec implementation designed to simulate the environment drink would run in when on the TINI to allow for testing on any machine. Most methods return false data or do nothing.

Version:
$Revision: #19 $
Author:
Marius Grigoriu [marius@csh.rit.edu], Bill Kuker [kukester@csh.rit.edu], Kevin Thompson [antiduh@csh.rit.edu]

Nested Class Summary
private  class FakeDrinkMachine.ButtonLoop
          A private class to do the callbacks for the buttons.
 
Field Summary
private  Object bus
          The 'bus' object that is used to communicate to the hardware with.
private  FakeDrinkMachine.ButtonLoop buttonloop
          The inner class that handles Button Event processing and dispatching.
private  ConfigMgr configMgr
          The object that we use to manipulate the configuration database.
private  Vector drinkButtonListeners
          The Vector of objects that want to be notified of button events.
private  DrinkLoggerSpec log
          The Object that we send our log messages to.
 
Fields inherited from class BasicDrinkMachine
numSlots, slotArray, slotDataFileName, slotMgr
 
Constructor Summary
FakeDrinkMachine(ConfigMgr _configMgr, DrinkLoggerSpec _log)
          Takes a string for the configfile to user.
 
Method Summary
 void addDrinkButtonListener(DrinkButtonListener dbl)
          Adds a listener to the list of objects requesting callbacks from the buttons.
private  void calcTemp(String addie)
          Pretends to tell a temperature sensor to calculate its current temperature.
 void delDrinkButtonListener(DrinkButtonListener dbl)
          Removes a listen from the list of objects requesting callbacks from the buttons.
 String drop(int slot)
          Drops a drink by pretending to activate the appropriate one-wire switches
private  Float getTemp(String addie)
          Pretends to fetch the temperature of a temperature sensor.
 Float getTempKey(String key)
          Returns the celsius temperature of a temperature sensor, given the name of the temp sensor.
 void lightOff(int slot)
          Pretends to turn a slots (empty) light off
 void lightOn(int slot)
          Pretends to turn a slots (empty) light on.
 void shutdown(boolean reboot)
          Shuts down the entire system.
 Vector slotTemp(int slot)
          Returns a Vector of Float objects that represent the temperatures of a given slot.
 float slotTempAvg(int slot)
          Returns a primitive float (not Float) for the average slot temp or -127 if there is no data available.
private  boolean toggle(String addie)
          Pretends to toggles the one-wire device indicated by the given address The address is just printed to standard error, and the method always returns true.
 long uptime()
          Pretends to return the TINI's uptime.
 
Methods inherited from class BasicDrinkMachine
drinksDropped, drinksLeft, formatSlotLine, getDrinkNames, getName, getNumSlots, getPrice, getSlot, getSlotArray, getSlotPrintout, isEnabled, setSlot
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

drinkButtonListeners

private Vector drinkButtonListeners
The Vector of objects that want to be notified of button events.


buttonloop

private FakeDrinkMachine.ButtonLoop buttonloop
The inner class that handles Button Event processing and dispatching.


bus

private Object bus
The 'bus' object that is used to communicate to the hardware with. In all reality, we're just pretending to use it.


log

private DrinkLoggerSpec log
The Object that we send our log messages to.


configMgr

private ConfigMgr configMgr
The object that we use to manipulate the configuration database.

Constructor Detail

FakeDrinkMachine

public FakeDrinkMachine(ConfigMgr _configMgr,
                        DrinkLoggerSpec _log)
                 throws IOException
Takes a string for the configfile to user. If the configfile isnt particularly healthy, an IOException is thrown.

Parameters:
_configMgr - The ConfigMgr to use.
_log - The DrinkLoggerSpec to use
Method Detail

shutdown

public void shutdown(boolean reboot)
Shuts down the entire system.

Specified by:
shutdown in interface DrinkMachineSpec
Specified by:
shutdown in class BasicDrinkMachine
Parameters:
reboot - Ignored.
See Also:
TINIDrinkMachine.shutdown(boolean)

uptime

public long uptime()
Pretends to return the TINI's uptime. Always returns zero, however.

Specified by:
uptime in interface DrinkMachineSpec
Specified by:
uptime in class BasicDrinkMachine
Returns:
The fake uptime, zero.

drop

public String drop(int slot)
Drops a drink by pretending to activate the appropriate one-wire switches

Specified by:
drop in interface DrinkMachineSpec
Specified by:
drop in class BasicDrinkMachine
Parameters:
slot - The slot to drop
Returns:
An error string if the drop failed, or null if the drop was successful.

lightOn

public void lightOn(int slot)
Pretends to turn a slots (empty) light on. This method actually just checks to make sure the given slot is valid and then attempts to retrieve the address for the light from the config. The method does not pretend to turn the light on, however.

Specified by:
lightOn in interface DrinkMachineSpec
Specified by:
lightOn in class BasicDrinkMachine
Parameters:
slot - The slot/drink/button associated with the light.
See Also:
lightOff(int)

lightOff

public void lightOff(int slot)
Pretends to turn a slots (empty) light off

Specified by:
lightOff in interface DrinkMachineSpec
Specified by:
lightOff in class BasicDrinkMachine
Parameters:
slot - The slot associated with the light
See Also:
lightOn(int)

getTempKey

public Float getTempKey(String key)
Returns the celsius temperature of a temperature sensor, given the name of the temp sensor. This method must sleep for 800 milliseconds to allow the sensor to calculate the temperature.

Specified by:
getTempKey in interface DrinkMachineSpec
Specified by:
getTempKey in class BasicDrinkMachine
Parameters:
key - The name (key) of the temp sensor to query.
Returns:
The temperature in celsius.

slotTemp

public Vector slotTemp(int slot)
Returns a Vector of Float objects that represent the temperatures of a given slot. The idea for this was to have a 3D map of temperatures in the cabinet. If the slot is invalid or no temperature sensors are associated with it, an empty Vector is returned.

Specified by:
slotTemp in interface DrinkMachineSpec
Specified by:
slotTemp in class BasicDrinkMachine
Parameters:
slot - The slot index associated with the temperature sensor
Returns:
The vector of temperatures, which may be empty if slot is invalid or there are no temperature sensors associated with the slot.
See Also:
getTempKey(String)

slotTempAvg

public float slotTempAvg(int slot)
Returns a primitive float (not Float) for the average slot temp or -127 if there is no data available.

Specified by:
slotTempAvg in interface DrinkMachineSpec
Specified by:
slotTempAvg in class BasicDrinkMachine
Parameters:
slot - The slot to determine the average temperature
Returns:
The average temperature in celsius.

addDrinkButtonListener

public void addDrinkButtonListener(DrinkButtonListener dbl)
Adds a listener to the list of objects requesting callbacks from the buttons.

Specified by:
addDrinkButtonListener in interface DrinkMachineSpec
Specified by:
addDrinkButtonListener in class BasicDrinkMachine
Parameters:
dbl - The DrinkButtonListener to add.

delDrinkButtonListener

public void delDrinkButtonListener(DrinkButtonListener dbl)
Removes a listen from the list of objects requesting callbacks from the buttons.

Specified by:
delDrinkButtonListener in interface DrinkMachineSpec
Specified by:
delDrinkButtonListener in class BasicDrinkMachine
Parameters:
dbl - The DrinkButtonListener to remove

toggle

private boolean toggle(String addie)
Pretends to toggles the one-wire device indicated by the given address The address is just printed to standard error, and the method always returns true.

Parameters:
addie - The address to pretend to toggle
Returns:
True, always.

calcTemp

private void calcTemp(String addie)
Pretends to tell a temperature sensor to calculate its current temperature. Does nothing but print that it pretended to.

Parameters:
addie - The address of the temperature sensor to poke.

getTemp

private Float getTemp(String addie)
               throws Exception
Pretends to fetch the temperature of a temperature sensor. This method only trys to synchronize on the bus, and then always return 42.0 degrees celsius.

Parameters:
addie - The address of the temperature sensor to read.
Throws:
Exception