]> rtime.felk.cvut.cz Git - CanFestival-3.git/commitdiff
Applied edward's patch for OD acces macros (optimization) and boudaries check (safety).
authoretisserant <etisserant>
Wed, 4 Jun 2008 08:57:06 +0000 (08:57 +0000)
committeretisserant <etisserant>
Wed, 4 Jun 2008 08:57:06 +0000 (08:57 +0000)
include/objacces.h
src/objacces.c

index 31d1fb08c8347af8c17768a8b2adf17b0d0ded12..f0b30289c40dc1377ac05f0984a0cd5c917ec2b9 100644 (file)
@@ -59,7 +59,11 @@ UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex,
                           UNS8 sizeDataDict, UNS8 sizeDataGiven, UNS32 code);
 
 
-/* Reads an entry from the object dictionary.\n
+/* _getODentry() Reads an entry from the object dictionary.\n
+ * 
+ *    use getODentry() macro to read from object and endianize
+ *    use readLocalDict() macro to read from object and not endianize   
+ *
  *  \code
  *  // Example usage:
  *  UNS8  *pbData;
@@ -86,16 +90,34 @@ UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex,
  *  \param pDataType : The type of the data. See objdictdef.h
  *  \param CheckAccess if other than 0, do not read if the data is Write Only
  *                     [Not used today. Put always 0].
+ *  \param Endianize  when not 0, data is endianized into network byte order
+ *                    when 0, data is not endianized and copied in machine native
+ *                    endianness 
  *  \return OD_SUCCESSFUL or SDO abort code. (See file def.h)
  */
-UNS32 getODentry( CO_Data* d, 
-                  UNS16 wIndex,
+UNS32 _getODentry( CO_Data* d, 
+                 UNS16 wIndex,
                  UNS8 bSubindex,
                  void * pDestData,
                  UNS8 * pExpectedSize,
                  UNS8 * pDataType,
-                 UNS8 checkAccess);
+                 UNS8 checkAccess,
+                 UNS8 endianize);
+
+#define getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
+                         pDataType,  checkAccess)                         \
+       _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
+                         pDataType,  checkAccess, 1)            
 
+/*
+ * readLocalDict() reads an entry from the object dictionary, but in 
+ * contrast to getODentry(), readLocalDict() doesn't endianize entry and reads
+ * entry in machine native endianness.
+ */
+#define readLocalDict( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
+                         pDataType,  checkAccess)                         \
+       _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
+                         pDataType,  checkAccess, 0)
 
 /* By this function you can write an entry into the object dictionary\n
  *  \code
@@ -117,20 +139,27 @@ UNS32 getODentry( CO_Data* d,
  *  \param CheckAccess if other than 0, do not read if the data is Read Only or Constant
  *  \return OD_SUCCESSFUL or SDO abort code. (See file def.h)
  */
-UNS32 setODentry( CO_Data* d, 
-                  UNS16 wIndex,
-                 UNS8 bSubindex, 
-                 void * pSourceData, 
-                 UNS8 * pExpectedSize, 
-                 UNS8 checkAccess);
-
-/*The same, without endianisation*/
-UNS32 writeLocalDict( CO_Data* d, 
-                  UNS16 wIndex,
-                 UNS8 bSubindex, 
-                 void * pSourceData, 
-                 UNS8 * pExpectedSize, 
-                 UNS8 checkAccess);
+UNS32 _setODentry( CO_Data* d,
+                   UNS16 wIndex,
+                   UNS8 bSubindex,
+                   void * pSourceData,
+                   UNS8 * pExpectedSize,
+                   UNS8 checkAccess,
+                   UNS8 endianize);
+
+/*
+ * setODentry converts SourceData from network byte order to machine native 
+ *            format, and writes that to OD.
+ */
+#define setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) \
+       _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess, 1)
+
+/*
+ * writeLocalDict writes machine native SourceData to OD.
+ */
+#define writeLocalDict( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) \
+       _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess, 0)
+
 
 
 /* Scan the index of object dictionary. Used only by setODentry and getODentry.
index 22636a1b29df94d95ef7a026da0064e25862aed6..1ab03bd7ce908cab227b99019e2473741206dd7e 100644 (file)
 **
 ** @return
 **/
