Implemented writeNetworkDictCallBack test in TestMasterSlave example. Fixed callback assignement race condition in sdo.c.
authoretisserant
Thu, 12 Apr 2007 16:20:22 +0200
changeset 154 1b3165f2d17d
parent 153 1c1ad874fe8f
child 155 746b49869cbc
Implemented writeNetworkDictCallBack test in TestMasterSlave example. Fixed callback assignement race condition in sdo.c.
examples/TestMasterSlave/Master.c
examples/TestMasterSlave/TestMasterSlave.h
examples/TestMasterSlave/TestSlave.c
examples/TestMasterSlave/TestSlave.od
src/sdo.c
--- a/examples/TestMasterSlave/Master.c	Thu Apr 12 16:17:35 2007 +0200
+++ b/examples/TestMasterSlave/Master.c	Thu Apr 12 16:20:22 2007 +0200
@@ -36,15 +36,119 @@
 	eprintf("TestMaster_SDOtimeoutError %d\n", line);
 }
 
-/*****************************************************************************/
+/********************************************************
+ * ConfigureSlaveNode is responsible to
+ *  - setup master RPDO 1 to receive TPDO 1 from id 2
+ *  - setup master RPDO 2 to receive TPDO 2 from id 2
+ ********************************************************/
 void TestMaster_initialisation()
 {
+	UNS32 PDO1_COBID = 0x0182; 
+	UNS32 PDO2_COBID = 0x0282;
+	UNS8 size = sizeof(UNS32); 
+
 	eprintf("TestMaster_initialisation\n");
+
+	/*****************************************
+	 * Define RPDOs to match slave ID=2 TPDOs*
+	 *****************************************/
+	setODentry( &TestMaster_Data, /*CO_Data* d*/
+			0x1400, /*UNS16 index*/
+			0x01, /*UNS8 subind*/ 
+			&PDO1_COBID, /*void * pSourceData,*/ 
+			&size, /* UNS8 * pExpectedSize*/
+			RW);  /* UNS8 checkAccess */
+			
+	setODentry( &TestMaster_Data, /*CO_Data* d*/
+			0x1401, /*UNS16 index*/
+			0x01, /*UNS8 subind*/ 
+			&PDO2_COBID, /*void * pSourceData,*/ 
+			&size, /* UNS8 * pExpectedSize*/
+			RW);  /* UNS8 checkAccess */
+}
+
+/********************************************************
+ * ConfigureSlaveNode is responsible to
+ *  - setup slave TPDO 1 transmit time
+ *  - setup slave TPDO 2 transmit time
+ *  - switch to operational mode
+ *  - send NMT to slave
+ ********************************************************
+ * This an example of :
+ * Network Dictionary Access (SDO) with Callback 
+ * Slave node state change request (NMT) 
+ ********************************************************
+ * This is called first by TestMaster_preOperational
+ * then it called again each time a SDO exchange is
+ * finished.
+ ********************************************************/
+static void ConfigureSlaveNode(CO_Data* d, UNS8 nodeId)
+{
+	// Step counts number of times ConfigureSlaveNode is called
+	static step = 1;
+	
+	UNS8 Transmission_Type = 0x01; 
+	UNS32 abortCode;
+	UNS8 res;
+	eprintf("Master : ConfigureSlaveNode %2.2x\n", nodeId);
+
+	switch(step++){
+		case 1: /*First step : setup Slave's TPDO 1 to be transmitted on SYNC*/
+			eprintf("Master : set slave %2.2x TPDO 1 transmit type\n", nodeId);
+			res = writeNetworkDictCallBack (d, /*CO_Data* d*/
+					*TestSlave_Data.bDeviceNodeId, /*UNS8 nodeId*/
+					0x1800, /*UNS16 index*/
+					0x02, /*UNS8 subindex*/
+					1, /*UNS8 count*/
+					0, /*UNS8 dataType*/
+					&Transmission_Type,/*void *data*/
+					ConfigureSlaveNode); /*SDOCallback_t Callback*/			break;
+		case 2:	/*Second step*/
+			/*check and warn for previous slave OD access error*/
+			if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
+				eprintf("Master : Couldn't set slave %2.2x TPDO 1 transmit type. AbortCode :%4.4x \n", nodeId, abortCode);
+
+			/* Finalise last SDO transfer with this node */
+			closeSDOtransfer(&TestMaster_Data,
+					*TestSlave_Data.bDeviceNodeId,
+					SDO_CLIENT);
+					
+			/*Setup Slave's TPDO 1 to be transmitted on SYNC*/
+			eprintf("Master : set slave %2.2x TPDO 2 transmit type\n", nodeId);
+			writeNetworkDictCallBack (d, /*CO_Data* d*/
+					*TestSlave_Data.bDeviceNodeId, /*UNS8 nodeId*/
+					0x1801, /*UNS16 index*/
+					0x02, /*UNS16 index*/
+					1, /*UNS8 count*/
+					0, /*UNS8 dataType*/
+					&Transmission_Type,/*void *data*/
+					ConfigureSlaveNode); /*SDOCallback_t Callback*/
+			break;
+		case 3: /*Last step*/
+			/*check and warn for previous slave OD access error*/
+			if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
+				eprintf("Master : Couldn't set slave %2.2x TPDO 2 transmit type. AbortCode :%4.4x \n", nodeId, abortCode);
+
+			/* Finalise last SDO transfer with this node */
+			closeSDOtransfer(&TestMaster_Data,
+					*TestSlave_Data.bDeviceNodeId,
+					SDO_CLIENT);
+
+			/* Put the master in operational mode */
+			setState(d, Operational);
+			  
+			/* Ask slave node to go in operational mode */
+			masterSendNMTstateChange (d, nodeId, NMT_Start_Node);
+	}
+			
 }
 
 void TestMaster_preOperational()
 {
+
 	eprintf("TestMaster_preOperational\n");
+	ConfigureSlaveNode(&TestMaster_Data, 2);
+	
 }
 
 void TestMaster_operational()
