]> rtime.felk.cvut.cz Git - CanFestival-3.git/blobdiff - objdictgen/nodemanager.py
Remove deletion PDO when mapping undefined in export to EDS
[CanFestival-3.git] / objdictgen / nodemanager.py
index 300d4cb2a7c12e3a7659524793adc0c422556d56..bbac2b1696c5aecb4c02ad925be8461addc76573 100755 (executable)
@@ -200,6 +200,7 @@ class NodeManager:
             self.CurrentNode.SetNodeType(type)
             self.CurrentNode.SetNodeDescription(description)
             AddIndexList = self.GetMandatoryIndexes()
+            AddSubIndexList = []
             if NMT == "NodeGuarding":
                 AddIndexList.extend([0x100C, 0x100D])
             elif NMT == "Heartbeat":
@@ -225,11 +226,24 @@ class NodeManager:
                     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
@@ -296,7 +310,7 @@ class NodeManager:
     """
     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]
@@ -332,7 +346,7 @@ class NodeManager:
     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 
@@ -663,7 +677,7 @@ class NodeManager:
             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"
@@ -789,6 +803,9 @@ class NodeManager:
     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()
     
@@ -1010,7 +1027,7 @@ class NodeManager:
             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])      
@@ -1025,7 +1042,7 @@ class NodeManager:
                 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: