Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
authoretisserant
Tue, 17 Mar 2009 00:03:18 +0100
changeset 539 187058b4a4b8
parent 538 49f6d796b692
child 540 6857b6ffb7a7
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
include/objacces.h
include/objdictdef.h
include/sdo.h
src/objacces.c
src/pdo.c
src/sdo.c
--- a/include/objacces.h	Mon Mar 16 23:04:39 2009 +0100
+++ b/include/objacces.h	Tue Mar 17 00:03:18 2009 +0100
@@ -64,7 +64,7 @@
  * @return
  */ 
 UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex, 
-			   UNS8 sizeDataDict, UNS8 sizeDataGiven, UNS32 code);
+			   UNS32 sizeDataDict, UNS32 sizeDataGiven, UNS32 code);
 
 
 /* _getODentry() Reads an entry from the object dictionary.\n
@@ -108,7 +108,7 @@
 		  UNS16 wIndex,
 		  UNS8 bSubindex,
 		  void * pDestData,
-		  UNS8 * pExpectedSize,
+		  UNS32 * pExpectedSize,
 		  UNS8 * pDataType,
 		  UNS8 checkAccess,
 		  UNS8 endianize);
@@ -188,7 +188,7 @@
                    UNS16 wIndex,
                    UNS8 bSubindex,
                    void * pSourceData,
-                   UNS8 * pExpectedSize,
+                   UNS32 * pExpectedSize,
                    UNS8 checkAccess,
                    UNS8 endianize);
 
--- a/include/objdictdef.h	Mon Mar 16 23:04:39 2009 +0100
+++ b/include/objdictdef.h	Tue Mar 17 00:03:18 2009 +0100
@@ -85,7 +85,7 @@
 {
     UNS8                    bAccessType;
     UNS8                    bDataType; /* Defines of what datatype the entry is */
-    UNS8                    size;      /* The size (in Byte) of the variable */
+    UNS32                   size;      /* The size (in Byte) of the variable */
     void*                   pObject;   /* This is the pointer of the Variable */
 } subindex;
 
--- a/include/sdo.h	Mon Mar 16 23:04:39 2009 +0100
+++ b/include/sdo.h	Tue Mar 17 00:03:18 2009 +0100
@@ -135,7 +135,7 @@
  * @param *data Pointer on the data
  * @return 0xFF if error. Else, returns 0.
  */
-UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8 * data);
+UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS32 nbBytes, UNS8 * data);
 
 /** 
  * @brief Add data to an existant line
@@ -145,7 +145,7 @@
  * @param *data Pointer on the data
  * @return 0xFF if error. Else, returns 0.
  */
-UNS8 SDOtoLine (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8 * data);
+UNS8 SDOtoLine (CO_Data* d, UNS8 line, UNS32 nbBytes, UNS8 * data);
 
 /** 
  * @brief Called when an internal SDO abort occurs.
@@ -224,7 +224,7 @@
  * @param *nbBytes Pointer on nbBytes
  * @return 0.
  */
-UNS8 getSDOlineRestBytes (CO_Data* d, UNS8 line, UNS8 * nbBytes);
+UNS8 getSDOlineRestBytes (CO_Data* d, UNS8 line, UNS32 * nbBytes);
 
 /** 
  * @brief Store in the line structure the nb of bytes which must be transmited (or received)
@@ -234,7 +234,7 @@
  * @param nbBytes
  * @return 0 if success, 0xFF if error.
  */
-UNS8 setSDOlineRestBytes (CO_Data* d, UNS8 line, UNS8 nbBytes);
+UNS8 setSDOlineRestBytes (CO_Data* d, UNS8 line, UNS32 nbBytes);
 
 /**
  * @brief Transmit a SDO frame on the bus bus_id
@@ -290,7 +290,7 @@
  * @return 0xFF if error, else return 0
  */
 UNS8 writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
