Adding differentiation of two some event subscribing but different capabilities,...
authorrtrimana <rtrimana@uci.edu>
Fri, 26 Jul 2019 20:11:43 +0000 (13:11 -0700)
committerrtrimana <rtrimana@uci.edu>
Fri, 26 Jul 2019 20:11:43 +0000 (13:11 -0700)
Extractor/ExtractorScript.py
eventSimulator/smokeCarbonMonoxideClearEvent.groovy [new file with mode: 0644]
eventSimulator/smokeCarbonMonoxideDetectedEvent.groovy [new file with mode: 0644]
eventSimulator/smokeCarbonMonoxideTestedEvent.groovy [new file with mode: 0644]

index f986e16..375a688 100644 (file)
@@ -1,7 +1,9 @@
 import os
 readyToReturn = 0
 ToReturn = ""
-eventMap = []
+eventList = []
+eventVarMap = {}
+capabilityMap = {}
 app1Capabilities = []
 app2Capabilities = []
 app1Subscribe = False
@@ -38,7 +40,7 @@ def GetToken(f):
                        return "EOF"
 
 def ExtractFunctions(F, appName):
-       global eventMap
+       global eventList
        global app1Subscribe
        global app2Subscribe
        Temp = GetToken(F)
@@ -56,18 +58,32 @@ def ExtractFunctions(F, appName):
                                        extractedFunctionsApp2.write("def %s = this.&" % NameofFunc)
                                        extractedFunctionsApp2.write("%s\n" % NameofFunc)
                
+               #Check input capability
+               if (Temp == "input"):
+                       Temp = GetToken(F) #Get '"'
+                       variable = GetToken(F)
+                       Temp = GetToken(F) #Get '"'
+                       Temp = GetToken(F) #Get ','
+                       Temp = GetToken(F) #Get '"'
+                       Temp = GetToken(F) #Get capability...
+                       capability = Temp
+                       capabilityMap[variable] = capability
+               
                #Check subscribed events
                if (Temp == "subscribe"):
                        if (appName == "App1"):
                                app1Subscribe = True
                        else:
                                app2Subscribe = True
+                       Temp = GetToken(F)
+                       variable = Temp
                        while (Temp != "\"" and Temp != "app" and Temp != "location"):
                                Temp = GetToken(F)
                        if Temp == "\"":
                                Temp = GetToken(F)
-                       if Temp not in eventMap:
-                               eventMap.append(Temp)
+                       if Temp not in eventList:
+                               eventList.append(Temp)
+                               eventVarMap[Temp] = variable
 
                #Check and analyze capabilities for physical interaction
                AnalyzeCapabilities(Temp, appName)
@@ -118,43 +134,45 @@ def AnalyzePhysicalInteraction(app1Capab, app2Capab):
                print ("\nWARNING: Potential PHYSICAL CONFLICT (sound) detected between App1 and App2!\n")
 
 def ExtractEvents(extractedEvents):
-       global eventMap
+       global eventList
+       global eventVarMap
+       global capabilityMap
        extractedEvents.write("while(true) {\n")
-       extractedEvents.write("\tdef eventNumber = Verify.getInt(0,%d)\n" % (len(eventMap) - 1))
+       extractedEvents.write("\tdef eventNumber = Verify.getInt(0,%d)\n" % (len(eventList) - 1))
        extractedEvents.write("\tswitch(eventNumber) {\n")
-       for i in range(len(eventMap)):
+       for i in range(len(eventList)):
                extractedEvents.write("\t\tcase %d:\n" % i)
