|
Insulin Pump |
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--GenericTestBed
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 ToyTestBedIn 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 |
protected HardwareSimulatorAPI hardware
protected DisplaySimulatorAPI display
Constructor Detail |
public GenericTestBed()
Method Detail |
public static final GenericTestBed getActiveTestBedObject()
public void launchNewInsulinPump()
setDurationOfOneSecondInMS(int)
), the method aNewSecondHasPassed()
will be called.setDurationOfOneSecondInMS(int)
,
aNewSecondHasPassed()
public abstract void aNewSecondHasPassed()
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.
getSimulationTime()
,
printMessage(String)
,
destroyInsulinPump()
,
setDurationOfOneSecondInMS(int)
public void destroyInsulinPump()
aNewSecondHasPassed()
to stop the test being
executed.public int getSimulationTime()
setDurationOfOneSecondInMS(int)
).setDurationOfOneSecondInMS(int)
public void printMessage(java.lang.String msg)
getSimulationTime()
,
aNewSecondHasPassed()
public void setDurationOfOneSecondInMS(int duration)
|
Insulin Pump |
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |