src/objacces.c
changeset 2 8d4a822f95e4
parent 1 b3dc740b4b04
child 8 eee2b0c89213
--- a/src/objacces.c	Wed May 10 21:05:57 2006 +0200
+++ b/src/objacces.c	Thu May 11 13:52:43 2006 +0200
@@ -98,6 +98,7 @@
   	(*pDataType == visible_string && *pExpectedSize > szData)) // We allow to fetch a shorter string than expected
   {
 	#ifdef CANOPEN_BIG_ENDIAN
+	      if(*pDataType > boolean && dataType < visible_string){
 	      {
 		// data must be transmited with low byte first
 		UNS8 i, j = 0;
@@ -153,22 +154,24 @@
   	*pExpectedSize == szData ||
   	(dataType == visible_string && *pExpectedSize < szData)) // We allow to store a shorter string than entry size
   {
+      #ifdef CANOPEN_BIG_ENDIAN
+	      if(dataType > boolean && dataType < visible_string){
+		// we invert the data source directly. This let us do range testing without
+		// additional temp variable
+		UNS8 i, j = 0;
+		for ( i = ptrTable->pSubindex[bSubindex].size >> 1 ; i > 0 ; i--) {
+			char tmp = ((char*)pSourceData)[i - 1];
+			((char*)pSourceData)[i - 1] = ((char*)pSourceData)[j];
+			((char*)pSourceData)[j++] = tmp;
+		}
+	      }
+      #endif
       errorCode = (*d->valueRangeTest)(dataType, pSourceData);
       if (errorCode) {
 	accessDictionaryError(wIndex, bSubindex, szData, *pExpectedSize, errorCode);
 	return errorCode;
       }
-      #ifdef CANOPEN_BIG_ENDIAN
-	      {
-		// data must be transmited with low byte first
-		UNS8 i, j = 0;
-		for ( i = ptrTable->pSubindex[bSubindex].size ; i > 0 ; i--) {
-			((char*)ptrTable->pSubindex[bSubindex].pObject)[i - 1] = ((char*)pSourceData)[j++];
-		}
-	      }
-      #else  	
-  	      memcpy(ptrTable->pSubindex[bSubindex].pObject,pSourceData, *pExpectedSize);
-      #endif
+      memcpy(ptrTable->pSubindex[bSubindex].pObject,pSourceData, *pExpectedSize);
       *pExpectedSize = szData;
       
       // Callbacks