Adding missing methods.
authorrtrimana <rtrimana@uci.edu>
Thu, 8 Aug 2019 20:24:25 +0000 (13:24 -0700)
committerrtrimana <rtrimana@uci.edu>
Thu, 8 Aug 2019 20:24:25 +0000 (13:24 -0700)
PresenceSensor/PresenceSensor.groovy
PresenceSensor/PresenceSensors.groovy

index b370736..7040a76 100644 (file)
@@ -2,6 +2,9 @@
 package PresenceSensor
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class PresenceSensor {
        private String id
        private String label
@@ -25,6 +28,56 @@ public class PresenceSensor {
                this.presence = value
                this.currentPresence = value
        }
+       
+       def statesSince() {
+               eventsSince()
+       }
+       
+       def statesSince(String info, Date dateObj) {
+               statesSince()
+       }
+       
+       def eventsSince(Date dateObj) {
+               eventsSince()
+       }
+
+       def eventsSince() {
+               def evtActive = [[name: "presence", value: "present", deviceId: "motionSensorID0", descriptionText: "",
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
+               def evtInactive = [[name: "presence", value: "not present", deviceId: "motionSensorID0", descriptionText: "",
+                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
+               def init = Verify.getInt(0,4)
+               def evtToSend = []
+               if (init == 0) {//return empty set
+                       return evtToSend
+               } else if (init == 1) {//send one active event
+                       evtActive.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 2) {//send two active events
+                       evtActive.each{
+                               evtToSend.add(it)
+                       }
+                       evtActive.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 3) {//send one inactive event
+                       evtInactive.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 4) {//send two inactive events
+                       evtInactive.each{
+                               evtToSend.add(it)
+                       }
+                       evtInactive.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               }
+       }
 
        def currentState(String deviceFeature) {
                return [rawDateCreated: [time: System.currentTimeMillis()]]
index fd88b33..782e25c 100644 (file)
@@ -76,6 +76,14 @@ public class PresenceSensors {
                presenceSensors[0].latestValue(deviceFeature)//It is called if we have only one device
        }
 
+       def statesSince(String info, Date dateObj) {
+               return presenceSensors[0].statesSince()
+       }
+
+       def eventsSince(Date dateObj) {
+               return presenceSensors[0].statesSince()
+       }
+
        def getAt(int ix) {
                presenceSensors[ix]
        }