--- a/Beremiz.py Thu Aug 16 12:03:00 2007 +0200
+++ b/Beremiz.py Mon Aug 20 14:28:08 2007 +0200
@@ -36,14 +36,11 @@
ieclib_path = os.path.join(base_folder, "matiec", "lib")
from PLCOpenEditor import PLCOpenEditor, ProjectDialog
-from TextViewer import *
-from plcopen.structures import IEC_KEYWORDS
+from TextViewer import TextViewer +from plcopen.structures import IEC_KEYWORDS, AddPlugin from PLCControler import PLCControler
-from networkedit import networkedit
-from nodelist import NodeList
-from nodemanager import NodeManager
-import config_utils, gen_cfile
__version__ = "$Revision$"
@@ -334,6 +331,15 @@
def __init__(self, parent):
+ for name in plugins.__all__: + module = getattr(plugins, name) + if len(module.BlockList) > 0: + function = module.GetBlockGenerationFunction(self) + blocklist = module.BlockList + for blocktype in blocklist["list"]: + blocktype["generate"] = function + AddPlugin(module.BlockList) self.CurrentProjectPath = ""
@@ -439,18 +445,18 @@
for bus_id, bus_type, bus_name in [line.split(" ") for line in lines[1:]]:
- if bus_type == "CanFestival":
- manager = NodeManager(os.path.join(base_folder, "CanFestival-3", "objdictgen"))
- nodelist = NodeList(manager)
- result = nodelist.LoadProject(projectpath, bus_name)
+ controller = getattr(plugins, bus_type).controller + result = manager.LoadProject(projectpath, bus_name) - self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type, "NodeList" : nodelist, "Editor" : None}
+ self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type, "Manager" : manager, "Editor" : None} message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
- self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type}
+ self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type, "Manager" : None, "Editor" : None} self.PLCManager = PLCControler()
plc_file = os.path.join(projectpath, "plc.xml")
@@ -471,8 +477,8 @@
- message = wx.MessageDialog(self, "\"%s\" folder is not a valid Beremiz project"%projectpath, "Error", wx.OK|wx.ICON_ERROR)
+ except Exception, message: + message = wx.MessageDialog(self, "\"%s\" folder is not a valid Beremiz project\n%s"%(projectpath,message), "Error", wx.OK|wx.ICON_ERROR) @@ -508,7 +514,7 @@
bus_infos = self.BusManagers[id]
file.write("0x%2.2X %s %s\n"%(id, bus_infos["Type"], bus_infos["Name"]))
- bus_infos["NodeList"].SaveProject(bus_infos["Name"])
+ bus_infos["Manager"].SaveProject(bus_infos["Name"]) @@ -577,12 +583,13 @@
busidlist = self.BusManagers.keys()
bus_infos = self.BusManagers[busidlist[selected]]
- if bus_infos["Type"] == "CanFestival":
+ view = getattr(plugins, bus_infos["Type"]).view if bus_infos["Editor"] == None:
- netedit = networkedit(self, bus_infos["NodeList"])
- netedit.SetBusId(busidlist[selected])
- bus_infos["Editor"] = netedit
+ editor = view(self, bus_infos["Manager"]) + editor.SetBusId(busidlist[selected]) + bus_infos["Editor"] = editor def CloseEditor(self, bus_id):
@@ -598,18 +605,18 @@
bus_id = int(values["busID"])
if self.BusManagers.get(bus_id, None) == None:
- if values["busType"] == "CanFestival":
- manager = NodeManager(os.path.join(base_folder, "CanFestival-3", "objdictgen"))
- nodelist = NodeList(manager)
- result = nodelist.LoadProject(self.CurrentProjectPath, values["busName"])
+ controller = getattr(plugins, values["busType"]).controller + result = manager.LoadProject(self.CurrentProjectPath, values["busName"]) - self.BusManagers[bus_id] = {"Name" : values["busName"], "Type" : values["busType"], "NodeList" : nodelist, "Editor" : None}
+ self.BusManagers[bus_id] = {"Name" : values["busName"], "Type" : values["busType"], "Manager" : manager, "Editor" : None} message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
- self.BusManagers[bus_id] = {"Name" : values["busName"], "Type" : values["busType"]}
+ self.BusManagers[bus_id] = {"Name" : values["busName"], "Type" : values["busType"], "Manager" : None, "Editor" : None} message = wx.MessageDialog(self, "The bus ID \"0x%2.2X\" is already used!"%bus_id, "Error", wx.OK|wx.ICON_ERROR)
@@ -708,11 +715,11 @@
locations.append(result.groups())
self.Log.write("Generating Network Configurations...\n")
for bus_id, bus_infos in self.BusManagers.items():
- if bus_infos["Type"] == "CanFestival":
- master = config_utils.GenerateConciseDCF(locations, bus_id, bus_infos["NodeList"])
- result = gen_cfile.GenerateFile("%s.c"%os.path.join(self.TargetDir, gen_cfile.FormatName(bus_infos["Name"])), master)
+ if bus_infos["Manager"]: + filepath = "%s.c"%os.path.join(self.TargetDir, gen_cfile.FormatName(bus_infos["Name"])) + result = bus_infos["Manager"].GenerateBus(filepath, bus_id, locations)
+ raise Exception, "Bus with id \"0x%2.2X\" can't be generated!"%bus_id self.Log.write("Generating Makefiles...\n")
self.Log.write("Compiling Project...\n")
@@ -804,7 +811,7 @@
def __init__(self, parent):
- for option in ["CanFestival","SVGUI"]:
+ for option in [""] + plugins.__all__: self.BusType.Append(option)
--- a/config_utils.py Thu Aug 16 12:03:00 2007 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,429 +0,0 @@
-#This file is part of Beremiz, a Integrated Development Environment for
-#programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
-#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
-#See COPYING file for copyrights details.
-#This library is free software; you can redistribute it and/or
-#modify it under the terms of the GNU General Public
-#License as published by the Free Software Foundation; either
-#version 2.1 of the License, or (at your option) any later version.
-#This library is distributed in the hope that it will be useful,
-#but WITHOUT ANY WARRANTY; without even the implied warranty of
-#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-#General Public License for more details.
-#You should have received a copy of the GNU General Public
-#License along with this library; if not, write to the Free Software
-#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-DicoTypes = {"BOOL":0x01, "SINT":0x02, "INT":0x03,"DINT":0x04,"LINT":0x10,
- "USINT":0x05,"UINT":0x06,"UDINT":0x07,"ULINT":0x1B,"REAL":0x08,
- "LREAL":0x11,"STRING":0x09,"BYTE":0x02,"WORD":0x03,"DWORD":0x04,
- "LWORD":0x1B,"WSTRING":0x0B}
-DictLocationsNotMapped = {}
-# Constants for PDO types
-SlavePDOType = {"I" : TPDO, "Q" : RPDO}
-InvertPDOType = {RPDO : TPDO, TPDO : RPDO}
-DefaultTransmitTypeMaster = 0x01
-GenerateMasterMapping = lambda x:[None] + [(loc_infos["type"], name) for name, loc_infos in x]
-TrashVariableSizes = {1 : 0x01, 8 : 0x05, 16 : 0x06, 32 : 0x07, 64 : 0x1B}
-def GetSlavePDOIndexes(slave, type, parameters = False):
- indexes.extend([idx for idx in slave.GetIndexes() if 0x1400 <= idx <= 0x15FF])
- indexes.extend([idx for idx in slave.GetIndexes() if 0x1800 <= idx <= 0x19FF])
- return [idx + 0x200 for idx in indexes]
-def LE_to_BE(value, size): # Convert Little Endian to Big Endian
- data = ("%" + str(size * 2) + "." + str(size * 2) + "X") % value
- list_car = [data[i:i+2] for i in xrange(0, len(data), 2)]
- return "".join([chr(int(car, 16)) for car in list_car])
-def SearchSlavePDOMapping(loc_infos, slave): # Search the TPDO or RPDO mapping where location is defined on the slave
- typeinfos = slave.GetEntryInfos(loc_infos["type"])
- model = (loc_infos["index"] << 16) + (loc_infos["subindex"] << 8) + typeinfos["size"]
- slavePDOidxlist = GetSlavePDOIndexes(slave, loc_infos["pdotype"])
- for PDOidx in slavePDOidxlist:
- values = slave.GetEntry(PDOidx)
- for subindex, mapping in enumerate(values):
- if subindex != 0 and mapping == model:
- return PDOidx, subindex
-def GenerateMappingDCF(cobid, idx, pdomapping, mapped): # Build concise DCF
- # Create entry for RPDO or TPDO parameters and Disable PDO
- dcfdata = LE_to_BE(idx, 2) + LE_to_BE(0x01, 1) + LE_to_BE(0x04, 4) + LE_to_BE((0x80000000 + cobid), 4)
- # Set Transmit type synchrone
- dcfdata += LE_to_BE(idx, 2) + LE_to_BE(0x02, 1) + LE_to_BE(0x01, 4) + LE_to_BE(DefaultTransmitTypeSlave, 1)
- # ---- INDEX ----- --- SUBINDEX ---- ----- SIZE ------ ------ DATA ------
- dcfdata += LE_to_BE(idx, 2) + LE_to_BE(0x01, 1) + LE_to_BE(0x04, 4) + LE_to_BE(0x00000000 + cobid, 4)
- if mapped == False and pdomapping != None:
- for subindex, (name, loc_infos) in enumerate(pdomapping):
- value = (loc_infos["index"] << 16) + (loc_infos["subindex"] << 8) + loc_infos["size"]
- dcfdata += LE_to_BE(idx + 0x200, 2) + LE_to_BE(subindex + 1, 1) + LE_to_BE(0x04, 4) + LE_to_BE(value, 4)
- return dcfdata, nbparams
-def GetNewCobID(nodeid, type): # Return a cobid not used
- global ListCobIDAvailable, SlavesPdoNumber
- if len(ListCobIDAvailable) == 0:
- nbSlavePDO = SlavesPdoNumber[nodeid][type]
- # For the fourth PDO -> cobid = 0x200 + ( numPdo parameters * 0x100) + nodeid
- newcobid = (0x200 + nbSlavePDO * 0x100 + nodeid)
- if newcobid in ListCobIDAvailable:
- ListCobIDAvailable.remove(newcobid)
- return newcobid, 0x1400 + nbSlavePDO
- return ListCobIDAvailable.pop(0), 0x1400 + nbSlavePDO
- # For the fourth PDO -> cobid = 0x180 + (numPdo parameters * 0x100) + nodeid
- newcobid = (0x180 + nbSlavePDO * 0x100 + nodeid)
- if newcobid in ListCobIDAvailable:
- ListCobIDAvailable.remove(newcobid)
- return newcobid, 0x1800 + nbSlavePDO
- return ListCobIDAvailable.pop(0), 0x1800 + nbSlavePDO
- for number in xrange(4):
- # For the fourth PDO -> cobid = 0x200 + ( numPdo * 0x100) + nodeid
- newcobid = (0x200 + number * 0x100 + nodeid)
- # For the fourth PDO -> cobid = 0x180 + (numPdo * 0x100) + nodeid
- newcobid = (0x180 + number * 0x100 + nodeid)
- if newcobid in ListCobIDAvailable:
- ListCobIDAvailable.remove(newcobid)
- return ListCobIDAvailable.pop(0)
-def GenerateConciseDCF(locations, busname, nodelist):
- global DictLocations, DictCobID, DictLocationsNotMapped, ListCobIDAvailable, SlavesPdoNumber, DefaultTransmitTypeSlave
- DictLocationsNotMapped = {}
- ListCobIDAvailable = range(0x180, 0x580)
- DictNameVariable = { "" : 1, "X": 2, "B": 3, "W": 4, "D": 5, "L": 6, "increment": 0x100, 1:("__I", 0x2000), 2:("__Q", 0x4000)}
- DefaultTransmitTypeSlave = 0xFF
- # Master Node initialisation
- manager = nodelist.Manager
- masternode = manager.GetCurrentNodeCopy()
- if not masternode.IsEntry(0x1F22):
- masternode.AddEntry(0x1F22, 1, "")
- manager.AddSubentriesToCurrent(0x1F22, 127, masternode)
- # Adding trash mappable variables for unused mapped datas
- idxTrashVariables = 0x2000 + masternode.GetNodeID()
- TrashVariableValue = {}
- manager.AddMapVariableToCurrent(idxTrashVariables, "trashvariables", 3, len(TrashVariableSizes), masternode)
- for subidx, (size, typeidx) in enumerate(TrashVariableSizes.items()):
- manager.SetCurrentEntry(idxTrashVariables, subidx + 1, "TRASH%d" % size, "name", None, masternode)
- manager.SetCurrentEntry(idxTrashVariables, subidx + 1, typeidx, "type", None, masternode)
- TrashVariableValue[size] = (idxTrashVariables << 16) + ((subidx + 1) << 8) + size
- # Extract Master Node current empty mapping index
- CurrentPDOParamsIdx = {RPDO : 0x1400 + len(GetSlavePDOIndexes(masternode, RPDO)),
- TPDO : 0x1800 + len(GetSlavePDOIndexes(masternode, TPDO))}
- # Get list of all Slave's CobID and Slave's default SDO server parameters
- for nodeid, nodeinfos in nodelist.SlaveNodes.items():
- node = nodeinfos["Node"]
- DictSDOparams[nodeid] = {"RSDO" : node.GetEntry(0x1200,0x01), "TSDO" : node.GetEntry(0x1200,0x02)}
- slaveRpdoIndexes = GetSlavePDOIndexes(node, RPDO, True)
- slaveTpdoIndexes = GetSlavePDOIndexes(node, TPDO, True)
- SlavesPdoNumber[nodeid] = {RPDO : len(slaveRpdoIndexes), TPDO : len(slaveTpdoIndexes)}
- for PdoIdx in slaveRpdoIndexes + slaveTpdoIndexes:
- pdo_cobid = node.GetEntry(PdoIdx, 0x01)
- pdo_cobid -= 0x80000000
- if pdo_cobid in ListCobIDAvailable:
- ListCobIDAvailable.remove(pdo_cobid)
- # Get list of locations check if exists and mappables -> put them in DictLocations
- for locationtype, name in locations:
- if name in DictLocations.keys():
- if DictLocations[name]["type"] != DicoTypes[locationtype]:
- raise ValueError, "Conflict type for location \"%s\"" % name
- loc = [i for i in name.split("_") if len(i) > 0]
- if len(loc) not in (4, 5):
- # Extract and check busname
- if loc[0][1].isdigit():
- busnamelocation = int(loc[0][1:])
- sizelocation = loc[0][1]
- busnamelocation = int(loc[0][2:])
- if busnamelocation != busname:
- continue # A ne pas remplacer par un message d'erreur
- # Extract and check nodeid
- if nodeid not in nodelist.SlaveNodes.keys():
- node = nodelist.SlaveNodes[nodeid]["Node"]
- # Extract and check index and subindex
- if not node.IsEntry(index, subindex):
- subentry_infos = node.GetSubentryInfos(index, subindex)
- if subentry_infos and subentry_infos["pdo"]:
- if sizelocation == "X" and len(loc) > 4:
- elif sizelocation != "X" and len(loc) > 4:
- locationtype = DicoTypes[locationtype]
- entryinfos = node.GetSubentryInfos(index, subindex)
- if entryinfos["type"] != locationtype:
- raise ValueError, "Invalid type for location \"%s\"" % name
- typeinfos = node.GetEntryInfos(locationtype)
- DictLocations[name] = {"type":locationtype, "pdotype":SlavePDOType[prefix],
- "nodeid": nodeid, "index": index,"subindex": subindex,
- "bit": numbit, "size": typeinfos["size"], "busname": busname, "sizelocation": sizelocation}
- # Create DictCobID with variables already mapped and add them in DictValidLocations
- for name, locationinfos in DictLocations.items():
- node = nodelist.SlaveNodes[locationinfos["nodeid"]]["Node"]
- result = SearchSlavePDOMapping(locationinfos, node)
- index, subindex = result
- cobid = nodelist.GetSlaveNodeEntry(locationinfos["nodeid"], index - 0x200, 1)
- if cobid not in DictCobID.keys():
- values = node.GetEntry(index)
- for value in values[1:]:
- mapping.append(value % 0x100)
- DictCobID[cobid] = {"type" : InvertPDOType[locationinfos["pdotype"]], "mapping" : mapping}
- DictCobID[cobid]["mapping"][subindex] = (locationinfos["type"], name)
- if locationinfos["nodeid"] not in DictLocationsNotMapped.keys():
- DictLocationsNotMapped[locationinfos["nodeid"]] = {TPDO : [], RPDO : []}
- DictLocationsNotMapped[locationinfos["nodeid"]][locationinfos["pdotype"]].append((name, locationinfos))
- # Check Master Pdo parameters for cobid already used and remove it in ListCobIDAvailable
- ListPdoParams = [idx for idx in masternode.GetIndexes() if 0x1400 <= idx <= 0x15FF or 0x1800 <= idx <= 0x19FF]
- for idx in ListPdoParams:
- cobid = masternode.GetEntry(idx, 0x01)
- if cobid not in DictCobID.keys():
- ListCobIDAvailable.pop(cobid)
- #-------------------------------------------------------------------------------
- # Build concise DCF for the others locations
- #-------------------------------------------------------------------------------
- for nodeid, locations in DictLocationsNotMapped.items():
- # Get current concise DCF
- node = nodelist.SlaveNodes[nodeid]["Node"]
- nodeDCF = masternode.GetEntry(0x1F22, nodeid)
- if nodeDCF != None and nodeDCF != '':
- tmpnbparams = [i for i in nodeDCF[:4]]
- nbparams = int(''.join(["%2.2x"%ord(i) for i in tmpnbparams]), 16)
- dataparams = nodeDCF[4:]
- for pdotype in (TPDO, RPDO):
- for name, loc_infos in locations[pdotype]:
- pdosize += loc_infos["size"]
- # If pdo's size > 64 bits
- result = GetNewCobID(nodeid, pdotype)
- SlavesPdoNumber[nodeid][pdotype] += 1
- new_cobid, new_idx = result
- data, nbaddedparams = GenerateMappingDCF(new_cobid, new_idx, pdomapping, False)
- nbparams += nbaddedparams
- DictCobID[new_cobid] = {"type" : InvertPDOType[pdotype], "mapping" : GenerateMasterMapping(pdomapping)}
- pdosize = loc_infos["size"]
- pdomapping = [(name, loc_infos)]
- pdomapping.append((name, loc_infos))
- if len(pdomapping) > 0:
- result = GetNewCobID(nodeid, pdotype)
- SlavesPdoNumber[nodeid][pdotype] += 1
- new_cobid, new_idx = result
- data, nbaddedparams = GenerateMappingDCF(new_cobid, new_idx, pdomapping, False)
- nbparams += nbaddedparams
- DictCobID[new_cobid] = {"type" : InvertPDOType[pdotype], "mapping" : GenerateMasterMapping(pdomapping)}
- dcf = LE_to_BE(nbparams, 0x04) + dataparams
- masternode.SetEntry(0x1F22, nodeid, dcf)
- #-------------------------------------------------------------------------------
- # Master Node Configuration
- #-------------------------------------------------------------------------------
- # Configure Master's SDO parameters entries
- for nodeid, SDOparams in DictSDOparams.items():
- SdoClient_index = [0x1280 + nodeid]
- manager.ManageEntriesOfCurrent(SdoClient_index,[], masternode)
- if SDOparams["RSDO"] != None:
- RSDO_cobid = SDOparams["RSDO"]
- RSDO_cobid = 0x600 + nodeid
- if SDOparams["TSDO"] != None:
- TSDO_cobid = SDOparams["TSDO"]
- TSDO_cobid = 0x580 + nodeid
- masternode.SetEntry(SdoClient_index[0], 0x01, RSDO_cobid)
- masternode.SetEntry(SdoClient_index[0], 0x02, TSDO_cobid)
- masternode.SetEntry(SdoClient_index[0], 0x03, nodeid)
- # Configure Master's PDO parameters entries and set cobid, transmit type
- for cobid, pdo_infos in DictCobID.items():
- current_idx = CurrentPDOParamsIdx[pdo_infos["type"]]
- addinglist = [current_idx, current_idx + 0x200]
- manager.ManageEntriesOfCurrent(addinglist, [], masternode)
- masternode.SetEntry(current_idx, 0x01, cobid)
- masternode.SetEntry(current_idx, 0x02, DefaultTransmitTypeMaster)
- if len(pdo_infos["mapping"]) > 2:
- manager.AddSubentriesToCurrent(current_idx + 0x200, len(pdo_infos["mapping"]) - 2, masternode)
- # Create Master's PDO mapping
- for subindex, variable in enumerate(pdo_infos["mapping"]):
- if type(variable) != IntType:
- typeidx, varname = variable
- indexname = DictNameVariable[DictLocations[variable[1]]["pdotype"]][0] + DictLocations[variable[1]]["sizelocation"] + str(DictLocations[variable[1]]["busname"]) + "_" + str(DictLocations[variable[1]]["nodeid"])
- mapvariableidx = DictNameVariable[DictLocations[variable[1]]["pdotype"]][1] + DictNameVariable[DictLocations[variable[1]]["sizelocation"]] * DictNameVariable["increment"]
- if not masternode.IsEntry(mapvariableidx):
- manager.AddMapVariableToCurrent(mapvariableidx, indexname, 3, 1, masternode)
- nbsubentries = masternode.GetEntry(mapvariableidx, 0x00)
- nbsubentries = masternode.GetEntry(mapvariableidx, 0x00)
- mapvariableidxbase = mapvariableidx
- while mapvariableidx < (mapvariableidxbase + 0x1FF) and nbsubentries == 0xFF:
- mapvariableidx += 0x800
- if not manager.IsCurrentEntry(mapvariableidx):
- manager.AddMapVariableToCurrent(mapvariableidx, indexname, 3, 1, masternode)
- nbsubentries = masternode.GetEntry(mapvariableidx, 0x00)
- if mapvariableidx < 0x6000:
- if DictLocations[variable[1]]["bit"] != None:
- subindexname = "_" + str(DictLocations[variable[1]]["index"]) + "_" + str(DictLocations[variable[1]]["subindex"]) + "_" + str(DictLocations[variable[1]]["bit"])
- subindexname = "_" + str(DictLocations[variable[1]]["index"]) + "_" + str(DictLocations[variable[1]]["subindex"])
- manager.AddSubentriesToCurrent(mapvariableidx, 1, masternode)
- masternode.SetMappingEntry(mapvariableidx, nbsubentries, values = {"name" : subindexname})
- masternode.SetMappingEntry(mapvariableidx, nbsubentries, values = {"type" : typeidx})
- typeinfos = manager.GetEntryInfos(typeidx)
- value = (mapvariableidx << 16) + ((nbsubentries) << 8) + typeinfos["size"]
- masternode.SetEntry(current_idx + 0x200, subindex, value)
- masternode.SetEntry(current_idx + 0x200, subindex, TrashVariableValue[variable])
- CurrentPDOParamsIdx[pdo_infos["type"]] += 1
-if __name__ == "__main__":
- from nodemanager import *
- manager = NodeManager(sys.path[0])
- nodelist = NodeList(manager)
- result = nodelist.LoadProject("/home/deobox/Desktop/TestMapping")
-## manager.CurrentNode.Print()
-## for nodeid, node in nodelist.SlaveNodes.items():
-## print "SlaveNode name=%s id=0x%2.2X :"%(node["Name"], nodeid)
- #filepath = "/home/deobox/beremiz/test_nodelist/listlocations.txt"
- filepath = "/home/deobox/Desktop/TestMapping/listlocations.txt"
- file = open(filepath,'r')
- locations = [location.split(' ') for location in [line.strip() for line in file.readlines() if len(line) > 0]]
- GenerateConciseDCF(locations, 32, nodelist)
- manager.CurrentNode.Print()
\ No newline at end of file
--- a/plugins/__init__.py Thu Aug 16 12:03:00 2007 +0200
+++ b/plugins/__init__.py Mon Aug 20 14:28:08 2007 +0200
@@ -1,6 +1,8 @@
from os import listdir, path
-l = listdir(path.split(__file__)[0])
+base_path = path.split(__file__)[0] -__all__ = [name[0:-3] for name in l if name.endswith(".py") and not name.startswith("__")]
+__all__ = [name for name in listdir(base_path) if path.isdir(path.join(base_path, name)) and name != "CVS" or name.endswith(".py") and not name.startswith("__")] + __import__(name, globals(), locals(), []) --- a/plugins/canfestival.py Thu Aug 16 12:03:00 2007 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/canfestival/canfestival.py Mon Aug 20 14:28:08 2007 +0200
@@ -0,0 +1,32 @@
+from nodelist import NodeList +from nodemanager import NodeManager +import config_utils, gen_cfile +class _Beremiz_CanFestival_Controller(NodeList): + def __init__(self, buspath, bus_id): + manager = NodeManager() + NodeList.__init__(self, manager) + self.LoadProject(buspath) + def Generate_C(self, filepath, locations): + return C code for network dictionnary + master = config_utils.GenerateConciseDCF(locations, self) + res = gen_cfile.GenerateFile(filepath, master) + s = str(self.bus_id)+"_IN(){}\n" + f = file(filepath, 'a') +def BlockListFactory(bmz_inst): +def ControllerFactory(): + return _Beremiz_CanFestival_Controller() \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/canfestival/config_utils.py Mon Aug 20 14:28:08 2007 +0200
@@ -0,0 +1,429 @@
+#This file is part of Beremiz, a Integrated Development Environment for +#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. +#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD +#See COPYING file for copyrights details. +#This library is free software; you can redistribute it and/or +#modify it under the terms of the GNU General Public +#License as published by the Free Software Foundation; either +#version 2.1 of the License, or (at your option) any later version. +#This library is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +#General Public License for more details. +#You should have received a copy of the GNU General Public +#License along with this library; if not, write to the Free Software +#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +DicoTypes = {"BOOL":0x01, "SINT":0x02, "INT":0x03,"DINT":0x04,"LINT":0x10, + "USINT":0x05,"UINT":0x06,"UDINT":0x07,"ULINT":0x1B,"REAL":0x08, + "LREAL":0x11,"STRING":0x09,"BYTE":0x02,"WORD":0x03,"DWORD":0x04, + "LWORD":0x1B,"WSTRING":0x0B} +DictLocationsNotMapped = {} +# Constants for PDO types +SlavePDOType = {"I" : TPDO, "Q" : RPDO} +InvertPDOType = {RPDO : TPDO, TPDO : RPDO} +DefaultTransmitTypeMaster = 0x01 +GenerateMasterMapping = lambda x:[None] + [(loc_infos["type"], name) for name, loc_infos in x] +TrashVariableSizes = {1 : 0x01, 8 : 0x05, 16 : 0x06, 32 : 0x07, 64 : 0x1B} +def GetSlavePDOIndexes(slave, type, parameters = False): + indexes.extend([idx for idx in slave.GetIndexes() if 0x1400 <= idx <= 0x15FF]) + indexes.extend([idx for idx in slave.GetIndexes() if 0x1800 <= idx <= 0x19FF]) + return [idx + 0x200 for idx in indexes] +def LE_to_BE(value, size): # Convert Little Endian to Big Endian + data = ("%" + str(size * 2) + "." + str(size * 2) + "X") % value + list_car = [data[i:i+2] for i in xrange(0, len(data), 2)] + return "".join([chr(int(car, 16)) for car in list_car]) +def SearchSlavePDOMapping(loc_infos, slave): # Search the TPDO or RPDO mapping where location is defined on the slave + typeinfos = slave.GetEntryInfos(loc_infos["type"]) + model = (loc_infos["index"] << 16) + (loc_infos["subindex"] << 8) + typeinfos["size"] + slavePDOidxlist = GetSlavePDOIndexes(slave, loc_infos["pdotype"]) + for PDOidx in slavePDOidxlist: + values = slave.GetEntry(PDOidx) + for subindex, mapping in enumerate(values): + if subindex != 0 and mapping == model: + return PDOidx, subindex +def GenerateMappingDCF(cobid, idx, pdomapping, mapped): # Build concise DCF + # Create entry for RPDO or TPDO parameters and Disable PDO + dcfdata = LE_to_BE(idx, 2) + LE_to_BE(0x01, 1) + LE_to_BE(0x04, 4) + LE_to_BE((0x80000000 + cobid), 4) + # Set Transmit type synchrone + dcfdata += LE_to_BE(idx, 2) + LE_to_BE(0x02, 1) + LE_to_BE(0x01, 4) + LE_to_BE(DefaultTransmitTypeSlave, 1) + # ---- INDEX ----- --- SUBINDEX ---- ----- SIZE ------ ------ DATA ------ + dcfdata += LE_to_BE(idx, 2) + LE_to_BE(0x01, 1) + LE_to_BE(0x04, 4) + LE_to_BE(0x00000000 + cobid, 4) + if mapped == False and pdomapping != None: + for subindex, (name, loc_infos) in enumerate(pdomapping): + value = (loc_infos["index"] << 16) + (loc_infos["subindex"] << 8) + loc_infos["size"] + dcfdata += LE_to_BE(idx + 0x200, 2) + LE_to_BE(subindex + 1, 1) + LE_to_BE(0x04, 4) + LE_to_BE(value, 4) + return dcfdata, nbparams +def GetNewCobID(nodeid, type): # Return a cobid not used + global ListCobIDAvailable, SlavesPdoNumber + if len(ListCobIDAvailable) == 0: + nbSlavePDO = SlavesPdoNumber[nodeid][type] + # For the fourth PDO -> cobid = 0x200 + ( numPdo parameters * 0x100) + nodeid + newcobid = (0x200 + nbSlavePDO * 0x100 + nodeid) + if newcobid in ListCobIDAvailable: + ListCobIDAvailable.remove(newcobid) + return newcobid, 0x1400 + nbSlavePDO + return ListCobIDAvailable.pop(0), 0x1400 + nbSlavePDO + # For the fourth PDO -> cobid = 0x180 + (numPdo parameters * 0x100) + nodeid + newcobid = (0x180 + nbSlavePDO * 0x100 + nodeid) + if newcobid in ListCobIDAvailable: + ListCobIDAvailable.remove(newcobid) + return newcobid, 0x1800 + nbSlavePDO + return ListCobIDAvailable.pop(0), 0x1800 + nbSlavePDO + for number in xrange(4): + # For the fourth PDO -> cobid = 0x200 + ( numPdo * 0x100) + nodeid + newcobid = (0x200 + number * 0x100 + nodeid) + # For the fourth PDO -> cobid = 0x180 + (numPdo * 0x100) + nodeid + newcobid = (0x180 + number * 0x100 + nodeid) + if newcobid in ListCobIDAvailable: + ListCobIDAvailable.remove(newcobid) + return ListCobIDAvailable.pop(0) +def GenerateConciseDCF(locations, busname, nodelist): + global DictLocations, DictCobID, DictLocationsNotMapped, ListCobIDAvailable, SlavesPdoNumber, DefaultTransmitTypeSlave + DictLocationsNotMapped = {} + ListCobIDAvailable = range(0x180, 0x580) + DictNameVariable = { "" : 1, "X": 2, "B": 3, "W": 4, "D": 5, "L": 6, "increment": 0x100, 1:("__I", 0x2000), 2:("__Q", 0x4000)} + DefaultTransmitTypeSlave = 0xFF + # Master Node initialisation + manager = nodelist.Manager + masternode = manager.GetCurrentNodeCopy() + if not masternode.IsEntry(0x1F22): + masternode.AddEntry(0x1F22, 1, "") + manager.AddSubentriesToCurrent(0x1F22, 127, masternode) + # Adding trash mappable variables for unused mapped datas + idxTrashVariables = 0x2000 + masternode.GetNodeID() + TrashVariableValue = {} + manager.AddMapVariableToCurrent(idxTrashVariables, "trashvariables", 3, len(TrashVariableSizes), masternode) + for subidx, (size, typeidx) in enumerate(TrashVariableSizes.items()): + manager.SetCurrentEntry(idxTrashVariables, subidx + 1, "TRASH%d" % size, "name", None, masternode) + manager.SetCurrentEntry(idxTrashVariables, subidx + 1, typeidx, "type", None, masternode) + TrashVariableValue[size] = (idxTrashVariables << 16) + ((subidx + 1) << 8) + size + # Extract Master Node current empty mapping index + CurrentPDOParamsIdx = {RPDO : 0x1400 + len(GetSlavePDOIndexes(masternode, RPDO)), + TPDO : 0x1800 + len(GetSlavePDOIndexes(masternode, TPDO))} + # Get list of all Slave's CobID and Slave's default SDO server parameters + for nodeid, nodeinfos in nodelist.SlaveNodes.items(): + node = nodeinfos["Node"] + DictSDOparams[nodeid] = {"RSDO" : node.GetEntry(0x1200,0x01), "TSDO" : node.GetEntry(0x1200,0x02)} + slaveRpdoIndexes = GetSlavePDOIndexes(node, RPDO, True) + slaveTpdoIndexes = GetSlavePDOIndexes(node, TPDO, True) + SlavesPdoNumber[nodeid] = {RPDO : len(slaveRpdoIndexes), TPDO : len(slaveTpdoIndexes)} + for PdoIdx in slaveRpdoIndexes + slaveTpdoIndexes: + pdo_cobid = node.GetEntry(PdoIdx, 0x01) + pdo_cobid -= 0x80000000 + if pdo_cobid in ListCobIDAvailable: + ListCobIDAvailable.remove(pdo_cobid) + # Get list of locations check if exists and mappables -> put them in DictLocations + for locationtype, name in locations: + if name in DictLocations.keys(): + if DictLocations[name]["type"] != DicoTypes[locationtype]: + raise ValueError, "Conflict type for location \"%s\"" % name + loc = [i for i in name.split("_") if len(i) > 0] + if len(loc) not in (4, 5): + # Extract and check busname + if loc[0][1].isdigit(): + busnamelocation = int(loc[0][1:]) + sizelocation = loc[0][1] + busnamelocation = int(loc[0][2:]) + if busnamelocation != busname: + continue # A ne pas remplacer par un message d'erreur + # Extract and check nodeid + if nodeid not in nodelist.SlaveNodes.keys(): + node = nodelist.SlaveNodes[nodeid]["Node"] + # Extract and check index and subindex + if not node.IsEntry(index, subindex): + subentry_infos = node.GetSubentryInfos(index, subindex) + if subentry_infos and subentry_infos["pdo"]: + if sizelocation == "X" and len(loc) > 4: + elif sizelocation != "X" and len(loc) > 4: + locationtype = DicoTypes[locationtype] + entryinfos = node.GetSubentryInfos(index, subindex) + if entryinfos["type"] != locationtype: + raise ValueError, "Invalid type for location \"%s\"" % name + typeinfos = node.GetEntryInfos(locationtype) + DictLocations[name] = {"type":locationtype, "pdotype":SlavePDOType[prefix], + "nodeid": nodeid, "index": index,"subindex": subindex, + "bit": numbit, "size": typeinfos["size"], "busname": busname, "sizelocation": sizelocation} + # Create DictCobID with variables already mapped and add them in DictValidLocations + for name, locationinfos in DictLocations.items(): + node = nodelist.SlaveNodes[locationinfos["nodeid"]]["Node"] + result = SearchSlavePDOMapping(locationinfos, node) + index, subindex = result + cobid = nodelist.GetSlaveNodeEntry(locationinfos["nodeid"], index - 0x200, 1) + if cobid not in DictCobID.keys(): + values = node.GetEntry(index) + for value in values[1:]: + mapping.append(value % 0x100) + DictCobID[cobid] = {"type" : InvertPDOType[locationinfos["pdotype"]], "mapping" : mapping} + DictCobID[cobid]["mapping"][subindex] = (locationinfos["type"], name) + if locationinfos["nodeid"] not in DictLocationsNotMapped.keys(): + DictLocationsNotMapped[locationinfos["nodeid"]] = {TPDO : [], RPDO : []} + DictLocationsNotMapped[locationinfos["nodeid"]][locationinfos["pdotype"]].append((name, locationinfos)) + # Check Master Pdo parameters for cobid already used and remove it in ListCobIDAvailable + ListPdoParams = [idx for idx in masternode.GetIndexes() if 0x1400 <= idx <= 0x15FF or 0x1800 <= idx <= 0x19FF] + for idx in ListPdoParams: + cobid = masternode.GetEntry(idx, 0x01) + if cobid not in DictCobID.keys(): + ListCobIDAvailable.pop(cobid) + #------------------------------------------------------------------------------- + # Build concise DCF for the others locations + #------------------------------------------------------------------------------- + for nodeid, locations in DictLocationsNotMapped.items(): + # Get current concise DCF + node = nodelist.SlaveNodes[nodeid]["Node"] + nodeDCF = masternode.GetEntry(0x1F22, nodeid) + if nodeDCF != None and nodeDCF != '': + tmpnbparams = [i for i in nodeDCF[:4]] + nbparams = int(''.join(["%2.2x"%ord(i) for i in tmpnbparams]), 16) + dataparams = nodeDCF[4:] + for pdotype in (TPDO, RPDO): + for name, loc_infos in locations[pdotype]: + pdosize += loc_infos["size"] + # If pdo's size > 64 bits + result = GetNewCobID(nodeid, pdotype) + SlavesPdoNumber[nodeid][pdotype] += 1 + new_cobid, new_idx = result + data, nbaddedparams = GenerateMappingDCF(new_cobid, new_idx, pdomapping, False) + nbparams += nbaddedparams + DictCobID[new_cobid] = {"type" : InvertPDOType[pdotype], "mapping" : GenerateMasterMapping(pdomapping)} + pdosize = loc_infos["size"] + pdomapping = [(name, loc_infos)] + pdomapping.append((name, loc_infos)) + if len(pdomapping) > 0: + result = GetNewCobID(nodeid, pdotype) + SlavesPdoNumber[nodeid][pdotype] += 1 + new_cobid, new_idx = result + data, nbaddedparams = GenerateMappingDCF(new_cobid, new_idx, pdomapping, False) + nbparams += nbaddedparams + DictCobID[new_cobid] = {"type" : InvertPDOType[pdotype], "mapping" : GenerateMasterMapping(pdomapping)} + dcf = LE_to_BE(nbparams, 0x04) + dataparams + masternode.SetEntry(0x1F22, nodeid, dcf) + #------------------------------------------------------------------------------- + # Master Node Configuration + #------------------------------------------------------------------------------- + # Configure Master's SDO parameters entries + for nodeid, SDOparams in DictSDOparams.items(): + SdoClient_index = [0x1280 + nodeid] + manager.ManageEntriesOfCurrent(SdoClient_index,[], masternode) + if SDOparams["RSDO"] != None: + RSDO_cobid = SDOparams["RSDO"] + RSDO_cobid = 0x600 + nodeid + if SDOparams["TSDO"] != None: + TSDO_cobid = SDOparams["TSDO"] + TSDO_cobid = 0x580 + nodeid + masternode.SetEntry(SdoClient_index[0], 0x01, RSDO_cobid) + masternode.SetEntry(SdoClient_index[0], 0x02, TSDO_cobid) + masternode.SetEntry(SdoClient_index[0], 0x03, nodeid) + # Configure Master's PDO parameters entries and set cobid, transmit type + for cobid, pdo_infos in DictCobID.items(): + current_idx = CurrentPDOParamsIdx[pdo_infos["type"]] + addinglist = [current_idx, current_idx + 0x200] + manager.ManageEntriesOfCurrent(addinglist, [], masternode) + masternode.SetEntry(current_idx, 0x01, cobid) + masternode.SetEntry(current_idx, 0x02, DefaultTransmitTypeMaster) + if len(pdo_infos["mapping"]) > 2: + manager.AddSubentriesToCurrent(current_idx + 0x200, len(pdo_infos["mapping"]) - 2, masternode) + # Create Master's PDO mapping + for subindex, variable in enumerate(pdo_infos["mapping"]): + if type(variable) != IntType: + typeidx, varname = variable + indexname = DictNameVariable[DictLocations[variable[1]]["pdotype"]][0] + DictLocations[variable[1]]["sizelocation"] + str(DictLocations[variable[1]]["busname"]) + "_" + str(DictLocations[variable[1]]["nodeid"]) + mapvariableidx = DictNameVariable[DictLocations[variable[1]]["pdotype"]][1] + DictNameVariable[DictLocations[variable[1]]["sizelocation"]] * DictNameVariable["increment"] + if not masternode.IsEntry(mapvariableidx): + manager.AddMapVariableToCurrent(mapvariableidx, indexname, 3, 1, masternode) + nbsubentries = masternode.GetEntry(mapvariableidx, 0x00) + nbsubentries = masternode.GetEntry(mapvariableidx, 0x00) + mapvariableidxbase = mapvariableidx + while mapvariableidx < (mapvariableidxbase + 0x1FF) and nbsubentries == 0xFF: + mapvariableidx += 0x800 + if not manager.IsCurrentEntry(mapvariableidx): + manager.AddMapVariableToCurrent(mapvariableidx, indexname, 3, 1, masternode) + nbsubentries = masternode.GetEntry(mapvariableidx, 0x00) + if mapvariableidx < 0x6000: + if DictLocations[variable[1]]["bit"] != None: + subindexname = "_" + str(DictLocations[variable[1]]["index"]) + "_" + str(DictLocations[variable[1]]["subindex"]) + "_" + str(DictLocations[variable[1]]["bit"]) + subindexname = "_" + str(DictLocations[variable[1]]["index"]) + "_" + str(DictLocations[variable[1]]["subindex"]) + manager.AddSubentriesToCurrent(mapvariableidx, 1, masternode) + masternode.SetMappingEntry(mapvariableidx, nbsubentries, values = {"name" : subindexname}) + masternode.SetMappingEntry(mapvariableidx, nbsubentries, values = {"type" : typeidx}) + typeinfos = manager.GetEntryInfos(typeidx) + value = (mapvariableidx << 16) + ((nbsubentries) << 8) + typeinfos["size"] + masternode.SetEntry(current_idx + 0x200, subindex, value) + masternode.SetEntry(current_idx + 0x200, subindex, TrashVariableValue[variable]) + CurrentPDOParamsIdx[pdo_infos["type"]] += 1 +if __name__ == "__main__": + from nodemanager import * + manager = NodeManager(sys.path[0]) + nodelist = NodeList(manager) + result = nodelist.LoadProject("/home/deobox/Desktop/TestMapping") +## manager.CurrentNode.Print() +## for nodeid, node in nodelist.SlaveNodes.items(): +## print "SlaveNode name=%s id=0x%2.2X :"%(node["Name"], nodeid) + #filepath = "/home/deobox/beremiz/test_nodelist/listlocations.txt" + filepath = "/home/deobox/Desktop/TestMapping/listlocations.txt" + file = open(filepath,'r') + locations = [location.split(' ') for location in [line.strip() for line in file.readlines() if len(line) > 0]] + GenerateConciseDCF(locations, 32, nodelist) + manager.CurrentNode.Print() \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/svgui/__init__.py Mon Aug 20 14:28:08 2007 +0200
@@ -0,0 +1,3 @@
\ No newline at end of file