edouard@629: /* edouard@629: This file is part of CanFestival, a library implementing CanOpen Stack. edouard@629: edouard@629: Copyright (C): Edouard TISSERANT and Francis DUPIN edouard@629: edouard@629: See COPYING file for copyrights details. edouard@629: edouard@629: This library is free software; you can redistribute it and/or edouard@629: modify it under the terms of the GNU Lesser General Public edouard@629: License as published by the Free Software Foundation; either edouard@629: version 2.1 of the License, or (at your option) any later version. edouard@629: edouard@629: This library is distributed in the hope that it will be useful, edouard@629: but WITHOUT ANY WARRANTY; without even the implied warranty of edouard@629: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU edouard@629: Lesser General Public License for more details. edouard@629: edouard@629: You should have received a copy of the GNU Lesser General Public edouard@629: License along with this library; if not, write to the Free Software edouard@629: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA edouard@629: */ edouard@629: edouard@629: /** @file edouard@629: * @brief Responsible for accessing the object dictionary. edouard@629: * edouard@629: * This file contains functions for accessing the object dictionary and edouard@629: * variables that are contained by the object dictionary. edouard@629: * Accessing the object dictionary contains setting local variables edouard@629: * as PDOs and accessing (read/write) all entries of the object dictionary edouard@629: * @warning Only the basic entries of an object dictionary are included edouard@629: * at the moment. edouard@629: */ edouard@629: edouard@629: /** @defgroup od Object Dictionary Management edouard@629: * @brief The Object Dictionary is the heart of each CANopen device containing all communication and application objects. edouard@629: * @ingroup userapi edouard@629: */ edouard@629: edouard@629: #ifndef __objacces_h__ edouard@629: #define __objacces_h__ edouard@629: edouard@629: #include edouard@629: edouard@629: greg@588: #ifdef __cplusplus greg@588: extern "C" { edouard@629: #endif edouard@629: edouard@629: edouard@629: typedef UNS32 (*valueRangeTest_t)(UNS8 typeValue, void *Value); edouard@629: typedef void (* storeODSubIndex_t)(CO_Data* d, UNS16 wIndex, UNS8 bSubindex); edouard@629: void _storeODSubIndex (CO_Data* d, UNS16 wIndex, UNS8 bSubindex); edouard@629: edouard@629: /** edouard@629: * @brief Print MSG_WAR (s) if error to the access to the object dictionary occurs. edouard@629: * edouard@629: * You must uncomment the lines in the file objaccess.c :\n edouard@629: * //#define DEBUG_CAN\n edouard@629: * //#define DEBUG_WAR_CONSOLE_ON\n edouard@629: * //#define DEBUG_ERR_CONSOLE_ON\n\n edouard@629: * Beware that sometimes, we force the sizeDataDict or sizeDataGiven to 0, when we wants to use edouard@629: * this function but we do not have the access to the right value. One example is edouard@629: * getSDOerror(). So do not take attention to these variables if they are null. edouard@629: * @param index edouard@629: * @param subIndex edouard@629: * @param sizeDataDict Size of the data defined in the dictionary edouard@629: * @param sizeDataGiven Size data given by the user. edouard@629: * @param code error code to print. (SDO abort code. See file def.h) edouard@629: * @return edouard@629: */ edouard@629: UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex, edouard@629: UNS32 sizeDataDict, UNS32 sizeDataGiven, UNS32 code); edouard@629: edouard@629: edouard@629: /* _getODentry() Reads an entry from the object dictionary.\n edouard@629: * edouard@629: * use getODentry() macro to read from object and endianize edouard@629: * use readLocalDict() macro to read from object and not endianize edouard@629: * edouard@629: * @code edouard@629: * // Example usage: edouard@629: * UNS8 *pbData; edouard@629: * UNS8 length; edouard@629: * UNS32 returnValue; edouard@629: * edouard@629: * returnValue = getODentry( (UNS16)0x100B, (UNS8)1, edouard@629: * (void * *)&pbData, (UNS8 *)&length ); edouard@629: * if( returnValue != SUCCESSFUL ) edouard@629: * { edouard@629: * // error handling edouard@629: * } edouard@629: * @endcode edouard@629: * @param *d Pointer to a CAN object data structure edouard@629: * @param wIndex The index in the object dictionary where you want to read edouard@629: * an entry edouard@629: * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is edouard@629: * used to tell you how many valid entries you can find edouard@629: * in this index. Look at the canopen standard for further edouard@629: * information edouard@629: * @param *pDestData Pointer to the pointer which points to the variable where edouard@629: * the value of this object dictionary entry should be copied edouard@629: * @param pExpectedSize This function writes the size of the copied value (in Byte) edouard@629: * into this variable. edouard@629: * @param *pDataType Pointer to the type of the data. See objdictdef.h edouard@629: * @param CheckAccess if other than 0, do not read if the data is Write Only edouard@629: * [Not used today. Put always 0]. edouard@629: * @param Endianize When not 0, data is endianized into network byte order edouard@629: * when 0, data is not endianized and copied in machine native edouard@629: * endianness edouard@629: * @return edouard@629: * - OD_SUCCESSFUL is returned upon success. edouard@629: * - SDO abort code is returned if error occurs . (See file def.h) edouard@629: */ edouard@629: UNS32 _getODentry( CO_Data* d, edouard@629: UNS16 wIndex, edouard@629: UNS8 bSubindex, edouard@629: void * pDestData, edouard@629: UNS32 * pExpectedSize, edouard@629: UNS8 * pDataType, edouard@629: UNS8 checkAccess, edouard@629: UNS8 endianize); edouard@629: edouard@629: /** edouard@629: * @ingroup od edouard@629: * @brief getODentry() to read from object and endianize edouard@629: * @param OD Pointer to a CAN object data structure edouard@629: * @param wIndex The index in the object dictionary where you want to read edouard@629: * an entry edouard@629: * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is edouard@629: * used to tell you how many valid entries you can find edouard@629: * in this index. Look at the canopen standard for further edouard@629: * information edouard@629: * @param *pDestData Pointer to the pointer which points to the variable where edouard@629: * the value of this object dictionary entry should be copied edouard@629: * @param pExpectedSize This function writes the size of the copied value (in Byte) edouard@629: * into this variable. edouard@629: * @param *pDataType Pointer to the type of the data. See objdictdef.h edouard@629: * @param checkAccess Flag that indicate if a check rights must be perfomed (0 : no , other than 0 : yes) edouard@629: * @param endianize Set to 1 : endianized into network byte order edouard@629: * @return edouard@629: * - OD_SUCCESSFUL is returned upon success. edouard@629: * - SDO abort code is returned if error occurs . (See file def.h) edouard@629: */ edouard@629: #define getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ edouard@629: pDataType, checkAccess) \ edouard@629: _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ edouard@629: pDataType, checkAccess, 1) edouard@629: edouard@629: /** edouard@629: * @ingroup od edouard@629: * @brief readLocalDict() reads an entry from the object dictionary, but in edouard@629: * contrast to getODentry(), readLocalDict() doesn't endianize entry and reads edouard@629: * entry in machine native endianness. edouard@629: * @param OD Pointer to a CAN object data structure edouard@629: * @param wIndex The index in the object dictionary where you want to read edouard@629: * an entry edouard@629: * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is edouard@629: * used to tell you how many valid entries you can find edouard@629: * in this index. Look at the canopen standard for further edouard@629: * information edouard@629: * @param *pDestData Pointer to the pointer which points to the variable where edouard@629: * the value of this object dictionary entry should be copied edouard@629: * @param pExpectedSize This function writes the size of the copied value (in Byte) edouard@629: * into this variable. edouard@629: * @param *pDataType Pointer to the type of the data. See objdictdef.h edouard@629: * @param checkAccess if other than 0, do not read if the data is Write Only edouard@629: * [Not used today. Put always 0]. edouard@629: * @param endianize Set to 0, data is not endianized and copied in machine native edouard@629: * endianness edouard@629: * @return edouard@629: * - OD_SUCCESSFUL is returned upon success. edouard@629: * - SDO abort code is returned if error occurs . (See file def.h) edouard@629: */ edouard@629: #define readLocalDict( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ edouard@629: pDataType, checkAccess) \ edouard@629: _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ edouard@629: pDataType, checkAccess, 0) edouard@629: edouard@629: /* By this function you can write an entry into the object dictionary edouard@629: * @param *d Pointer to a CAN object data structure edouard@629: * @param wIndex The index in the object dictionary where you want to write edouard@629: * an entry edouard@629: * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is edouard@629: * used to tell you how many valid entries you can find edouard@629: * in this index. Look at the canopen standard for further edouard@629: * information edouard@629: * @param *pSourceData Pointer to the variable that holds the value that should edouard@629: * be copied into the object dictionary edouard@629: * @param *pExpectedSize The size of the value (in Byte). edouard@629: * @param checkAccess Flag that indicate if a check rights must be perfomed (0 : no , other than 0 : yes) edouard@629: * @param endianize When not 0, data is endianized into network byte order edouard@629: * when 0, data is not endianized and copied in machine native edouard@629: * endianness edouard@629: * @return edouard@629: * - OD_SUCCESSFUL is returned upon success. edouard@629: * - SDO abort code is returned if error occurs . (See file def.h) edouard@629: */ edouard@629: UNS32 _setODentry( CO_Data* d, edouard@629: UNS16 wIndex, edouard@629: UNS8 bSubindex, edouard@629: void * pSourceData, edouard@629: UNS32 * pExpectedSize, edouard@629: UNS8 checkAccess, edouard@629: UNS8 endianize); edouard@629: edouard@629: /** edouard@629: * @ingroup od edouard@629: * @brief setODentry converts SourceData from network byte order to machine native edouard@629: * format, and writes that to OD. edouard@629: * @code edouard@629: * // Example usage: edouard@629: * UNS8 B; edouard@629: * B = 0xFF; // set transmission type edouard@629: * edouard@629: * retcode = setODentry( (UNS16)0x1800, (UNS8)2, &B, sizeof(UNS8), 1 ); edouard@629: * @endcode edouard@629: * @param d Pointer to a CAN object data structure edouard@629: * @param wIndex The index in the object dictionary where you want to write edouard@629: * an entry edouard@629: * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is edouard@629: * used to tell you how many valid entries you can find edouard@629: * in this index. Look at the canopen standard for further edouard@629: * information edouard@629: * @param *pSourceData Pointer to the variable that holds the value that should edouard@629: * be copied into the object dictionary edouard@629: * @param *pExpectedSize The size of the value (in Byte). edouard@629: * @param checkAccess Flag that indicate if a check rights must be perfomed (0 : no , other than 0 : yes) edouard@629: * @param endianize Set to 1 : endianized into network byte order edouard@629: * @return edouard@629: * - OD_SUCCESSFUL is returned upon success. edouard@629: * - SDO abort code is returned if error occurs . (See file def.h) edouard@629: */ edouard@629: #define setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, \ edouard@629: checkAccess) \ edouard@629: _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, \ edouard@629: checkAccess, 1) edouard@629: edouard@629: /** @fn UNS32 writeLocalDict(d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) edouard@629: * @ingroup od edouard@629: * @hideinitializer edouard@629: * @brief Writes machine native SourceData to OD. edouard@629: * @param d Pointer to a CAN object data structure edouard@629: * @param wIndex The index in the object dictionary where you want to write edouard@629: * an entry edouard@629: * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is edouard@629: * used to tell you how many valid entries you can find edouard@629: * in this index. Look at the canopen standard for further edouard@629: * information edouard@629: * @param *pSourceData Pointer to the variable that holds the value that should edouard@629: * be copied into the object dictionary edouard@629: * @param *pExpectedSize The size of the value (in Byte). edouard@629: * @param checkAccess Flag that indicate if a check rights must be perfomed (0 : no , other than 0 : yes) edouard@629: * @param endianize Data is not endianized and copied in machine native endianness edouard@629: * @return edouard@629: * - OD_SUCCESSFUL is returned upon success. edouard@629: * - SDO abort code is returned if error occurs . (See file def.h) edouard@629: * \n\n edouard@629: * @code edouard@629: * // Example usage: edouard@629: * UNS8 B; edouard@629: * B = 0xFF; // set transmission type edouard@629: * edouard@629: * retcode = writeLocalDict( (UNS16)0x1800, (UNS8)2, &B, sizeof(UNS8), 1 ); edouard@629: * @endcode edouard@629: */ edouard@629: #define writeLocalDict( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) \ edouard@629: _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess, 0) edouard@629: edouard@629: edouard@629: edouard@629: /** edouard@629: * @brief Scan the index of object dictionary. Used only by setODentry and getODentry. edouard@629: * @param *d Pointer to a CAN object data structure edouard@629: * @param wIndex edouard@629: * @param *errorCode : OD_SUCCESSFUL if index foundor SDO abort code. (See file def.h) edouard@629: * @param **Callback edouard@629: * @return NULL if index not found. Else : return the table part of the object dictionary. edouard@629: */ edouard@629: const indextable * scanIndexOD (CO_Data* d, UNS16 wIndex, UNS32 *errorCode, ODCallback_t **Callback); edouard@629: edouard@629: UNS32 RegisterSetODentryCallBack(CO_Data* d, UNS16 wIndex, UNS8 bSubindex, ODCallback_t Callback); edouard@629: greg@588: #ifdef __cplusplus greg@588: } edouard@629: #endif edouard@629: edouard@629: #endif /* __objacces_h__ */