src/objacces.c
changeset 175 e255529b6f7d
parent 161 c4908cc776a9
child 208 05d95c45b388
equal deleted inserted replaced
174:cd1638bc0cb0 175:e255529b6f7d
    63 #endif
    63 #endif
    64   return 0; 
    64   return 0; 
    65 }	
    65 }	
    66 
    66 
    67 
    67 
    68 UNS32 getODentry( CO_Data* d, 
    68 UNS32 _getODentry( CO_Data* d, 
    69                   UNS16 wIndex,
    69                   UNS16 wIndex,
    70 		  UNS8 bSubindex,
    70 		  UNS8 bSubindex,
    71 		  void * pDestData,
    71 		  void * pDestData,
    72 		  UNS8 * pExpectedSize,
    72 		  UNS8 * pExpectedSize,
    73 		  UNS8 * pDataType,
    73 		  UNS8 * pDataType,
    74 		  UNS8 checkAccess)
    74 		  UNS8 checkAccess,
       
    75 		  UNS8 endianize)
    75 { /* DO NOT USE MSG_ERR because the macro may send a PDO -> infinite loop if it fails. */
    76 { /* DO NOT USE MSG_ERR because the macro may send a PDO -> infinite loop if it fails. */
    76   UNS32 errorCode;
    77   UNS32 errorCode;
    77   UNS8 szData;
    78   UNS8 szData;
    78   const indextable *ptrTable;
    79   const indextable *ptrTable;
    79   ODCallback_t *Callback;
    80   ODCallback_t *Callback;
   100    if(	*pExpectedSize == 0 ||
   101    if(	*pExpectedSize == 0 ||
   101   	*pExpectedSize == szData ||
   102   	*pExpectedSize == szData ||
   102   	(*pDataType == visible_string && *pExpectedSize < szData)) {/* We allow to fetch a shorter string than expected */
   103   	(*pDataType == visible_string && *pExpectedSize < szData)) {/* We allow to fetch a shorter string than expected */
   103      
   104      
   104 #  ifdef CANOPEN_BIG_ENDIAN
   105 #  ifdef CANOPEN_BIG_ENDIAN
   105      if(*pDataType > boolean && *pDataType < visible_string) {
   106      if(endianize && *pDataType > boolean && *pDataType < visible_string) {
   106        /* data must be transmited with low byte first */
   107        /* data must be transmited with low byte first */
   107        UNS8 i, j = 0;
   108        UNS8 i, j = 0;
   108        MSG_WAR(boolean, "data type ", *pDataType);
   109        MSG_WAR(boolean, "data type ", *pDataType);
   109        MSG_WAR(visible_string, "data type ", *pDataType);
   110        MSG_WAR(visible_string, "data type ", *pDataType);
   110        for ( i = szData ; i > 0 ; i--) {
   111        for ( i = szData ; i > 0 ; i--) {
   139 			   *pExpectedSize, OD_LENGTH_DATA_INVALID);
   140 			   *pExpectedSize, OD_LENGTH_DATA_INVALID);
   140      return OD_LENGTH_DATA_INVALID;
   141      return OD_LENGTH_DATA_INVALID;
   141    }
   142    }
   142 }
   143 }
   143 
   144 
   144 UNS32 setODentry( CO_Data* d, 
   145 UNS32 getODentry( CO_Data* d, 
       
   146                   UNS16 wIndex,
       
   147 		  UNS8 bSubindex,
       
   148 		  void * pDestData,
       
   149 		  UNS8 * pExpectedSize,
       
   150 		  UNS8 * pDataType,
       
   151 		  UNS8 checkAccess)
       
   152 {
       
   153 	return _getODentry( d, 
       
   154                   wIndex,
       
   155 		  bSubindex,
       
   156 		  pDestData,
       
   157 		  pExpectedSize,
       
   158 		  pDataType,
       
   159 		  checkAccess,
       
   160 		  1);//endianize
       
   161 }
       
   162 
       
   163 UNS32 readLocalDict( CO_Data* d, 
       
   164                   UNS16 wIndex,
       
   165 		  UNS8 bSubindex,
       
   166 		  void * pDestData,
       
   167 		  UNS8 * pExpectedSize,
       
   168 		  UNS8 * pDataType,
       
   169 		  UNS8 checkAccess)
       
   170 {
       
   171 		return _getODentry( d, 
       
   172                   wIndex,
       
   173 		  bSubindex,
       
   174 		  pDestData,
       
   175 		  pExpectedSize,
       
   176 		  pDataType,
       
   177 		  checkAccess,
       
   178 		  0);//do not endianize
       
   179 }
       
   180 
       
   181 UNS32 _setODentry( CO_Data* d, 
   145                   UNS16 wIndex,
   182                   UNS16 wIndex,
   146 		  UNS8 bSubindex, 
   183 		  UNS8 bSubindex, 
   147 		  void * pSourceData, 
   184 		  void * pSourceData, 
   148 		  UNS8 * pExpectedSize, 
   185 		  UNS8 * pExpectedSize, 
   149 		  UNS8 checkAccess)
   186 		  UNS8 checkAccess,
       
   187 		  UNS8 endianize)
   150 {
   188 {
   151   UNS8 szData;
   189   UNS8 szData;
   152   UNS8 dataType;
   190   UNS8 dataType;
   153   UNS32 errorCode;
   191   UNS32 errorCode;
   154   const indextable *ptrTable;
   192   const indextable *ptrTable;
   176   if( *pExpectedSize == 0 ||
   214   if( *pExpectedSize == 0 ||
   177   	*pExpectedSize == szData ||
   215   	*pExpectedSize == szData ||
   178   	(dataType == visible_string && *pExpectedSize < szData)) /* We allow to store a shorter string than entry size */
   216   	(dataType == visible_string && *pExpectedSize < szData)) /* We allow to store a shorter string than entry size */
   179   {
   217   {
   180       #ifdef CANOPEN_BIG_ENDIAN
   218       #ifdef CANOPEN_BIG_ENDIAN
   181 	      if(dataType > boolean && dataType < visible_string)
   219 	      if(endianize && dataType > boolean && dataType < visible_string)
   182 	      {
   220 	      {
   183 			/* we invert the data source directly. This let us do range testing without */
   221 			/* we invert the data source directly. This let us do range testing without */
   184 			/* additional temp variable */
   222 			/* additional temp variable */
   185 		 	UNS8 i;
   223 		 	UNS8 i;
   186 	  		for ( i = 0 ; i < ( ptrTable->pSubindex[bSubindex].size >> 1)  ; i++) 
   224 	  		for ( i = 0 ; i < ( ptrTable->pSubindex[bSubindex].size >> 1)  ; i++) 
   214       accessDictionaryError(wIndex, bSubindex, szData, *pExpectedSize, OD_LENGTH_DATA_INVALID);
   252       accessDictionaryError(wIndex, bSubindex, szData, *pExpectedSize, OD_LENGTH_DATA_INVALID);
   215       return OD_LENGTH_DATA_INVALID;
   253       return OD_LENGTH_DATA_INVALID;
   216   }
   254   }
   217 }
   255 }
   218 
   256 
       
   257 UNS32 setODentry( CO_Data* d, 
       
   258                   UNS16 wIndex,
       
   259 		  UNS8 bSubindex, 
       
   260 		  void * pSourceData, 
       
   261 		  UNS8 * pExpectedSize, 
       
   262 		  UNS8 checkAccess)
       
   263 {
       
   264 	return _setODentry( d, 
       
   265                   wIndex,
       
   266 		  bSubindex, 
       
   267 		  pSourceData, 
       
   268 		  pExpectedSize, 
       
   269 		  checkAccess,
       
   270 		  1);//endianize
       
   271 }
       
   272 
       
   273 UNS32 writeLocalDict( CO_Data* d, 
       
   274                   UNS16 wIndex,
       
   275 		  UNS8 bSubindex, 
       
   276 		  void * pSourceData, 
       
   277 		  UNS8 * pExpectedSize, 
       
   278 		  UNS8 checkAccess)
       
   279 {
       
   280 	return _setODentry( d, 
       
   281                   wIndex,
       
   282 		  bSubindex, 
       
   283 		  pSourceData, 
       
   284 		  pExpectedSize, 
       
   285 		  checkAccess,
       
   286 		  0);//do not endianize
       
   287 }
       
   288 
       
   289 
       
   290 
   219 
   291 
   220 const indextable * scanIndexOD (CO_Data* d, UNS16 wIndex, UNS32 *errorCode, ODCallback_t **Callback)
   292 const indextable * scanIndexOD (CO_Data* d, UNS16 wIndex, UNS32 *errorCode, ODCallback_t **Callback)
   221 {
   293 {
   222   return (*d->scanIndexOD)(wIndex, errorCode, Callback);
   294   return (*d->scanIndexOD)(wIndex, errorCode, Callback);
   223 }
   295 }