Solving conflicts
authoramiraj <amiraj.95@uci.edu>
Tue, 6 Aug 2019 23:00:20 +0000 (16:00 -0700)
committeramiraj <amiraj.95@uci.edu>
Tue, 6 Aug 2019 23:00:20 +0000 (16:00 -0700)
Extractor/Extractor.groovy
Momentary/Momentaries.groovy [new file with mode: 0644]
Momentary/Momentary.groovy [new file with mode: 0644]
Runner.py

index 4c90690d7266816e62564a6e679c21e3e9b30280..16038e3b078f450b6f02b7e9b7d182de96ad8751 100644 (file)
@@ -76,6 +76,8 @@ import Button.Button
 import Button.Buttons
 import ThreeAxis.ThreeAxis
 import ThreeAxis.ThreeAxises
+import Momentary.Momentary
+import Momentary.Momentaries
 import Timer.SimulatedTimer
 
 //GlobalVariables
@@ -295,6 +297,11 @@ def timeToday(String time, Object timeZone) {
 @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
@@ -895,6 +902,41 @@ def input(LinkedHashMap metaData) {
                                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")){
diff --git a/Momentary/Momentaries.groovy b/Momentary/Momentaries.groovy
new file mode 100644 (file)
index 0000000..aa4e177
--- /dev/null
@@ -0,0 +1,68 @@
+//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]
+       }
+}
diff --git a/Momentary/Momentary.groovy b/Momentary/Momentary.groovy
new file mode 100644 (file)
index 0000000..6b9f0e0
--- /dev/null
@@ -0,0 +1,31 @@
+//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!")
+       }
+       
+}
index 0c0492eeca8d105a1e2ccedc264be0e996396b9a..e5700dfa327527e6a9e53e7c3f1f8b2c47a4f951 100644 (file)
--- a/Runner.py
+++ b/Runner.py
@@ -118,6 +118,8 @@ Out.write("import Button.Button\n")
 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")