--- a/examples/TestMasterSlave/TestMasterSlave.h	Thu Apr 12 16:17:35 2007 +0200
+++ b/examples/TestMasterSlave/TestMasterSlave.h	Thu Apr 12 16:20:22 2007 +0200
@@ -20,6 +20,7 @@
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 #ifdef USE_XENO
+//#define eprintf(...) if(0){}
 #define eprintf(...)
 #else
 #define eprintf(...) printf (__VA_ARGS__)
--- a/examples/TestMasterSlave/TestSlave.c	Thu Apr 12 16:17:35 2007 +0200
+++ b/examples/TestMasterSlave/TestSlave.c	Thu Apr 12 16:20:22 2007 +0200
@@ -165,7 +165,7 @@
 /* index 0x1800 :   Transmit PDO 1 Parameter. */
                     UNS8 TestSlave_highestSubIndex_obj1800 = 5; /* number of subindex - 1*/
                     UNS32 TestSlave_obj1800_COB_ID_used_by_PDO = 0x182;	/* 386 */
-                    UNS8 TestSlave_obj1800_Transmission_Type = 0x1;	/* 1 */
+                    UNS8 TestSlave_obj1800_Transmission_Type = 0x0;	/* 0 */
                     UNS16 TestSlave_obj1800_Inhibit_Time = 0x0;	/* 0 */
                     UNS16 TestSlave_obj1800_Compatibility_Entry = 0x0;	/* 0 */
                     UNS16 TestSlave_obj1800_Event_Timer = 0x0;	/* 0 */
@@ -182,7 +182,7 @@
 /* index 0x1801 :   Transmit PDO 2 Parameter. */
                     UNS8 TestSlave_highestSubIndex_obj1801 = 5; /* number of subindex - 1*/
                     UNS32 TestSlave_obj1801_COB_ID_used_by_PDO = 0x282;	/* 642 */
