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"
38 carbonMonoxideDetectors.add(new CarbonMonoxideDetector(id, label, displayName, this.currentCarbonMonoxideValue, this.carbonMonoxideLatestValue))
42 def setValue(LinkedHashMap eventDataMap) {
43 if (eventDataMap["value"] != carbonMonoxideDetectors[0].currentCarbonMonoxideValue) {
44 carbonMonoxideDetectors[0].setValue(eventDataMap["value"])
45 this.carbonMonoxideLatestValue = carbonMonoxideDetectors[0].carbonMonoxideLatestValue
46 this.carbonMonoxide = carbonMonoxideDetectors[0].currentCarbonMonoxideValue
47 this.currentCarbonMonoxideValue = carbonMonoxideDetectors[0].currentCarbonMonoxideValue
48 sendEvent(eventDataMap)
52 //Methods for closures
53 def count(Closure Input) {
54 carbonMonoxideDetectors.count(Input)
57 carbonMonoxideDetectors.size()
59 def each(Closure Input) {
60 carbonMonoxideDetectors.each(Input)
62 def find(Closure Input) {
63 carbonMonoxideDetectors.find(Input)
65 def collect(Closure Input) {
66 carbonMonoxideDetectors.collect(Input)
70 def currentValue(String deviceFeature) {
71 carbonMonoxideDetectors[0].currentValue(deviceFeature)//It is called if we have only one device
74 def latestValue(String deviceFeature) {
75 carbonMonoxideDetectors[0].latestValue(deviceFeature)//It is called if we have only one device
79 carbonMonoxideDetectors[ix]