611 |
611 |
612 # Construct debugger natively supported types |
612 # Construct debugger natively supported types |
613 DebugTypes = [t for t in zip(*TypeHierarchy_list)[0] if not t.startswith("ANY")] + \ |
613 DebugTypes = [t for t in zip(*TypeHierarchy_list)[0] if not t.startswith("ANY")] + \ |
614 ["STEP","TRANSITION","ACTION"] |
614 ["STEP","TRANSITION","ACTION"] |
615 |
615 |
616 import runtime |
|
617 import re |
616 import re |
618 import targets |
617 import targets |
619 import connectors |
618 import connectors |
620 from discovery import DiscoveryDialog |
619 from discovery import DiscoveryDialog |
621 |
620 |
1037 Generate trace/debug code out of PLC variable list |
1036 Generate trace/debug code out of PLC variable list |
1038 """ |
1037 """ |
1039 self.GetIECProgramsAndVariables() |
1038 self.GetIECProgramsAndVariables() |
1040 |
1039 |
1041 # prepare debug code |
1040 # prepare debug code |
1042 debug_code = runtime.code("plc_debug") % { |
1041 debug_code = targets.code("plc_debug") % { |
1043 "programs_declarations": |
1042 "programs_declarations": |
1044 "\n".join(["extern %(type)s %(C_path)s;"%p for p in self._ProgramList]), |
1043 "\n".join(["extern %(type)s %(C_path)s;"%p for p in self._ProgramList]), |
1045 "extern_variables_declarations":"\n".join([ |
1044 "extern_variables_declarations":"\n".join([ |
1046 {"PT":"extern %(type)s *%(C_path)s;", |
1045 {"PT":"extern %(type)s *%(C_path)s;", |
1047 "VAR":"extern %(type)s %(C_path)s;"}[v["vartype"]]%v |
1046 "VAR":"extern %(type)s %(C_path)s;"}[v["vartype"]]%v |
1098 # in retreive, publish, init, cleanup |
1097 # in retreive, publish, init, cleanup |
1099 locstrs = map(lambda x:"_".join(map(str,x)), |
1098 locstrs = map(lambda x:"_".join(map(str,x)), |
1100 [loc for loc,Cfiles,DoCalls in self.LocationCFilesAndCFLAGS if loc and DoCalls]) |
1099 [loc for loc,Cfiles,DoCalls in self.LocationCFilesAndCFLAGS if loc and DoCalls]) |
1101 |
1100 |
1102 # Generate main, based on template |
1101 # Generate main, based on template |
1103 plc_main_code = runtime.code("plc_common_main") % { |
1102 plc_main_code = targets.code("plc_common_main") % { |
1104 "calls_prototypes":"\n".join([( |
1103 "calls_prototypes":"\n".join([( |
1105 "int __init_%(s)s(int argc,char **argv);\n"+ |
1104 "int __init_%(s)s(int argc,char **argv);\n"+ |
1106 "void __cleanup_%(s)s();\n"+ |
1105 "void __cleanup_%(s)s();\n"+ |
1107 "void __retrieve_%(s)s();\n"+ |
1106 "void __retrieve_%(s)s();\n"+ |
1108 "void __publish_%(s)s();")%{'s':locstr} for locstr in locstrs]), |
1107 "void __publish_%(s)s();")%{'s':locstr} for locstr in locstrs]), |
1119 "if(init_level >= %d) "%i+ |
1118 "if(init_level >= %d) "%i+ |
1120 "__cleanup_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]) |
1119 "__cleanup_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]) |
1121 } |
1120 } |
1122 |
1121 |
1123 target_name = self.BeremizRoot.getTargetType().getcontent()["name"] |
1122 target_name = self.BeremizRoot.getTargetType().getcontent()["name"] |
1124 plc_main_code += targets.code(target_name) |
1123 plc_main_code += targets.targetcode(target_name) |
1125 return plc_main_code |
1124 return plc_main_code |
1126 |
1125 |
1127 |
1126 |
1128 def _build(self): |
1127 def _build(self): |
1129 """ |
1128 """ |
1174 shutil.rmtree(extrafilespath) |
1173 shutil.rmtree(extrafilespath) |
1175 # Recreate directory |
1174 # Recreate directory |
1176 os.mkdir(extrafilespath) |
1175 os.mkdir(extrafilespath) |
1177 # Then write the files |
1176 # Then write the files |
1178 for fname,fobject in ExtraFiles: |
1177 for fname,fobject in ExtraFiles: |
1179 print fname,fobject |
|
1180 fpath = os.path.join(extrafilespath,fname) |
1178 fpath = os.path.join(extrafilespath,fname) |
1181 open(fpath, "wb").write(fobject.read()) |
1179 open(fpath, "wb").write(fobject.read()) |
1182 # Now we can forget ExtraFiles (will close files object) |
1180 # Now we can forget ExtraFiles (will close files object) |
1183 del ExtraFiles |
1181 del ExtraFiles |
1184 |
1182 |
1436 extrafilespath = self._getExtraFilesPath() |
1434 extrafilespath = self._getExtraFilesPath() |
1437 extrafiles = [(name, open(os.path.join(extrafilespath, name), |
1435 extrafiles = [(name, open(os.path.join(extrafilespath, name), |
1438 'rb').read()) \ |
1436 'rb').read()) \ |
1439 for name in os.listdir(extrafilespath) \ |
1437 for name in os.listdir(extrafilespath) \ |
1440 if not name=="CVS"] |
1438 if not name=="CVS"] |
1441 |
|
1442 for filename, unused in extrafiles: |
|
1443 print filename |
|
1444 |
1439 |
1445 # Send PLC on target |
1440 # Send PLC on target |
1446 builder = self.GetBuilder() |
1441 builder = self.GetBuilder() |
1447 if builder is not None: |
1442 if builder is not None: |
1448 data = builder.GetBinaryCode() |
1443 data = builder.GetBinaryCode() |