Browse Source

Updates to Mv code

Yentl Van Tendeloo 8 years ago
parent
commit
7aefd81dfa
3 changed files with 29 additions and 29 deletions
  1. 1 0
      integration/code/cbd_runtime.mvc
  2. 9 11
      integration/code/cbd_semantics.alc
  3. 19 18
      interface/CBD/main.py

+ 1 - 0
integration/code/cbd_runtime.mvc

@@ -58,6 +58,7 @@ SCD CausalBlockDiagrams_Runtime{
             target_lower_cardinality = 1
             target_upper_cardinality = 1
         }
+    }
 
     Association Link(Block, Block){
     }

+ 9 - 11
integration/code/cbd_semantics.alc

@@ -150,14 +150,13 @@ Void function step_simulation(model : Element, schedule : Element):
 	String block
 	String elem
 	String blocktype
-	String output_string
 	Element delay_blocks
 	Integer i
 
 	time = "time"
 
 	delay_blocks = create_node()
-	output_string = "("
+	output("SIM_TIME " + cast_v2s(read_attribute(model, time, "current_time")))
 	i = 0
 	while (i < read_nr_out(schedule)):
 		block = list_read(schedule, i)
@@ -203,8 +202,8 @@ Void function step_simulation(model : Element, schedule : Element):
 
 		unset_attribute(model, block, "signal")
 		instantiate_attribute(model, block, "signal", signal)
-		output_string = output_string + (((block + " = ") + cast_v2s(signal)) + "; ")
-	output_string = output_string + ")"
+		output((("SIM_PROBE " + cast_v2s(block)) + " ") + cast_v2s(signal))
+	output("SIM_END")
 	
 	while (read_nr_out(delay_blocks) > 0):
 		block = set_pop(delay_blocks)
@@ -219,7 +218,6 @@ Void function step_simulation(model : Element, schedule : Element):
 	new_time = cast_s2i(cast_v2s(read_attribute(model, time, "current_time"))) + 1
 	unset_attribute(model, time, "current_time")
 	instantiate_attribute(model, time, "current_time", new_time)
-	output(output_string)
 
 	return !
 
@@ -238,7 +236,7 @@ Void function execute_cbd(design_model : Element):
 	runtime_model = retype_to_runtime(design_model)
 	runtime_model = sanitize(runtime_model, old_runtime_model)
 	running = False
-	conforming = string_eq(conformance_scd(design_model), "OK")
+	conforming = value_eq(conformance_scd(design_model), "OK")
 
 	schedule_init = create_schedule(runtime_model, read_attribute(runtime_model, "time", "start_time"))
 	schedule_run = create_schedule(runtime_model, -1)
@@ -277,15 +275,15 @@ Void function execute_cbd(design_model : Element):
 			Element attr_list
 			attr_list = dict_keys(getAttributeList(model, cmd))
 			while (0 < read_nr_out(attr_list)):
-				output(set_pop(attr_list))
+				output("AVAILABLE_ATTR_VALUE " + set_pop(attr_list))
+			output("AVAILABLE_ATTR_END")
 
 		elif (cmd == "read_attribute"):
 			// Returns the value of an attribute
-			output(read_attribute(runtime_model, input(), input()))
+			output("ATTR_VALUE " + cast_v2s(read_attribute(runtime_model, input(), input())))
 
-		elif (cmd == "modify"):
+		elif (boolean_or(boolean_or(cmd == "set_attribute", cmd == "instantiate_node"), cmd == "instantiate_association")):
 			// Modify the structure
-			cmd = input()
 			if (cmd == "set_attribute"):
 				// Setting an attribute
 				String element_name
@@ -309,7 +307,7 @@ Void function execute_cbd(design_model : Element):
 				instantiate_link(design_model, input(), input(), input(), input())
 
 			// After changes, we check whether or not the design model conforms
-			conforming = string_eq(conformance_scd(design_model), "OK")
+			conforming = value_eq(conformance_scd(design_model), "OK")
 			if (conforming):
 				// Conforming, so do the retyping and sanitization step
 				runtime_model = retype_to_runtime(design_model)

+ 19 - 18
interface/CBD/main.py

@@ -60,29 +60,30 @@ class FakeLayer():
 attribute = []
 available_attrs = []
 simulation = []
+#simulation = [(1, {"a": 1, "b": 2}), (2, {"a": 3}), (3, {"a": 4, "b": 6})]
 
 def poll(address):
-    working_attribute = []
     working_available_attrs = []
-    working_simulation = []
+    working_simulation = None
 
     while 1:
         returnvalue = urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "username": "CBD_env"}))).read()
-        if returnvalue.startswith("AVAILABLE:"):
-            working_available_attrs.append(returnvalue.split(":", 1)[1])
-        elif returnvalue.startswith("ATTRIBUTE:"):
-            working_attribute.append(returnvalue.split(":", 1)[1])
-        elif returnvalue.startswith("SIMULATION:"):
-            working_simulation.append(returnvalue.split(":", 1)[1])
-        elif returnvalue.startswith("FINISH_AVAILABLE"):
-            available_attrs.append(working_available_attrs)
-            working_available_attrs = []
-        elif returnvalue.startswith("FINISH_ATTRIBUTE"):
-            attributes.append(working_attributes)
-            working_attributes = []
-        elif returnvalue.startswith("FINISH_SIMULATION"):
+        print("Process " + str(returnvalue))
+        if (returnvalue.startswith("AVAILABLE_ATTR_VALUE")):
+            working_available_attrs.append(returnvalue.split(" ", 1)[1])
+        elif (returnvalue.startswith("AVAILABLE_ATTR_END")):
+            available_attrs.append(working_available)
+            working_available = []
+        elif (returnvalue.startswith("ATTR_VALUE")):
+            attribute.append(returnvalue.split(" ", 1)[1])
+        elif (returnvalue.startswith("SIM_TIME")):
+            working_simulation = (float(returnvalue.split(" ", 1)[1]), {})
+        elif (returnvalue.startswith("SIM_PROBE")):
+            blockname, blockvalue = returnvalue.split(" ", 1)[1].rsplit(" ", 1)
+            working_simulation[1][blockname] = blockvalue
+        elif (returnvalue.startswith("SIM_END")):
             simulation.append(working_simulation)
-            working_simulation = []
+            working_simulation = None
 
 class MvLayer():
     def __init__(self, address):
@@ -116,12 +117,12 @@ class MvLayer():
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % value, "username": "CBD_env"}))).read()
 
     def instantiate_block(self, name, block_type):
-        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"instantiate"', "username": "CBD_env"}))).read()
+        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"instantiate_node"', "username": "CBD_env"}))).read()
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % (block_type), "username": "CBD_env"}))).read()
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % (name), "username": "CBD_env"}))).read()
 
     def instantiate_link(self, name, link_type, source, target):
-        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"instantiate"', "username": "CBD_env"}))).read()
+        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"instantiate_association"', "username": "CBD_env"}))).read()
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % (link_type), "username": "CBD_env"}))).read()
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % (name), "username": "CBD_env"}))).read()
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % (source), "username": "CBD_env"}))).read()