SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
authoretisserant
Wed, 25 Jun 2008 17:09:24 +0200
changeset 169 8e87b69286c0
parent 168 8a0727f5fd13
child 170 acc6a61c493c
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
Re-use of node creation dialog from CanFestival for slave node creation.
plugins/canfestival/canfestival.py
plugins/canfestival/cf_runtime.c
--- a/plugins/canfestival/canfestival.py	Wed Jun 25 17:01:07 2008 +0200
+++ b/plugins/canfestival/canfestival.py	Wed Jun 25 17:09:24 2008 +0200
@@ -10,6 +10,8 @@
 from objdictedit import objdictedit
 import canfestival_config
 from plugger import PlugTemplate
+from commondialogs import CreateNodeDialog
+import wx
 
 from gnosis.xml.pickle import *
 from gnosis.xml.pickle.util import setParanoia
@@ -42,15 +44,33 @@
         if(os.path.isfile(odfilepath)):
             self.OpenFileInCurrent(odfilepath)
         else:
-            self.CreateNewNode("SlaveNode",  # Name - will be changed at build time
-                               0x00,         # NodeID - will be changed at build time
-                               "slave",      # Type
-                               "",           # description 
-                               "None",       # profile
-                               "",           # prfile filepath
-                               "heartbeat",  # NMT
-                               [])           # options
-            
+            self.FilePath = ""
+            dialog = CreateNodeDialog(None, wx.OK)
+            dialog.Type.Enable(False)
+            dialog.GenSYNC.Enable(False)
+            if dialog.ShowModal() == wx.ID_OK:
+                name, id, nodetype, description = dialog.GetValues()
+                profile, filepath = dialog.GetProfile()
+                NMT = dialog.GetNMTManagement()
+                options = dialog.GetOptions()
+                self.CreateNewNode(name,       # Name - will be changed at build time
+                                   id,         # NodeID - will be changed at build time
+                                   "slave",    # Type
+                                   description,# description 
+                                   profile,    # profile
+                                   filepath,   # prfile filepath
+                                   NMT,        # NMT
+                                   options)     # options
+            else:
+                self.CreateNewNode("SlaveNode",  # Name - will be changed at build time
+                                   0x00,         # NodeID - will be changed at build time
+                                   "slave",      # Type
+                                   "",           # description 
+                                   "None",       # profile
+                                   "", # prfile filepath
+                                   "heartbeat",  # NMT
+                                   [])           # options
+            dialog.Destroy()
     _View = None
     def _OpenView(self, logger):
         if not self._View:
@@ -160,7 +180,7 @@
             logger.write_error("Error: No Master generated\n")
             return
         
-        new_dialog = objdictedit(None, [masterpath])
+        new_dialog = objdictedit(None, filesOpen=[masterpath])
         new_dialog.Show()
 
     PluginMethods = [
@@ -227,7 +247,8 @@
       </xsd:element>
     </xsd:schema>
     """
-    PlugChildsTypes = [("CanOpenNode",_NodeListPlug, "CanOpen Master"),("CanOpenSlave",_SlavePlug, "CanOpen Slave")]
+    PlugChildsTypes = [("CanOpenNode",_NodeListPlug, "CanOpen Master"),
+                       ("CanOpenSlave",_SlavePlug, "CanOpen Slave")]
     def GetParamsAttributes(self, path = None):
         infos = PlugTemplate.GetParamsAttributes(self, path = None)
         for element in infos:
@@ -251,7 +272,8 @@
                        "nodes_open" : "",
                        "nodes_close" : "",
                        "nodes_send_sync" : "",
-                       "nodes_proceed_sync" : ""}
+                       "nodes_proceed_sync" : "",
+                       "slavebootups" : ""}
         for child in self.IECSortedChilds():
             childlocstr = "_".join(map(str,child.GetCurrentLocation()))
             nodename = "OD_%s" % childlocstr
@@ -261,10 +283,40 @@
             if child_data is None:
                 # Not a slave -> master
                 child_data = getattr(child, "CanFestivalNode")
+                # Apply sync setting
                 if child_data.getSync_TPDOs():
                     format_dict["nodes_send_sync"] += 'NODE_SEND_SYNC(%s)\n    '%(nodename)
                     format_dict["nodes_proceed_sync"] += 'NODE_PROCEED_SYNC(%s)\n    '%(nodename)
-
+                # initialize and declare node table for post_SlaveBootup lookup
+                
+                SlaveIDs = child.GetSlaveIDs()
+                for id in SlaveIDs:
+                    format_dict["slavebootups"] += """
+int %s_slave_%d_booted = 0;
+"""%(nodename, id)
+                format_dict["slavebootups"] += """
+static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){
+    switch(nodeId){
+"""%(nodename)
+                for id in SlaveIDs:
+                    format_dict["slavebootups"] += """
+        case %d:
+            %s_slave_%d_booted = 1;
+            break;
+"""%(id, nodename, id)
+                format_dict["slavebootups"] += """
+        default:
+            break;
+    }
+    if( """
+                format_dict["slavebootups"] += " && ".join(["%s_slave_%d_booted"%(nodename, id) for id in SlaveIDs])
+                
+                format_dict["slavebootups"] += """ )
+        Master_post_SlaveBootup(d,nodeId);
+}
+%s_Data.post_SlaveBootup = %s_post_SlaveBootup;
+"""%(nodename,nodename)
+                
             format_dict["nodes_includes"] += '#include "%s.h"\n'%(nodename)
             format_dict["board_decls"] += 'BOARD_DECL(%s, "%s", "%s")\n'%(
                    nodename,
--- a/plugins/canfestival/cf_runtime.c	Wed Jun 25 17:01:07 2008 +0200
+++ b/plugins/canfestival/cf_runtime.c	Wed Jun 25 17:09:24 2008 +0200
@@ -11,7 +11,6 @@
 static int init_level=0;
 extern int common_ticktime__;
 
-
 static void Master_post_SlaveBootup(CO_Data* d, UNS8 nodeId)
 {
     /* Put the master in operational mode */
@@ -21,6 +20,8 @@
     masterSendNMTstateChange (d, 0, NMT_Start_Node);
 }
 
+%(slavebootups)s
+
 #define NODE_INIT(nodename, nodeid) \
     /* Artificially force sync state to 1 so that it is not started */\
     nodename##_Data.CurrentCommunicationState.csSYNC = -1;\
@@ -65,7 +66,6 @@
 }
 
 #define NODE_OPEN(nodename)\
-    nodename##_Data.post_SlaveBootup = Master_post_SlaveBootup;\
     if(!canOpen(&nodename##Board,&nodename##_Data)){\
         printf("Cannot open " #nodename " Board (%%s,%%s)\n",nodename##Board.busname, nodename##Board.baudrate);\
         return -1;\