1 //Create a class for lock device
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
14 //When we have only one device
15 private String id = "lockID0"
16 private String label = "lock0"
17 private String displayName = "lock0"
18 private String lockState = "locked"
19 private String currentLock = "locked"
20 private String lockLatestValue = "locked"
22 Locks(Closure sendEvent, int deviceNumbers) {
23 this.sendEvent = sendEvent
24 this.timers = new SimulatedTimer()
25 this.deviceNumbers = deviceNumbers
28 def init = Verify.getBoolean()
30 this.lockState = "locked"
31 this.currentLock = "locked"
32 this.lockLatestValue = "locked"
34 this.lockState = "unlocked"
35 this.currentLock = "unlocked"
36 this.lockLatestValue = "unlocked"
38 locks.add(new Lock(sendEvent,id, label, displayName, this.lockState, this.lockLatestValue))
43 if (lockState != "locked") {
44 //lockLatestValue = lockState
45 lockLatestValue = "locked"
47 currentLock = "locked"
52 def lock(LinkedHashMap metaData) {
53 if (lockState != "locked") {
54 def task = timers.runAfter(metaData["delay"]) {
55 //lockLatestValue = lockState
56 lockLatestValue = "locked"
58 currentLock = "locked"
65 if (lockState != "unlocked") {
66 //lockLatestValue = lockState
67 lockLatestValue = "unlocked"
68 lockState = "unlocked"
69 currentLock = "unlocked"
75 def unlock(LinkedHashMap metaData) {
76 if (lockState != "unlocked") {
77 def task = timers.runAfter(metaData["delay"]) {
78 //lockLatestValue = lockState
79 lockLatestValue = "unlocked"
80 lockState = "unlocked"
81 currentLock = "unlocked"
87 //Methods for closures
88 def count(Closure Input) {
94 def each(Closure Input) {
97 def find(Closure Input) {
100 def sort(Closure Input) {
103 def collect(Closure Input) {
108 def setValue(LinkedHashMap eventDataMap) {
109 if (eventDataMap["value"] != locks[0].lockState) {
110 locks[0].setValue(eventDataMap["value"])
111 this.lockState = locks[0].lockState
112 this.currentLock = locks[0].lockState
113 this.lockLatestValue = locks[0].lockLatestValue
114 sendEvent(eventDataMap)
118 def currentValue(String deviceFeature) {
119 locks[0].currentValue(deviceFeature)
122 def latestValue(String deviceFeature) {
123 locks[0].latestValue(deviceFeature)