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 sort(Closure Input) {
64 def collect(Closure Input) {
65 contacts.collect(Input)
69 def setValue(LinkedHashMap eventDataMap) {
70 if (eventDataMap["value"] != contacts[0].contactState) {
71 this.latestValue = eventDataMap["value"]
72 this.contactState = eventDataMap["value"]
73 this.currentContact = eventDataMap["value"]
74 contacts[0].setValue(eventDataMap["value"])
75 sendEvent(eventDataMap)
80 this.alarmState = "armed"
85 this.alarmState = "not armed"
89 def currentValue(String deviceFeature) {
90 contacts[0].currentValue(deviceFeature)//It is called if we have only one device
93 def currentState(String deviceFeature) {
94 contacts[0].currentState(deviceFeature)//It is called if we have only one device
97 def latestValue(String deviceFeature) {
98 contacts[0].latestValue(deviceFeature)//It is called if we have only one device