X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=AccelerationSensor%2FAccelerationSensor.groovy;h=905e018010b3aa721104da31a3326bd4c5543dfd;hb=55f57d1619271ede7bbd5c83e6218df6772afc89;hp=1bec3cd303ea0785c7a499fde1525cf05b16420c;hpb=c3be64e00452e6b9789207f5746ab4089fcf1f0f;p=smartthings-infrastructure.git diff --git a/AccelerationSensor/AccelerationSensor.groovy b/AccelerationSensor/AccelerationSensor.groovy index 1bec3cd..905e018 100644 --- a/AccelerationSensor/AccelerationSensor.groovy +++ b/AccelerationSensor/AccelerationSensor.groovy @@ -2,6 +2,9 @@ package AccelerationSensor import Timer.SimulatedTimer +//JPF's Verify API +import gov.nasa.jpf.vm.Verify + public class AccelerationSensor { private String id private String label @@ -9,8 +12,6 @@ public class AccelerationSensor { private String acceleration private String currentAcceleration private String accelerationLatestValue - private List states = [] - private List timeOfStates = [] AccelerationSensor(String id, String label, String displayName, String acceleration, String accelerationLatestValue) { this.id = id @@ -22,22 +23,86 @@ public class AccelerationSensor { } def setValue(String value) { - this.accelerationLatestValue = acceleration println("the acceleration sensor with id:$id is triggered to $value!") + this.accelerationLatestValue = value this.acceleration = value this.currentAcceleration = value - this.states.add(value) - this.timeOfStates.add(System.currentTimeMillis()) } - def statesSince(String info, Date dateObj) { - def List happenedStates = [] - def sinceThen = dateObj.time - for (int i = 0;i < timeOfStates.size();i++) { - if (timeOfStates[i]>=sinceThen) - happenedStates.add(states[i]) + def statesSince() { + def evtActive = [[name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']] + def evtInactive = [[name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", 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 eventsSince() { + def evtActive = [[name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']] + def evtInactive = [[name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", 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 } - return happenedStates }