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 batteryValue = 50
25 private int batteryLatestValue = 50
28 SmokeDetectors(Closure sendEvent, int deviceNumbers) {
29 this.sendEvent = sendEvent
30 this.deviceNumbers = deviceNumbers
31 this.smokeDetectors = []
33 /*def init = Verify.getInt(0,2)
35 this.currentSmokeValue = "clear"
36 this.smokeLatestValue = "clear"
37 } else if (initSmoke == 1) {
38 this.currentSmokeValue = "detected"
39 this.smokeLatestValue = "detected"
41 this.currentSmokeValue = "tested"
42 this.smokeLatestValue = "tested"
45 def initCarbonMonoxide = Verify.getInt(0,2)
46 if (initCarbonMonoxide == 0) {
47 this.currentCarbonMonoxideValue = "clear"
48 this.carbonMonoxideLatestValue = "clear"
49 } else if (initCarbonMonoxide == 1) {
50 this.currentCarbonMonoxideValue = "detected"
51 this.carbonMonoxideLatestValue = "detected"
53 this.currentCarbonMonoxideValue = "tested"
54 this.carbonMonoxideLatestValue = "tested"
57 smokeDetectors.add(new SmokeDetector(id, label, displayName, this.currentSmokeValue, this.smokeLatestValue, this.carbonMonoideValue, this.batteryValue))
61 def setValue(LinkedHashMap eventDataMap) {
62 if (eventDataMap["name"].contains("smoke")) {
63 if (eventDataMap["value"] != smokeDetectors[0].currentSmokeValue) {
64 this.smokeLatestValue = eventDataMap["value"]
65 this.smoke = eventDataMap["value"]
66 this.currentSmokeValue = eventDataMap["value"]
67 smokeDetectors[0].setValue(eventDataMap["value"], eventDataMap["name"])
68 sendEvent(eventDataMap)
70 } else if (eventDataMap["name"].contains("carbonMonoxide")) {
71 if (eventDataMap["value"] != smokeDetectors[0].currentCarbonMonoxideValue) {
72 this.carbonMonoxideLatestValue = eventDataMap["value"]
73 this.carbonMonoxide = eventDataMap["value"]
74 this.currentCarbonMonoxideValue = eventDataMap["value"]
75 smokeDetectors[0].setValue(eventDataMap["value"], eventDataMap["name"])
76 sendEvent(eventDataMap)
78 } else if (eventDataMap["name"].contains("battery")) {
79 if (eventDataMap["value"].toInteger() != smokeDetectors[0].battery) {
80 this.battery = eventDataMap["value"].toInteger()
81 this.batteryLatestValue = eventDataMap["value"].toInteger()
82 smokeDetectors[0].setValue(eventDataMap["value"], eventDataMap["name"])
83 sendEvent(eventDataMap)
88 //Methods for closures
89 def count(Closure Input) {
90 smokeDetectors.count(Input)
95 def each(Closure Input) {
96 smokeDetectors.each(Input)
98 def find(Closure Input) {
99 smokeDetectors.find(Input)
101 def sort(Closure Input) {
102 smokeDetectors.sort(Input)
104 def collect(Closure Input) {
105 smokeDetectors.collect(Input)
109 def currentValue(String deviceFeature) {
110 smokeDetectors[0].currentValue(deviceFeature)//It is called if we have only one device
113 def latestValue(String deviceFeature) {
114 smokeDetectors[0].latestValue(deviceFeature)//It is called if we have only one device