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