45 "initFunction", |
45 "initFunction", |
46 "cleanUpFunction", |
46 "cleanUpFunction", |
47 "retrieveFunction", |
47 "retrieveFunction", |
48 "publishFunction"] |
48 "publishFunction"] |
49 EditorType = CFileEditor |
49 EditorType = CFileEditor |
50 |
50 |
51 def GetIconName(self): |
51 def GetIconName(self): |
52 return "Cfile" |
52 return "Cfile" |
53 |
53 |
54 def CodeFileName(self): |
54 def CodeFileName(self): |
55 return os.path.join(self.CTNPath(), "cfile.xml") |
55 return os.path.join(self.CTNPath(), "cfile.xml") |
56 |
56 |
57 def CTNGenerate_C(self, buildpath, locations): |
57 def CTNGenerate_C(self, buildpath, locations): |
58 """ |
58 """ |
59 Generate C code |
59 Generate C code |
60 @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
60 @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
61 @param locations: List of complete variables locations \ |
61 @param locations: List of complete variables locations \ |
68 @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
68 @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
69 """ |
69 """ |
70 current_location = self.GetCurrentLocation() |
70 current_location = self.GetCurrentLocation() |
71 # define a unique name for the generated C file |
71 # define a unique name for the generated C file |
72 location_str = "_".join(map(str, current_location)) |
72 location_str = "_".join(map(str, current_location)) |
73 |
73 |
74 text = "/* Code generated by Beremiz c_ext confnode */\n\n" |
74 text = "/* Code generated by Beremiz c_ext confnode */\n\n" |
75 text += "#include <stdio.h>\n\n" |
75 text += "#include <stdio.h>\n\n" |
76 |
76 |
77 # Adding includes |
77 # Adding includes |
78 text += "/* User includes */\n" |
78 text += "/* User includes */\n" |
79 text += self.CodeFile.includes.getanyText().strip() |
79 text += self.CodeFile.includes.getanyText().strip() |
80 text += "\n" |
80 text += "\n" |
81 |
81 |
82 text += '#include "iec_types_all.h"\n\n' |
82 text += '#include "iec_types_all.h"\n\n' |
83 |
83 |
84 # Adding variables |
84 # Adding variables |
85 config = self.GetCTRoot().GetProjectConfigNames()[0] |
85 config = self.GetCTRoot().GetProjectConfigNames()[0] |
86 text += "/* User variables reference */\n" |
86 text += "/* User variables reference */\n" |
87 for variable in self.CodeFile.variables.variable: |
87 for variable in self.CodeFile.variables.variable: |
88 var_infos = { |
88 var_infos = { |
91 variable.getname().upper()), |
91 variable.getname().upper()), |
92 "type": "__IEC_%s_t" % variable.gettype()} |
92 "type": "__IEC_%s_t" % variable.gettype()} |
93 text += "extern %(type)s %(global)s;\n" % var_infos |
93 text += "extern %(type)s %(global)s;\n" % var_infos |
94 text += "#define %(name)s %(global)s.value\n" % var_infos |
94 text += "#define %(name)s %(global)s.value\n" % var_infos |
95 text += "\n" |
95 text += "\n" |
96 |
96 |
97 # Adding user global variables and routines |
97 # Adding user global variables and routines |
98 text += "/* User internal user variables and routines */\n" |
98 text += "/* User internal user variables and routines */\n" |
99 text += self.CodeFile.globals.getanyText().strip() |
99 text += self.CodeFile.globals.getanyText().strip() |
100 text += "\n" |
100 text += "\n" |
101 |
101 |
102 # Adding Beremiz confnode functions |
102 # Adding Beremiz confnode functions |
103 text += "/* Beremiz confnode functions */\n" |
103 text += "/* Beremiz confnode functions */\n" |
104 text += "int __init_%s(int argc,char **argv)\n{\n" % location_str |
104 text += "int __init_%s(int argc,char **argv)\n{\n" % location_str |
105 text += self.CodeFile.initFunction.getanyText().strip() |
105 text += self.CodeFile.initFunction.getanyText().strip() |
106 text += " return 0;\n}\n\n" |
106 text += " return 0;\n}\n\n" |
107 |
107 |
108 text += "void __cleanup_%s(void)\n{\n" % location_str |
108 text += "void __cleanup_%s(void)\n{\n" % location_str |
109 text += self.CodeFile.cleanUpFunction.getanyText().strip() |
109 text += self.CodeFile.cleanUpFunction.getanyText().strip() |
110 text += "\n}\n\n" |
110 text += "\n}\n\n" |
111 |
111 |
112 text += "void __retrieve_%s(void)\n{\n" % location_str |
112 text += "void __retrieve_%s(void)\n{\n" % location_str |
113 text += self.CodeFile.retrieveFunction.getanyText().strip() |
113 text += self.CodeFile.retrieveFunction.getanyText().strip() |
114 text += "\n}\n\n" |
114 text += "\n}\n\n" |
115 |
115 |
116 text += "void __publish_%s(void)\n{\n" % location_str |
116 text += "void __publish_%s(void)\n{\n" % location_str |
117 text += self.CodeFile.publishFunction.getanyText().strip() |
117 text += self.CodeFile.publishFunction.getanyText().strip() |
118 text += "\n}\n\n" |
118 text += "\n}\n\n" |
119 |
119 |
120 Gen_Cfile_path = os.path.join(buildpath, "CFile_%s.c" % location_str) |
120 Gen_Cfile_path = os.path.join(buildpath, "CFile_%s.c" % location_str) |
121 cfile = open(Gen_Cfile_path,'w') |
121 cfile = open(Gen_Cfile_path,'w') |
122 cfile.write(text) |
122 cfile.write(text) |
123 cfile.close() |
123 cfile.close() |
124 |
124 |
125 matiec_CFLAGS = '"-I%s"' % os.path.abspath(self.GetCTRoot().GetIECLibPath()) |
125 matiec_CFLAGS = '"-I%s"' % os.path.abspath(self.GetCTRoot().GetIECLibPath()) |
126 |
126 |
127 return [(Gen_Cfile_path, str(self.CExtension.getCFLAGS() + matiec_CFLAGS))],str(self.CExtension.getLDFLAGS()),True |
127 return [(Gen_Cfile_path, str(self.CExtension.getCFLAGS() + matiec_CFLAGS))],str(self.CExtension.getLDFLAGS()),True |
128 |
|