|
@@ -48,13 +48,12 @@ Element function translate_to_runtime(design_model : Element):
|
|
while (list_len(all_blocks) > 0):
|
|
while (list_len(all_blocks) > 0):
|
|
element_name = set_pop(all_blocks)
|
|
element_name = set_pop(all_blocks)
|
|
mm_type_name = reverseKeyLookup(design_model["metamodel"]["model"], dict_read_node(design_model["type_mapping"], design_model["model"][element_name]))
|
|
mm_type_name = reverseKeyLookup(design_model["metamodel"]["model"], dict_read_node(design_model["type_mapping"], design_model["model"][element_name]))
|
|
- instantiate_node(runtime_model, mm_type_name, element_name)
|
|
|
|
|
|
+ element_name = instantiate_node(runtime_model, mm_type_name, element_name)
|
|
|
|
+ if (mm_type_name == "ConstantBlock"):
|
|
|
|
+ instantiate_attribute(runtime_model, element_name, "value", read_attribute(design_model, element_name, "value"))
|
|
|
|
+ elif (mm_type_name == "DelayBlock"):
|
|
|
|
+ instantiate_attribute(runtime_model, element_name, "memory", 0.0)
|
|
instantiate_attribute(runtime_model, element_name, "signal", 0.0)
|
|
instantiate_attribute(runtime_model, element_name, "signal", 0.0)
|
|
- all_attributes = getAttributeList(design_model, element_name)
|
|
|
|
- while (read_nr_out(all_attributes) > 0):
|
|
|
|
- attr_name = set_pop(all_attributes)
|
|
|
|
- if (bool_not(set_in(runtime_model["model"], read_attribute(design_model, element_name, attr_name)))):
|
|
|
|
- instantiate_attribute(runtime_model, element_name, attr_name, read_attribute(design_model, element_name, attr_name))
|
|
|
|
log(" Converted block " + element_name)
|
|
log(" Converted block " + element_name)
|
|
|
|
|
|
// Don't merge this together with the block conversion, as the destination block might not exist yet!
|
|
// Don't merge this together with the block conversion, as the destination block might not exist yet!
|
|
@@ -111,7 +110,6 @@ Void function create_schedule(model : Element, is_time_zero : Boolean):
|
|
schedule = instantiate_node(model, "Schedule", "schedule_init")
|
|
schedule = instantiate_node(model, "Schedule", "schedule_init")
|
|
else:
|
|
else:
|
|
schedule = instantiate_node(model, "Schedule", "schedule_run")
|
|
schedule = instantiate_node(model, "Schedule", "schedule_run")
|
|
- instantiate_attribute(model, schedule, "active", True)
|
|
|
|
|
|
|
|
while (read_nr_out(all_blocks) > 0):
|
|
while (read_nr_out(all_blocks) > 0):
|
|
element_name = set_pop(all_blocks)
|
|
element_name = set_pop(all_blocks)
|
|
@@ -138,7 +136,6 @@ Void function create_schedule(model : Element, is_time_zero : Boolean):
|
|
|
|
|
|
if (ready):
|
|
if (ready):
|
|
new_schedule = instantiate_node(model, "Schedule", "")
|
|
new_schedule = instantiate_node(model, "Schedule", "")
|
|
- instantiate_attribute(model, new_schedule, "active", False)
|
|
|
|
instantiate_link(model, "LinkedBlock", "", schedule, element_name)
|
|
instantiate_link(model, "LinkedBlock", "", schedule, element_name)
|
|
instantiate_link(model, "NextSchedule", "", schedule, new_schedule)
|
|
instantiate_link(model, "NextSchedule", "", schedule, new_schedule)
|
|
schedule = new_schedule
|
|
schedule = new_schedule
|
|
@@ -175,7 +172,6 @@ Void function list_CBD(model : Element):
|
|
|
|
|
|
output("Schedule (== 0):")
|
|
output("Schedule (== 0):")
|
|
elem = "schedule_init"
|
|
elem = "schedule_init"
|
|
- log("Model " + cast_e2s(model["model"][elem]))
|
|
|
|
while (read_nr_out(allOutgoingAssociationInstances(model, elem, "LinkedBlock")) > 0):
|
|
while (read_nr_out(allOutgoingAssociationInstances(model, elem, "LinkedBlock")) > 0):
|
|
block = readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, elem, "LinkedBlock")))
|
|
block = readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, elem, "LinkedBlock")))
|
|
output(" " + block)
|
|
output(" " + block)
|
|
@@ -183,7 +179,6 @@ Void function list_CBD(model : Element):
|
|
|
|
|
|
output("Schedule (> 0):")
|
|
output("Schedule (> 0):")
|
|
elem = "schedule_run"
|
|
elem = "schedule_run"
|
|
- log("Model " + cast_e2s(model["model"][elem]))
|
|
|
|
while (read_nr_out(allOutgoingAssociationInstances(model, elem, "LinkedBlock")) > 0):
|
|
while (read_nr_out(allOutgoingAssociationInstances(model, elem, "LinkedBlock")) > 0):
|
|
block = readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, elem, "LinkedBlock")))
|
|
block = readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, elem, "LinkedBlock")))
|
|
output(" " + block)
|
|
output(" " + block)
|
|
@@ -194,39 +189,46 @@ Void function list_CBD(model : Element):
|
|
Void function step_simulation(model : Element):
|
|
Void function step_simulation(model : Element):
|
|
String time
|
|
String time
|
|
String schedule
|
|
String schedule
|
|
- Float value
|
|
|
|
|
|
+ Float signal
|
|
Element incoming
|
|
Element incoming
|
|
String selected
|
|
String selected
|
|
|
|
+ String block
|
|
|
|
+ String elem
|
|
|
|
+ String blocktype
|
|
|
|
|
|
time = "time"
|
|
time = "time"
|
|
- if (readAttribute(model, time, "current_time") == 0):
|
|
|
|
|
|
+ if (cast_s2i(cast_v2s(read_attribute(model, time, "current_time"))) == 0):
|
|
schedule = "schedule_init"
|
|
schedule = "schedule_init"
|
|
else:
|
|
else:
|
|
schedule = "schedule_run"
|
|
schedule = "schedule_run"
|
|
|
|
|
|
|
|
+ output("==== START ====")
|
|
while (read_nr_out(allOutgoingAssociationInstances(model, schedule, "LinkedBlock")) > 0):
|
|
while (read_nr_out(allOutgoingAssociationInstances(model, schedule, "LinkedBlock")) > 0):
|
|
- block = readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, elem, "LinkedBlock")))
|
|
|
|
- schedule = readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, elem, "NextSchedule")))
|
|
|
|
|
|
+ block = readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, schedule, "LinkedBlock")))
|
|
|
|
+ schedule = readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, schedule, "NextSchedule")))
|
|
|
|
|
|
// Execute "block"
|
|
// Execute "block"
|
|
blocktype = readType(model, block)
|
|
blocktype = readType(model, block)
|
|
|
|
+ unset_attribute(model, block, "signal")
|
|
if (blocktype == "ConstantBlock"):
|
|
if (blocktype == "ConstantBlock"):
|
|
- unset_attribute(model, block, "signal")
|
|
|
|
- instantiate_attribute(model, block, "signal", read_attribute(model, block, "value"))
|
|
|
|
|
|
+ signal = read_attribute(model, block, "value")
|
|
|
|
+ log("Value: " + cast_v2s(read_attribute(model, block, "value")))
|
|
elif (blocktype == "AdditionBlock"):
|
|
elif (blocktype == "AdditionBlock"):
|
|
- unset_attribute(model, block, "signal")
|
|
|
|
- value = 0.0
|
|
|
|
- incoming = allIncomingAssociationInstances(model, schedule, "Link")
|
|
|
|
|
|
+ signal = 0.0
|
|
|
|
+ incoming = allIncomingAssociationInstances(model, block, "Link")
|
|
while (read_nr_out(incoming) > 0):
|
|
while (read_nr_out(incoming) > 0):
|
|
selected = readAssociationSource(model, set_pop(incoming))
|
|
selected = readAssociationSource(model, set_pop(incoming))
|
|
- value = value + cast_v2f(read_attribute(model, selected, "signal"))
|
|
|
|
- instantiate_attribute(model, block, "signal", value)
|
|
|
|
|
|
+ log("V += " + cast_v2s(read_attribute(model, selected, "signal")))
|
|
|
|
+ signal = signal + cast_s2f(cast_v2s(read_attribute(model, selected, "signal")))
|
|
|
|
+ instantiate_attribute(model, block, "signal", signal)
|
|
|
|
+ output(((" " + block) + " = ") + cast_v2s(read_attribute(model, block, "signal")))
|
|
|
|
|
|
// Increase simulation time
|
|
// Increase simulation time
|
|
Integer new_time
|
|
Integer new_time
|
|
- new_time = cast_v2i(read_attribute(model, time, "current_time")) + 1
|
|
|
|
|
|
+ new_time = cast_s2i(cast_v2s(read_attribute(model, time, "current_time"))) + 1
|
|
unset_attribute(model, time, "current_time")
|
|
unset_attribute(model, time, "current_time")
|
|
instantiate_attribute(model, time, "current_time", new_time)
|
|
instantiate_attribute(model, time, "current_time", new_time)
|
|
|
|
+ output("==== END ====")
|
|
|
|
|
|
return !
|
|
return !
|
|
|
|
|
|
@@ -287,5 +289,5 @@ Void function execute_cbd(model : Element):
|
|
output("Did not understand command!")
|
|
output("Did not understand command!")
|
|
output("Use 'help' for a list of available options")
|
|
output("Use 'help' for a list of available options")
|
|
|
|
|
|
- if (cast_v2i(read_attribute(model, "time", "current_time")) > cast_v2i(read_attribute(model, "time", "termination_time"))):
|
|
|
|
|
|
+ if (cast_s2i(cast_v2s(read_attribute(model, "time", "current_time"))) > cast_s2i(cast_v2s(read_attribute(model, "time", "termination_time")))):
|
|
running = False
|
|
running = False
|