import os
readyToReturn = 0
ToReturn = ""
-eventMap = []
+eventList = []
+eventVarMap = {}
+capabilityMap = {}
app1Capabilities = []
app2Capabilities = []
app1Subscribe = False
return "EOF"
def ExtractFunctions(F, appName):
- global eventMap
+ global eventList
global app1Subscribe
global app2Subscribe
Temp = GetToken(F)
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)
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")
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")
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")
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")
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")
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")
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")
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")
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")
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")
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)
###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: