import Button.Buttons
import ThreeAxis.ThreeAxis
import ThreeAxis.ThreeAxises
+import Momentary.Momentary
+import Momentary.Momentaries
import Timer.SimulatedTimer
//GlobalVariables
@Field def threeAxisObject0
@Field def threeAxisObject1
@Field def threeAxisObject2
+//Global Object for class momentary switch device!
+@Field momentaryObjects = 0
+@Field def momentaryObject0
+@Field def momentaryObject1
+@Field def momentaryObject2
//Global variables
extractedObjectsConstructorApp2.append(metaData['name']+" = obj.accelerationSensorObject\n")
}
break
+ case "capability.momentary":
+ globalObjects.eachLine { line ->
+ if(line.contains("momentoryObject")){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def momentaryObject = new Momentaries(sendEvent, 1)\n")
+
+ if (momentaryObjects == 0) {
+ momentaryObject0 = metaData['name']
+ this[momentaryObject0] = new Momentaries({}, 1)
+ } else if (momentaryObjects == 1) {
+ momentaryObject1 = metaData['name']
+ this[momentaryObject1] = new Momentaries({}, 1)
+ } else if (momentaryObjects == 2) {
+ momentaryObject2 = metaData['name']
+ this[momentaryObject2] = new Momentaries({}, 1)
+ }
+
+ momentaryObjects=momentaryObjects+1
+
+ settings.put(metaData['name'], new Momentaries({}, 1))
+
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class momentory switch class!\n")
+ extractedObjectsApp1.append("def "+metaData['name']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['name']+" = obj.momentaryObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class momentory Sensor!\n")
+ extractedObjectsApp2.append("def "+metaData['name']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['name']+" = obj.momentaryObject\n")
+ }
+ break
case "capability.motionSensor":
globalObjects.eachLine { line ->
if(line.contains("motionSensorObject")){
--- /dev/null
+//Create a class for momentory switch device
+package Momentary
+import Timer.SimulatedTimer
+
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
+public class Momentaries {
+ int deviceNumbers
+ List momentaries
+ def sendEvent
+
+ //If we have only one device
+ private String id = "momentaryID0"
+ private String label = "momentary0"
+ private String displayName = "momentary0"
+
+ Momentaries(Closure sendEvent, int deviceNumbers) {
+ this.sendEvent = sendEvent
+ this.deviceNumbers = deviceNumbers
+ this.momentaries = []
+
+ /*def init = Verify.getBoolean()
+ if (init) {
+ this.doorState = "closed"
+ this.doorLatestValue = "closed"
+ } else {
+ this.doorState = "open"
+ this.doorLatestValue = "open"
+ }*/
+ momentaries.add(new Momentary(sendEvent, id, label, displayName))
+ }
+
+ //Methods for closures
+ def count(Closure Input) {
+ momentaries.count(Input)
+ }
+ def size() {
+ momentaries.size()
+ }
+ def each(Closure Input) {
+ momentaries.each(Input)
+ }
+ def find(Closure Input) {
+ momentaries.find(Input)
+ }
+ def sort(Closure Input) {
+ momentaries.sort(Input)
+ }
+ def collect(Closure Input) {
+ momentaries.collect(Input)
+ }
+
+ //By Apps
+ def push() {
+ momentaries[0].push()
+ }
+
+ //By Model Checker
+ def setValue(LinkedHashMap eventDataMap) {
+ momentaries[0].setValue(eventDataMap["value"])
+ sendEvent(eventDataMap)
+ }
+
+ def getAt(int ix) {
+ momentaries[ix]
+ }
+}
--- /dev/null
+//Create a class for momentory switch device
+package Momentary
+import Timer.SimulatedTimer
+
+public class Momentary {
+ private String id
+ private String label
+ private String displayName
+ def sendEvent
+
+
+ Momentary(Closure sendEvent, String id, String label, String displayName) {
+ this.sendEvent = sendEvent
+ this.id = id
+ this.label = label
+ this.displayName = displayName
+ }
+
+ //By Apps
+ def push() {
+ println("the momentary switch with id:$id is pushed!")
+ sendEvent([name: "momentary", value: "pushed", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+
+ //By Model Checker
+ def setValue(String value) {
+ println("the momentary switch with id:$id is pushed!")
+ }
+
+}
Out.write("import Button.Buttons\n")
Out.write("import ThreeAxis.ThreeAxis\n")
Out.write("import ThreeAxis.ThreeAxises\n")
+Out.write("import Momentary.Momentary\n")
+Out.write("import Momentary.Momentaries\n")
Out.write("import Event.Event\n")
Out.write("import Timer.SimulatedTimer\n")
Out.write("\n")