1 //Create a class for contact sensor
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class ContactSensors {
9 private int deviceNumbers
13 //For one device(We cannot have obj.id)-> We should have obj[0].id
14 private String id = "contactSensorID0"
15 private String label = "contactSensor0"
16 private String displayName = "contactSensor0"
17 private String contactState = "closed"
18 private String currentContact = "closed"
19 private String latestValue = "closed"
20 private String alarmState = "armed"
23 ContactSensors(Closure sendEvent, int deviceNumbers) {
24 this.sendEvent = sendEvent
25 this.deviceNumbers = deviceNumbers
28 def initSensor = Verify.getBoolean()
30 this.contactState = "closed"
31 this.currentContact = "closed"
32 this.latestValue = "closed"
34 this.contactState = "open"
35 this.currentContact = "open"
36 this.latestValue = "open"
39 def initAlarm = Verify.getBoolean()
41 this.alarmState = "armed"
43 this.alarmState = "not armed"
45 contacts.add(new ContactSensor(id, label, displayName, this.contactState, this.currentContact, this.alarmState, this.latestValue))
48 //Methods for closures
49 def count(Closure Input) {
55 def each(Closure Input) {
58 def find(Closure Input) {
61 def collect(Closure Input) {
62 contacts.collect(Input)
66 def setValue(LinkedHashMap eventDataMap) {
67 if (eventDataMap["value"] != contacts[0].contactState) {
68 contacts[0].setValue(eventDataMap["value"])
69 this.latestValue = contacts[0].latestValue
70 this.contactState = contacts[0].contactState
71 this.currentContact = contacts[0].contactState
72 sendEvent(eventDataMap)
78 this.alarmState = "armed"
83 this.alarmState = "not armed"
86 def currentValue(String deviceFeature) {
87 contacts[0].currentValue(deviceFeature)//It is called if we have only one device
90 def latestValue(String deviceFeature) {
91 contacts[0].latestValue(deviceFeature)//It is called if we have only one device