1 //Create a class for smoke detector
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class SmokeDetectors {
9 private int deviceNumbers
10 private List smokeDetectors
13 //For one device(We cannot have obj.id)-> We should have obj[0].id
14 private String id = "smokeDetectorID0"
15 private String label = "smokeDetector0"
16 private String displayName = "smokeDetector0"
17 private String smoke = "clear"
18 private String currentSmokeValue = "clear"
19 private String smokeLatestValue = "clear"
22 SmokeDetectors(Closure sendEvent, int deviceNumbers) {
23 this.sendEvent = sendEvent
24 this.deviceNumbers = deviceNumbers
25 this.smokeDetectors = []
27 def init = Verify.getInt(0,2)
29 this.currentSmokeValue = "clear"
30 this.smokeLatestValue = "clear"
31 } else if (init == 1) {
32 this.currentSmokeValue = "detected"
33 this.smokeLatestValue = "detected"
35 this.currentSmokeValue = "tested"
36 this.smokeLatestValue = "tested"
38 smokeDetectors.add(new SmokeDetector(id, label, displayName, this.currentSmokeValue, this.smokeLatestValue))
42 def setValue(LinkedHashMap eventDataMap) {
43 if (eventDataMap["value"] != smokeDetectors[0].currentSmokeValue) {
44 smokeDetectors[0].setValue(eventDataMap["value"])
45 this.smokeLatestValue = smokeDetectors[0].smokeLatestValue
46 this.smoke = smokeDetectors[0].currentSmokeValue
47 this.currentSmokeValue = smokeDetectors[0].currentSmokeValue
48 sendEvent(eventDataMap)
52 //Methods for closures
53 def count(Closure Input) {
54 smokeDetectors.count(Input)
59 def each(Closure Input) {
60 smokeDetectors.each(Input)
62 def find(Closure Input) {
63 smokeDetectors.find(Input)
65 def collect(Closure Input) {
66 smokeDetectors.collect(Input)
70 def currentValue(String deviceFeature) {
71 smokeDetectors[0].currentValue(deviceFeature)//It is called if we have only one device
74 def latestValue(String deviceFeature) {
75 smokeDetectors[0].latestValue(deviceFeature)//It is called if we have only one device