Explorar el Código

Make initial state configurable for controller to EPN transformation

Yentl Van Tendeloo hace 8 años
padre
commit
4925efefdd

+ 3 - 3
models/control_model.mvc

@@ -2,17 +2,17 @@ Control_PW control_model_PW {
     PW_Control/Up up {
         isInitial = False
         isError = False
-        name = "up"
+        name = "ctrl_up"
     }
     PW_Control/Down down {
         isInitial = False
         isError = False
-        name = "down"
+        name = "ctrl_down"
     }
     PW_Control/Neutral neutral {
         isInitial = True
         isError = True
-        name = "neutral"
+        name = "ctrl_neutral"
     }
 
     PW_Control/UpPressed (down, neutral) {

+ 38 - 5
models/control_to_EPN.mvc

@@ -39,7 +39,7 @@ All_RAM Control2EPN {
                         $
                     value_tokens = $
                         Integer function value(model : Element, name : String, mapping : Element):
-                            return 1!
+                            return 0!
                         $
                 }
                 Post_Encapsulated_PetriNet/Port post_ports_11 {
@@ -102,7 +102,7 @@ All_RAM Control2EPN {
                         $
                     value_tokens = $
                         Integer function value(model : Element, name : String, mapping : Element):
-                            return 1!
+                            return 0!
                         $
                 }
                 Post_Encapsulated_PetriNet/Port post_ports_14 {
@@ -123,7 +123,18 @@ All_RAM Control2EPN {
                         $
                     value_tokens = $
                         Integer function value(model : Element, name : String, mapping : Element):
-                            return 0!
+                            // Set the detected output based on the initial state
+                            Element states
+                            String state
+
+                            states = allInstances(model, "PW_Control/State")
+                            while (read_nr_out(states) > 0):
+                                state = set_pop(states)
+                                if (value_eq(read_attribute(model, state, "isInitial"), True)):
+                                    if (read_type(model, state) == "PW_Control/Up"):
+                                        return 1!
+                                    else:
+                                        return 0!
                         $
                 }
                 Post_Encapsulated_PetriNet/Port post_ports_15 {
@@ -144,7 +155,18 @@ All_RAM Control2EPN {
                         $
                     value_tokens = $
                         Integer function value(model : Element, name : String, mapping : Element):
-                            return 1!
+                            // Set the detected output based on the initial state
+                            Element states
+                            String state
+
+                            states = allInstances(model, "PW_Control/State")
+                            while (read_nr_out(states) > 0):
+                                state = set_pop(states)
+                                if (value_eq(read_attribute(model, state, "isInitial"), True)):
+                                    if (read_type(model, state) == "PW_Control/Neutral"):
+                                        return 1!
+                                    else:
+                                        return 0!
                         $
                 }
                 Post_Encapsulated_PetriNet/Port post_ports_16 {
@@ -165,7 +187,18 @@ All_RAM Control2EPN {
                         $
                     value_tokens = $
                         Integer function value(model : Element, name : String, mapping : Element):
-                            return 0!
+                            // Set the detected output based on the initial state
+                            Element states
+                            String state
+
+                            states = allInstances(model, "PW_Control/State")
+                            while (read_nr_out(states) > 0):
+                                state = set_pop(states)
+                                if (value_eq(read_attribute(model, state, "isInitial"), True)):
+                                    if (read_type(model, state) == "PW_Control/Down"):
+                                        return 1!
+                                    else:
+                                        return 0!
                         $
                 }
                 Post_Encapsulated_PetriNet/Port post_ports_17 {

+ 5 - 0
models/environment_model.mvc

@@ -2,21 +2,26 @@ Environment_PW environment_model_PW {
     PW_Environment/Group {
         PW_Environment/Event {
             name = "cmdUp"
+            initial = False
         }
         PW_Environment/Event {
             name = "cmdNeutral"
+            initial = True
         }
         PW_Environment/Event {
             name = "cmdDown"
+            initial = False
         }
     }
 
     PW_Environment/Group {
         PW_Environment/Event {
             name = "objPresent"
+            initial = False
         }
         PW_Environment/Event {
             name = "no_objPresent"
+            initial = True
         }
     }
 }

+ 6 - 1
models/environment_to_EPN.mvc

@@ -24,7 +24,12 @@ A B {
                         $
                     value_tokens = $
                         Integer function value(model : Element, name : String, mapping : Element):
-                            return 0!
+                            Boolean initial
+                            initial = read_attribute(model, mapping["1"], "initial")
+                            if (initial):
+                                return 1!
+                            else:
+                                return 0!
                         $
                 }
                 Post_Encapsulated_PetriNet/Port cp_port {

+ 25 - 3
models/plant_to_EPN.mvc

@@ -105,7 +105,18 @@ A B {
                         $
                     value_tokens = $
                         Integer function value(model : Element, name : String, mapping : Element):
-                            return 0!
+                            // Set the detected output based on the initial state
+                            Element states
+                            String state
+
+                            states = allInstances(model, "PW_Plant/State")
+                            while (read_nr_out(states) > 0):
+                                state = set_pop(states)
+                                if (value_eq(read_attribute(model, state, "isInitial"), True)):
+                                    if (read_type(model, state) == "PW_Plant/ErrorState"):
+                                        return 1!
+                                    else:
+                                        return 0!
                         $
                 }
                 Post_Encapsulated_PetriNet/Port post_ports_14 {
@@ -127,7 +138,18 @@ A B {
                         $
                     value_tokens = $
                         Integer function value(model : Element, name : String, mapping : Element):
-                            return 1!
+                            // Set the detected output based on the initial state
+                            Element states
+                            String state
+
+                            states = allInstances(model, "PW_Plant/State")
+                            while (read_nr_out(states) > 0):
+                                state = set_pop(states)
+                                if (value_eq(read_attribute(model, state, "isInitial"), True)):
+                                    if (read_type(model, state) == "PW_Plant/ErrorState"):
+                                        return 0!
+                                    else:
+                                        return 1!
                         $
                 }
                 Post_Encapsulated_PetriNet/Port post_ports_15 {
@@ -171,7 +193,7 @@ A B {
                         $
                     value_tokens = $
                         Integer function value(model : Element, name : String, mapping : Element):
-                            return 1!
+                            return 0!
                         $
                 }
                 Post_Encapsulated_PetriNet/Port post_ports_17 {