+#ifdef DEBUG_WAR_CONSOLE_ON
 UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex,
                            UNS8 sizeDataDict, UNS8 sizeDataGiven, UNS32 code)
 {
-#ifdef DEBUG_WAR_CONSOLE_ON
   MSG_WAR(0x2B09,"Dictionary index : ", index);
   MSG_WAR(0X2B10,"           subindex : ", subIndex);
   switch (code) {
@@ -84,9 +84,11 @@ UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex,
   default :
     MSG_WAR(0x2B20, "Unknown error code : ", code);
   }
-#endif
   return 0;
 }
+#else
+#define accessDictionaryError(index, subIndex, sizeDataDict, sizeDataGiven, code)
+#endif
 
 /*!
 **
@@ -192,68 +194,6 @@ UNS32 _getODentry( CO_Data* d,
   }
 }
 
-/*!
-**
-**
-** @param d
-** @param wIndex
-** @param bSubindex
-** @param pDestData
-** @param pExpectedSize
-** @param pDataType
-** @param checkAccess
-**
-** @return
-**/
-UNS32 getODentry( CO_Data* d,
-                  UNS16 wIndex,
-                  UNS8 bSubindex,
-                  void * pDestData,
-                  UNS8 * pExpectedSize,
-                  UNS8 * pDataType,
-                  UNS8 checkAccess)
-{
-  return _getODentry( d,
-                      wIndex,
-                      bSubindex,
-                      pDestData,
-                      pExpectedSize,
-                      pDataType,
-                      checkAccess,
-                      1);//endianize
-}
-
-/*!
-**
-**
-** @param d
-** @param wIndex
-** @param bSubindex
-** @param pDestData
-** @param pExpectedSize
-** @param pDataType
-** @param checkAccess
-**
-** @return
-**/
-UNS32 readLocalDict( CO_Data* d,
-                     UNS16 wIndex,
-                     UNS8 bSubindex,
-                     void * pDestData,
-                     UNS8 * pExpectedSize,
-                     UNS8 * pDataType,
-                     UNS8 checkAccess)
-{
-  return _getODentry( d,
-                      wIndex,
-                      bSubindex,
-                      pDestData,
-                      pExpectedSize,
-                      pDataType,
-                      checkAccess,
-                      0);//do not endianize
-}
-
 /*!
 **
 **
@@ -360,62 +300,6 @@ UNS32 _setODentry( CO_Data* d,
     }
 }
 
-/*!
-**
-**
-** @param d
-** @param wIndex
-** @param bSubindex
-** @param pSourceData
-** @param pExpectedSize
-** @param checkAccess
-**
-** @return
-**/
-UNS32 setODentry( CO_Data* d,
-                  UNS16 wIndex,
-                  UNS8 bSubindex,
-                  void * pSourceData,
-                  UNS8 * pExpectedSize,
-                  UNS8 checkAccess)
-{
-  return _setODentry( d,
-                      wIndex,
-                      bSubindex,
-                      pSourceData,
-                      pExpectedSize,
-                      checkAccess,
-                      1);//endianize
-}
-
-/*!
-**
-**
-** @param d
-** @param wIndex
-** @param bSubindex
-** @param pSourceData
-** @param pExpectedSize
-** @param checkAccess
-**
-** @return
-**/
-UNS32 writeLocalDict( CO_Data* d,
-                      UNS16 wIndex,
-                      UNS8 bSubindex,
-                      void * pSourceData,
-                      UNS8 * pExpectedSize,
-                      UNS8 checkAccess)
-{
-  return _setODentry( d,
-                      wIndex,
-                      bSubindex,
-                      pSourceData,
-                      pExpectedSize,
-                      checkAccess,
-                      0);//do not endianize
-}
-
 /*!
 **
 **
@@ -443,11 +327,12 @@ const indextable * scanIndexOD (CO_Data* d, UNS16 wIndex, UNS32 *errorCode, ODCa
 **/
 UNS32 RegisterSetODentryCallBack(CO_Data* d, UNS16 wIndex, UNS8 bSubindex, ODCallback_t Callback)
 {
-  UNS32 errorCode;
-  ODCallback_t *CallbackList;
+UNS32 errorCode;
+ODCallback_t *CallbackList;
+const indextable *odentry;
 
-  scanIndexOD (d, wIndex, &errorCode, &CallbackList);
-  if(errorCode == OD_SUCCESSFUL && CallbackList)
+  odentry = scanIndexOD (d, wIndex, &errorCode, &CallbackList);
+  if(errorCode == OD_SUCCESSFUL  &&  CallbackList  &&  bSubindex < odentry->bSubCount) 
     CallbackList[bSubindex] = Callback;
   return errorCode;
 }