svghmi/svghmi.py
branchsvghmi
changeset 2765 887aba5ef178
parent 2764 b75cc2cf4e50
child 2767 302347f48193
equal deleted inserted replaced
2764:b75cc2cf4e50 2765:887aba5ef178
   166 
   166 
   167         print(hmi_tree_root.pprint())
   167         print(hmi_tree_root.pprint())
   168 
   168 
   169         variable_decl_array = []
   169         variable_decl_array = []
   170         extern_variables_declarations = []
   170         extern_variables_declarations = []
   171         bofs = 0
   171         buf_index = 0
   172         for node in hmi_tree_root.traverse():
   172         for node in hmi_tree_root.traverse():
   173             if hasattr(node, "iectype"):
   173             if hasattr(node, "iectype"):
   174                 sz = DebugTypesSize.get(node.iectype, 0)
   174                 sz = DebugTypesSize.get(node.iectype, 0)
   175                 variable_decl_array += [
   175                 variable_decl_array += [
   176                     "{&(" + ".".join(node.path) + "), " + node.iectype + {
   176                     "{&(" + ".".join(node.path) + "), " + node.iectype + {
   177                         "EXT": "_P_ENUM",
   177                         "EXT": "_P_ENUM",
   178                         "IN":  "_P_ENUM",
   178                         "IN":  "_P_ENUM",
   179                         "MEM": "_O_ENUM",
   179                         "MEM": "_O_ENUM",
   180                         "OUT": "_O_ENUM",
   180                         "OUT": "_O_ENUM",
   181                         "VAR": "_ENUM"
   181                         "VAR": "_ENUM"
   182                     }[node.vartype] + "}"]
   182                     }[node.vartype] + ", " +
   183                 bofs += sz
   183                     str(buf_index) + ", 0}"]
       
   184                 buf_index += sz
   184                 if len(node.path) == 1:
   185                 if len(node.path) == 1:
   185                     extern_variables_declarations += [
   186                     extern_variables_declarations += [
   186                         "extern __IEC_" + node.iectype + "_" +
   187                         "extern __IEC_" + node.iectype + "_" +
   187                         "t" if node.vartype is "VAR" else "p"
   188                         "t" if node.vartype is "VAR" else "p"
   188                         + ".".join(node.path) + ";"]
   189                         + ".".join(node.path) + ";"]
   203         svghmi_c_code = svghmi_c_file.read()
   204         svghmi_c_code = svghmi_c_file.read()
   204         svghmi_c_file.close()
   205         svghmi_c_file.close()
   205         svghmi_c_code = svghmi_c_code % { 
   206         svghmi_c_code = svghmi_c_code % { 
   206             "variable_decl_array": ",\n".join(variable_decl_array),
   207             "variable_decl_array": ",\n".join(variable_decl_array),
   207             "extern_variables_declarations": "\n".join(extern_variables_declarations),
   208             "extern_variables_declarations": "\n".join(extern_variables_declarations),
   208             "varinit":"",
   209             "buffer_size": buf_index
   209             "varret":"",
       
   210             "varpub":""
       
   211             }
   210             }
   212 
   211 
   213         gen_svghmi_c_path = os.path.join(buildpath, "svghmi.c")
   212         gen_svghmi_c_path = os.path.join(buildpath, "svghmi.c")
   214         gen_svghmi_c = open(gen_svghmi_c_path, 'w')
   213         gen_svghmi_c = open(gen_svghmi_c_path, 'w')
   215         gen_svghmi_c.write(svghmi_c_code)
   214         gen_svghmi_c.write(svghmi_c_code)