"""
Constructor
"""
- def __init__(self, cwd):
+ def __init__(self):
self.LastNewIndex = 0
self.FilePaths = {}
self.FileNames = {}
self.NodeIndex = None
self.CurrentNode = None
- self.ScriptDirectory = cwd
self.UndoBuffers = {}
#-------------------------------------------------------------------------------
self.CurrentNode.SetNodeType(type)
self.CurrentNode.SetNodeDescription(description)
AddIndexList = self.GetMandatoryIndexes()
+ AddSubIndexList = []
if NMT == "NodeGuarding":
AddIndexList.extend([0x100C, 0x100D])
elif NMT == "Heartbeat":
AddIndexList.append(0x1017)
for option in options:
if option == "DS302":
- DS302Path = os.path.join(self.ScriptDirectory, "config/DS-302.prf")
+ DS302Path = os.path.join(os.path.split(__file__)[0], "config/DS-302.prf")
# Charging DS-302 profile if choosen by user
if os.path.isfile(DS302Path):
try:
AddIndexList.extend([0x1010, 0x1011, 0x1020])
elif option == "StoreEDS":
AddIndexList.extend([0x1021, 0x1022])
+ if type == "slave":
+ # add default SDO server
+ AddIndexList.append(0x1200)
+ # add default 4 receive and 4 transmit PDO
+ for comm, mapping in [(0x1400, 0x1600),(0x1800, 0x1A00)]:
+ firstparamindex = self.GetLineFromIndex(comm)
+ firstmappingindex = self.GetLineFromIndex(mapping)
+ AddIndexList.extend(range(firstparamindex, firstparamindex + 4))
+ for idx in range(firstmappingindex, firstmappingindex + 4):
+ AddIndexList.append(idx)
+ AddSubIndexList.append((idx, 8))
# Add a new buffer
index = self.AddNodeBuffer(self.CurrentNode.Copy(), False)
self.SetCurrentFilePath("")
# Add Mandatory indexes
self.ManageEntriesOfCurrent(AddIndexList, [])
+ for idx, num in AddSubIndexList:
+ self.AddSubentriesToCurrent(idx, num)
return index
else:
return result
node.SetSpecificMenu(AddMenuEntries)
return None
except:
- return "Syntax Error\nBad OD Profile file!."
+ return "Syntax Error\nBad OD Profile file!"
else:
# Default profile
node.SetProfileName("None")
Open a file and store it in a new buffer
"""
def OpenFileInCurrent(self, filepath):
- # Open and load file
- file = open(filepath, "r")
- node = load(file)
- file.close()
- self.CurrentNode = node
- # Add a new buffer and defining current state
- index = self.AddNodeBuffer(self.CurrentNode.Copy(), True)
- self.SetCurrentFilePath(filepath)
- return index
+ try:
+ # Open and load file
+ file = open(filepath, "r")
+ node = load(file)
+ file.close()
+ self.CurrentNode = node
+ self.CurrentNode.SetNodeID(0)
+ # Add a new buffer and defining current state
+ index = self.AddNodeBuffer(self.CurrentNode.Copy(), True)
+ self.SetCurrentFilePath(filepath)
+ return index
+ except:
+ return "Unable to load file \"%s\"!"%filepath
"""
Save current node in a file
"""
def CloseCurrent(self, ignore = False):
# Verify if it's not forced that the current node is saved before closing it
- if self.UndoBuffers[self.NodeIndex].IsCurrentSaved() or ignore:
+ if self.NodeIndex in self.UndoBuffers and (self.UndoBuffers[self.NodeIndex].IsCurrentSaved() or ignore):
self.RemoveNodeBuffer(self.NodeIndex)
+ if len(self.UndoBuffers) > 0:
+ previousindexes = [idx for idx in self.UndoBuffers.keys() if idx < self.NodeIndex]
+ nextindexes = [idx for idx in self.UndoBuffers.keys() if idx > self.NodeIndex]
+ if len(previousindexes) > 0:
+ previousindexes.sort()
+ self.NodeIndex = previousindexes[-1]
+ elif len(nextindexes) > 0:
+ nextindexes.sort()
+ self.NodeIndex = nextindexes[0]
+ else:
+ self.NodeIndex = None
+ else:
+ self.NodeIndex = None
return True
return False
"""
def ImportCurrentFromEDSFile(self, filepath):
# Generate node from definition in a xml file
- result = eds_utils.GenerateNode(filepath, self.ScriptDirectory)
+ result = eds_utils.GenerateNode(filepath)
if isinstance(result, Node):
self.CurrentNode = result
index = self.AddNodeBuffer(self.CurrentNode.Copy(), False)
Export to an eds file and store it in a new buffer if no node edited
"""
def ExportCurrentToEDSFile(self, filepath):
- return eds_utils.GenerateEDSFile(filepath, self)
+ return eds_utils.GenerateEDSFile(filepath, self.CurrentNode)
"""
Build the C definition of Object Dictionary for current node
number of subentry (except 0) doesn't exceed nbmax defined
"""
def AddSubentriesToCurrent(self, index, number, node = None):
+ disable_buffer = node != None
if node == None:
- disable_buffer = True
- node = self.CurrentNode
- else:
- disable_buffer = False
+ node = self.CurrentNode
# Informations about entry
length = node.GetEntry(index, 0)
infos = node.GetEntryInfos(index)
# Informations about entry
infos = self.GetEntryInfos(index)
length = self.CurrentNode.GetEntry(index, 0)
+ if "nbmin" in infos:
+ nbmin = infos["nbmin"]
+ else:
+ nbmin = 1
# Entry is a record, or is an array of manufacturer specific
if infos["struct"] & OD_IdenticalSubindexes or 0x2000 <= index <= 0x5FFF and infos["struct"] & OD_IdenticalSubindexes:
- for i in xrange(min(number, length - 1)):
+ for i in xrange(min(number, length - nbmin)):
self.RemoveCurrentVariable(index, length - i)
self.BufferCurrentNode()
Add entries specified in addinglist and remove entries specified in removinglist
"""
def ManageEntriesOfCurrent(self, addinglist, removinglist, node = None):
+ disable_buffer = node != None
if node == None:
- disable_buffer = True
node = self.CurrentNode
- else:
- disable_buffer = False
# Add all the entries in addinglist
for index in addinglist:
infos = self.GetEntryInfos(index)
default = subentry_infos["default"]
else:
default = self.GetTypeDefaultValue(subentry_infos["type"])
- node.AddEntry(index, 1, default)
+ node.AddEntry(index, value = [])
+ if "nbmin" in subentry_infos:
+ for i in xrange(subentry_infos["nbmin"]):
+ node.AddEntry(index, i + 1, default)
+ else:
+ node.AddEntry(index, 1, default)
# Second case entry is a record
else:
i = 1
return None
+ """
+ Reset an subentry from current node to its default value
+ """
+ def SetCurrentEntryToDefault(self, index, subindex, node = None):
+ disable_buffer = node != None
+ if node == None:
+ node = self.CurrentNode
+ if node.IsEntry(index, subindex):
+ subentry_infos = self.GetSubentryInfos(index, subindex)
+ if "default" in subentry_infos:
+ default = subentry_infos["default"]
+ else:
+ default = self.GetTypeDefaultValue(subentry_infos["type"])
+ node.SetEntry(index, subindex, default)
+ if not disable_buffer:
+ self.BufferCurrentNode()
+
"""
Remove an entry from current node. Analize the index to perform the correct
method
def AddMapVariableToCurrent(self, index, name, struct, number, node = None):
if 0x2000 <= index <= 0x5FFF:
+ disable_buffer = node != None
if node == None:
- disable_buffer = True
node = self.CurrentNode
- else:
- disable_buffer = False
if not node.IsEntry(index):
node.AddMappingEntry(index, name = name, struct = struct)
if struct == var:
self.BufferCurrentNode()
def SetCurrentEntry(self, index, subIndex, value, name, editor, node = None):
-
+ disable_buffer = node != None
if node == None:
- disable_buffer = True
- node = self.CurrentNode
- else:
- disable_buffer = False
+ node = self.CurrentNode
if node and node.IsEntry(index):
if name == "value":
if editor == "map":
node.SetEntry(index, subIndex, int(value))
except:
pass
+ elif editor == "float":
+ try:
+ node.SetEntry(index, subIndex, float(value))
+ except:
+ pass
elif editor == "domain":
try:
if len(value) % 2 != 0:
node.SetEntry(index, subIndex, value)
except:
pass
+ elif editor == "dcf":
+ node.SetEntry(index, subIndex, value)
else:
subentry_infos = self.GetSubentryInfos(index, subIndex)
type = subentry_infos["type"]
type = node.GetEntry(type)[1]
if dic[type] == 0:
try:
- if value.startswith("0x"):
+ if value.startswith("$NODEID"):
+ value = "\"%s\""%value
+ elif value.startswith("0x"):
value = int(value, 16)
else:
value = int(value)
def GetBufferNumber(self):
return len(self.UndoBuffers)
+ def GetBufferIndexes(self):
+ return self.UndoBuffers.keys()
+
def LoadCurrentPrevious(self):
self.CurrentNode = self.UndoBuffers[self.NodeIndex].Previous().Copy()
type = self.CurrentNode.GetNodeType()
description = self.CurrentNode.GetNodeDescription()
return name, id, type, description
-
+
def SetCurrentNodeInfos(self, name, id, type, description):
self.CurrentNode.SetNodeName(name)
self.CurrentNode.SetNodeID(id)
self.CurrentNode.SetNodeDescription(description)
self.BufferCurrentNode()
+ def GetCurrentNodeDefaultStringSize(self):
+ if self.CurrentNode:
+ return self.CurrentNode.GetDefaultStringSize()
+ else:
+ return Node.DefaultStringSize
+
+ def SetCurrentNodeDefaultStringSize(self, size):
+ if self.CurrentNode:
+ self.CurrentNode.SetDefaultStringSize(size)
+ else:
+ Node.DefaultStringSize = size
+
def GetCurrentProfileName(self):
if self.CurrentNode:
return self.CurrentNode.GetProfileName()
return self.CurrentNode.IsEntry(index)
return False
- def GetCurrentEntry(self, index, subIndex = None):
+ def GetCurrentEntry(self, index, subIndex = None, compute = True):
if self.CurrentNode:
- return self.CurrentNode.GetEntry(index, subIndex)
+ return self.CurrentNode.GetEntry(index, subIndex, compute)
return None
def GetCurrentParamsEntry(self, index, subIndex = None):
entry_infos = node.GetEntryInfos(index)
data = []
editors = []
- values = node.GetEntry(index)
+ values = node.GetEntry(index, compute = False)
params = node.GetParamsEntry(index)
- if type(values) == ListType:
+ if isinstance(values, ListType):
for i, value in enumerate(values):
data.append({"value" : value})
data[-1].update(params[i])
dic["access"] = AccessType[infos["access"]]
dic["save"] = OptionType[dic["save"]]
editor = {"subindex" : None, "save" : "option", "callback" : "option", "comment" : "string"}
- if type(values) == ListType and i == 0:
+ if isinstance(values, ListType) and i == 0:
editor["name"] = None
editor["type"] = None
if 0x1600 <= index <= 0x17FF or 0x1A00 <= index <= 0x1C00:
editor["value"] = "map"
dic["value"] = node.GetMapName(dic["value"])
else:
- if dic["type"].startswith("VISIBLE_STRING"):
+ if dic["type"].startswith("VISIBLE_STRING") or dic["type"].startswith("OCTET_STRING"):
editor["value"] = "string"
elif dic["type"] in ["TIME_OF_DAY","TIME_DIFFERENCE"]:
editor["value"] = "time"
elif dic["type"] == "DOMAIN":
- editor["value"] = "domain"
+ if index == 0x1F22:
+ editor["value"] = "dcf"
+ else:
+ editor["value"] = "domain"
dic["value"] = dic["value"].encode('hex_codec')
elif dic["type"] == "BOOLEAN":
editor["value"] = "bool"
if result:
values = result.groups()
if values[0] == "UNSIGNED":
- format = "0x%0" + str(int(values[1])/4) + "X"
- dic["value"] = format%dic["value"]
+ try:
+ format = "0x%0" + str(int(values[1])/4) + "X"
+ dic["value"] = format%dic["value"]
+ except:
+ pass
editor["value"] = "string"
if values[0] == "INTEGER":
editor["value"] = "number"
elif values[0] == "REAL":
editor["value"] = "float"
- elif values[0] == "VISIBLE_STRING":
+ elif values[0] in ["VISIBLE_STRING", "OCTET_STRING"]:
editor["length"] = values[0]
result = range_model.match(dic["type"])
if result:
else:
return None
+ def AddToDCF(self, node_id, index, subindex, size, value):
+ if self.CurrentNode.IsEntry(0x1F22, node_id):
+ dcf_value = self.CurrentNode.GetEntry(0x1F22, node_id)
+ if dcf_value != "":
+ nbparams = BE_to_LE(dcf_value[:4])
+ else:
+ nbparams = 0
+ new_value = LE_to_BE(nbparams + 1, 4) + dcf_value[4:]
+ new_value += LE_to_BE(index, 2) + LE_to_BE(subindex, 1) + LE_to_BE(size, 4) + LE_to_BE(value, size)
+ self.CurrentNode.SetEntry(0x1F22, node_id, new_value)
+
#-------------------------------------------------------------------------------
# Node Informations Functions
#-------------------------------------------------------------------------------