]> 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 d79a7da5d2535e954f455f394d92b987d5e0c3cf..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"
@@ -675,6 +689,11 @@ class NodeManager:
                         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:
@@ -784,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()
     
@@ -922,7 +944,7 @@ class NodeManager:
         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)
@@ -930,6 +952,18 @@ class NodeManager:
         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()
@@ -993,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])      
@@ -1008,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:
@@ -1045,7 +1079,7 @@ class NodeManager:
                         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"
@@ -1072,7 +1106,7 @@ class NodeManager:
                                 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:
@@ -1088,7 +1122,10 @@ class NodeManager:
     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)