1 //Create a class for carbon monoxide detector
2 package CarbonMonoxideDetector
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class CarbonMonoxideDetectors {
9 private int deviceNumbers
10 private List carbonMonoxideDetectors
13 //For one device(We cannot have obj.id)-> We should have obj[0].id
14 private String id = "carbonMonoxideDetectorID0"
15 private String label = "carbonMonoxideDetector0"
16 private String displayName = "carbonMonoxideDetector0"
17 private String carbonMonoxide = "clear"
18 private String currentCarbonMonoxideValue = "clear"
19 private String carbonMonoxideLatestValue = "clear"
22 CarbonMonoxideDetectors(Closure sendEvent, int deviceNumbers) {
23 this.sendEvent = sendEvent
24 this.deviceNumbers = deviceNumbers
25 this.carbonMonoxideDetectors = []
27 def init = Verify.getInt(0,2)
29 this.carbonMonoxide = "clear"
30 this.carbonMonoxideLatestValue = "clear"
31 } else if (init == 1) {
32 this.carbonMonoxide = "detected"
33 this.carbonMonoxideLatestValue = "detected"
35 this.carbonMonoxide = "tested"
36 this.carbonMonoxideLatestValue = "tested"
39 carbonMonoxideDetectors.add(new CarbonMonoxideDetector(id, label, displayName, this.currentCarbonMonoxideValue, this.carbonMonoxideLatestValue))
41 carbonMonoxideDetectors.add(new CarbonMonoxideDetector(id, label, displayName, this.carbonMonoxide, this.carbonMonoxideLatestValue))
42 >>>>>>> e378d6a65b25030f8914dc97f04b81ddff351d9c
46 def setValue(LinkedHashMap eventDataMap) {
47 if (eventDataMap["value"] != carbonMonoxideDetectors[0].currentCarbonMonoxideValue) {
48 carbonMonoxideDetectors[0].setValue(eventDataMap["value"])
49 this.carbonMonoxideLatestValue = carbonMonoxideDetectors[0].carbonMonoxideLatestValue
50 this.carbonMonoxide = carbonMonoxideDetectors[0].currentCarbonMonoxideValue
51 this.currentCarbonMonoxideValue = carbonMonoxideDetectors[0].currentCarbonMonoxideValue
52 sendEvent(eventDataMap)
56 //Methods for closures
57 def count(Closure Input) {
58 carbonMonoxideDetectors.count(Input)
61 carbonMonoxideDetectors.size()
63 def each(Closure Input) {
64 carbonMonoxideDetectors.each(Input)
66 def find(Closure Input) {
67 carbonMonoxideDetectors.find(Input)
69 def collect(Closure Input) {
70 carbonMonoxideDetectors.collect(Input)
74 def currentValue(String deviceFeature) {
75 carbonMonoxideDetectors[0].currentValue(deviceFeature)//It is called if we have only one device
78 def latestValue(String deviceFeature) {
79 carbonMonoxideDetectors[0].latestValue(deviceFeature)//It is called if we have only one device
83 carbonMonoxideDetectors[ix]