-		       UNS8 subIndex, UNS8 count, UNS8 dataType, void *data);
+		       UNS8 subIndex, UNS32 count, UNS8 dataType, void *data);
 
 /** 
  * @ingroup sdo
@@ -308,7 +308,7 @@
  * @return 0xFF if error, else return 0
  */
 UNS8 writeNetworkDictCallBack (CO_Data* d, UNS8 nodeId, UNS16 index,
-		       UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback);
+		       UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback);
 
 /**
  * @ingroup sdo 
@@ -330,7 +330,7 @@
  * @return 0xFF if error, else return 0
  */
 UNS8 writeNetworkDictCallBackAI (CO_Data* d, UNS8 nodeId, UNS16 index,
-		       UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize);
+		       UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize);
 
 /**
  * @ingroup sdo 
@@ -399,7 +399,7 @@
  * while (getReadResultNetworkDict (0, 0x05, &data, &size) != SDO_UPLOAD_IN_PROGRESS);
  * @endcode
 */
-UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data, UNS8 *size, UNS32 * abortCode);
+UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data, UNS32 *size, UNS32 * abortCode);
 
 /**
  * @brief Use this function after a writeNetworkDict to get the result of the write
--- a/src/objacces.c	Mon Mar 16 23:04:39 2009 +0100
+++ b/src/objacces.c	Tue Mar 17 00:03:18 2009 +0100
@@ -54,7 +54,7 @@
 **/
 #ifdef DEBUG_WAR_CONSOLE_ON
 UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex,
