]> rtime.felk.cvut.cz Git - CanFestival-3.git/blobdiff - src/sdo.c
Changed getReadResultNetworkDict behaviour about size. Do not copy more data than...
[CanFestival-3.git] / src / sdo.c
index 8d277556dd7a6494e57a71c42900c12741004509..827bfccb0fd29e11c36ed915cd29b76c3989e226 100644 (file)
--- a/src/sdo.c
+++ b/src/sdo.c
@@ -32,9 +32,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 /* #define DEBUG_WAR_CONSOLE_ON */
 /* #define DEBUG_ERR_CONSOLE_ON */
 
-#include "objacces.h"
-#include "sdo.h"
 #include "canfestival.h"
+#include "sysdep.h"
 
 /* Uncomment if your compiler does not support inline functions */
 #define NO_INLINE 
@@ -218,22 +217,14 @@ UNS32 objdictToSDOline (CO_Data* d, UNS8 line)
   errorCode = getODentry(d,    d->transfers[line].index,
                                d->transfers[line].subIndex,
                                (void *)d->transfers[line].data,
-                               &size, &dataType, 0);
+                               &size, &dataType, 1);
   
   if (errorCode != OD_SUCCESSFUL)
     return errorCode;
 
   d->transfers[line].count = size;
   d->transfers[line].offset = 0;
-#if 0
-   /*Me laisser a, please ! (FD)*/
-  {
-    UNS8 i;
-    for (i = 0 ; i < 10 ; i++) {
-      MSG_WAR(i, "data= ", d->transfers[line].data[i]);
-    }     
-  }
-#endif
+
   return 0;
 }
 
@@ -512,7 +503,7 @@ UNS8 sendSDO (CO_Data* d, UNS8 whoami, s_SDO sdo)
   }                            
 
   /*get the server->client cobid*/
