浏览代码

Fixed most bugs: something starts working

Yentl Van Tendeloo 8 年之前
父节点
当前提交
5a2971493d
共有 4 个文件被更改,包括 45 次插入18 次删除
  1. 1 2
      integration/code/fsa_design.mvc
  2. 1 2
      integration/code/fsa_runtime.mvc
  3. 2 0
      integration/code/fsa_semantics.alc
  4. 41 14
      interface/FSA/main.py

+ 1 - 2
integration/code/fsa_design.mvc

@@ -12,8 +12,6 @@ SCD FiniteStateAutomata_Design{
     }
 
     Class State {
-        lower_cardinality = 1
-
         name : String {
             target_lower_cardinality = 1
             target_upper_cardinality = 1
@@ -21,6 +19,7 @@ SCD FiniteStateAutomata_Design{
     }
 
     Class InitialState {
+        lower_cardinality = 1
         upper_cardinality = 1
     }
 

+ 1 - 2
integration/code/fsa_runtime.mvc

@@ -12,8 +12,6 @@ SCD FiniteStateAutomata_Runtime{
     }
 
     Class State {
-        lower_cardinality = 1
-
         name : String {
             target_lower_cardinality = 1
             target_upper_cardinality = 1
@@ -21,6 +19,7 @@ SCD FiniteStateAutomata_Runtime{
     }
 
     Class InitialState {
+        lower_cardinality = 1
         upper_cardinality = 1
     }
 

+ 2 - 0
integration/code/fsa_semantics.alc

@@ -188,7 +188,9 @@ Void function execute_fsa(design_model : Element):
 
 		elif (cmd == "read_attribute"):
 			// Returns the value of an attribute
+			log("Sending attribute value for")
 			output("ATTR_VALUE " + cast_v2s(read_attribute(design_model, input(), input())))
+			log("Sending OK")
 
 		elif (bool_or(cmd == "switch_initial", bool_or(bool_or(cmd == "set_attribute", cmd == "instantiate_node"), bool_or(cmd == "delete_element", cmd == "instantiate_association")))):
 			// Modify the structure

+ 41 - 14
interface/FSA/main.py

@@ -89,6 +89,8 @@ outp_evts = []
 #state = [(0, "idle"), (2, "armed"), (6, "detected"), (8, "idle")]
 #outp_evts = [(6, "soundAlarm"), ]
 
+do_color = "grey"
+
 def poll(address):
     simulation_time = None
     working_available_attrs = []
@@ -119,12 +121,15 @@ def poll(address):
         elif (returnvalue.startswith("SIM_RAISE")):
             outp_evts.append((simulation_time, returnvalue.split(" ", 1)[1]))
         elif (returnvalue.startswith("CONFORMANCE_OK")):
-            root.configure(background="grey")
+            global do_color
+            do_color = "grey"
         elif (returnvalue.startswith("CONFORMANCE_FAIL")):
-            root.configure(background="red")
-        elif (returnvalue.startswith("REQUEST_CURRENT_STATE"):
-            root.configure(background="blue")
+            global do_color
+            do_color = "red"
+        elif (returnvalue.startswith("REQUEST_CURRENT_STATE")):
+            global do_color
             global request_new_state
+            do_color = "blue"
             request_new_state = True
         else:
             print("Error: got unknown result: " + returnvalue)
@@ -139,22 +144,40 @@ class MvLayer():
         thrd.daemon = True
         thrd.start()
 
+        def color():
+            while 1:
+                global do_color
+                root.configure(bg=do_color)
+                time.sleep(0.1)
+
+        thrd = threading.Thread(target=color)
+        thrd.daemon = True
+        thrd.start()
+
     def read_available_attributes(self, name):
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"read_available_attributes"', "username": username}))).read()
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % name, "username": username}))).read()
 
-        while not available_attrs:
-            time.sleep(0.1)
-        return available_attrs.pop(0)
+        while 1:
+            try:
+                print("Attribute: " + str(available_attrs))
+                return available_attrs.pop(0)
+            except IndexError:
+                time.sleep(0.1)
 
     def read_attribute(self, name, attr):
+        print("Sending read_attribute")
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"read_attribute"', "username": username}))).read()
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % name, "username": username}))).read()
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % attr, "username": username}))).read()
 
-        while not attribute:
-            time.sleep(0.1)
-        return attribute.pop(0)
+        print("Waiting for attribute")
+        while 1:
+            try:
+                print("Attribute: " + str(attribute))
+                return attribute.pop(0)
+            except IndexError:
+                time.sleep(0.1)
 
     def set_attribute(self, name, attr, value):
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"set_attribute"', "username": username}))).read()
@@ -212,8 +235,8 @@ class InterfaceCore():
     drawn = set()
     refs = dict()
 
-    #mv = MvLayer(address)
-    mv = FakeLayer(address)
+    mv = MvLayer(address)
+    #mv = FakeLayer(address)
 
     def delete(self, x, y):
         lname = self.find((x, y))
@@ -231,15 +254,18 @@ class InterfaceCore():
             # Something already there, so don't add, but modify
             lname = self.find((event.x, event.y))
 
+            global request_new_state
             if request_new_state:
-                global request_new_state
                 request_new_state = True
                 self.mv.set_current(lname)
             else:
                 attrs = self.mv.read_available_attributes(lname)
 
+                print("Processing attributes " + str(attrs))
                 for attr, t in attrs:
+                    print("Reading attribute " + str(attr))
                     old_value = self.mv.read_attribute(lname, attr)
+                    print("Got value " + str(old_value))
                     if old_value == "None":
                         old_value = None
 
@@ -254,8 +280,9 @@ class InterfaceCore():
                     else:
                         print("Got unknown type: " + str(t))
                     self.mv.set_attribute(lname, attr, new_value)
+                    print("Set value")
 
-                    if attr == "name":
+                    if attr in ["name", "event"]:
                         if lname in names:
                             self.canvas.delete(names[lname])
                             del names[lname]