Some bugs fixed
authorlbessard
Wed, 12 Sep 2007 17:18:43 +0200
changeset 273 58b39f97e352
parent 272 bbdbf0c17d3c
child 274 39beb1c7542a
Some bugs fixed
Improved node print method
objdictgen/networkedit.py
objdictgen/node.py
objdictgen/nodelist.py
objdictgen/objdictedit.py
objdictgen/subindextable.py
--- a/objdictgen/networkedit.py	Tue Sep 11 17:34:31 2007 +0200
+++ b/objdictgen/networkedit.py	Wed Sep 12 17:18:43 2007 +0200
@@ -100,7 +100,7 @@
             wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame',
                   parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616),
                   style=wx.DEFAULT_FRAME_STYLE, title='')
-            self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=ID_HTMLFRAME)
+            self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
             
             self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT,
                   name='HtmlContent', parent=self, pos=wx.Point(0, 0),
@@ -319,7 +319,7 @@
         self._init_utils()
         self.SetClientSize(wx.Size(1000, 700))
         self.SetMenuBar(self.menuBar1)
-        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=ID_NETWORKEDIT)
+        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
         if not self.ModeSolo:
             self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=ID_NETWORKEDITFILEMENUITEMS1)
             accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, 83, ID_NETWORKEDITFILEMENUITEMS1)])
@@ -701,6 +701,14 @@
                     edititem.SetText("Other Profile")
                     edititem.Enable(False)
 
+    def GetProfileCallBack(self, text):
+        def ProfileCallBack(event):
+            self.Manager.AddSpecificEntryToCurrent(text)
+            self.RefreshBufferState()
+            self.RefreshCurrentIndexList()
+            event.Skip()
+        return ProfileCallBack
+
 #-------------------------------------------------------------------------------
 #                              Buffer Functions
 #-------------------------------------------------------------------------------
@@ -810,7 +818,6 @@
                 if index not in new_profile:
                     removinglist.append(index)
             self.Manager.ManageEntriesOfCurrent(addinglist, removinglist)
-            self.Manager.GenerateMapList()
             self.Manager.BufferCurrentNode()
             self.RefreshBufferState()
             self.RefreshCurrentIndexList()
--- a/objdictgen/node.py	Tue Sep 11 17:34:31 2007 +0200
+++ b/objdictgen/node.py	Wed Sep 12 17:18:43 2007 +0200
@@ -202,7 +202,7 @@
                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
                  {"name" : "COB ID Client to Server (Transmit SDO)", "type" : 0x07, "access" : 'rw', "pdo" : False},
                  {"name" : "COB ID Server to Client (Receive SDO)", "type" : 0x07, "access" : 'rw', "pdo" : False},
