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"
20 private String carbonMonoxide = "clear"
21 private String currentCarbonMonoxideValue = "clear"
22 private String carbonMonoxideLatestValue = "clear"
23 private int battery = 50
24 private int batteryLatestValue = 50
27 SmokeDetectors(Closure sendEvent, int deviceNumbers) {
28 this.sendEvent = sendEvent
29 this.deviceNumbers = deviceNumbers
30 this.smokeDetectors = []
33 def initBattery = Verify.getIntFromList(30, 50, 70)
34 this.battery = initBattery
35 this.batteryLatestValue = initBattery
37 def initSmoke = Verify.getInt(0,2)
40 /*def init = Verify.getInt(0,2)
42 >>>>>>> a02c9807815a35c0f57241ee6510a3d312499049
43 this.currentSmokeValue = "clear"
44 this.smokeLatestValue = "clear"
45 } else if (initSmoke == 1) {
46 this.currentSmokeValue = "detected"
47 this.smokeLatestValue = "detected"
49 this.currentSmokeValue = "tested"
50 this.smokeLatestValue = "tested"
54 def initCarbonMonoxide = Verify.getInt(0,2)
55 if (initCarbonMonoxide == 0) {
56 this.currentCarbonMonoxideValue = "clear"
57 this.carbonMonoxideLatestValue = "clear"
58 } else if (initCarbonMonoxide == 1) {
59 this.currentCarbonMonoxideValue = "detected"
60 this.carbonMonoxideLatestValue = "detected"
62 this.currentCarbonMonoxideValue = "tested"
63 this.carbonMonoxideLatestValue = "tested"
65 smokeDetectors.add(new SmokeDetector(id, label, displayName, this.currentSmokeValue, this.smokeLatestValue, this.currentCarbonMonoxideValue,
66 this.carbonMonoxideLatestValue, this.battery))
69 smokeDetectors.add(new SmokeDetector(id, label, displayName, this.currentSmokeValue, this.smokeLatestValue))
70 >>>>>>> a02c9807815a35c0f57241ee6510a3d312499049
74 def setValue(LinkedHashMap eventDataMap) {
75 if (eventDataMap["name"].contains("smoke")) {
76 if (eventDataMap["value"] != smokeDetectors[0].currentSmokeValue) {
77 this.smokeLatestValue = eventDataMap["value"]
78 this.smoke = eventDataMap["value"]
79 this.currentSmokeValue = eventDataMap["value"]
80 smokeDetectors[0].setValue(eventDataMap["value"], eventDataMap["name"])
81 sendEvent(eventDataMap)
83 } else if (eventDataMap["name"].contains("carbonMonoxide")) {
84 if (eventDataMap["value"] != smokeDetectors[0].currentCarbonMonoxideValue) {
85 this.carbonMonoxideLatestValue = eventDataMap["value"]
86 this.carbonMonoxide = eventDataMap["value"]
87 this.currentCarbonMonoxideValue = eventDataMap["value"]
88 smokeDetectors[0].setValue(eventDataMap["value"], eventDataMap["name"])
89 sendEvent(eventDataMap)
91 } else if (eventDataMap["name"].contains("battery")) {
92 if (eventDataMap["value"].toInteger() != smokeDetectors[0].battery) {
93 this.battery = eventDataMap["value"].toInteger()
94 this.batteryLatestValue = eventDataMap["value"].toInteger()
95 smokeDetectors[0].setValue(eventDataMap["value"], eventDataMap["name"])
96 sendEvent(eventDataMap)
101 //Methods for closures
102 def count(Closure Input) {
103 smokeDetectors.count(Input)
106 smokeDetectors.size()
108 def each(Closure Input) {
109 smokeDetectors.each(Input)
111 def find(Closure Input) {
112 smokeDetectors.find(Input)
114 def sort(Closure Input) {
115 smokeDetectors.sort(Input)
117 def collect(Closure Input) {
118 smokeDetectors.collect(Input)
122 def currentValue(String deviceFeature) {
123 smokeDetectors[0].currentValue(deviceFeature)//It is called if we have only one device
126 def latestValue(String deviceFeature) {
127 smokeDetectors[0].latestValue(deviceFeature)//It is called if we have only one device