From c1971948245fda1774c4c76451387ae8c0b7ebc0 Mon Sep 17 00:00:00 2001 From: amiraj Date: Fri, 2 Aug 2019 16:38:56 -0700 Subject: [PATCH] creating eventsSince for ContactSensor and AeonKeyFobs + commenting runAfter method call + commenting not required queues for timers and functions based on that(We have no delay) --- AeonKeyFob/AeonKeyFob.groovy | 49 +++++++++++---- AeonKeyFob/AeonKeyFobs.groovy | 5 +- ColorControl/ColorControl.groovy | 4 +- ColorControl/ColorControls.groovy | 2 +- ContactSensor/ContactSensor.groovy | 49 +++++++++++++++ ContactSensor/ContactSensors.groovy | 4 ++ GlobalVariables/GlobalVariablesEachApp.groovy | 4 -- Methods/runIn.groovy | 10 ++-- Methods/runOnce.groovy | 2 +- Methods/schedule.groovy | 60 ++++++++++--------- Methods/unschedule.groovy | 12 ++-- 11 files changed, 143 insertions(+), 58 deletions(-) diff --git a/AeonKeyFob/AeonKeyFob.groovy b/AeonKeyFob/AeonKeyFob.groovy index 8ece0c6..72e5afd 100644 --- a/AeonKeyFob/AeonKeyFob.groovy +++ b/AeonKeyFob/AeonKeyFob.groovy @@ -2,12 +2,13 @@ package AeonKeyFob import Timer.SimulatedTimer +//JPF's Verify API +import gov.nasa.jpf.vm.Verify + public class AeonKeyFob { private String id private String label private String displayName - private List events = [] - private List timeOfEvents = [] AeonKeyFob(String id, String label, String displayName) { this.id = id @@ -19,17 +20,43 @@ public class AeonKeyFob { def data = eventDataMap["data"] def value = eventDataMap["value"] println("the button with number $data is $value!") - this.events.add(eventDataMap) - this.timeOfEvents.add(System.currentTimeMillis()) } - def eventsSince(Date dateObj) { - def List happenedEvents = [] - def sinceThen = dateObj.time - for (int i = 0;i < timeOfEvents.size();i++) { - if (timeOfEvents[i]>=sinceThen) - happenedEvents.add(events[i]) + def eventsSince() { + def evtHeld = [[name: "button", value: "held", deviceId: "aeonKeyFobID0", descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']] + def evtPushed = [[name: "button", value: "pushed", deviceId: "aeonKeyFobID0", 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 held event + evtHeld.each{ + evtToSend.add(it) + } + return evtToSend + } else if (init == 2) {//send two held events + evtHeld.each{ + evtToSend.add(it) + } + evtHeld.each{ + evtToSend.add(it) + } + return evtToSend + } else if (init == 3) {//send one pushed event + evtPushed.each{ + evtToSend.add(it) + } + return evtToSend + } else if (init == 4) {//send two pushed events + evtPushed.each{ + evtToSend.add(it) + } + evtPushed.each{ + evtToSend.add(it) + } + return evtToSend } - return happenedEvents } } diff --git a/AeonKeyFob/AeonKeyFobs.groovy b/AeonKeyFob/AeonKeyFobs.groovy index bbb1a35..6383898 100644 --- a/AeonKeyFob/AeonKeyFobs.groovy +++ b/AeonKeyFob/AeonKeyFobs.groovy @@ -2,6 +2,9 @@ package AeonKeyFob import Timer.SimulatedTimer +//JPF's Verify API +import gov.nasa.jpf.vm.Verify + public class AeonKeyFobs { private int deviceNumbers private List aeonKeyFobs @@ -50,7 +53,7 @@ public class AeonKeyFobs { //methods def eventsSince(Date dateObj) { - return aeonKeyFobs[0].eventsSince(dateObj) + return aeonKeyFobs[0].eventsSince() } diff --git a/ColorControl/ColorControl.groovy b/ColorControl/ColorControl.groovy index 53658dc..4d6eaf7 100644 --- a/ColorControl/ColorControl.groovy +++ b/ColorControl/ColorControl.groovy @@ -4,6 +4,7 @@ import Timer.SimulatedTimer public class ColorControl { + def sendEvent private String id private String label private String displayName @@ -14,7 +15,7 @@ public class ColorControl { private int saturation private int colorTemperature - ColorControl(String id, String label, String displayName, String color, int hue, int saturation, int level, String currentSwitch, int colorTemperature) { + ColorControl(Closure sendEvent, String id, String label, String displayName, String color, int hue, int saturation, int level, String currentSwitch, int colorTemperature) { this.id = id this.label = label this.displayName = displayName @@ -24,6 +25,7 @@ public class ColorControl { this.level = level this.currentSwitch = currentSwitch this.colorTemperature = colorTemperature + this.sendEvent = sendEvent } //By model checker diff --git a/ColorControl/ColorControls.groovy b/ColorControl/ColorControls.groovy index 5b29f55..5262e91 100644 --- a/ColorControl/ColorControls.groovy +++ b/ColorControl/ColorControls.groovy @@ -40,7 +40,7 @@ public class ColorControls { this.color = "blue" }*/ - colorControls.add(new ColorControl(id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature)) + colorControls.add(new ColorControl(sendEvent, id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature)) } //Methods for closures diff --git a/ContactSensor/ContactSensor.groovy b/ContactSensor/ContactSensor.groovy index 413b58c..4a10a57 100644 --- a/ContactSensor/ContactSensor.groovy +++ b/ContactSensor/ContactSensor.groovy @@ -2,6 +2,9 @@ package ContactSensor import Timer.SimulatedTimer +//JPF's Verify API +import gov.nasa.jpf.vm.Verify + public class ContactSensor { private String id private String label @@ -24,6 +27,52 @@ public class ContactSensor { this.alarmState = alarmState } + def eventsSince() { + def evtOpen = [[name: "contact.open", value: "open", deviceId: "contactSensorID0", descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'], + [name: "contact", value: "open", deviceId: "contactSensorID0", descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'], + [name: "tamper.tampered", value: "open", deviceId: "contactSensorID0", descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']] + def evtClosed = [[name: "contact.closed", value: "closed", deviceId: "contactSensorID0", descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'], + [name: "contact", value: "closed", deviceId: "contactSensorID0", descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'], + [name: "tamper.tampered", value: "closed", deviceId: "contactSensorID0", 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 open event + evtOpen.each{ + evtToSend.add(it) + } + return evtToSend + } else if (init == 2) {//send two open events + evtOpen.each{ + evtToSend.add(it) + } + evtOpen.each{ + evtToSend.add(it) + } + return evtToSend + } else if (init == 3) {//send one closed event + evtClosed.each{ + evtToSend.add(it) + } + return evtToSend + } else if (init == 4) {//send two closed events + evtClosed.each{ + evtToSend.add(it) + } + evtClosed.each{ + evtToSend.add(it) + } + return evtToSend + } + } + def setValue(String value) { println("the contact sensor with id:$id is triggered to $value!") this.contactState = value diff --git a/ContactSensor/ContactSensors.groovy b/ContactSensor/ContactSensors.groovy index 74508a8..5f5f20e 100644 --- a/ContactSensor/ContactSensors.groovy +++ b/ContactSensor/ContactSensors.groovy @@ -59,6 +59,10 @@ public class ContactSensors { } } + def eventsSince(Date dateObj) { + return contacts[0].eventsSince() + } + def on() { this.alarmState = "armed" contacts[0].on() diff --git a/GlobalVariables/GlobalVariablesEachApp.groovy b/GlobalVariables/GlobalVariablesEachApp.groovy index 8ae34ad..ae8b936 100644 --- a/GlobalVariables/GlobalVariablesEachApp.groovy +++ b/GlobalVariables/GlobalVariablesEachApp.groovy @@ -8,10 +8,6 @@ def functionList = [] def objectList = [] //Create a global variable for Events in Subscribe method def eventList = [] -//Create a global list for function schedulers -def timersFuncList = [] -//Create a global list for timer schedulers -def timersList = [] //Create a global variable for settings def settings //Zip code diff --git a/Methods/runIn.groovy b/Methods/runIn.groovy index 6e4bea3..1ca8d95 100644 --- a/Methods/runIn.groovy +++ b/Methods/runIn.groovy @@ -1,14 +1,15 @@ ///////////////////////////////////////////////////////////////////// ////runIn(time, func) def runIn(int seconds, Closure functionToCall) { - if (timersFuncList.contains(functionToCall)) { + /*if (timersFuncList.contains(functionToCall)) { timersList[timersFuncList.indexOf(functionToCall)].cancel() def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds*0, functionToCall) } else { timersFuncList.add(functionToCall) timersList.add(new SimulatedTimer()) def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds*0, functionToCall) - } + }*/ + functionToCall() } def runIn(int seconds, Closure functionToCall, LinkedHashMap metaData) { @@ -20,9 +21,10 @@ def runIn(int seconds, String nameOfFunction, LinkedHashMap metaData) { } def runIn(int seconds, String nameOfFunction) { - timersFuncList.add(nameOfFunction) + /*timersFuncList.add(nameOfFunction) timersList.add(new SimulatedTimer()) def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(seconds*1000*0) { "$nameOfFunction"() - } + }*/ + "$nameOfFunction"() } diff --git a/Methods/runOnce.groovy b/Methods/runOnce.groovy index 335cc19..308f6c3 100644 --- a/Methods/runOnce.groovy +++ b/Methods/runOnce.groovy @@ -1,4 +1,4 @@ ///////////////////////////////////////////////////////////////////// def runOnce(Date date, Closure methodToCall) { - methodTocall() + methodToCall() } diff --git a/Methods/schedule.groovy b/Methods/schedule.groovy index 307b221..1d8c810 100644 --- a/Methods/schedule.groovy +++ b/Methods/schedule.groovy @@ -1,49 +1,51 @@ ///////////////////////////////////////////////////////////////////// ////schedule(time, nameOfFunction as String) def schedule(String time, String nameOfFunction) { - //def _inputTime = time.split(':') - //Date date = new Date() - //def _currentTime = date.format("HH:mm:ss").split(':') + /*def _inputTime = time.split(':') + Date date = new Date() + def _currentTime = date.format("HH:mm:ss").split(':') - //Convert input time and current time to minutes - //def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60 - //def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2]) - //def delay + Convert input time and current time to minutes + def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60 + def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2]) + def delay - //if (inputTime < currentTime) { - // delay = 24*60*60-inputTime+currentTime - //} else { - // delay = inputTime-currentTime - //} + if (inputTime < currentTime) { + delay = 24*60*60-inputTime+currentTime + } else { + delay = inputTime-currentTime + } timersFuncList.add(nameOfFunction) timersList.add(new SimulatedTimer()) - def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(/*delay*1000*0*/0) { + def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*1000*0) { "$nameOfFunction"() - } + }*/ + "$nameOfFunction"() } ////schedule(time, nameOfFunction as Closure) def schedule(String time, Closure nameOfFunction) { - //def _inputTime = time.split(':') - //Date date = new Date() - //def _currentTime = date.format("HH:mm:ss").split(':') + /*def _inputTime = time.split(':') + Date date = new Date() + def _currentTime = date.format("HH:mm:ss").split(':') - //Convert input time and current time to minutes - //def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60 - //def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2]) - //def delay + Convert input time and current time to minutes + def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60 + def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2]) + def delay - //if (inputTime < currentTime) { - // delay = 24*60*60-inputTime+currentTime - //} else { - // delay = inputTime-currentTime - //} + if (inputTime < currentTime) { + delay = 24*60*60-inputTime+currentTime + } else { + delay = inputTime-currentTime + } if (timersFuncList.contains(nameOfFunction)) { timersList[timersFuncList.indexOf(nameOfFunction)].cancel() - def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(/*delay*0*/0, nameOfFunction0) + def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(0, nameOfFunction) } else { timersFuncList.add(nameOfFunction) timersList.add(new SimulatedTimer()) - def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(/*delay*0*/0, nameOfFunction) - } + def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(0, nameOfFunction) + }*/ + nameOfFunction() } diff --git a/Methods/unschedule.groovy b/Methods/unschedule.groovy index 7f6ca1f..22ff922 100644 --- a/Methods/unschedule.groovy +++ b/Methods/unschedule.groovy @@ -1,29 +1,29 @@ ///////////////////////////////////////////////////////////////////// ////unschedule(func) def unschedule(Closure functionToUnschedule) { - for (int i = 0;i < timersFuncList.size();i++) { + /*for (int i = 0;i < timersFuncList.size();i++) { if (timersFuncList[i] == functionToUnschedule) { if (timersList != null) timersList[i].cancel() } - } + }*/ } def unschedule(String nameOfFunctionToUnschedule) { - for (int i = 0;i < timersFuncList.size();i++) { + /*for (int i = 0;i < timersFuncList.size();i++) { if (timersFuncList[i] instanceof String) { if (timersFuncList[i] == nameOfFunctionToUnschedule) { if (timersList != null) timersList[i].cancel() } } - } + }*/ } def unschedule() { - for (int i = 0;i < timersFuncList.size();i++) { + /*for (int i = 0;i < timersFuncList.size();i++) { if (timersList != null) timersList[i].cancel() - } + }*/ } -- 2.34.1