-               if eventMap[i] == "lock":
+               if eventList[i] == "lock":
                        event = open("eventSimulator/lockEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "unlock":
+               elif eventList[i] == "unlock":
                        event = open("eventSimulator/unlockEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "contact.open":
+               elif eventList[i] == "contact.open":
                        event = open("eventSimulator/contactOpenEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "contact.closed":
+               elif eventList[i] == "contact.closed":
                        event = open("eventSimulator/contactClosedEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "nfcTouch":
+               elif eventList[i] == "nfcTouch":
                        event = open("eventSimulator/nfcTouchEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "app": #Case for Touched event
+               elif eventList[i] == "app": #Case for Touched event
                        event = open("eventSimulator/appTouchEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "button":
+               elif eventList[i] == "button":
                        #Write two events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -168,7 +186,7 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "presence":
+               elif eventList[i] == "presence":
                        #Write two events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -182,7 +200,7 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "doorState":
+               elif eventList[i] == "doorState":
                        #Write two events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -196,7 +214,7 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "motion":
+               elif eventList[i] == "motion":
                        #Write two events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -210,7 +228,7 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "smoke":
+               elif eventList[i] == "smoke":
                        #Write three events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,2)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -229,31 +247,44 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "carbonMonoxide":
+               elif eventList[i] == "carbonMonoxide":
+                       #Check which capability
+                       variable = eventVarMap[eventList[i]]
+                       capability = capabilityMap[variable]
+       
                        #Write three events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,2)\n")
-                       extractedEvents.write("\t\t\tif (event == 0) {\n")
-                       event = open("eventSimulator/carbonMonoxideClearEvent.groovy", "r")                     
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")                      
+                       if capability == "capability.smokeDetector":
+                               event = open("eventSimulator/smokeCarbonMonoxideClearEvent.groovy", "r")
+                       elif capability == "capability.carbonMonoxideDetector":
+                               event = open("eventSimulator/carbonMonoxideClearEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t} else if (event == 1) {\n")
-                       event = open("eventSimulator/carbonMonoxideDetectedEvent.groovy", "r")
+                       if capability == "capability.smokeDetector":
+                               event = open("eventSimulator/smokeCarbonMonoxideDetectedEvent.groovy", "r")
+                       elif capability == "capability.carbonMonoxideDetector":
+                               event = open("eventSimulator/carbonMonoxideDetectedEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t} else {\n")
-                       event = open("eventSimulator/carbonMonoxideTestedEvent.groovy", "r")
+                       if capability == "capability.smokeDetector":
+                               event = open("eventSimulator/smokeCarbonMonoxideTestedEvent.groovy", "r")
+                       elif capability == "capability.carbonMonoxideDetector":
+                               event = open("eventSimulator/carbonMonoxideTestedEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "battery":
+               elif eventList[i] == "battery":
                        event = open("eventSimulator/batteryChargeEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "thermostatMode":
+               elif eventList[i] == "thermostatMode":
                        #Write five events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,4)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -282,7 +313,7 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "switch":
+               elif eventList[i] == "switch":
                        #Write two events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -296,7 +327,7 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "location": #Case for Location event
+               elif eventList[i] == "location": #Case for Location event
                        #Write three events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,2)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -315,7 +346,7 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "acceleration":
+               elif eventList[i] == "acceleration":
                        #Write two events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -329,7 +360,7 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "beacon":
+               elif eventList[i] == "beacon":
                        #Write two events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -343,17 +374,17 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventMap[i] == "color":
+               elif eventList[i] == "color":
                        event = open("eventSimulator/colorChangeEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "hue":
+               elif eventList[i] == "hue":
                        event = open("eventSimulator/hueChangeEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "saturation":
+               elif eventList[i] == "saturation":
                        event = open("eventSimulator/saturationChangeEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
@@ -362,14 +393,13 @@ def ExtractEvents(extractedEvents):
                ###TODO: Add more events later
                extractedEvents.write("\t\t\tbreak\n")
        extractedEvents.write("\t}\n")
-       #extractedEvents.write("\tcounter--\n")
        extractedEvents.write("}\n")
        
 def CheckIfOnlyTouchEvents():
        #Check and throw an error if it is all touch events
        #This is called Direct-Direct interaction and we do not model-check for this case
        onlyTouchEvents = True
-       for item in eventMap:
+       for item in eventList:
                if item != "nfcTouch" and item != "app":
                        onlyTouchEvents = False
        if onlyTouchEvents is True and app1Subscribe is True and app2Subscribe is True:
diff --git a/eventSimulator/smokeCarbonMonoxideClearEvent.groovy b/eventSimulator/smokeCarbonMonoxideClearEvent.groovy
new file mode 100644 (file)
index 0000000..09db47c
--- /dev/null
@@ -0,0 +1,2 @@
+                       smokeDetectorObject.setValue([name: "carbonMonoxide", value: "clear", deviceId: "smokeDetectorID0", descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
diff --git a/eventSimulator/smokeCarbonMonoxideDetectedEvent.groovy b/eventSimulator/smokeCarbonMonoxideDetectedEvent.groovy
new file mode 100644 (file)
index 0000000..5aa27d1
--- /dev/null
@@ -0,0 +1,2 @@
+                       smokeDetectorObject.setValue([name: "carbonMonoxide", value: "detected", deviceId: "smokeDetectorID0", descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])
diff --git a/eventSimulator/smokeCarbonMonoxideTestedEvent.groovy b/eventSimulator/smokeCarbonMonoxideTestedEvent.groovy
new file mode 100644 (file)
index 0000000..0c6e18e
--- /dev/null
@@ -0,0 +1,2 @@
+                       smokeDetectorObject.setValue([name: "carbonMonoxide", value: "tested", deviceId: "smokeDetectorID0", descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])