--- a/svghmi/svghmi.c Tue Aug 20 10:32:34 2019 +0200
+++ b/svghmi/svghmi.c Thu Aug 22 14:58:53 2019 +0200
@@ -1,7 +1,37 @@
+#include "iec_types_all.h"
+%(extern_variables_declarations)s + /* TODO : w/r buffer, flags, locks */ +static hmi_tree_item_t hmi_tree_item[] = { +void __retrieve_svghmi() --- a/svghmi/svghmi.py Tue Aug 20 10:32:34 2019 +0200
+++ b/svghmi/svghmi.py Thu Aug 22 14:58:53 2019 +0200
@@ -20,6 +20,7 @@
from util.ProcessLogger import ProcessLogger
+from runtime.typemapping import DebugTypesSize @@ -36,10 +37,14 @@
ScriptDirectory = paths.AbsDir(__file__)
class HMITreeNode(object):
- def __init__(self, path, name, nodetype):
+ def __init__(self, path, name, nodetype, iectype = None, vartype = None): + if iectype is not None: if nodetype in ["HMI_LABEL", "HMI_ROOT"]:
@@ -85,6 +90,13 @@
+ if hasattr(self, "children"): + for c in self.children: + for yoodl in c.traverse(): # module scope for HMITree root
# so that CTN can use HMITree deduced in Library
# note: this only works because library's Generate_C is
@@ -145,21 +157,58 @@
# deduce HMI tree from PLC HMI_* instances
for v in hmi_types_instances:
- path = v["IEC_path"].split(".")
+ path = v["C_path"].split(".") # ignores variables starting with _TMP_
if path[-1].startswith("_TMP_"):
- new_node = HMITreeNode(path, path[-1], v["derived"])
+ new_node = HMITreeNode(path, path[-1], v["derived"], v["type"], v["vartype"]) hmi_tree_root.place_node(new_node)
print(hmi_tree_root.pprint())
+ variable_decl_array = [] + extern_variables_declarations = [] + for node in hmi_tree_root.traverse(): + if hasattr(node, "iectype"): + sz = DebugTypesSize.get(node.iectype, 0) + variable_decl_array += [ + "{&(" + ".".join(node.path) + "), " + node.iectype + { + if len(node.path) == 1: + extern_variables_declarations += [ + "extern __IEC_" + node.iectype + "_" + + "t" if node.vartype is "VAR" else "p" + + ".".join(node.path) + ";"] + # TODO : filter only requiered external declarations + if v["C_path"].find('.') < 0 and v["vartype"] == "FB" : + extern_variables_declarations += [ + "extern %(type)s %(C_path)s;" % v] + # TODO check if programs need to be declared separately + # "programs_declarations": "\n".join(["extern %(type)s %(C_path)s;" % + # p for p in self._ProgramList]), # TODO generate C code to observe/access HMI tree variables
svghmi_c_filepath = paths.AbsNeighbourFile(__file__, "svghmi.c")
svghmi_c_file = open(svghmi_c_filepath, 'r')
svghmi_c_code = svghmi_c_file.read()
- svghmi_c_code = svghmi_c_code % { "hmi_tree": "TODO !!!"}
+ svghmi_c_code = svghmi_c_code % { + "variable_decl_array": ",\n".join(variable_decl_array), + "extern_variables_declarations": "\n".join(extern_variables_declarations), gen_svghmi_c_path = os.path.join(buildpath, "svghmi.c")
gen_svghmi_c = open(gen_svghmi_c_path, 'w')
@@ -243,8 +292,6 @@
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
- # TODO fetch HMI tree from library
svgfile = self._getSVGpath()
if os.path.exists(svgfile):
@@ -260,8 +307,8 @@
# call xslt transform on Inkscape's SVG to generate XHTML
result = transform.transform(svgdom)
- print(transform.xslt.error_log)
+ # print(transform.xslt.error_log) # - Errors on HMI semantics