Insulin Pump


Class GenericTestBed

java.lang.Object
  |
  +--GenericTestBed
Direct Known Subclasses:
SampleTestBed, ToyTestBed

public abstract class GenericTestBed
extends java.lang.Object

This abstract class provides the basic interface to implement a test bed class. To use it, you need to subclass it and define the method aNewSecondHasPassed(). Your implementation of aNewSecondHasPassed() should contain the code you want to be executed by the test bed each time the control loop of the insulin pump (in Class Clock) has completed one cycle. This happens every seconds (Note that 'seconds' might be speeded up see setDurationOfOneSecondInMS(int)).

Here is an example on how to use this class to define your own test bed class:

public class ToyTestBed extends GenericTestBed {

    public void aNewSecondHasPassed() {
	if (getSimulationTime()==5)
	    hardware.removeInsulinReservoir() ;
	if (getSimulationTime()==7)
	    display.pushButtonAdministerInsulin(4) ;
	if (getSimulationTime()>10)
	    destroyInsulinPump();
    } // EndMethod aNewSecondHasPassed

    public static void main(String[] args) {
 	ToyTestBed testBed = new ToyTestBed() ;
	testBed.setDurationOfOneSecondInMS(500); // twice faster
	testBed.launchNewInsulinPump() ;	    
	System.exit(0);
    } // EndMain

} // EndClass ToyTestBed
In this example the class ToyTestBed is subclassed from GenericTestBed. It can be launched by usind java ToyTestBed on the command line.

When launched, main executes first and creates a new ToyTestBed object. It sets to duration of one simulation 'second' to 500 ms (resulting in a 2x speedup) ( The method aNewSecondHasPassed() is defined:

 testBed.setDurationOfOneSecondInMS(500) ;
The insulin pump is then launched inside the testbed using
 testBed.launchNewInsulinPump() ;
After this line the control is given to the insulin pump software, which regularly call back the method aNewSecondHasPassed() of ToyTestBed. In aNewSecondHasPassed(), ToyTestBed checks is the insulin pump execution has reached some particular deadline. If yes it triggers some hardware action using the hardware and display object. For instance, after 5 seconds the insulin reservoir is removed. After 7 second, the test bed request 4 doses of insulin to be injected, and after 10 seconds, the insulin pump software is stopped.

Note that this example is very simple and does not use the display to read displays. Have a look at the source of SampleTestBed for a more complete example of how a safety property can be tested by using GenericTestBed class.


Field Summary
protected  DisplaySimulatorAPI display
           
protected  HardwareSimulatorAPI hardware
           
 
Constructor Summary
GenericTestBed()
           
 
Method Summary
abstract  void aNewSecondHasPassed()
          This method is called each time the Clock class completes a control loop cycle.
 void destroyInsulinPump()
          Stops the pump being executed and destroys it.
static GenericTestBed getActiveTestBedObject()
           
 int getSimulationTime()
          An helper method to get the time elapsed since the start of the pump (in seconds.
 void launchNewInsulinPump()
          Creates a new insulin pump and starts executing it.Only one insulin pump is allowed at a time.
 void printMessage(java.lang.String msg)
          An helper method to pretty-print messages on the console.
 void setDurationOfOneSecondInMS(int duration)
          By default one second lasts 1000ms in the controlling loop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hardware

protected HardwareSimulatorAPI hardware

display

protected DisplaySimulatorAPI display
Constructor Detail

GenericTestBed

public GenericTestBed()
Method Detail

getActiveTestBedObject

public static final GenericTestBed getActiveTestBedObject()

launchNewInsulinPump

public void launchNewInsulinPump()
Creates a new insulin pump and starts executing it.Only one insulin pump is allowed at a time. Every second of the execution time ('seconds' might be speeded up see setDurationOfOneSecondInMS(int)), the method aNewSecondHasPassed() will be called.
See Also:
setDurationOfOneSecondInMS(int), aNewSecondHasPassed()

aNewSecondHasPassed

public abstract void aNewSecondHasPassed()
This method is called each time the Clock class completes a control loop cycle. In this method you can use the hardware simulation interface hardware to simulate failures, the display simulation interface display to activate the human computer interface and read the displays.

GenericTestBed provides a number of 'helper' methods (listed below) that you can use inside aNewSecondHasPassed() to get information on the simulation, print messages, and to modify some parameters of the execution. Note that the pump will execute until destroyInsulinPump() is called. If destroyInsulinPump() is not called inside aNewSecondHasPassed() the pump never stops.

See Also:
getSimulationTime(), printMessage(String), destroyInsulinPump(), setDurationOfOneSecondInMS(int)

destroyInsulinPump

public void destroyInsulinPump()
Stops the pump being executed and destroys it. Should be called inside aNewSecondHasPassed() to stop the test being executed.

getSimulationTime

public int getSimulationTime()
An helper method to get the time elapsed since the start of the pump (in seconds. Note that 'seconds' might be speeded up see setDurationOfOneSecondInMS(int)).
See Also:
setDurationOfOneSecondInMS(int)

printMessage

public void printMessage(java.lang.String msg)
An helper method to pretty-print messages on the console. Prefixes all messages with the current 'execution time' in seconds.
See Also:
getSimulationTime(), aNewSecondHasPassed()

setDurationOfOneSecondInMS

public void setDurationOfOneSecondInMS(int duration)
By default one second lasts 1000ms in the controlling loop. If you want the controller to run faster, set a value lower than 1000ms. Setting the duration to 0 has the controller running as fast as possible (best for testing).

Insulin Pump