--- 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
+import plugins
__version__ = "$Revision$"
@@ -334,6 +331,15 @@
def __init__(self, parent):
self._init_ctrls(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 = ""
self.PLCManager = None
@@ -439,18 +445,18 @@
raise Exception
for bus_id, bus_type, bus_name in [line.split(" ") for line in lines[1:]]:
id = int(bus_id, 16)
- 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
+ if controller != None:
+ manager = controller()
+ result = manager.LoadProject(projectpath, bus_name)
if not result:
- 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}
else:
message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
message.ShowModal()
message.Destroy()
else:
- self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type}
+ self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type, "Manager" : None, "Editor" : None}
file.close()
self.PLCManager = PLCControler()
plc_file = os.path.join(projectpath, "plc.xml")
@@ -471,8 +477,8 @@
self.RefreshBusList()
self.RefreshButtons()
self.RefreshMainMenu()
- except Exception:
- 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)
message.ShowModal()
message.Destroy()
@@ -508,7 +514,7 @@
for id in busidlist:
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"])
file.close()
event.Skip()
@@ -577,12 +583,13 @@
busidlist = self.BusManagers.keys()
busidlist.sort()
bus_infos = self.BusManagers[busidlist[selected]]
- if bus_infos["Type"] == "CanFestival":
+ view = getattr(plugins, bus_infos["Type"]).view
+ if view != None:
if bus_infos["Editor"] == None:
- netedit = networkedit(self, bus_infos["NodeList"])
- netedit.SetBusId(busidlist[selected])
- netedit.Show()
- bus_infos["Editor"] = netedit
+ editor = view(self, bus_infos["Manager"])
+ editor.SetBusId(busidlist[selected])
+ editor.Show()
+ bus_infos["Editor"] = editor
event.Skip()
def CloseEditor(self, bus_id):
@@ -598,18 +605,18 @@
else:
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
+ if controller != None:
+ manager = controller()
+ result = manager.LoadProject(self.CurrentProjectPath, values["busName"])
if not result:
- 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}
else:
message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
message.ShowModal()
message.Destroy()
else:
- self.BusManagers[bus_id] = {"Name" : values["busName"], "Type" : values["busType"]}
+ self.BusManagers[bus_id] = {"Name" : values["busName"], "Type" : values["busType"], "Manager" : None, "Editor" : None}
else:
message = wx.MessageDialog(self, "The bus ID \"0x%2.2X\" is already used!"%bus_id, "Error", wx.OK|wx.ICON_ERROR)
message.ShowModal()
@@ -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)
if result:
- raise Exception
+ 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):
self._init_ctrls(parent)
- for option in ["CanFestival","SVGUI"]:
+ for option in [""] + plugins.__all__:
self.BusType.Append(option)
def OnOK(self, event):
--- 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 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-#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
-
-from types import *
-
-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}
-
-DictLocations = {}
-DictCobID = {}
-DictLocationsNotMapped = {}
-ListCobIDAvailable = []
-SlavesPdoNumber = {}
-
-# Constants for PDO types
-RPDO = 1
-TPDO = 2
-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 = []
- if type & RPDO:
- indexes.extend([idx for idx in slave.GetIndexes() if 0x1400 <= idx <= 0x15FF])
- if type & TPDO:
- indexes.extend([idx for idx in slave.GetIndexes() if 0x1800 <= idx <= 0x19FF])
- if not parameters:
- return [idx + 0x200 for idx in indexes]
- else:
- return 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)]
- list_car.reverse()
- 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)
- if values != None:
- for subindex, mapping in enumerate(values):
- if subindex != 0 and mapping == model:
- return PDOidx, subindex
- return None
-
-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)
- # Re-Enable PDO
- # ---- 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)
- nbparams = 3
- if mapped == False and pdomapping != None:
- # Map Variables
- 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)
- nbparams += 1
- return dcfdata, nbparams
-
-def GetNewCobID(nodeid, type): # Return a cobid not used
- global ListCobIDAvailable, SlavesPdoNumber
-
- if len(ListCobIDAvailable) == 0:
- return None
-
- nbSlavePDO = SlavesPdoNumber[nodeid][type]
- if type == RPDO:
- if nbSlavePDO < 4:
- # 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
-
- elif type == TPDO:
- if nbSlavePDO < 4:
- # 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):
- if type == RPDO:
- # For the fourth PDO -> cobid = 0x200 + ( numPdo * 0x100) + nodeid
- newcobid = (0x200 + number * 0x100 + nodeid)
- elif type == TPDO:
- # For the fourth PDO -> cobid = 0x180 + (numPdo * 0x100) + nodeid
- newcobid = (0x180 + number * 0x100 + nodeid)
- else:
- return None
- if newcobid in ListCobIDAvailable:
- ListCobIDAvailable.remove(newcobid)
- return newcobid
- return ListCobIDAvailable.pop(0)
-
-
-def GenerateConciseDCF(locations, busname, nodelist):
- global DictLocations, DictCobID, DictLocationsNotMapped, ListCobIDAvailable, SlavesPdoNumber, DefaultTransmitTypeSlave
-
- DictLocations = {}
- DictCobID = {}
- DictLocationsNotMapped = {}
- DictSDOparams = {}
- ListCobIDAvailable = range(0x180, 0x580)
- SlavesPdoNumber = {}
- 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"]
- node.SetNodeID(nodeid)
- 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)
- if pdo_cobid > 0x600 :
- 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
- else:
- loc = [i for i in name.split("_") if len(i) > 0]
- if len(loc) not in (4, 5):
- continue
-
- prefix = loc[0][0]
-
- # Extract and check busname
- if loc[0][1].isdigit():
- sizelocation = ""
- busnamelocation = int(loc[0][1:])
- else:
- 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
- nodeid = int(loc[1])
- if nodeid not in nodelist.SlaveNodes.keys():
- continue
- node = nodelist.SlaveNodes[nodeid]["Node"]
-
- # Extract and check index and subindex
- index = int(loc[2])
- subindex = int(loc[3])
- if not node.IsEntry(index, subindex):
- continue
- subentry_infos = node.GetSubentryInfos(index, subindex)
-
- if subentry_infos and subentry_infos["pdo"]:
- if sizelocation == "X" and len(loc) > 4:
- numbit = loc[4]
- elif sizelocation != "X" and len(loc) > 4:
- continue
- else:
- numbit = None
-
- 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)
- if result != None:
- index, subindex = result
- cobid = nodelist.GetSlaveNodeEntry(locationinfos["nodeid"], index - 0x200, 1)
- if cobid not in DictCobID.keys():
- mapping = [None]
- 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)
-
- else:
- 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]]
- tmpnbparams.reverse()
- nbparams = int(''.join(["%2.2x"%ord(i) for i in tmpnbparams]), 16)
- dataparams = nodeDCF[4:]
- else:
- nbparams = 0
- dataparams = ""
-
- for pdotype in (TPDO, RPDO):
- pdosize = 0
- pdomapping = []
- for name, loc_infos in locations[pdotype]:
- pdosize += loc_infos["size"]
- # If pdo's size > 64 bits
- if pdosize > 64:
- result = GetNewCobID(nodeid, pdotype)
- if result:
- SlavesPdoNumber[nodeid][pdotype] += 1
- new_cobid, new_idx = result
- data, nbaddedparams = GenerateMappingDCF(new_cobid, new_idx, pdomapping, False)
- dataparams += data
- nbparams += nbaddedparams
- DictCobID[new_cobid] = {"type" : InvertPDOType[pdotype], "mapping" : GenerateMasterMapping(pdomapping)}
- pdosize = loc_infos["size"]
- pdomapping = [(name, loc_infos)]
- else:
- pdomapping.append((name, loc_infos))
- if len(pdomapping) > 0:
- result = GetNewCobID(nodeid, pdotype)
- if result:
- SlavesPdoNumber[nodeid][pdotype] += 1
- new_cobid, new_idx = result
- data, nbaddedparams = GenerateMappingDCF(new_cobid, new_idx, pdomapping, False)
- dataparams += data
- 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"]
- else:
- RSDO_cobid = 0x600 + nodeid
-
- if SDOparams["TSDO"] != None:
- TSDO_cobid = SDOparams["TSDO"]
- else:
- 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 subindex == 0:
- continue
- new_index = False
-
- 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)
- new_index = True
- nbsubentries = masternode.GetEntry(mapvariableidx, 0x00)
- else:
- 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)
- new_index = True
- 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"])
- else:
- subindexname = "_" + str(DictLocations[variable[1]]["index"]) + "_" + str(DictLocations[variable[1]]["subindex"])
- if not new_index:
- manager.AddSubentriesToCurrent(mapvariableidx, 1, masternode)
- nbsubentries += 1
- masternode.SetMappingEntry(mapvariableidx, nbsubentries, values = {"name" : subindexname})
- masternode.SetMappingEntry(mapvariableidx, nbsubentries, values = {"type" : typeidx})
-
- # Map Variable
- typeinfos = manager.GetEntryInfos(typeidx)
- if typeinfos != None:
- value = (mapvariableidx << 16) + ((nbsubentries) << 8) + typeinfos["size"]
- masternode.SetEntry(current_idx + 0x200, subindex, value)
- else:
- masternode.SetEntry(current_idx + 0x200, subindex, TrashVariableValue[variable])
-
- CurrentPDOParamsIdx[pdo_infos["type"]] += 1
- #masternode.Print()
- return masternode
-
-if __name__ == "__main__":
- from nodemanager import *
- from nodelist import *
- import sys
-
- manager = NodeManager(sys.path[0])
- nodelist = NodeList(manager)
- result = nodelist.LoadProject("/home/deobox/Desktop/TestMapping")
-
-## if result != None:
-## print result
-## else:
-## print "MasterNode :"
-## manager.CurrentNode.Print()
-## for nodeid, node in nodelist.SlaveNodes.items():
-## print "SlaveNode name=%s id=0x%2.2X :"%(node["Name"], nodeid)
-## node["Node"].Print()
-
- #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]]
- file.close()
- GenerateConciseDCF(locations, 32, nodelist)
- print "MasterNode :"
- manager.CurrentNode.Print()
- #masternode.Print()
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/.cvsignore Mon Aug 20 14:28:08 2007 +0200
@@ -0,0 +1,1 @@
+*.pyc
--- 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("__")]
+for name in __all__:
+ __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 @@
-toto = "ljhlkj"
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/canfestival/.cvsignore Mon Aug 20 14:28:08 2007 +0200
@@ -0,0 +1,1 @@
+*.pyc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/canfestival/__init__.py Mon Aug 20 14:28:08 2007 +0200
@@ -0,0 +1,2 @@
+from networkedit import networkedit as view
+from canfestival import *
--- /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):
+ self.bus_id = bus_id
+ manager = NodeManager()
+ NodeList.__init__(self, manager)
+ self.LoadProject(buspath)
+
+ def SaveBus(self):
+ self.SaveProject()
+
+ def Generate_C(self, filepath, locations):
+ """
+ return C code for network dictionnary
+ """
+ master = config_utils.GenerateConciseDCF(locations, self)
+ res = gen_cfile.GenerateFile(filepath, master)
+ if not res:
+ s = str(self.bus_id)+"_IN(){}\n"
+ f = file(filepath, 'a')
+ f.write(s)
+ else:
+ pass # error
+
+def BlockListFactory(bmz_inst):
+ return []
+
+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 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+#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
+
+from types import *
+
+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}
+
+DictLocations = {}
+DictCobID = {}
+DictLocationsNotMapped = {}
+ListCobIDAvailable = []
+SlavesPdoNumber = {}
+
+# Constants for PDO types
+RPDO = 1
+TPDO = 2
+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 = []
+ if type & RPDO:
+ indexes.extend([idx for idx in slave.GetIndexes() if 0x1400 <= idx <= 0x15FF])
+ if type & TPDO:
+ indexes.extend([idx for idx in slave.GetIndexes() if 0x1800 <= idx <= 0x19FF])
+ if not parameters:
+ return [idx + 0x200 for idx in indexes]
+ else:
+ return 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)]
+ list_car.reverse()
+ 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)
+ if values != None:
+ for subindex, mapping in enumerate(values):
+ if subindex != 0 and mapping == model:
+ return PDOidx, subindex
+ return None
+
+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)
+ # Re-Enable PDO
+ # ---- 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)
+ nbparams = 3
+ if mapped == False and pdomapping != None:
+ # Map Variables
+ 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)
+ nbparams += 1
+ return dcfdata, nbparams
+
+def GetNewCobID(nodeid, type): # Return a cobid not used
+ global ListCobIDAvailable, SlavesPdoNumber
+
+ if len(ListCobIDAvailable) == 0:
+ return None
+
+ nbSlavePDO = SlavesPdoNumber[nodeid][type]
+ if type == RPDO:
+ if nbSlavePDO < 4:
+ # 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
+
+ elif type == TPDO:
+ if nbSlavePDO < 4:
+ # 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):
+ if type == RPDO:
+ # For the fourth PDO -> cobid = 0x200 + ( numPdo * 0x100) + nodeid
+ newcobid = (0x200 + number * 0x100 + nodeid)
+ elif type == TPDO:
+ # For the fourth PDO -> cobid = 0x180 + (numPdo * 0x100) + nodeid
+ newcobid = (0x180 + number * 0x100 + nodeid)
+ else:
+ return None
+ if newcobid in ListCobIDAvailable:
+ ListCobIDAvailable.remove(newcobid)
+ return newcobid
+ return ListCobIDAvailable.pop(0)
+
+
+def GenerateConciseDCF(locations, busname, nodelist):
+ global DictLocations, DictCobID, DictLocationsNotMapped, ListCobIDAvailable, SlavesPdoNumber, DefaultTransmitTypeSlave
+
+ DictLocations = {}
+ DictCobID = {}
+ DictLocationsNotMapped = {}
+ DictSDOparams = {}
+ ListCobIDAvailable = range(0x180, 0x580)
+ SlavesPdoNumber = {}
+ 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"]
+ node.SetNodeID(nodeid)
+ 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)
+ if pdo_cobid > 0x600 :
+ 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
+ else:
+ loc = [i for i in name.split("_") if len(i) > 0]
+ if len(loc) not in (4, 5):
+ continue
+
+ prefix = loc[0][0]
+
+ # Extract and check busname
+ if loc[0][1].isdigit():
+ sizelocation = ""
+ busnamelocation = int(loc[0][1:])
+ else:
+ 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
+ nodeid = int(loc[1])
+ if nodeid not in nodelist.SlaveNodes.keys():
+ continue
+ node = nodelist.SlaveNodes[nodeid]["Node"]
+
+ # Extract and check index and subindex
+ index = int(loc[2])
+ subindex = int(loc[3])
+ if not node.IsEntry(index, subindex):
+ continue
+ subentry_infos = node.GetSubentryInfos(index, subindex)
+
+ if subentry_infos and subentry_infos["pdo"]:
+ if sizelocation == "X" and len(loc) > 4:
+ numbit = loc[4]
+ elif sizelocation != "X" and len(loc) > 4:
+ continue
+ else:
+ numbit = None
+
+ 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)
+ if result != None:
+ index, subindex = result
+ cobid = nodelist.GetSlaveNodeEntry(locationinfos["nodeid"], index - 0x200, 1)
+ if cobid not in DictCobID.keys():
+ mapping = [None]
+ 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)
+
+ else:
+ 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]]
+ tmpnbparams.reverse()
+ nbparams = int(''.join(["%2.2x"%ord(i) for i in tmpnbparams]), 16)
+ dataparams = nodeDCF[4:]
+ else:
+ nbparams = 0
+ dataparams = ""
+
+ for pdotype in (TPDO, RPDO):
+ pdosize = 0
+ pdomapping = []
+ for name, loc_infos in locations[pdotype]:
+ pdosize += loc_infos["size"]
+ # If pdo's size > 64 bits
+ if pdosize > 64:
+ result = GetNewCobID(nodeid, pdotype)
+ if result:
+ SlavesPdoNumber[nodeid][pdotype] += 1
+ new_cobid, new_idx = result
+ data, nbaddedparams = GenerateMappingDCF(new_cobid, new_idx, pdomapping, False)
+ dataparams += data
+ nbparams += nbaddedparams
+ DictCobID[new_cobid] = {"type" : InvertPDOType[pdotype], "mapping" : GenerateMasterMapping(pdomapping)}
+ pdosize = loc_infos["size"]
+ pdomapping = [(name, loc_infos)]
+ else:
+ pdomapping.append((name, loc_infos))
+ if len(pdomapping) > 0:
+ result = GetNewCobID(nodeid, pdotype)
+ if result:
+ SlavesPdoNumber[nodeid][pdotype] += 1
+ new_cobid, new_idx = result
+ data, nbaddedparams = GenerateMappingDCF(new_cobid, new_idx, pdomapping, False)
+ dataparams += data
+ 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"]
+ else:
+ RSDO_cobid = 0x600 + nodeid
+
+ if SDOparams["TSDO"] != None:
+ TSDO_cobid = SDOparams["TSDO"]
+ else:
+ 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 subindex == 0:
+ continue
+ new_index = False
+
+ 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)
+ new_index = True
+ nbsubentries = masternode.GetEntry(mapvariableidx, 0x00)
+ else:
+ 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)
+ new_index = True
+ 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"])
+ else:
+ subindexname = "_" + str(DictLocations[variable[1]]["index"]) + "_" + str(DictLocations[variable[1]]["subindex"])
+ if not new_index:
+ manager.AddSubentriesToCurrent(mapvariableidx, 1, masternode)
+ nbsubentries += 1
+ masternode.SetMappingEntry(mapvariableidx, nbsubentries, values = {"name" : subindexname})
+ masternode.SetMappingEntry(mapvariableidx, nbsubentries, values = {"type" : typeidx})
+
+ # Map Variable
+ typeinfos = manager.GetEntryInfos(typeidx)
+ if typeinfos != None:
+ value = (mapvariableidx << 16) + ((nbsubentries) << 8) + typeinfos["size"]
+ masternode.SetEntry(current_idx + 0x200, subindex, value)
+ else:
+ masternode.SetEntry(current_idx + 0x200, subindex, TrashVariableValue[variable])
+
+ CurrentPDOParamsIdx[pdo_infos["type"]] += 1
+ #masternode.Print()
+ return masternode
+
+if __name__ == "__main__":
+ from nodemanager import *
+ from nodelist import *
+ import sys
+
+ manager = NodeManager(sys.path[0])
+ nodelist = NodeList(manager)
+ result = nodelist.LoadProject("/home/deobox/Desktop/TestMapping")
+
+## if result != None:
+## print result
+## else:
+## print "MasterNode :"
+## manager.CurrentNode.Print()
+## for nodeid, node in nodelist.SlaveNodes.items():
+## print "SlaveNode name=%s id=0x%2.2X :"%(node["Name"], nodeid)
+## node["Node"].Print()
+
+ #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]]
+ file.close()
+ GenerateConciseDCF(locations, 32, nodelist)
+ print "MasterNode :"
+ manager.CurrentNode.Print()
+ #masternode.Print()
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/svgui/.cvsignore Mon Aug 20 14:28:08 2007 +0200
@@ -0,0 +1,1 @@
+*.pyc
--- /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 @@
+from svgui import *
+controller = None
+view = None
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/svgui/svgui.py Mon Aug 20 14:28:08 2007 +0200
@@ -0,0 +1,60 @@
+
+TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L",
+ "USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", "REAL" : "D", "LREAL" : "L",
+ "STRING" : "B", "BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L", "WSTRING" : "W"}
+
+def GetBlockGenerationFunction(beremiz):
+ def generate_svgui_block(generator, block, body, link):
+ controller = generator.GetController()
+ name = block.getInstanceName()
+ type = block.getTypeName()
+ block_infos = GetBlockType(type)
+ bus_id, name = [word for word in name.split("_") if word != ""]
+ block_id = beremiz.GetSVGUIElementId(bus_id, name)
+ if block_id == None:
+ raise ValueError, "No corresponding block found"
+ if not generator.ComputedBlocks.get(name, False):
+ for num, variable in enumerate(block.inputVariables.getVariable()):
+ connections = variable.connectionPointIn.getConnections()
+ if connections and len(connections) == 1:
+ parameter = "__I%s%d_%d_%d"%(TYPECONVERSION[block_infos["inputs"][num][1]], bus_id, block_id, num)
+ value = generator.ComputeFBDExpression(body, connections[0])
+ generator.Program += (" %s := %s;\n"%(parameter, generator.ExtractModifier(variable, value)))
+ generator.ComputedBlocks[name] = True
+ if link:
+ connectionPoint = link.getPosition()[-1]
+ 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 "__Q%s%d_%d_%d"%(TYPECONVERSION[block_infos["outputs"][num][1]], bus_id, block_id, num)
+ raise ValueError, "No output variable found"
+ else:
+ return None
+ return generate_svgui_block
+
+BlockList = {"name" : "SVGUI function blocks", "list" :
+ [{"name" : "Container", "type" : "functionBlock", "extensible" : False,
+ "inputs" : [("X","FLOAT","none"),("SetX","BOOL","none"),("Y","FLOAT","none"),("SetY","BOOL","none"),("Angle","FLOAT","none"),("SetAngle","BOOL","none")],
+ "outputs" : [("X","FLOAT","none"),("X Changed","BOOL","none"),("Y","FLOAT","none"),("Y Changed","BOOL","none"),("Angle","FLOAT","none"),("Angle Changed","BOOL","none")],
+ "comment" : "SVGUI Container"},
+ {"name" : "Button", "type" : "functionBlock", "extensible" : False,
+ "inputs" : [("Show","BOOL","none"),("Toggle","BOOL","none")],
+ "outputs" : [("Visible","BOOL","none"),("State","BOOL","none")],
+ "comment" : "SVGUI Button"},
+ {"name" : "TextCtrl", "type" : "functionBlock", "extensible" : False,
+ "inputs" : [("Text","STRING","none"),("Set Text","BOOL","none")],
+ "outputs" : [("Text","STRING","none"),("Text Changed","BOOL","none")],
+ "comment" : "SVGUI Text Control"},
+ {"name" : "ScrollBar", "type" : "functionBlock", "extensible" : False,
+ "inputs" : [("Position","UINT","none"),("Set Position","BOOL","none")],
+ "outputs" : [("Position","UINT","none"),("Position Changed","BOOL","none")],
+ "comment" : "SVGUI ScrollBar"},
+ {"name" : "NoteBook", "type" : "functionBlock", "extensible" : False,
+ "inputs" : [("Selected","UINT","none"),("Set Selected","BOOL","none")],
+ "outputs" : [("Selected","UINT","none"),("Selected Changed","BOOL","none")],
+ "comment" : "SVGUI Notebook"},
+ {"name" : "RotatingCtrl", "type" : "functionBlock", "extensible" : False,
+ "inputs" : [("Angle","FLOAT","none"),("Set Angle","BOOL","none")],
+ "outputs" : [("Angle","FLOAT","none"),("Angle changed","BOOL","none")],
+ "comment" : "SVGUI Rotating Control"},
+ ]}