PLC and plugins compilation with gcc now starts (and fail).
--- a/plugger.py Tue Sep 18 18:04:07 2007 +0200
+++ b/plugger.py Thu Sep 20 17:30:32 2007 +0200
@@ -160,12 +160,29 @@
def _Generate_C(self, buildpath, locations, logger):
# Generate plugins [(Cfiles, CFLAGS)], LDFLAGS
PlugCFilesAndCFLAGS, PlugLDFLAGS = self.PlugGenerate_C(buildpath, locations, logger)
+ # if some files heve been generated put them in the list with their location
+ if PlugCFilesAndCFLAGS:
+ LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), PlugCFilesAndCFLAGS)]
+ else:
+ LocationCFilesAndCFLAGS = []
+
+ # plugin asks some some LDFLAGS
+ if PlugLDFLAGS:
+ # LDFLAGS can be either string
+ if type(PlugLDFLAGS)==type(str()):
+ LDFLAGS=[PlugLDFLAGS]
+ #or list of strings
+ elif type(PlugLDFLAGS)==type(list()):
+ LDFLAGS=PlugLDFLAGS[:]
+ else:
+ LDFLAGS=[]
+
# recurse through all childs, and stack their results
- for PlugChild in self.IterChilds():
+ for PlugChild in self.IECSortedChilds():
new_location = PlugChild.GetCurrentLocation()
# How deep are we in the tree ?
depth=len(new_location)
- CFilesAndCFLAGS, LDFLAGS = \
+ _LocationCFilesAndCFLAGS, _LDFLAGS = \
PlugChild._Generate_C(
#keep the same path
buildpath,
@@ -174,10 +191,10 @@
#propagete logger
logger)
# stack the result
- PlugCFilesAndCFLAGS += CFilesAndCFLAGS
- PlugLDFLAGS += LDFLAGS
-
- return PlugCFilesAndCFLAGS,PlugLDFLAGS
+ LocationCFilesAndCFLAGS += _LocationCFilesAndCFLAGS
+ LDFLAGS += _LDFLAGS
+
+ return LocationCFilesAndCFLAGS,LDFLAGS
def BlockTypesFactory(self):
return []
@@ -190,25 +207,40 @@
for PlugInstance in PluggedChilds:
yield PlugInstance
- def _GetChildBySomething(self, sep, something, matching):
- toks = matching.split(sep,1)
+ def IECSortedChilds(self):
+ # reorder childs by IEC_channels
+ ordered = [(chld.BaseParams.getIEC_Channel(),chld) for chld in self.IterChilds()]
+ if ordered:
+ ordered.sort()
+ return zip(*ordered)[1]
+ else:
+ return []
+
+ def _GetChildBySomething(self, something, toks):
for PlugInstance in self.IterChilds():
# if match component of the name
if getattr(PlugInstance.BaseParams, something) == toks[0]:
# if Name have other components
- if len(toks) == 2:
+ if len(toks) >= 2:
# Recurse in order to find the latest object
- return PlugInstance._GetChildBySomething( sep, something, toks[1])
+ return PlugInstance._GetChildBySomething( something, toks[1:])
# No sub name -> found
return PlugInstance
# Not found
return None
def GetChildByName(self, Name):
- return self._GetChildBySomething('.',"Name", Name)
+ if Name:
+ toks = Name.split('.')
+ return self._GetChildBySomething("Name", toks)
+ else:
+ return self
def GetChildByIECLocation(self, Location):
- return self._GetChildBySomething('_',"IEC_Channel", Name)
+ if Location:
+ return self._GetChildBySomething("IEC_Channel", Location)
+ else:
+ return self
def GetCurrentLocation(self):
"""
@@ -216,20 +248,28 @@
"""
return self.PlugParent.GetCurrentLocation() + (self.BaseParams.getIEC_Channel(),)
+ def GetCurrentName(self):
+ """
+ @return: String "ParentParentName.ParentName.Name"
+ """
+ return self.PlugParent._GetCurrentName() + self.BaseParams.getName()
+
+ def _GetCurrentName(self):
+ """
+ @return: String "ParentParentName.ParentName.Name."
+ """
+ return self.PlugParent._GetCurrentName() + self.BaseParams.getName() + "."
+
def GetPlugRoot(self):
return self.PlugParent.GetPlugRoot()
def GetPlugInfos(self):
childs = []
# reorder childs by IEC_channels
- ordered = [(chld.BaseParams.getIEC_Channel(),chld) for chld in self.IterChilds()]
- if ordered:
- ordered.sort()
- for child in zip(*ordered)[1]:
- childs.append(child.GetPlugInfos())
+ for child in self.IECSortedChilds():
+ childs.append(child.GetPlugInfos())
return {"name" : "%d-%s"%(self.BaseParams.getIEC_Channel(),self.BaseParams.getName()), "type" : self.BaseParams.getName(), "values" : childs}
-
def FindNewName(self, DesiredName, logger):
"""
Changes Name to DesiredName if available, Name-N if not.
@@ -464,13 +504,6 @@
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <xsd:simpleType name="Win32Compiler">
- <xsd:restriction base="xsd:string">
- <xsd:enumeration value="Cygwin"/>
- <xsd:enumeration value="MinGW"/>
- <xsd:enumeration value="VC++"/>
- </xsd:restriction>
- </xsd:simpleType>
<xsd:element name="BeremizRoot">
<xsd:complexType>
<xsd:element name="TargetType">
@@ -478,39 +511,35 @@
<xsd:choice>
<xsd:element name="Win32">
<xsd:complexType>
- <xsd:attribute name="ToolChain" type="ppx:Win32Compiler" use="required" default="MinGW"/>
<xsd:attribute name="Priority" type="xsd:integer" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="Linux">
<xsd:complexType>
- <xsd:attribute name="Compiler" type="xsd:string" use="required" default="gcc"/>
<xsd:attribute name="Nice" type="xsd:integer" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="Xenomai">
<xsd:complexType>
<xsd:attribute name="xeno-config" type="xsd:string" use="required" default="/usr/xenomai/"/>
- <xsd:attribute name="Compiler" type="xsd:string" use="required"/>
<xsd:attribute name="Priority" type="xsd:integer" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="RTAI">
<xsd:complexType>
- <xsd:attribute name="xeno-config" type="xsd:string" use="required"/>
- <xsd:attribute name="Compiler" type="xsd:string" use="required"/>
+ <xsd:attribute name="rtai-config" type="xsd:string" use="required"/>
<xsd:attribute name="Priority" type="xsd:integer" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="Library">
<xsd:complexType>
<xsd:attribute name="Dynamic" type="xsd:boolean" use="required" default="true"/>
- <xsd:attribute name="Compiler" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
+ <xsd:attribute name="Compiler" type="xsd:string" use="required" default="gcc"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
@@ -548,7 +577,13 @@
def GetCurrentLocation(self):
return ()
-
+
+ def GetCurrentName(self):
+ return ""
+
+ def _GetCurrentName(self):
+ return ""
+
def GetProjectPath(self):
return self.ProjectPath
@@ -645,7 +680,7 @@
ex: [((0,0,4,5),'I','STRING','__IX_0_0_4_5'),...]
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
"""
- return [(C_file_name, "") for C_file_name in self.PLCGeneratedCFiles ] , ""
+ return [(C_file_name, "-I"+ieclib_path) for C_file_name in self.PLCGeneratedCFiles ] , ""
def _getBuildPath(self):
return os.path.join(self.ProjectPath, "build")
@@ -674,10 +709,10 @@
# Failed !
logger.write_error("Error : ST/IL/SFC code generator returned %d\n"%result)
return False
- logger.write("Compiling ST Program in to C Program...\n")
+ logger.write("Compiling IEC Program in to C code...\n")
# Now compile IEC code into many C files
# files are listed to stdout, and errors to stderr.
- status, result, err_result = logger.LogCommand("%s %s -I %s %s"%(iec2cc_path, plc_file, ieclib_path, buildpath))
+ status, result, err_result = logger.LogCommand("%s %s -I %s %s"%(iec2cc_path, plc_file, ieclib_path, buildpath), no_stdout=True)
if status:
# Failed !
logger.write_error("Error : IEC to C compiler returned %d\n"%status)
@@ -734,11 +769,13 @@
logger.write_error("SoftPLC code generation failed !\n")
return False
- logger.write("SoftPLC code generation successfull\n")
+ #logger.write("SoftPLC code generation successfull\n")
+
+ logger.write("Generating plugins code ...\n")
# Generate C code and compilation params from plugin hierarchy
try:
- CFilesAndCFLAGS, LDFLAGS = self._Generate_C(
+ LocationCFilesAndCFLAGS,LDFLAGS = self._Generate_C(
buildpath,
self.PLCGeneratedLocatedVars,
logger)
@@ -747,14 +784,29 @@
logger.write_error(str(msg))
return False
- logger.write("Plugins code generation successfull\n")
-
+
+ #debug
+ #import pprint
+ #pp = pprint.PrettyPrinter(indent=4)
+ #logger.write("LocationCFilesAndCFLAGS :\n"+pp.pformat(LocationCFilesAndCFLAGS)+"\n")
+ #logger.write("LDFLAGS :\n"+pp.pformat(LDFLAGS)+"\n")
+
# Compile the resulting code into object files.
- for CFile, CFLAG in CFilesAndCFLAGS:
- logger.write(str((CFile,CFLAG)))
+ compiler = self.BeremizRoot.getCompiler()
+ for Location, CFilesAndCFLAGS in LocationCFilesAndCFLAGS:
+ if Location:
+ logger.write("Plugin : " + self.GetChildByIECLocation(Location).GetCurrentName() + " " + str(Location)+"\n")
+ else:
+ logger.write("PLC :\n")
+
+ for CFile, CFLAGS in CFilesAndCFLAGS:
+ bn = os.path.basename(CFile)
+ logger.write(" [CC] "+bn+" -> "+os.path.splitext(bn)[0]+".o\n")
+ objectfilename = os.path.splitext(bn)[0]+".o"
+ status, result, err_result = logger.LogCommand("%s -c %s -o %s %s"%(compiler, CFile, objectfilename, CFLAGS))
+
# Link object files into something that can be executed on target
- logger.write(LDFLAGS)
def _showIECcode(self, logger):
plc_file = self._getIECcodepath()
@@ -793,4 +845,3 @@
logger.write_error("Not impl\n")
PluginMethods = [("EditPLC",_EditPLC), ("Build",_build), ("Clean",_Clean), ("Run",_Run), ("Show IEC code",_showIECcode)]
-
--- a/plugins/c_ext/c_ext.py Tue Sep 18 18:04:07 2007 +0200
+++ b/plugins/c_ext/c_ext.py Thu Sep 20 17:30:32 2007 +0200
@@ -73,8 +73,8 @@
lst = self.CFileBaseNames()
dlg = wx.MultiChoiceDialog( self.GetPlugRoot().AppFrame,
- "Pick some fruit from\nthis list",
- "wx.MultiChoiceDialog", lst)
+ "Choose C files to Edit :",
+ "Edit", lst)
if (dlg.ShowModal() == wx.ID_OK):
selections = dlg.GetSelections()
@@ -85,7 +85,7 @@
self.SaveCView(sel)
self._Views.pop(sel)
evt.Skip()
- New_View = wx.Frame(self.GetPlugRoot().AppFrame,-1)
+ New_View = wx.Frame(self.GetPlugRoot().AppFrame,-1,selected)
New_View.Bind(wx.EVT_CLOSE, _onclose)
ed = CppSTC(New_View, wx.NewId())
ed.SetText(open(self.CFileName(selected)).read())
--- a/plugins/canfestival/canfestival.py Tue Sep 18 18:04:07 2007 +0200
+++ b/plugins/canfestival/canfestival.py Thu Sep 20 17:30:32 2007 +0200
@@ -1,6 +1,8 @@
import os, sys
base_folder = os.path.split(sys.path[0])[0]
sys.path.append(os.path.join(base_folder, "CanFestival-3", "objdictgen"))
+CanfestivalIncludePath = os.path.join(base_folder, "CanFestival-3", "include")
+CanfestivalLibPath = os.path.join(base_folder, "CanFestival-3", "src")
from nodelist import NodeList
from nodemanager import NodeManager
@@ -83,7 +85,7 @@
if res :
raise Exception, res
- return [(Gen_OD_path,"")],""
+ return [(Gen_OD_path,"-I"+CanfestivalIncludePath)],""
class RootClass:
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
@@ -99,6 +101,6 @@
PlugChildsTypes = [("CanOpenNode",_NodeListPlug)]
def PlugGenerate_C(self, buildpath, locations, logger):
- return [],""
+ return [],"-L"+CanfestivalLibPath+" -lcanfestival"
--- a/plugins/svgui/svgui.py Tue Sep 18 18:04:07 2007 +0200
+++ b/plugins/svgui/svgui.py Thu Sep 20 17:30:32 2007 +0200
@@ -182,7 +182,8 @@
text += "IMPLEMENT_APP_NO_MAIN(SVGViewApp);\n"
text += "IMPLEMENT_WX_THEME_SUPPORT;\n"
text += "SVGViewApp *myapp = NULL;\n"
- text += "pthread_t wxMainLoop,automate;\n"
+ text += "pthread_t wxMainLoop;\n"
+# text += "pthread_t wxMainLoop,automate;\n"
text += "int myargc = 0;\n"
text += "char** myargv = NULL;\n\n"
@@ -207,17 +208,18 @@
# text += " return args;\n"
# text += "}\n\n"
- if (self.SVGUIRootElement):
- width = self.SVGUIRootElement.GetBBox().GetWidth()
- height = self.SVGUIRootElement.GetBBox().GetHeight()
- else :
- width = 250
- height = 350
+# if (self.SVGUIRootElement):
+# width = self.SVGUIRootElement.GetBBox().GetWidth()
+# height = self.SVGUIRootElement.GetBBox().GetHeight()
+# else :
+# width = 250
+# height = 350
text += "bool SVGViewApp::OnInit()\n{\n"
text += " #ifndef __WXMSW__\n"
text += " setlocale(LC_NUMERIC, \"C\");\n"
text += " #endif\n"
- text += " frame = new MainFrame(NULL, wxT(\"Program\"),wxDefaultPosition, wxSize((int)"+str(width)+", (int)"+str(height)+"));\n"
+ #text += " frame = new MainFrame(NULL, wxT(\"Program\"),wxDefaultPosition, wxSize((int)"+str(width)+", (int)"+str(height)+"));\n"
+ text += " frame = new MainFrame(NULL, wxT(\"Program\"),wxDefaultPosition, wxDefaultSize);\n"
text += " myapp = this;\n"
# text += " pthread_create(&automate, NULL, SimulAutomate, NULL);\n"
text += " return true;\n"
@@ -227,7 +229,9 @@
text += " myargc = argc;\n"
text += " myargv = argv;\n"
text += " pthread_create(&wxMainLoop, NULL, InitWxEntry, NULL);\n"
- text += " pause();\n"
+ text += "}\n\n"
+
+ text += "int __cleanup_"+self.BusNumber+"()\n{\n"
text += "}\n\n"
text += "int __retrive_"+self.BusNumber+"()\n{\n"
@@ -321,6 +325,7 @@
if info["name"] == "id":
element_id = str(info["value"])
text += " out_state_"+element_id+" = UNCHANGED;\n"
+ text += " in_state_"+element_id+" = UNCHANGED;\n"
text += "}\n\n"
return text
@@ -753,8 +758,9 @@
def PlugGenerate_C(self, buildpath, locations, logger):
current_location = self.GetCurrentLocation()
self.BusNumber = "_".join(map(lambda x:str(x), current_location))
- self.GenerateProgram(buildpath)
- Gen_C_file = os.path.join(buildpath, "program.cpp" )
+ progname = self.BusNumber + "_SVGUI"
+ self.GenerateProgram(buildpath, progname)
+ Gen_C_file = os.path.join(buildpath, progname+".cpp" )
return [(Gen_C_file,"")],""
def BlockTypesFactory(self):
@@ -770,7 +776,7 @@
for num, variable in enumerate(block.inputVariables.getVariable()):
connections = variable.connectionPointIn.getConnections()
if connections and len(connections) == 1:
- parameter = "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["inputs"][num][1]], current_location, block_id, num)
+ parameter = "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["inputs"][num][1]], current_location, block_id, num+1)
value = generator.ComputeFBDExpression(body, connections[0])
generator.Program += (" %s := %s;\n"%(parameter, generator.ExtractModifier(variable, value)))
generator.ComputedBlocks[name] = True
@@ -779,7 +785,7 @@
for num, variable in enumerate(block.outputVariables.getVariable()):
blockPointx, blockPointy = variable.connectionPointOut.getRelPosition()
if block.getX() + blockPointx == connectionPoint.getX() and block.getY() + blockPointy == connectionPoint.getY():
- return "%sI%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["outputs"][num][1]], current_location, block_id, num)
+ return "%sI%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["outputs"][num][1]], current_location, block_id, num+1)
raise ValueError, "No output variable found"
else:
return None
@@ -792,9 +798,9 @@
current_location = ".".join(map(str, self.GetCurrentLocation()))
variables = []
for num, (input_name, input_type, input_modifier) in enumerate(block_infos["inputs"]):
- variables.append((input_type, None, "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[input_type], current_location, block_id, num), None))
+ variables.append((input_type, None, "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[input_type], current_location, block_id, num+1), None))
for num, (output_name, output_type, output_modifier) in enumerate(block_infos["outputs"]):
- variables.append((output_type, None, "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[input_type], current_location, block_id, num), None))
+ variables.append((output_type, None, "%sI%s%s.%d.%d"%("%", TYPECONVERSION[input_type], current_location, block_id, num+1), None))
return variables
return [{"name" : "SVGUI function blocks", "list" :