-                           UNS8 sizeDataDict, UNS8 sizeDataGiven, UNS32 code)
+                           UNS32 sizeDataDict, UNS32 sizeDataGiven, UNS32 code)
 {
   MSG_WAR(0x2B09,"Dictionary index : ", index);
   MSG_WAR(0X2B10,"           subindex : ", subIndex);
@@ -108,14 +108,14 @@
                    UNS16 wIndex,
                    UNS8 bSubindex,
                    void * pDestData,
-                   UNS8 * pExpectedSize,
+                   UNS32 * pExpectedSize,
                    UNS8 * pDataType,
                    UNS8 checkAccess,
                    UNS8 endianize)
 { /* DO NOT USE MSG_ERR because the macro may send a PDO -> infinite
     loop if it fails. */
   UNS32 errorCode;
-  UNS8 szData;
+  UNS32 szData;
   const indextable *ptrTable;
   ODCallback_t *Callback;
 
@@ -211,11 +211,11 @@
                    UNS16 wIndex,
                    UNS8 bSubindex,
                    void * pSourceData,
-                   UNS8 * pExpectedSize,
+                   UNS32 * pExpectedSize,
                    UNS8 checkAccess,
                    UNS8 endianize)
 {
-  UNS8 szData;
+  UNS32 szData;
   UNS8 dataType;
   UNS32 errorCode;
   const indextable *ptrTable;
--- a/src/pdo.c	Mon Mar 16 23:04:39 2009 +0100
+++ b/src/pdo.c	Tue Mar 17 00:03:18 2009 +0100
@@ -71,12 +71,12 @@
       UNS32 *pMappingParameter =
         (UNS32 *) TPDO_map->pSubindex[prp_j + 1].pObject;
       UNS16 index = (UNS16) ((*pMappingParameter) >> 16);
-      UNS8 Size = (UNS8) (*pMappingParameter & (UNS32) 0x000000FF);     /* Size in bits */
+      UNS32 Size = (UNS32) (*pMappingParameter & (UNS32) 0x000000FF);     /* Size in bits */
 
       /* get variable only if Size != 0 and Size is lower than remaining bits in the PDO */
       if (Size && ((offset + Size) <= 64))
         {
-          UNS8 ByteSize = 1 + ((Size - 1) >> 3);        /*1->8 => 1 ; 9->16 => 2, ... */
+          UNS32 ByteSize = 1 + ((Size - 1) >> 3);        /*1->8 => 1 ; 9->16 => 2, ... */
           UNS8 subIndex =
             (UNS8) (((*pMappingParameter) >> (UNS8) 8) & (UNS32) 0x000000FF);
 
@@ -241,7 +241,7 @@
                 while (numMap < *pMappingCount)
                   {
                     UNS8 tmp[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
-                    UNS8 ByteSize;
+                    UNS32 ByteSize;
                     pMappingParameter =
                       (UNS32 *) (d->objdict + offsetObjdict +
                                  numPdo)->pSubindex[numMap + 1].pObject;
@@ -268,7 +268,7 @@
                         CopyBits (Size, (UNS8 *) & m->data[offset >> 3],
                                   offset % 8, 0, ((UNS8 *) tmp), 0, 0);
                         /*1->8 => 1 ; 9->16 =>2, ... */
-                        ByteSize = 1 + ((Size - 1) >> 3);
+                        ByteSize = (UNS32)(1 + ((Size - 1) >> 3));
 
                         objDict =
                           setODentry (d, (UNS16) ((*pMappingParameter) >> 16),
--- a/src/sdo.c	Mon Mar 16 23:04:39 2009 +0100
+++ b/src/sdo.c	Tue Mar 17 00:03:18 2009 +0100
@@ -62,7 +62,7 @@
 ** @return
 **/
 INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
-		       UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize);
+		       UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize);
 
 /*!
 ** Called by readNetworkDict
@@ -184,10 +184,10 @@
 **/
 UNS32 SDOlineToObjdict (CO_Data* d, UNS8 line)
 {
-  UNS8      size;
+  UNS32 size;
   UNS32 errorCode;
   MSG_WAR(0x3A08, "Enter in SDOlineToObjdict ", line);
-  size = (UNS8)d->transfers[line].count;
+  size = d->transfers[line].count;
   errorCode = setODentry(d, d->transfers[line].index, d->transfers[line].subIndex,
 			 (void *) d->transfers[line].data, &size, 1);
   if (errorCode != OD_SUCCESSFUL)
@@ -207,7 +207,7 @@
 **/
 UNS32 objdictToSDOline (CO_Data* d, UNS8 line)
 {
-  UNS8  size = 0;
+  UNS32  size = 0;
   UNS8  dataType;
   UNS32 errorCode;
 
@@ -238,9 +238,9 @@
 **
 ** @return
 **/
-UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8* data) {
+UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS32 nbBytes, UNS8* data) {
   UNS8 i;
-  UNS8 offset;
+  UNS32 offset;
 
   if ((d->transfers[line].offset + nbBytes) > SDO_MAX_LENGTH_TRANSFERT) {
     MSG_ERR(0x1A10,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFERT", nbBytes);
@@ -250,7 +250,7 @@
     MSG_ERR(0x1A11,"SDO Size of data too large. Exceed count", nbBytes);
     return 0xFF;
   }
-  offset = (UNS8)d->transfers[line].offset;
+  offset = d->transfers[line].offset;
   for (i = 0 ; i < nbBytes ; i++)
     * (data + i) = d->transfers[line].data[offset + i];
   d->transfers[line].offset = d->transfers[line].offset + nbBytes;
@@ -267,19 +267,21 @@
 **
 ** @return
 **/
-UNS8 SDOtoLine (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8* data)
+UNS8 SDOtoLine (CO_Data* d, UNS8 line, UNS32 nbBytes, UNS8* data)
 {
   UNS8 i;
-  UNS8 offset;
+  UNS32 offset;
 
   if ((d->transfers[line].offset + nbBytes) > SDO_MAX_LENGTH_TRANSFERT) {
     MSG_ERR(0x1A15,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFERT", nbBytes);
     return 0xFF;
   }
-  offset = (UNS8)d->transfers[line].offset;
+  offset = d->transfers[line].offset;
   for (i = 0 ; i < nbBytes ; i++)
     d->transfers[line].data[offset + i] = * (data + i);
   d->transfers[line].offset = d->transfers[line].offset + nbBytes;
+  d->transfers[line].count = d->transfers[line].offset; 
+  
   return 0;
 }
 
@@ -328,7 +330,7 @@
 **/
 void resetSDOline ( CO_Data* d, UNS8 line )
 {
-  UNS8 i;
+  UNS32 i;
   MSG_WAR(0x3A25, "reset SDO line nb : ", line);
   initSDOline(d, line, 0, 0, 0, SDO_RESET);
   for (i = 0 ; i < SDO_MAX_LENGTH_TRANSFERT ; i++)
@@ -451,12 +453,13 @@
 **
 ** @return
 **/
-UNS8 getSDOlineRestBytes (CO_Data* d, UNS8 line, UNS8 * nbBytes)
+UNS8 getSDOlineRestBytes (CO_Data* d, UNS8 line, UNS32 * nbBytes)
 {
   if (d->transfers[line].count == 0) /* if received initiate SDO protocol with e=0 and s=0 */
     * nbBytes = 0;
   else
-    * nbBytes = (UNS8)d->transfers[line].count - (UNS8)d->transfers[line].offset;
+    * nbBytes = d->transfers[line].count - d->transfers[line].offset;
+  
   return 0;
 }
 
@@ -469,7 +472,7 @@
 **
 ** @return
 **/
-UNS8 setSDOlineRestBytes (CO_Data* d, UNS8 line, UNS8 nbBytes)
+UNS8 setSDOlineRestBytes (CO_Data* d, UNS8 line, UNS32 nbBytes)
 {
   if (nbBytes > SDO_MAX_LENGTH_TRANSFERT) {
     MSG_ERR(0x1A35,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFERT", nbBytes);
@@ -613,7 +616,7 @@
 {
   UNS8 err;
   UNS8 line;
-  UNS8 nbBytes; /* received or to be transmited. */
+  UNS32 nbBytes; /* received or to be transmited. */
   UNS8 nodeId = 0;  /* The node from which the SDO is received */
   UNS8 *pNodeId = NULL;
   UNS8 whoami = SDO_UNKNOWN;  /* SDO_SERVER or SDO_CLIENT.*/
@@ -864,8 +867,7 @@
       }
       else {/* So, if it is not an expedited transfert */
 	if (getSDOs(m->data[0])) {
-	  /* TODO : if e and s = 0, not reading m->data[4] but put nbBytes = 0 */
-	  nbBytes = m->data[4]; /* Transfert limited to 255 bytes. */
+	  nbBytes = 0; 
 	  err = setSDOlineRestBytes(d, nodeId, nbBytes);
 	  if (err) {
 	    failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
@@ -1248,13 +1250,14 @@
 ** @return
 **/
 INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
-		       UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize)
+		       UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize)
 {
   UNS8 err;
   UNS8 SDOfound = 0;
   UNS8 line;
   s_SDO sdo;    /* SDO to transmit */
-  UNS8 i, j;
+  UNS8 i;
+  UNS32 j;
   UNS16     lastIndex;
   UNS16     offset;
   UNS8      *pNodeIdServer;
@@ -1333,9 +1336,8 @@
   }
   else { /** Normal transfert */
     sdo.body.data[0] = (1 << 5) | 1;
-    sdo.body.data[4] = count; /* nb of byte to transmit. Max = 255. (canfestival2 limitation). */
-    for (i = 5 ; i < 8 ; i++)
-      sdo.body.data[i] = 0;
+    for (i = 4 ; i < 8 ; i++)
+      sdo.body.data[i] = 0;   
   }
   sdo.body.data[1] = index & 0xFF;        /* LSB */
   sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */
@@ -1369,7 +1371,7 @@
 ** @return
 **/
 UNS8 writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
-		       UNS8 subIndex, UNS8 count, UNS8 dataType, void *data)
+		       UNS8 subIndex, UNS32 count, UNS8 dataType, void *data)
 {
 	return _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, NULL, 1);
 }
@@ -1389,13 +1391,13 @@
 ** @return
 **/
 UNS8 writeNetworkDictCallBack (CO_Data* d, UNS8 nodeId, UNS16 index,
-		       UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback)
+		       UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback)
 {
 	return _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, Callback, 1);
 }
 
 UNS8 writeNetworkDictCallBackAI (CO_Data* d, UNS8 nodeId, UNS16 index,
-		       UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize)
+		       UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize)
 {
 	UNS8 ret;
 	UNS16 lastIndex;
@@ -1629,10 +1631,10 @@
 **
 ** @return
 **/
-UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data, UNS8 *size,
+UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data, UNS32 *size,
 			       UNS32 * abortCode)
 {
-  UNS8 i;
+  UNS32 i;
   UNS8 err;
   UNS8 line;
   * abortCode = 0;
@@ -1649,8 +1651,8 @@
 
   /* Transfert is finished. Put the value in the data. */
   /* use transfers[line].count as max size */
-  if( (UNS8)d->transfers[line].count < *size )
-  	*size = (UNS8)d->transfers[line].count;
+  if( d->transfers[line].count < *size )
+  	*size = d->transfers[line].count;
   for  ( i = 0 ; i < *size ; i++) {
 # ifdef CANOPEN_BIG_ENDIAN
     if (d->transfers[line].dataType != visible_string)