self.CurrentNode.SetNodeType(type)
self.CurrentNode.SetNodeDescription(description)
AddIndexList = self.GetMandatoryIndexes()
+ AddSubIndexList = []
if NMT == "NodeGuarding":
AddIndexList.extend([0x100C, 0x100D])
elif NMT == "Heartbeat":
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
"""
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]
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
if name == "value":
if editor == "map":
value = node.GetMapValue(value)
- if value:
+ if value is not None:
node.SetEntry(index, subIndex, value)
elif editor == "bool":
value = value == "True"
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:
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()
editors = []
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"
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:
def AddToDCF(self, node_id, index, subindex, size, value):
if self.CurrentNode.IsEntry(0x1F22, node_id):
dcf_value = self.CurrentNode.GetEntry(0x1F22, node_id)
- nbparams = BE_to_LE(dcf_value[:4])
+ 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)