1 //Create a class for contact sensor
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class ContactSensor {
11 private String displayName
12 private String contactState
13 private String currentContact
14 private String latestValue
15 private String alarmState
16 private List events = []
17 private List timeOfEvents = []
20 ContactSensor(String id, String label, String displayName, String contactState, String currentContact, String alarmState, String latestValue) {
23 this.displayName = displayName
24 this.contactState = contactState
25 this.currentContact = currentContact
26 this.latestValue = latestValue
27 this.alarmState = alarmState
31 def evtOpen = [[name: "contact", value: "open", deviceId: "contactSensorID0", descriptionText: "",
32 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
33 def evtClosed = [[name: "contact", value: "closed", deviceId: "contactSensorID0", descriptionText: "",
34 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
35 def init = Verify.getInt(0,4)
37 if (init == 0) {//return empty set
39 } else if (init == 1) {//send one open event
44 } else if (init == 2) {//send two open events
52 } else if (init == 3) {//send one closed event
57 } else if (init == 4) {//send two closed events
68 def setValue(String value) {
69 println("the contact sensor with id:$id is triggered to $value!")
70 this.contactState = value
71 this.currentContact = value
72 this.latestValue = value
77 println("the contact sensor with id:$id is armed!")
78 this.alarmState = "armed"
82 println("the contact sensor with id:$id is not armed!")
83 this.alarmState = "not armed"
86 def currentValue(String deviceFeature) {
87 if (deviceFeature == "contact") {
92 def currentState(String deviceFeature) {
93 if (deviceFeature == "contact") {
98 def latestValue(String deviceFeature) {
99 if (deviceFeature == "contact") {