From: etisserant Date: Mon, 16 Mar 2009 23:03:18 +0000 (+0000) Subject: Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks... X-Git-Url: https://rtime.felk.cvut.cz/gitweb/CanFestival-3.git/commitdiff_plain/0e25f80fdbaef8b9216bf835839882ee8506a491?hp=c07f592be87c3ec4758208aab6dd342789776b97 Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch. --- diff --git a/include/objacces.h b/include/objacces.h index e819f29..b5ee04a 100644 --- a/include/objacces.h +++ b/include/objacces.h @@ -64,7 +64,7 @@ void _storeODSubIndex (CO_Data* d, UNS16 wIndex, UNS8 bSubindex); * @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 @@ UNS32 _getODentry( CO_Data* d, UNS16 wIndex, UNS8 bSubindex, void * pDestData, - UNS8 * pExpectedSize, + UNS32 * pExpectedSize, UNS8 * pDataType, UNS8 checkAccess, UNS8 endianize); @@ -188,7 +188,7 @@ UNS32 _setODentry( CO_Data* d, UNS16 wIndex, UNS8 bSubindex, void * pSourceData, - UNS8 * pExpectedSize, + UNS32 * pExpectedSize, UNS8 checkAccess, UNS8 endianize); diff --git a/include/objdictdef.h b/include/objdictdef.h index 8361ee6..60948b8 100644 --- a/include/objdictdef.h +++ b/include/objdictdef.h @@ -85,7 +85,7 @@ typedef struct td_subindex { 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; diff --git a/include/sdo.h b/include/sdo.h index 96245c7..b8dd7d3 100644 --- a/include/sdo.h +++ b/include/sdo.h @@ -135,7 +135,7 @@ UNS32 objdictToSDOline (CO_Data* d, UNS8 line); * @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 @@ UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8 * data); * @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 @@ UNS8 closeSDOtransfer (CO_Data* d, UNS8 nodeId, UNS8 whoami); * @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 @@ UNS8 getSDOlineRestBytes (CO_Data* d, UNS8 line, UNS8 * nbBytes); * @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 @@ UNS8 proceedSDO (CO_Data* d, Message *m); * @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 @@ UNS8 writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, * @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 @@ UNS8 writeNetworkDictCallBack (CO_Data* d, UNS8 nodeId, UNS16 index, * @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 @@ UNS8 readNetworkDictCallbackAI (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIn * 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 diff --git a/src/objacces.c b/src/objacces.c index 1ab03bd..8e6a897 100644 --- a/src/objacces.c +++ b/src/objacces.c @@ -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 @@ UNS32 _getODentry( CO_Data* d, 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 @@ UNS32 _setODentry( CO_Data* d, 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; diff --git a/src/pdo.c b/src/pdo.c index 457c495..7618266 100644 --- a/src/pdo.c +++ b/src/pdo.c @@ -71,12 +71,12 @@ UNS8 buildPDO (CO_Data * d, UNS8 numPdo, Message * pdo) 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 @@ proceedPDO (CO_Data * d, Message * m) 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 @@ proceedPDO (CO_Data * d, Message * m) 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), diff --git a/src/sdo.c b/src/sdo.c index 8edf5be..b4e0e01 100644 --- a/src/sdo.c +++ b/src/sdo.c @@ -62,7 +62,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** @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 @@ void resetSDO (CO_Data* d) **/ 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 SDOlineToObjdict (CO_Data* d, UNS8 line) **/ UNS32 objdictToSDOline (CO_Data* d, UNS8 line) { - UNS8 size = 0; + UNS32 size = 0; UNS8 dataType; UNS32 errorCode; @@ -238,9 +238,9 @@ UNS32 objdictToSDOline (CO_Data* d, UNS8 line) ** ** @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 @@ UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8* data) { 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 @@ UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8* data) { ** ** @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 @@ UNS8 failedSDO (CO_Data* d, UNS8 nodeId, UNS8 whoami, UNS16 index, **/ 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 @@ UNS8 closeSDOtransfer (CO_Data* d, UNS8 nodeId, UNS8 whoami) ** ** @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 @@ UNS8 getSDOlineRestBytes (CO_Data* d, UNS8 line, UNS8 * nbBytes) ** ** @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 proceedSDO (CO_Data* d, Message *m) { 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 @@ UNS8 proceedSDO (CO_Data* d, Message *m) } 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 @@ UNS8 proceedSDO (CO_Data* d, Message *m) ** @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 @@ INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, } 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 @@ INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, ** @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 @@ UNS8 writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, ** @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 @@ UNS8 readNetworkDictCallbackAI (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIn ** ** @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 @@ UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data, UNS8 *size, /* 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)