svghmi/svghmi.py
branchsvghmi
changeset 2828 be947a338760
parent 2826 1e5abecc3cde
child 2830 15d7bd79d9e8
equal deleted inserted replaced
2827:af32e80d108f 2828:be947a338760
   209         extern_variables_declarations = []
   209         extern_variables_declarations = []
   210         buf_index = 0
   210         buf_index = 0
   211         item_count = 0
   211         item_count = 0
   212         found_heartbeat = False
   212         found_heartbeat = False
   213 
   213 
   214         # find heartbeat in hmi tree
       
   215         # it is supposed to come first, but some HMI_* intances 
       
   216         # in config's globals might shift them
       
   217         hearbeat_IEC_path = ['CONFIG', 'HEARTBEAT']
   214         hearbeat_IEC_path = ['CONFIG', 'HEARTBEAT']
       
   215 
   218         for node in hmi_tree_root.traverse():
   216         for node in hmi_tree_root.traverse():
   219             if node.path == hearbeat_IEC_path:
   217             if not found_heartbeat and node.path == hearbeat_IEC_path:
   220                 hmi_tree_hearbeat_index = item_count
   218                 hmi_tree_hearbeat_index = item_count
   221                 found_heartbeat = True
   219                 found_heartbeat = True
   222                 extern_variables_declarations += [
   220                 extern_variables_declarations += [
   223                     "#define heartbeat_index "+str(hmi_tree_hearbeat_index)
   221                     "#define heartbeat_index "+str(hmi_tree_hearbeat_index)
   224                 ]
   222                 ]
   225                 break;
       
   226 
       
   227         for node in hmi_tree_root.traverse():
       
   228             if hasattr(node, "iectype") and node.nodetype != "HMI_NODE":
   223             if hasattr(node, "iectype") and node.nodetype != "HMI_NODE":
   229                 sz = DebugTypesSize.get(node.iectype, 0)
   224                 sz = DebugTypesSize.get(node.iectype, 0)
   230                 variable_decl_array += [
   225                 variable_decl_array += [
   231                     "{&(" + node.cpath + "), " + node.iectype + {
   226                     "{&(" + node.cpath + "), " + node.iectype + {
   232                         "EXT": "_P_ENUM",
   227                         "EXT": "_P_ENUM",
   241                 if len(node.path) == 1:
   236                 if len(node.path) == 1:
   242                     extern_variables_declarations += [
   237                     extern_variables_declarations += [
   243                         "extern __IEC_" + node.iectype + "_" +
   238                         "extern __IEC_" + node.iectype + "_" +
   244                         "t" if node.vartype is "VAR" else "p"
   239                         "t" if node.vartype is "VAR" else "p"
   245                         + node.cpath + ";"]
   240                         + node.cpath + ";"]
   246                 
   241 
   247         assert(found_heartbeat)
   242         assert(found_heartbeat)
   248 
   243 
   249         # TODO : filter only requiered external declarations
   244         # TODO : filter only requiered external declarations
   250         for v in varlist :
   245         for v in varlist:
   251             if v["C_path"].find('.') < 0 :  # and v["vartype"] == "FB" :
   246             if v["C_path"].find('.') < 0:
   252                 extern_variables_declarations += [
   247                 extern_variables_declarations += [
   253                     "extern %(type)s %(C_path)s;" % v]
   248                     "extern %(type)s %(C_path)s;" % v]
   254 
   249 
   255         # TODO check if programs need to be declared separately
   250         # TODO check if programs need to be declared separately
   256         # "programs_declarations": "\n".join(["extern %(type)s %(C_path)s;" %
   251         # "programs_declarations": "\n".join(["extern %(type)s %(C_path)s;" %
   502 """)
   497 """)
   503 
   498 
   504         target_file.close()
   499         target_file.close()
   505 
   500 
   506         res += ((target_fname, open(target_path, "rb")),)
   501         res += ((target_fname, open(target_path, "rb")),)
   507         
   502 
   508         svghmi_cmds = {}
   503         svghmi_cmds = {}
   509         for thing in ["Start", "Stop", "Watchdog"]:
   504         for thing in ["Start", "Stop", "Watchdog"]:
   510              given_command = self.GetParamsAttributes("SVGHMI.On"+thing)["value"]
   505              given_command = self.GetParamsAttributes("SVGHMI.On"+thing)["value"]
   511              svghmi_cmds[thing] = (
   506              svghmi_cmds[thing] = (
   512                 "Popen(" +
   507                 "Popen(" +
   513                 repr(shlex.split(given_command.format(port="8008", name=view_name))) + 
   508                 repr(shlex.split(given_command.format(port="8008", name=view_name))) +
   514                 ")") if given_command else "# no command given"
   509                 ")") if given_command else "# no command given"
   515 
   510 
   516         runtimefile_path = os.path.join(buildpath, "runtime_svghmi1_%s.py" % location_str)
   511         runtimefile_path = os.path.join(buildpath, "runtime_svghmi1_%s.py" % location_str)
   517         runtimefile = open(runtimefile_path, 'w')
   512         runtimefile = open(runtimefile_path, 'w')
   518         runtimefile.write("""
   513         runtimefile.write("""
   519 # TODO : multi        
   514 # TODO : multi
   520 def watchdog_trigger():
   515 def watchdog_trigger():
   521     {svghmi_cmds.Watchdog}
   516     {svghmi_cmds[Watchdog]}
   522 
   517 
   523 def _runtime_svghmi1_{location}_start():
   518 def _runtime_svghmi1_{location}_start():
   524     svghmi_root.putChild('{view_name}',File('{xhtml}', defaultType='application/xhtml+xml'))
   519     svghmi_root.putChild('{view_name}',File('{xhtml}', defaultType='application/xhtml+xml'))
   525     {svghmi_cmds.Start}
   520     {svghmi_cmds[Start]}
   526 
   521 
   527 def _runtime_svghmi1_{location}_stop():
   522 def _runtime_svghmi1_{location}_stop():
   528     svghmi_root.delEntity('{view_name}')
   523     svghmi_root.delEntity('{view_name}')
   529     {svghmi_cmds.Stop}
   524     {svghmi_cmds[Stop]}
   530 
   525 
   531         """.format(location=location_str,
   526         """.format(location=location_str,
   532                    xhtml=target_fname,
   527                    xhtml=target_fname,
   533                    view_name=view_name,
   528                    view_name=view_name,
   534                    svghmi_cmds=type("dicobj",(object,),svghmi_cmds)))
   529                    svghmi_cmds=svghmi_cmds))
   535 
   530 
   536         runtimefile.close()
   531         runtimefile.close()
   537 
   532 
   538         res += (("runtime_svghmi1_%s.py" % location_str, open(runtimefile_path, "rb")),)
   533         res += (("runtime_svghmi1_%s.py" % location_str, open(runtimefile_path, "rb")),)
   539 
   534