-  if ( whoami == SDO_SERVER )  {/*case server. Easy because today only one server SDO is authorized in CanFestival*/
+  if ( whoami == SDO_SERVER )  {/*case server. only one SDO server*/
     offset = d->firstIndex->SDO_SVR;
     if (offset == 0) {
       MSG_ERR(0x1A42, "SendSDO : No SDO server found", 0); 
@@ -530,7 +521,7 @@ UNS8 sendSDO (CO_Data* d, UNS8 whoami, s_SDO sdo)
       MSG_ERR(0x1A42, "SendSDO : No SDO client index found", 0); 
       return 0xFF;
     }
-    /* First, have to find at the index where is defined the communication with the server node */
+    /* find index for communication server node */
     while (offset <= lastIndex){
       MSG_WAR(0x3A43,"Reading index : ", 0x1280 + sdoNum);
       if (d->objdict[offset].bSubCount <= 3) {
@@ -550,11 +541,11 @@ UNS8 sendSDO (CO_Data* d, UNS8 whoami, s_SDO sdo)
       MSG_WAR (0x2A45, "No SDO client corresponds to the mesage to send to node ", sdo.nodeId);
       return 0xFF;
     }
-    /* Second, read the cobid client->server */
+    /* read the client->server cobid */
     pwCobId = (UNS32*) d->objdict[offset].pSubindex[1].pObject;
   }
   /* message copy for sending */
-  m.cob_id.w = *pwCobId;
+  m.cob_id = UNS16_LE(*pwCobId);
   m.rtr = NOT_A_REQUEST; 
   /* the length of SDO must be 8 */
   m.len = 8;
@@ -611,8 +602,7 @@ UNS8 proceedSDO (CO_Data* d, Message *m)
   UNS8 line;
   UNS8 nbBytes; /* received or to be transmited. */
   UNS8 nodeId = 0;  /* The node from which the SDO is received */
-  UNS32 nodeId_32; /* node id in 32 bits, for temporary use */
-  UNS32 *pNodeId = NULL;
+  UNS8 *pNodeId = NULL;
   UNS8 whoami = SDO_UNKNOWN;  /* SDO_SERVER or SDO_CLIENT.*/
   UNS32 errorCode; /* while reading or writing in the local object dictionary.*/
   s_SDO sdo;    /* SDO to transmit */
@@ -620,7 +610,7 @@ UNS8 proceedSDO (CO_Data* d, Message *m)
   UNS8 subIndex;
   UNS32 abortCode;
   UNS8 i,j;
-  UNS32 *     pCobId = NULL;
+  UNS32 *pCobId = NULL;
   UNS16 offset;
   UNS16 lastIndex;
 
@@ -637,7 +627,7 @@ UNS8 proceedSDO (CO_Data* d, Message *m)
          return 0xFF;
        }
       pCobId = (UNS32*) d->objdict[offset].pSubindex[1].pObject;
-      if ( *pCobId == (*m).cob_id.w ) {
+      if ( *pCobId == UNS16_LE(m->cob_id) ) {
        whoami = SDO_SERVER;
        MSG_WAR(0x3A62, "proceedSDO. I am server. index : ", 0x1200 + j);
        /* In case of server, the node id of the client may be unknown. So we put the index minus offset */
@@ -660,12 +650,11 @@ UNS8 proceedSDO (CO_Data* d, Message *m)
        }
        /* a) Looking for the cobid received. */
        pCobId = (UNS32*) d->objdict[offset].pSubindex[2].pObject;
-       if (*pCobId == (*m).cob_id.w ) {
+       if (*pCobId == UNS16_LE(m->cob_id) ) {
         /* b) cobid found, so reading the node id of the server. */
-        pNodeId = (UNS32*) d->objdict[offset].pSubindex[3].pObject;
+        pNodeId = (UNS8*) d->objdict[offset].pSubindex[3].pObject;
         whoami = SDO_CLIENT;
-        nodeId_32 = *pNodeId;
-        nodeId = (UNS8)nodeId_32;
+        nodeId = *pNodeId;
         MSG_WAR(0x3A64, "proceedSDO. I am server. index : ", 0x1280 + j);
         MSG_WAR(0x3A65, "                 Server nodeId : ", nodeId);
         break;
@@ -680,7 +669,7 @@ UNS8 proceedSDO (CO_Data* d, Message *m)
 
   /* Test if the size of the SDO is ok */
   if ( (*m).len != 8) {
-    MSG_ERR(0x1A67, "Error size SDO. CobId  : ", (*m).cob_id.w);
+    MSG_ERR(0x1A67, "Error size SDO. CobId  : ", UNS16_LE(m->cob_id));
     failedSDO(d, nodeId, whoami, 0, 0, SDOABT_GENERAL_ERROR);
     return 0xFF;
   }
@@ -689,7 +678,7 @@ UNS8 proceedSDO (CO_Data* d, Message *m)
     MSG_WAR(0x3A68, "I am CLIENT. Received SDO from nodeId : ", nodeId);
   }
   else {
-    MSG_WAR(0x3A69, "I am SERVER. Received SDO cobId : ", (*m).cob_id.w);
+    MSG_WAR(0x3A69, "I am SERVER. Received SDO cobId : ", UNS16_LE(m->cob_id));
   }
     
   /* Testing the command specifier */
@@ -1189,7 +1178,8 @@ UNS8 proceedSDO (CO_Data* d, Message *m)
     break;  
 
    case 4:
-     abortCode = (*m).data[3] |
+     abortCode = 
+      (UNS32)m->data[4] |
       ((UNS32)m->data[5] << 8) |
       ((UNS32)m->data[6] << 16) |
       ((UNS32)m->data[7] << 24);
@@ -1254,8 +1244,8 @@ INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
   UNS8 i, j;
   UNS16     lastIndex;
   UNS16     offset;
-  UNS32      *pNodeIdServer;
-  UNS32      nodeIdServer;
+  UNS8      *pNodeIdServer;
+  UNS8      nodeIdServer;
 
   MSG_WAR(0x3AC0, "Send SDO to write in the dictionary of node : ", nodeId);
   MSG_WAR(0x3AC1, "                                   At index : ", index);
@@ -1288,12 +1278,12 @@ INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
         return 0xFF;
      }
      /* looking for the nodeId server */
-     pNodeIdServer = (UNS32*) d->objdict[offset].pSubindex[3].pObject;
+     pNodeIdServer = (UNS8*) d->objdict[offset].pSubindex[3].pObject;
      nodeIdServer = *pNodeIdServer;
      MSG_WAR(0x1AD2, "index : ", 0x1280 + i);
      MSG_WAR(0x1AD3, "nodeIdServer : ", nodeIdServer);
    
-    if(nodeIdServer == (UNS32)nodeId) {
+    if(nodeIdServer == nodeId) {
       SDOfound = 1;
       break;
     }
@@ -1410,8 +1400,8 @@ INLINE UNS8 _readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subInde
   UNS8 i;
   UNS8 line;
   s_SDO sdo;    /* SDO to transmit */
-  UNS32      *pNodeIdServer;
-  UNS32      nodeIdServer;
+  UNS8      *pNodeIdServer;
+  UNS8      nodeIdServer;
   UNS16     offset;
   UNS16     lastIndex;
   MSG_WAR(0x3AD5, "Send SDO to read in the dictionary of node : ", nodeId);
@@ -1448,10 +1438,10 @@ INLINE UNS8 _readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subInde
         return 0xFF;
      }
      /* looking for the nodeId server */
-     pNodeIdServer = (UNS32*) d->objdict[offset].pSubindex[3].pObject;
+     pNodeIdServer = (UNS8*) d->objdict[offset].pSubindex[3].pObject;
      nodeIdServer = *pNodeIdServer;
    
-    if(nodeIdServer == (UNS32)nodeId) {
+    if(nodeIdServer == nodeId) {
       SDOfound = 1;
       break;
     }
@@ -1519,15 +1509,15 @@ UNS8 readNetworkDictCallback (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subInde
 }
 
 /*!                                                                                                
-**                                                                                                 
-**                                                                                                 
-** @param d                                                                                        
-** @param nodeId                                                                                   
-** @param data                                                                                     
-** @param size                                                                                     
-** @param abortCode                                                                                
-**                                                                                                 
-** @return                                                                                         
+**
+**
+** @param d
+** @param nodeId
+** @param data
+** @param size pointer to expected size, changed into returned size. Expected size will be truncated to transfered data size 
+** @param abortCode
+**
+** @return
 **/   
 UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data, UNS8 *size, 
                               UNS32 * abortCode)
@@ -1547,7 +1537,9 @@ UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data, UNS8 *size,
     return d->transfers[line].state;
 
   /* Transfert is finished. Put the value in the data. */
-  * size = (UNS8)d->transfers[line].count;
+  /* use transfers[line].count as max size */
+  if( (UNS8)d->transfers[line].count < *size )
+       *size = (UNS8)d->transfers[line].count;
   for  ( i = 0 ; i < *size ; i++) {
 # ifdef CANOPEN_BIG_ENDIAN
     if (d->transfers[line].dataType != visible_string)