src/objacces.c
changeset 2 8d4a822f95e4
parent 1 b3dc740b4b04
child 8 eee2b0c89213
equal deleted inserted replaced
1:b3dc740b4b04 2:8d4a822f95e4
    96   if(	*pExpectedSize == 0 ||
    96   if(	*pExpectedSize == 0 ||
    97   	*pExpectedSize == szData ||
    97   	*pExpectedSize == szData ||
    98   	(*pDataType == visible_string && *pExpectedSize > szData)) // We allow to fetch a shorter string than expected
    98   	(*pDataType == visible_string && *pExpectedSize > szData)) // We allow to fetch a shorter string than expected
    99   {
    99   {
   100 	#ifdef CANOPEN_BIG_ENDIAN
   100 	#ifdef CANOPEN_BIG_ENDIAN
       
   101 	      if(*pDataType > boolean && dataType < visible_string){
   101 	      {
   102 	      {
   102 		// data must be transmited with low byte first
   103 		// data must be transmited with low byte first
   103 		UNS8 i, j = 0;
   104 		UNS8 i, j = 0;
   104 		for ( i = ptrTable->pSubindex[bSubindex].size ; i > 0 ; i--) {
   105 		for ( i = ptrTable->pSubindex[bSubindex].size ; i > 0 ; i--) {
   105 			((char*)pDestData)[j++] = ((char*)ptrTable->pSubindex[bSubindex].pObject)[i-1];
   106 			((char*)pDestData)[j++] = ((char*)ptrTable->pSubindex[bSubindex].pObject)[i-1];
   151 
   152 
   152   if( *pExpectedSize == 0 ||
   153   if( *pExpectedSize == 0 ||
   153   	*pExpectedSize == szData ||
   154   	*pExpectedSize == szData ||
   154   	(dataType == visible_string && *pExpectedSize < szData)) // We allow to store a shorter string than entry size
   155   	(dataType == visible_string && *pExpectedSize < szData)) // We allow to store a shorter string than entry size
   155   {
   156   {
       
   157       #ifdef CANOPEN_BIG_ENDIAN
       
   158 	      if(dataType > boolean && dataType < visible_string){
       
   159 		// we invert the data source directly. This let us do range testing without
       
   160 		// additional temp variable
       
   161 		UNS8 i, j = 0;
       
   162 		for ( i = ptrTable->pSubindex[bSubindex].size >> 1 ; i > 0 ; i--) {
       
   163 			char tmp = ((char*)pSourceData)[i - 1];
       
   164 			((char*)pSourceData)[i - 1] = ((char*)pSourceData)[j];
       
   165 			((char*)pSourceData)[j++] = tmp;
       
   166 		}
       
   167 	      }
       
   168       #endif
   156       errorCode = (*d->valueRangeTest)(dataType, pSourceData);
   169       errorCode = (*d->valueRangeTest)(dataType, pSourceData);
   157       if (errorCode) {
   170       if (errorCode) {
   158 	accessDictionaryError(wIndex, bSubindex, szData, *pExpectedSize, errorCode);
   171 	accessDictionaryError(wIndex, bSubindex, szData, *pExpectedSize, errorCode);
   159 	return errorCode;
   172 	return errorCode;
   160       }
   173       }
   161       #ifdef CANOPEN_BIG_ENDIAN
   174       memcpy(ptrTable->pSubindex[bSubindex].pObject,pSourceData, *pExpectedSize);
   162 	      {
       
   163 		// data must be transmited with low byte first
       
   164 		UNS8 i, j = 0;
       
   165 		for ( i = ptrTable->pSubindex[bSubindex].size ; i > 0 ; i--) {
       
   166 			((char*)ptrTable->pSubindex[bSubindex].pObject)[i - 1] = ((char*)pSourceData)[j++];
       
   167 		}
       
   168 	      }
       
   169       #else  	
       
   170   	      memcpy(ptrTable->pSubindex[bSubindex].pObject,pSourceData, *pExpectedSize);
       
   171       #endif
       
   172       *pExpectedSize = szData;
   175       *pExpectedSize = szData;
   173       
   176       
   174       // Callbacks
   177       // Callbacks
   175       if(Callback && Callback[bSubindex]){
   178       if(Callback && Callback[bSubindex]){
   176       	 (*Callback[bSubindex])(d, ptrTable, bSubindex);
   179       	 (*Callback[bSubindex])(d, ptrTable, bSubindex);