-                 {"name" : "Node ID of the SDO Server", "type" : 0x04, "access" : 'rw', "pdo" : False}]},
+                 {"name" : "Node ID of the SDO Server", "type" : 0x05, "access" : 'rw', "pdo" : False}]},
     0x1400 : {"name" : "Receive PDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" :
                 [{"name" : "Highest SubIndex Supported", "type" : 0x05, "access" : 'ro', "pdo" : False},
                  {"name" : "COB ID used by PDO", "type" : 0x07, "access" : 'rw', "pdo" : False, "default" : "{True:self.ID+(base+2)*0x100,False:0}[base<4]"},
@@ -815,18 +815,39 @@
     Print the Dictionary values
     """
     def Print(self):
+        print self.PrintString()
+    
+    def PrintString(self):
+        result = ""
         listindex = self.Dictionary.keys()
         listindex.sort()
         for index in listindex:
+            name = self.GetEntryName(index)
             values = self.Dictionary[index]
-            if index != 0x1F22 and type(values) != IntType:
-                values = [i for i in values]
-                for i, value in enumerate(values):
-                    if type(value) == IntType:
-                        values[i] = "%X"%value
-                values = "[" + ",".join(values) + "]"
-            print "%04X : %s"%(index, values)
-
+            if isinstance(values, ListType):
+                result += "%04X (%s):\n"%(index, name)
+                for subidx, value in enumerate(values):
+                    subentry_infos = self.GetSubentryInfos(index, subidx + 1)
+                    if index == 0x1F22 and value:
+                        nb_params = BE_to_LE(value[:4])
+                        data = value[4:]
+                        value = str(nb_params)
+                        i = 0
+                        while i < len(data):
+                            value += "\n\t"
+                            value += "%4.4X"%BE_to_LE(data[i:i+2])
+                            value += " %2.2X"%BE_to_LE(data[i+2:i+3])
+                            size = BE_to_LE(data[i+3:i+7])
+                            value += " %8.8X"%size
+                            value += (" %"+"%d"%(size * 2)+"."+"%d"%(size * 2)+"X")%BE_to_LE(data[i+7:i+7+size])
+                            i += 7 + size
+                    elif isinstance(value, IntType):
+                        value = "%X"%value
+                    result += "  %3.3d (%s): %s\n"%(subidx+1, subentry_infos["name"], value)
+            else:
+                result += "%04X (%s): %s\n"%(index, name, values)
+        return result
+            
     def CompileValue(self, value, index):
         if type(value) == StringType and value.find("self.ID") != -1:
             base = self.GetBaseIndex(index)
@@ -996,3 +1017,16 @@
     def GetMapList(self):
         list = ["None"] + [name for index, subIndex, size, name in self.GetMapVariableList()]
         return ",".join(list)
+
+def BE_to_LE(value):
+    """
+    Convert Big Endian to Little Endian 
+    @param value: value expressed in Big Endian
+    @param size: number of bytes generated
+    @return: a string containing the value converted
+    """
+    
+    data = [char for char in value]
+    data.reverse()
+    return int("".join(["%2.2X"%ord(char) for char in data]), 16)
+    
\ No newline at end of file
--- a/objdictgen/nodelist.py	Tue Sep 11 17:34:31 2007 +0200
+++ b/objdictgen/nodelist.py	Wed Sep 12 17:18:43 2007 +0200
@@ -250,7 +250,6 @@
         if order > 0:
             nodeindexes = self.SlaveNodes.keys()
             nodeindexes.sort()
-            print nodeindexes
             if order <= len(nodeindexes):
                 return self.SlaveNodes[nodeindexes[order - 1]]["Node"]
         return None
@@ -262,6 +261,7 @@
             else:
                 node = self.SlaveNodes[self.CurrentSelected]["Node"]
                 if node:
+                    node.SetNodeID(self.CurrentSelected)
                     return node.IsEntry(index)
         return False
     
@@ -272,6 +272,7 @@
             else:
                 node = self.SlaveNodes[self.CurrentSelected]["Node"]
                 if node:
+                    node.SetNodeID(self.CurrentSelected)
                     return node.GetEntryInfos(index)
         return None
 
@@ -282,6 +283,7 @@
             else:
                 node = self.SlaveNodes[self.CurrentSelected]["Node"]
                 if node:
+                    node.SetNodeID(self.CurrentSelected)
                     return node.GetSubentryInfos(index, subindex)
         return None
 
@@ -292,6 +294,7 @@
             else:
                 node = self.SlaveNodes[self.CurrentSelected]["Node"]
                 if node:
+                    node.SetNodeID(self.CurrentSelected)
                     validindexes = []
                     for index in node.GetIndexes():
                         if min <= index <= max:
@@ -305,6 +308,7 @@
         if self.CurrentSelected != None:
             node = self.SlaveNodes[self.CurrentSelected]["Node"]
             if node:
+                node.SetNodeID(self.CurrentSelected)
                 return self.Manager.GetNodeEntryValues(node, index)
             else:
                 print "Can't find node"
--- a/objdictgen/objdictedit.py	Tue Sep 11 17:34:31 2007 +0200
+++ b/objdictgen/objdictedit.py	Wed Sep 12 17:18:43 2007 +0200
@@ -71,7 +71,7 @@
             wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame',
                   parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616),
                   style=wx.DEFAULT_FRAME_STYLE, title='')
-            self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=ID_HTMLFRAME)
+            self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
             
             self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT,
                   name='HtmlContent', parent=self, pos=wx.Point(0, 0),
@@ -305,7 +305,7 @@
         self._init_utils()
         self.SetClientSize(wx.Size(1000, 700))
         self.SetMenuBar(self.menuBar1)
-        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=ID_OBJDICTEDIT)
+        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
 
         self.FileOpened = wx.Notebook(id=ID_OBJDICTEDITFILEOPENED,
               name='FileOpened', parent=self, pos=wx.Point(0, 0),
--- a/objdictgen/subindextable.py	Tue Sep 11 17:34:31 2007 +0200
+++ b/objdictgen/subindextable.py	Wed Sep 12 17:18:43 2007 +0200
@@ -612,7 +612,7 @@
                         self.IndexListMenu.FindItemByPosition(0).Enable(False)
                         self.IndexListMenu.FindItemByPosition(1).Enable(True)
                         self.PopupMenu(self.IndexListMenu)
-                    elif 0x1000 <= index <= 0x1BFF:
+                    elif 0x1000 <= index <= 0x1FFF:
                         self.IndexListMenu.FindItemByPosition(0).Enable(False)
                         self.IndexListMenu.FindItemByPosition(1).Enable(False)
                         self.PopupMenu(self.IndexListMenu)