754 return False |
754 return False |
755 |
755 |
756 self.logger.write(_("Compiling IEC Program into C code...\n")) |
756 self.logger.write(_("Compiling IEC Program into C code...\n")) |
757 buildpath = self._getBuildPath() |
757 buildpath = self._getBuildPath() |
758 buildcmd = "\"%s\" %s -I \"%s\" -T \"%s\" \"%s\"" % ( |
758 buildcmd = "\"%s\" %s -I \"%s\" -T \"%s\" \"%s\"" % ( |
759 self.iec2c_cfg.getCmd(), |
759 self.iec2c_cfg.getCmd(), |
760 self.iec2c_cfg.getOptions(), |
760 self.iec2c_cfg.getOptions(), |
761 iec2c_libpath, |
761 iec2c_libpath, |
762 buildpath, |
762 buildpath, |
763 self._getIECcodepath()) |
763 self._getIECcodepath()) |
764 |
764 |
765 try: |
765 try: |
766 # Invoke compiler. Output files are listed to stdout, errors to stderr |
766 # Invoke compiler. Output files are listed to stdout, errors to stderr |
767 status, result, err_result = ProcessLogger(self.logger, buildcmd, |
767 status, result, err_result = ProcessLogger(self.logger, buildcmd, |
768 no_stdout=True, no_stderr=True).spin() |
768 no_stdout=True, no_stderr=True).spin() |
872 @param locations: ignored |
872 @param locations: ignored |
873 @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
873 @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
874 """ |
874 """ |
875 |
875 |
876 return ([(C_file_name, self.plcCFLAGS) |
876 return ([(C_file_name, self.plcCFLAGS) |
877 for C_file_name in self.PLCGeneratedCFiles], |
877 for C_file_name in self.PLCGeneratedCFiles], |
878 "", # no ldflags |
878 "", # no ldflags |
879 False) # do not expose retreive/publish calls |
879 False) # do not expose retreive/publish calls |
880 |
880 |
881 def ResetIECProgramsAndVariables(self): |
881 def ResetIECProgramsAndVariables(self): |
882 """ |
882 """ |
1025 |
1025 |
1026 # Generate main, based on template |
1026 # Generate main, based on template |
1027 if not self.BeremizRoot.getDisable_Extensions(): |
1027 if not self.BeremizRoot.getDisable_Extensions(): |
1028 plc_main_code = targets.GetCode("plc_main_head.c") % { |
1028 plc_main_code = targets.GetCode("plc_main_head.c") % { |
1029 "calls_prototypes": "\n".join([( |
1029 "calls_prototypes": "\n".join([( |
1030 "int __init_%(s)s(int argc,char **argv);\n" + |
1030 "int __init_%(s)s(int argc,char **argv);\n" + |
1031 "void __cleanup_%(s)s(void);\n" + |
1031 "void __cleanup_%(s)s(void);\n" + |
1032 "void __retrieve_%(s)s(void);\n" + |
1032 "void __retrieve_%(s)s(void);\n" + |
1033 "void __publish_%(s)s(void);") % {'s': locstr} for locstr in locstrs]), |
1033 "void __publish_%(s)s(void);") % {'s': locstr} for locstr in locstrs]), |
1034 "retrieve_calls": "\n ".join([ |
1034 "retrieve_calls": "\n ".join([ |
1035 "__retrieve_%s();" % locstr for locstr in locstrs]), |
1035 "__retrieve_%s();" % locstr for locstr in locstrs]), |
1036 "publish_calls": "\n ".join([ # Call publish in reverse order |
1036 "publish_calls": "\n ".join([ # Call publish in reverse order |
1037 "__publish_%s();" % locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]), |
1037 "__publish_%s();" % locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]), |
1038 "init_calls": "\n ".join([ |
1038 "init_calls": "\n ".join([ |
1039 "init_level=%d; " % (i+1) + |
1039 "init_level=%d; " % (i+1) + |
1040 "if((res = __init_%s(argc,argv))){" % locstr + |
1040 "if((res = __init_%s(argc,argv))){" % locstr + |
1041 # "printf(\"%s\"); "%locstr + #for debug |
1041 # "printf(\"%s\"); "%locstr + #for debug |
1042 "return res;}" for i, locstr in enumerate(locstrs)]), |
1042 "return res;}" for i, locstr in enumerate(locstrs)]), |
1043 "cleanup_calls": "\n ".join([ |
1043 "cleanup_calls": "\n ".join([ |
1044 "if(init_level >= %d) " % i + |
1044 "if(init_level >= %d) " % i + |
1045 "__cleanup_%s();" % locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]) |
1045 "__cleanup_%s();" % locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]) |
1046 } |
1046 } |
1047 else: |
1047 else: |
1048 plc_main_code = targets.GetCode("plc_main_head.c") % { |
1048 plc_main_code = targets.GetCode("plc_main_head.c") % { |
1049 "calls_prototypes": "\n", |
1049 "calls_prototypes": "\n", |
1050 "retrieve_calls": "\n", |
1050 "retrieve_calls": "\n", |
1159 # Header file for extensions |
1159 # Header file for extensions |
1160 open(os.path.join(buildpath, "beremiz.h"), "w").write(targets.GetHeader()) |
1160 open(os.path.join(buildpath, "beremiz.h"), "w").write(targets.GetHeader()) |
1161 |
1161 |
1162 # Template based part of C code generation |
1162 # Template based part of C code generation |
1163 # files are stacked at the beginning, as files of confnode tree root |
1163 # files are stacked at the beginning, as files of confnode tree root |
1164 for generator, filename, name in [ |
1164 c_source = [ |
1165 # debugger code |
1165 # debugger code |
1166 (self.Generate_plc_debugger, "plc_debugger.c", "Debugger"), |
1166 (self.Generate_plc_debugger, "plc_debugger.c", "Debugger"), |
1167 # init/cleanup/retrieve/publish, run and align code |
1167 # init/cleanup/retrieve/publish, run and align code |
1168 (self.Generate_plc_main, "plc_main.c", "Common runtime")]: |
1168 (self.Generate_plc_main, "plc_main.c", "Common runtime") |
|
1169 ] |
|
1170 |
|
1171 for generator, filename, name in c_source: |
1169 try: |
1172 try: |
1170 # Do generate |
1173 # Do generate |
1171 code = generator() |
1174 code = generator() |
1172 if code is None: |
1175 if code is None: |
1173 raise Exception |
1176 raise Exception |
1492 self.IECdebug_lock.acquire() |
1495 self.IECdebug_lock.acquire() |
1493 # If no entry exist, create a new one with a fresh WeakKeyDictionary |
1496 # If no entry exist, create a new one with a fresh WeakKeyDictionary |
1494 IECdebug_data = self.IECdebug_datas.get(IECPath, None) |
1497 IECdebug_data = self.IECdebug_datas.get(IECPath, None) |
1495 if IECdebug_data is None: |
1498 if IECdebug_data is None: |
1496 IECdebug_data = [ |
1499 IECdebug_data = [ |
1497 WeakKeyDictionary(), # Callables |
1500 WeakKeyDictionary(), # Callables |
1498 [], # Data storage [(tick, data),...] |
1501 [], # Data storage [(tick, data),...] |
1499 "Registered", # Variable status |
1502 "Registered", # Variable status |
1500 None, |
1503 None, |
1501 buffer_list] # Forced value |
1504 buffer_list] # Forced value |
1502 self.IECdebug_datas[IECPath] = IECdebug_data |
1505 self.IECdebug_datas[IECPath] = IECdebug_data |
1503 else: |
1506 else: |
1504 IECdebug_data[4] |= buffer_list |
1507 IECdebug_data[4] |= buffer_list |
1505 |
1508 |
1506 IECdebug_data[0][callableobj] = buffer_list |
1509 IECdebug_data[0][callableobj] = buffer_list |
1819 extrafiles = [] |
1822 extrafiles = [] |
1820 for extrafilespath in [self._getExtraFilesPath(), |
1823 for extrafilespath in [self._getExtraFilesPath(), |
1821 self._getProjectFilesPath()]: |
1824 self._getProjectFilesPath()]: |
1822 |
1825 |
1823 extrafiles.extend( |
1826 extrafiles.extend( |
1824 [(name, open(os.path.join(extrafilespath, name), |
1827 [(name, open(os.path.join(extrafilespath, name), |
1825 'rb').read()) |
1828 'rb').read()) |
1826 for name in os.listdir(extrafilespath)]) |
1829 for name in os.listdir(extrafilespath)]) |
1827 |
1830 |
1828 # Send PLC on target |
1831 # Send PLC on target |
1829 builder = self.GetBuilder() |
1832 builder = self.GetBuilder() |
1830 if builder is not None: |
1833 if builder is not None: |
1831 data = builder.GetBinaryCode() |
1834 data = builder.GetBinaryCode() |