-                    UNS8 TestSlave_obj1801_Transmission_Type = 0x1;	/* 1 */
+                    UNS8 TestSlave_obj1801_Transmission_Type = 0x0;	/* 0 */
                     UNS16 TestSlave_obj1801_Inhibit_Time = 0x0;	/* 0 */
                     UNS16 TestSlave_obj1801_Compatibility_Entry = 0x0;	/* 0 */
                     UNS16 TestSlave_obj1801_Event_Timer = 0x0;	/* 0 */
--- a/examples/TestMasterSlave/TestSlave.od	Thu Apr 12 16:17:35 2007 +0200
+++ b/examples/TestMasterSlave/TestSlave.od	Thu Apr 12 16:20:22 2007 +0200
@@ -1,10 +1,10 @@
 <?xml version="1.0"?>
 <!DOCTYPE PyObject SYSTEM "PyObjects.dtd">
-<PyObject module="node" class="Node" id="146839660">
-<attr name="Profile" type="dict" id="146845180" >
+<PyObject module="node" class="Node" id="19120640">
+<attr name="Profile" type="dict" id="19883904" >
 </attr>
 <attr name="Name" type="string" value="TestSlave" />
-<attr name="Dictionary" type="dict" id="146301924" >
+<attr name="Dictionary" type="dict" id="19884976" >
   <entry>
     <key type="numeric" value="4096" />
     <val type="numeric" value="301" />
@@ -22,14 +22,8 @@
     <val type="numeric" value="0" />
   </entry>
   <entry>
-    <key type="numeric" value="6145" />
-    <val type="list" id="146840204" >
-      <item type="numeric" value="642" />
-      <item type="numeric" value="1" />
-      <item type="numeric" value="0" />
-      <item type="numeric" value="0" />
-      <item type="numeric" value="0" />
-    </val>
+    <key type="numeric" value="8193" />
+    <val type="numeric" value="0" />
   </entry>
   <entry>
     <key type="numeric" value="4101" />
@@ -40,22 +34,22 @@
     <val type="numeric" value="0" />
   </entry>
   <entry>
-    <key type="numeric" value="8193" />
-    <val type="numeric" value="0" />
-  </entry>
-  <entry>
-    <key type="numeric" value="6144" />
-    <val type="list" id="146840492" >
-      <item type="numeric" value="386" />
-      <item type="numeric" value="1" />
-      <item type="numeric" value="0" />
-      <item type="numeric" value="0" />
-      <item type="numeric" value="0" />
-    </val>
+    <key type="numeric" value="6145" />
+    <val type="list" id="16937976" >
+      <item type="numeric" value="642" />
+      <item type="numeric" value="0" />
+      <item type="numeric" value="0" />
+      <item type="numeric" value="0" />
+      <item type="numeric" value="0" />
+    </val>
+  </entry>
+  <entry>
+    <key type="numeric" value="4102" />
+    <val type="numeric" value="0" />
   </entry>
   <entry>
     <key type="numeric" value="4112" />
-    <val type="list" id="146839916" >
+    <val type="list" id="19124376" >
       <item type="numeric" value="0" />
       <item type="numeric" value="0" />
       <item type="numeric" value="0" />
@@ -64,58 +58,64 @@
   </entry>
   <entry>
     <key type="numeric" value="4113" />
-    <val type="list" id="146839788" >
-      <item type="numeric" value="0" />
-      <item type="numeric" value="0" />
-      <item type="numeric" value="0" />
-      <item type="numeric" value="0" />
+    <val type="list" id="19124304" >
+      <item type="numeric" value="0" />
+      <item type="numeric" value="0" />
+      <item type="numeric" value="0" />
+      <item type="numeric" value="0" />
+    </val>
+  </entry>
+  <entry>
+    <key type="numeric" value="6657" />
+    <val type="list" id="16938120" >
+      <item type="numeric" value="537001992" />
+      <item type="numeric" value="537067528" />
+    </val>
+  </entry>
+  <entry>
+    <key type="numeric" value="6656" />
+    <val type="list" id="19119784" >
+      <item type="numeric" value="536870920" />
+      <item type="numeric" value="536936456" />
     </val>
   </entry>
   <entry>
     <key type="numeric" value="4608" />
