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
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
}
}
package AeonKeyFob
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class AeonKeyFobs {
private int deviceNumbers
private List aeonKeyFobs
//methods
def eventsSince(Date dateObj) {
- return aeonKeyFobs[0].eventsSince(dateObj)
+ return aeonKeyFobs[0].eventsSince()
}
public class ColorControl {
+ def sendEvent
private String id
private String label
private String displayName
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
this.level = level
this.currentSwitch = currentSwitch
this.colorTemperature = colorTemperature
+ this.sendEvent = sendEvent
}
//By model checker
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
package ContactSensor
import Timer.SimulatedTimer
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
public class ContactSensor {
private String id
private String label
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
}
}
+ def eventsSince(Date dateObj) {
+ return contacts[0].eventsSince()
+ }
+
def on() {
this.alarmState = "armed"
contacts[0].on()
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
/////////////////////////////////////////////////////////////////////
////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) {
}
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"()
}
/////////////////////////////////////////////////////////////////////
def runOnce(Date date, Closure methodToCall) {
- methodTocall()
+ methodToCall()
}
/////////////////////////////////////////////////////////////////////
////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()
}
/////////////////////////////////////////////////////////////////////
////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()
- }
+ }*/
}