Explorar el Código

working version of service-enabled pypdevs simulator

Simon Van Mierlo hace 9 años
padre
commit
e804ca91ed

+ 6 - 2
integration/code/pdevs_client.alc

@@ -22,5 +22,9 @@ Boolean function main(model : Element):
         if (has_input()):
             the_input = input()
             log("Got input from console!")
-            log(the_input)
-            comm_set(port, cast_v2s(the_input))
+            log(cast_v2s(the_input))
+            if (is_physical_string(the_input)):
+                comm_set(port, the_input)
+            else:
+                comm_set(port, cast_v2s(the_input))
+        sleep(0.05)

+ 4 - 4
interface/PDEVS/console.py

@@ -100,8 +100,8 @@ def raw_inputter():
             set_defaults(inp, ['inf'])
             params = [{"termination_time": float(inp[1])}]
         elif inp[0] == "realtime":
-            set_defaults(inp, ['inf', 1.0])
-            params = [{"termination_time": float(inp[1]), "realtime_scale": float(inp[2])}]
+            set_defaults(inp, [1.0, 'inf'])
+            params = [{"realtime_scale": float(inp[1]), "termination_time": float(inp[2])}]
         elif inp[0] == "small_step":
             set_defaults(inp, ['inf'])
             params = [{"termination_time": float(inp[1])}]
@@ -127,7 +127,7 @@ def raw_inputter():
                 print("Breakpoint removal requires 2 parameters!")
                 continue
             # Merge together the final part again
-            inp = [inp[0], inp[1], " ".join(inp[2:-2]).replace("\\n", "\n"), get_bool(inp[-2]), get_bool(inp[-1])]
+            inp = [inp[0], inp[1], " ".join(inp[2:-2]).replace("\\n", "\n").replace('\\t', '\t'), get_bool(inp[-2]), get_bool(inp[-1])]
             print("Generated parameters: " + str(inp))
             params = inp[1:]
         elif inp[0] == "del_breakpoint":
@@ -204,7 +204,7 @@ def raw_inputter():
             continue
         params.insert(0, action)
         print "Console sending input to the Modelverse! %s" % params
-        controller.addInput(Event("mv_input", "input", params))
+        controller.addInput(Event("mv_input", "input", [json.dumps(params)]))
         
 input_thread = threading.Thread(target=raw_inputter)
 input_thread.daemon = True

+ 4 - 1
interface/PDEVS/register_service.py

@@ -17,7 +17,10 @@ def pypdevs_service(port):
     def inputter():
         print "Waiting for input..."
         while 1:
-            params = json.loads(service_get(port))
+            input = service_get(port)
+            print 'raw input = %s' % input
+            params = json.loads(input)
+            print 'json parsed = %s' % params
             if not isinstance(params, list):
                 params = [params]
             print "Sending input to simulator: %s" % params

+ 2 - 1
models/devs_to_string.alc

@@ -33,7 +33,7 @@ Boolean function devs_to_string(model: Element):
         model_rep = ((model_rep + "class ") + cast_i2s(read_attribute(model, curr_atomic, "name"))) + "(AtomicDEVS):\n"
         model_rep = ((model_rep + "\tdef __init__(self, name=") + cast_v2s(read_attribute(model, curr_atomic, "name"))) + "):\n"
         model_rep = model_rep + "\t\tAtomicDEVS.__init__(self, name)\n"
-        model_rep = ((model_rep + "\t\tself.state = {'name': ") + cast_v2s(read_attribute(model, curr_atomic, "initialState"))) + "}\n"
+        model_rep = model_rep + "\t\tself.state = self.initialState()\n"
         model_rep = model_rep + "\t\tself.my_ports = {"
         all_ports = allAssociationDestinations(model, curr_atomic, "ParallelDEVS/DEVSBlockToPort")
         while (read_nr_out(all_ports) > 0):
@@ -47,6 +47,7 @@ Boolean function devs_to_string(model: Element):
             if (read_nr_out(all_ports) > 0):
                 model_rep = model_rep + ", "
         model_rep = model_rep + "}\n"
+        model_rep = model_rep + "\tdef initialState(self):\n" + cast_i2s(read_attribute(model, curr_atomic, "initialState")) + "\n"
         model_rep = ((model_rep + "\tdef timeAdvance(self):\n") + cast_i2s(read_attribute(model, curr_atomic, "timeAdvance"))) + "\n"
         model_rep = ((model_rep + "\tdef outputFnc(self):\n") + cast_i2s(read_attribute(model, curr_atomic, "outputFnc"))) + "\n"
         model_rep = ((model_rep + "\tdef intTransition(self):\n") + cast_i2s(read_attribute(model, curr_atomic, "intTransition"))) + "\n"

+ 1 - 1
models/paralleldevs_design.mvc

@@ -11,7 +11,7 @@ Class AtomicDEVSBlock: BaseDEVSBlock {
     intTransition: ActionCode
     extTransition: ActionCode
     confTransition: ActionCode
-    initialState: String
+    initialState: ActionCode
 }
 
 Class CoupledDEVSBlock: BaseDEVSBlock {}

+ 12 - 3
models/produce_consume_PDEVS.mvc

@@ -1,9 +1,12 @@
 include "primitives.alh"
 
 AtomicDEVSBlock Generator {
-    initialState = "generating"
     name = "Generator"
     
+    initialState = """
+        return {'name': 'generating'}
+    """
+    
     intTransition = """
         if self.state['name'] == 'generating':
             new_state = {}
@@ -33,9 +36,12 @@ AtomicDEVSBlock Generator {
 }
 
 AtomicDEVSBlock Processor {
-    initialState = "idle"
     name = "Processor"
     
+    initialState = """
+        return {'name': 'idle'}
+    """
+    
     intTransition = """
         if self.state['name'] == 'processing':
             new_state = {}
@@ -75,9 +81,12 @@ AtomicDEVSBlock Processor {
 }
 
 AtomicDEVSBlock Collector {
-    initialState = "waiting"
     name = "Collector"
     
+    initialState = """
+        return {'name': 'waiting', 'nr_of_jobs': 0}
+    """
+    
     intTransition = """
         return AtomicDEVS.intTransition(self, my_inputs)
     """