-    <val type="list" id="146839884" >
+    <val type="list" id="19124448" >
       <item type="numeric" value="1537" />
       <item type="numeric" value="1409" />
     </val>
   </entry>
   <entry>
-    <key type="numeric" value="6657" />
-    <val type="list" id="146839692" >
-      <item type="numeric" value="537001992" />
-      <item type="numeric" value="537067528" />
-    </val>
-  </entry>
-  <entry>
-    <key type="numeric" value="6656" />
-    <val type="list" id="146840428" >
-      <item type="numeric" value="536870920" />
-      <item type="numeric" value="536936456" />
-    </val>
-  </entry>
-  <entry>
     <key type="numeric" value="4119" />
     <val type="numeric" value="1000" />
   </entry>
   <entry>
     <key type="numeric" value="4120" />
-    <val type="list" id="146839980" >
-      <item type="numeric" value="0" />
-      <item type="numeric" value="0" />
-      <item type="numeric" value="0" />
-      <item type="numeric" value="0" />
-    </val>
-  </entry>
-  <entry>
-    <key type="numeric" value="4102" />
-    <val type="numeric" value="0" />
-  </entry>
-</attr>
-<attr name="SpecificMenu" type="list" id="146275244" >
-</attr>
-<attr name="ParamsDictionary" type="dict" id="146844772" >
+    <val type="list" id="19119568" >
+      <item type="numeric" value="0" />
+      <item type="numeric" value="0" />
+      <item type="numeric" value="0" />
+      <item type="numeric" value="0" />
+    </val>
+  </entry>
+  <entry>
+    <key type="numeric" value="6144" />
+    <val type="list" id="19118776" >
+      <item type="numeric" value="386" />
+      <item type="numeric" value="0" />
+      <item type="numeric" value="0" />
+      <item type="numeric" value="0" />
+      <item type="numeric" value="0" />
+    </val>
+  </entry>
+</attr>
+<attr name="SpecificMenu" type="list" id="19118704" >
+</attr>
+<attr name="ParamsDictionary" type="dict" id="19886496" >
   <entry>
     <key type="numeric" value="8192" />
-    <val type="dict" id="146846148" >
+    <val type="dict" id="19886784" >
       <entry>
         <key type="string" value="callback" />
         <val type="False" value="" />
@@ -124,7 +124,7 @@
   </entry>
   <entry>
     <key type="numeric" value="4112" />
-    <val type="dict" id="146857740" >
+    <val type="dict" id="19884192" >
       <entry>
         <key type="string" value="callback" />
         <val type="True" value="" />
@@ -133,7 +133,7 @@
   </entry>
   <entry>
     <key type="numeric" value="4113" />
-    <val type="dict" id="147802964" >
+    <val type="dict" id="19884480" >
       <entry>
         <key type="string" value="callback" />
         <val type="True" value="" />
@@ -141,18 +141,18 @@
     </val>
   </entry>
 </attr>
-<attr name="UserMapping" type="dict" id="146845876" >
+<attr name="UserMapping" type="dict" id="19890160" >
   <entry>
     <key type="numeric" value="8192" />
-    <val type="dict" id="146844636" >
+    <val type="dict" id="19890448" >
       <entry>
         <key type="string" value="need" />
         <val type="False" value="" />
       </entry>
       <entry>
         <key type="string" value="values" />
