483 # import necessary stuff from PLCOpenEditor |
483 # import necessary stuff from PLCOpenEditor |
484 from PLCControler import PLCControler |
484 from PLCControler import PLCControler |
485 from PLCOpenEditor import PLCOpenEditor, ProjectDialog |
485 from PLCOpenEditor import PLCOpenEditor, ProjectDialog |
486 from TextViewer import TextViewer |
486 from TextViewer import TextViewer |
487 from plcopen.structures import IEC_KEYWORDS, AddPluginBlockList, ClearPluginTypes, PluginTypes |
487 from plcopen.structures import IEC_KEYWORDS, AddPluginBlockList, ClearPluginTypes, PluginTypes |
|
488 import runtime |
488 import re |
489 import re |
489 |
490 |
490 class PluginsRoot(PlugTemplate, PLCControler): |
491 class PluginsRoot(PlugTemplate, PLCControler): |
491 """ |
492 """ |
492 This class define Root object of the plugin tree. |
493 This class define Root object of the plugin tree. |
678 @param locations: List of complete variables locations \ |
679 @param locations: List of complete variables locations \ |
679 [(IEC_loc, IEC_Direction, IEC_Type, Name)]\ |
680 [(IEC_loc, IEC_Direction, IEC_Type, Name)]\ |
680 ex: [((0,0,4,5),'I','STRING','__IX_0_0_4_5'),...] |
681 ex: [((0,0,4,5),'I','STRING','__IX_0_0_4_5'),...] |
681 @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
682 @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
682 """ |
683 """ |
683 return [(C_file_name, "-I"+ieclib_path) for C_file_name in self.PLCGeneratedCFiles ] , "" |
684 return [(C_file_name, self.CFLAGS) for C_file_name in self.PLCGeneratedCFiles ] , "" |
684 |
685 |
685 def _getBuildPath(self): |
686 def _getBuildPath(self): |
686 return os.path.join(self.ProjectPath, "build") |
687 return os.path.join(self.ProjectPath, "build") |
687 |
688 |
688 def _getIECcodepath(self): |
689 def _getIECcodepath(self): |
747 locations.append(resdict) |
748 locations.append(resdict) |
748 # Keep track of generated C files for later use by self.PlugGenerate_C |
749 # Keep track of generated C files for later use by self.PlugGenerate_C |
749 self.PLCGeneratedCFiles = C_files |
750 self.PLCGeneratedCFiles = C_files |
750 # Keep track of generated located variables for later use by self._Generate_C |
751 # Keep track of generated located variables for later use by self._Generate_C |
751 self.PLCGeneratedLocatedVars = locations |
752 self.PLCGeneratedLocatedVars = locations |
|
753 # compute CFLAGS for plc |
|
754 self.CFLAGS = "-I"+ieclib_path |
752 return True |
755 return True |
753 |
756 |
754 def _build(self, logger): |
757 def _build(self, logger): |
755 """ |
758 """ |
756 Method called by user to (re)build SoftPLC and plugin tree |
759 Method called by user to (re)build SoftPLC and plugin tree |
788 #debug |
791 #debug |
789 #import pprint |
792 #import pprint |
790 #pp = pprint.PrettyPrinter(indent=4) |
793 #pp = pprint.PrettyPrinter(indent=4) |
791 #logger.write("LocationCFilesAndCFLAGS :\n"+pp.pformat(LocationCFilesAndCFLAGS)+"\n") |
794 #logger.write("LocationCFilesAndCFLAGS :\n"+pp.pformat(LocationCFilesAndCFLAGS)+"\n") |
792 #logger.write("LDFLAGS :\n"+pp.pformat(LDFLAGS)+"\n") |
795 #logger.write("LDFLAGS :\n"+pp.pformat(LDFLAGS)+"\n") |
|
796 |
|
797 # Generate main |
|
798 locstrs = map(lambda x:"_".join(map(str,x)), [loc for loc in zip(*LocationCFilesAndCFLAGS)[0] if loc]) |
|
799 plc_main = runtime.code("plc_common_main") % { |
|
800 "calls_prototypes":"".join([""" |
|
801 void __init%(s)s(); |
|
802 void __cleanup%(s)s(); |
|
803 void __retrive%(s)s(); |
|
804 void __publish%(s)s();"""%{'s':locstr} for locstr in locstrs]), |
|
805 "retrive_calls":"".join([""" |
|
806 __retrive%(s)s();"""%{'s':locstr} for locstr in locstrs]), |
|
807 "publish_calls":"".join([""" |
|
808 __publish%(s)s();"""%{'s':locstr} for locstr in locstrs]), |
|
809 "init_calls":"".join([""" |
|
810 __init%(s)s();"""%{'s':locstr} for locstr in locstrs]), |
|
811 "cleanup_calls":"".join([""" |
|
812 __cleanup%(s)s();"""%{'s':locstr} for locstr in locstrs])} |
|
813 target_name = self.BeremizRoot.TargetType.content["name"] |
|
814 plc_main += runtime.code("plc_%s_main"%target_name) |
|
815 |
|
816 main_path = os.path.join(buildpath, "main.c" ) |
|
817 f = open(main_path,'w') |
|
818 f.write(plc_main) |
|
819 f.close() |
|
820 # First element is necessarely root |
|
821 LocationCFilesAndCFLAGS[0][1].insert(0,(main_path, self.CFLAGS)) |
793 |
822 |
794 # Compile the resulting code into object files. |
823 # Compile the resulting code into object files. |
795 compiler = self.BeremizRoot.getCompiler() |
824 compiler = self.BeremizRoot.getCompiler() |
796 for Location, CFilesAndCFLAGS in LocationCFilesAndCFLAGS: |
825 for Location, CFilesAndCFLAGS in LocationCFilesAndCFLAGS: |
797 if Location: |
826 if Location: |
800 logger.write("PLC :\n") |
829 logger.write("PLC :\n") |
801 |
830 |
802 for CFile, CFLAGS in CFilesAndCFLAGS: |
831 for CFile, CFLAGS in CFilesAndCFLAGS: |
803 bn = os.path.basename(CFile) |
832 bn = os.path.basename(CFile) |
804 logger.write(" [CC] "+bn+" -> "+os.path.splitext(bn)[0]+".o\n") |
833 logger.write(" [CC] "+bn+" -> "+os.path.splitext(bn)[0]+".o\n") |
805 objectfilename = os.path.splitext(bn)[0]+".o" |
834 objectfilename = os.path.splitext(CFile)[0]+".o" |
806 status, result, err_result = logger.LogCommand("%s -c %s -o %s %s"%(compiler, CFile, objectfilename, CFLAGS)) |
835 status, result, err_result = logger.LogCommand("%s -c %s -o %s %s"%(compiler, CFile, objectfilename, CFLAGS)) |
|
836 if status != 0: |
|
837 logger.write_error("Build failed\n") |
|
838 return False |
|
839 |
|
840 return True |
807 |
841 |
808 |
842 |
809 # Link object files into something that can be executed on target |
843 # Link object files into something that can be executed on target |
810 |
844 |
811 def _showIECcode(self, logger): |
845 def _showIECcode(self, logger): |