--- 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)] + LocationCFilesAndCFLAGS = [] + # plugin asks some some LDFLAGS + # LDFLAGS can be either string + if type(PlugLDFLAGS)==type(str()): + elif type(PlugLDFLAGS)==type(list()): # 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 ?
- CFilesAndCFLAGS, LDFLAGS = \
+ _LocationCFilesAndCFLAGS, _LDFLAGS = \ @@ -174,10 +191,10 @@
- PlugCFilesAndCFLAGS += CFilesAndCFLAGS
+ LocationCFilesAndCFLAGS += _LocationCFilesAndCFLAGS - return PlugCFilesAndCFLAGS,PlugLDFLAGS
+ return LocationCFilesAndCFLAGS,LDFLAGS def BlockTypesFactory(self):
@@ -190,25 +207,40 @@
for PlugInstance in PluggedChilds:
- 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()] + return zip(*ordered)[1] + 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
# Recurse in order to find the latest object
- return PlugInstance._GetChildBySomething( sep, something, toks[1])
+ return PlugInstance._GetChildBySomething( something, toks[1:]) def GetChildByName(self, Name):
- return self._GetChildBySomething('.',"Name", Name)
+ return self._GetChildBySomething("Name", toks) def GetChildByIECLocation(self, Location):
- return self._GetChildBySomething('_',"IEC_Channel", Name)
+ return self._GetChildBySomething("IEC_Channel", Location) 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() + "." return self.PlugParent.GetPlugRoot()
# reorder childs by IEC_channels
- ordered = [(chld.BaseParams.getIEC_Channel(),chld) for chld in self.IterChilds()]
- 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:element name="BeremizRoot">
<xsd:element name="TargetType">
@@ -478,39 +511,35 @@
<xsd:element name="Win32">
- <xsd:attribute name="ToolChain" type="ppx:Win32Compiler" use="required" default="MinGW"/>
<xsd:attribute name="Priority" type="xsd:integer" use="required"/>
<xsd:element name="Linux">
- <xsd:attribute name="Compiler" type="xsd:string" use="required" default="gcc"/>
<xsd:attribute name="Nice" type="xsd:integer" use="required"/>
<xsd:element name="Xenomai">
<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:element name="RTAI">
- <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:element name="Library">
<xsd:attribute name="Dynamic" type="xsd:boolean" use="required" default="true"/>
- <xsd:attribute name="Compiler" type="xsd:string" use="required"/>
+ <xsd:attribute name="Compiler" type="xsd:string" use="required" default="gcc"/> @@ -548,7 +577,13 @@
def GetCurrentLocation(self):
+ def GetCurrentName(self): + def _GetCurrentName(self): def GetProjectPath(self):
@@ -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 ] , "" return os.path.join(self.ProjectPath, "build")
@@ -674,10 +709,10 @@
logger.write_error("Error : ST/IL/SFC code generator returned %d\n"%result)
- 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) logger.write_error("Error : IEC to C compiler returned %d\n"%status)
@@ -734,11 +769,13 @@
logger.write_error("SoftPLC code generation failed !\n")
- 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
- CFilesAndCFLAGS, LDFLAGS = self._Generate_C(
+ LocationCFilesAndCFLAGS,LDFLAGS = self._Generate_C( self.PLCGeneratedLocatedVars,
@@ -747,14 +784,29 @@
logger.write_error(str(msg))
- logger.write("Plugins code generation successfull\n")
+ #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: + logger.write("Plugin : " + self.GetChildByIECLocation(Location).GetCurrentName() + " " + str(Location)+"\n") + 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
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/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 @@
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 @@
- return [(Gen_OD_path,"")],""
+ return [(Gen_OD_path,"-I"+CanfestivalIncludePath)],"" XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
@@ -99,6 +101,6 @@
PlugChildsTypes = [("CanOpenNode",_NodeListPlug)]
def PlugGenerate_C(self, buildpath, locations, logger):
+ 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"
- if (self.SVGUIRootElement):
- width = self.SVGUIRootElement.GetBBox().GetWidth()
- height = self.SVGUIRootElement.GetBBox().GetHeight()
+# if (self.SVGUIRootElement): +# width = self.SVGUIRootElement.GetBBox().GetWidth() +# height = self.SVGUIRootElement.GetBBox().GetHeight() text += "bool SVGViewApp::OnInit()\n{\n"
text += " #ifndef __WXMSW__\n"
text += " setlocale(LC_NUMERIC, \"C\");\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 += "int __cleanup_"+self.BusNumber+"()\n{\n" text += "int __retrive_"+self.BusNumber+"()\n{\n"
@@ -321,6 +325,7 @@
element_id = str(info["value"])
text += " out_state_"+element_id+" = UNCHANGED;\n"
+ text += " in_state_"+element_id+" = UNCHANGED;\n" @@ -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"
@@ -792,9 +798,9 @@
current_location = ".".join(map(str, self.GetCurrentLocation()))
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 [{"name" : "SVGUI function blocks", "list" :