-        <val type="list" id="146840396" >
-          <item type="dict" id="146846420" >
+        <val type="list" id="19119856" >
+          <item type="dict" id="19890736" >
             <entry>
               <key type="string" value="access" />
               <val type="string" value="rw" />
@@ -184,15 +184,15 @@
   </entry>
   <entry>
     <key type="numeric" value="8193" />
-    <val type="dict" id="146845316" >
+    <val type="dict" id="19891024" >
       <entry>
         <key type="string" value="need" />
         <val type="False" value="" />
       </entry>
       <entry>
         <key type="string" value="values" />
-        <val type="list" id="146840268" >
-          <item type="dict" id="146846692" >
+        <val type="list" id="19124664" >
+          <item type="dict" id="19891312" >
             <entry>
               <key type="string" value="access" />
               <val type="string" value="rw" />
@@ -224,15 +224,15 @@
   </entry>
   <entry>
     <key type="numeric" value="8194" />
-    <val type="dict" id="146845740" >
+    <val type="dict" id="19891600" >
       <entry>
         <key type="string" value="need" />
         <val type="False" value="" />
       </entry>
       <entry>
         <key type="string" value="values" />
-        <val type="list" id="146840908" >
-          <item type="dict" id="146846964" >
+        <val type="list" id="19120072" >
+          <item type="dict" id="19891888" >
             <entry>
               <key type="string" value="access" />
               <val type="string" value="rw" />
@@ -264,15 +264,15 @@
   </entry>
   <entry>
     <key type="numeric" value="8195" />
-    <val type="dict" id="146845044" >
+    <val type="dict" id="19892224" >
       <entry>
         <key type="string" value="need" />
         <val type="False" value="" />
       </entry>
       <entry>
         <key type="string" value="values" />
-        <val type="list" id="146840108" >
-          <item type="dict" id="146847236" >
+        <val type="list" id="19124592" >
+          <item type="dict" id="19892512" >
             <entry>
               <key type="string" value="access" />
               <val type="string" value="rw" />
@@ -303,7 +303,7 @@
     </val>
   </entry>
 </attr>
-<attr name="DS302" type="dict" id="146846012" >
+<attr name="DS302" type="dict" id="19893632" >
 </attr>
 <attr name="ProfileName" type="string" value="DS-301" />
 <attr name="Type" type="string" value="slave" />
--- a/src/sdo.c	Thu Apr 12 16:17:35 2007 +0200
+++ b/src/sdo.c	Thu Apr 12 16:20:22 2007 +0200
@@ -978,7 +978,7 @@
 	failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
 	return 0xFF;
       }
-      /* Reset the wathdog */
+      /* Reset the watchdog */
       RestartSDO_TIMER(line)
       index = d->transfers[line].index;
       subIndex = d->transfers[line].subIndex;
@@ -1154,7 +1154,9 @@
   sdo.body.data[1] = index & 0xFF;        /* LSB */
   sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */
   sdo.body.data[3] = subIndex;
-  
+
+  d->transfers[line].Callback = Callback;
+    
   err = sendSDO(d, SDO_CLIENT, sdo);
   if (err) {
     MSG_ERR(0x1AD1, "SDO. Error while sending SDO to node : ", nodeId);
@@ -1162,7 +1164,8 @@
     resetSDOline(d, line);
     return 0xFF;
   }
-  d->transfers[line].Callback = Callback;
+
+  
   return 0;
 }
 
@@ -1255,6 +1258,7 @@
   sdo.body.data[3] = subIndex;
   for (i = 4 ; i < 8 ; i++)
     sdo.body.data[i] = 0;
+  d->transfers[line].Callback = Callback;
   err = sendSDO(d, SDO_CLIENT, sdo);
   if (err) {
     MSG_ERR(0x1AE5, "SDO. Error while sending SDO to node : ", nodeId);
@@ -1262,7 +1266,6 @@
     resetSDOline(d, line);
     return 0xFF;
   }		
-  d->transfers[line].Callback = Callback;
   return 0;
 }