Modbus: Change to several header files to make them a little more consistent with Nuttx coding stanards. Still not very close

This commit is contained in:
Gregory Nutt 2015-04-07 13:50:36 -06:00
parent 6e462908ba
commit af7f087ccf
5 changed files with 168 additions and 148 deletions

View File

@ -284,8 +284,6 @@ eMBErrorCode eMBSetSlaveID(uint8_t ucSlaveID, bool xIsRunning,
eMBErrorCode eMBRegisterCB(uint8_t ucFunctionCode,
pxMBFunctionHandler pxHandler);
/* ----------------------- Callback -----------------------------------------*/
/* The protocol stack does not internally allocate any memory for the
* registers. This makes the protocol stack very small and also usable on
* low end targets. In addition the values don't have to be in the memory

View File

@ -1,4 +1,6 @@
/*
/****************************************************************************
* apps/include/modbus/mbframe.h
*
* FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
* Copyright (c) 2006 Christian Walter <wolti@sil.at>
* All rights reserved.
@ -25,18 +27,20 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* File: $Id: mbframe.h,v 1.9 2006/12/07 22:10:34 wolti Exp $
*/
****************************************************************************/
#ifndef _MB_FRAME_H
#define _MB_FRAME_H
#ifndef __APPS_INCLUDE_MODBUS_MBFRAME_H
#define __APPS_INCLUDE_MODBUS_MBFRAME_H
#ifdef __cplusplus
PR_BEGIN_EXTERN_C
#endif
/*!
* Constants which defines the format of a modbus frame. The example is
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Constants which defines the format of a Modbus frame. The example is
* shown for a Modbus RTU/ASCII frame. Note that the Modbus PDU is not
* dependent on the underlying transport.
*
@ -60,28 +64,27 @@ PR_BEGIN_EXTERN_C
* </code>
*/
/* ----------------------- Defines ------------------------------------------*/
#define MB_PDU_SIZE_MAX 253 /*!< Maximum size of a PDU. */
#define MB_PDU_SIZE_MIN 1 /*!< Function Code */
#define MB_PDU_FUNC_OFF 0 /*!< Offset of function code in PDU. */
#define MB_PDU_DATA_OFF 1 /*!< Offset for response data in PDU. */
/* ----------------------- Prototypes 0-------------------------------------*/
/****************************************************************************
* Public Types
****************************************************************************/
typedef void (*pvMBFrameStart)(void);
typedef void (*pvMBFrameStop)(void);
typedef eMBErrorCode (*peMBFrameReceive)(uint8_t *pucRcvAddress,
uint8_t **pucFrame,
uint16_t *pusLength);
typedef eMBErrorCode (*peMBFrameSend)(uint8_t slaveAddress,
const uint8_t *pucFrame,
uint16_t usLength);
typedef void (*pvMBFrameClose)(void);
#ifdef __cplusplus
PR_END_EXTERN_C
#endif
#endif
#endif /* __APPS_INCLUDE_MODBUS_MBFRAME_H */

View File

@ -1,4 +1,6 @@
/*
/****************************************************************************
* apps/include/modbus/mbfunc.h
*
* FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
* Copyright (c) 2006 Christian Walter <wolti@sil.at>
* All rights reserved.
@ -25,15 +27,19 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* File: $Id: mbfunc.h,v 1.12 2006/12/07 22:10:34 wolti Exp $
*/
****************************************************************************/
#ifndef _MB_FUNC_H
#define _MB_FUNC_H
#ifndef __APPS_INCLUDE_MODBUS_MBFUNC_H
#define __APPS_INCLUDE_MODBUS_MBFUNC_H
#ifdef __cplusplus
PR_BEGIN_EXTERN_C
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef CONFIG_MB_FUNC_OTHER_REP_SLAVEID_BUF
eMBException eMBFuncReportSlaveID(uint8_t *pucFrame, uint16_t *usLen);
#endif
@ -77,4 +83,5 @@ eMBException eMBFuncReadWriteMultipleHoldingRegister( uint8_t * pucFrame, uin
#ifdef __cplusplus
PR_END_EXTERN_C
#endif
#endif
#endif /* __APPS_INCLUDE_MODBUS_MBFUNC_H */

View File

@ -1,4 +1,6 @@
/*
/****************************************************************************
* apps/include/modbus/mbproto.h
*
* FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
* Copyright (c) 2006 Christian Walter <wolti@sil.at>
* All rights reserved.
@ -25,19 +27,22 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* File: $Id: mbproto.h,v 1.14 2006/12/07 22:10:34 wolti Exp $
*/
****************************************************************************/
#ifndef _MB_PROTO_H
#define _MB_PROTO_H
#ifndef __APPS_INCLUDE_MODBUS_MBPROTO_H
#define __APPS_INCLUDE_MODBUS_MBPROTO_H
#ifdef __cplusplus
PR_BEGIN_EXTERN_C
#endif
/* ----------------------- Defines ------------------------------------------*/
#define MB_ADDRESS_BROADCAST ( 0 ) /*! Modbus broadcast address. */
#define MB_ADDRESS_MIN ( 1 ) /*! Smallest possible slave address. */
#define MB_ADDRESS_MAX ( 247 ) /*! Biggest possible slave address. */
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define MB_ADDRESS_BROADCAST (0) /* Modbus broadcast address. */
#define MB_ADDRESS_MIN (1) /* Smallest possible slave address. */
#define MB_ADDRESS_MAX (247) /* Biggest possible slave address. */
#define MB_FUNC_NONE (0)
#define MB_FUNC_READ_COILS (1)
#define MB_FUNC_READ_DISCRETE_INPUTS (2)
@ -54,7 +59,11 @@ PR_BEGIN_EXTERN_C
#define MB_FUNC_DIAG_GET_COM_EVENT_LOG (12)
#define MB_FUNC_OTHER_REPORT_SLAVEID (17)
#define MB_FUNC_ERROR (128)
/* ----------------------- Type definitions ---------------------------------*/
/****************************************************************************
* Public Type Definitions
****************************************************************************/
typedef enum
{
MB_EX_NONE = 0x00,
@ -65,8 +74,8 @@ PR_BEGIN_EXTERN_C
MB_EX_ACKNOWLEDGE = 0x05,
MB_EX_SLAVE_BUSY = 0x06,
MB_EX_MEMORY_PARITY_ERROR = 0x08,
MB_EX_GATEWAY_PATH_FAILED = 0x0A,
MB_EX_GATEWAY_TGT_FAILED = 0x0B
MB_EX_GATEWAY_PATH_FAILED = 0x0a,
MB_EX_GATEWAY_TGT_FAILED = 0x0b
} eMBException;
typedef eMBException(*pxMBFunctionHandler)(uint8_t *pucFrame, uint16_t *pusLength);
@ -80,4 +89,5 @@ typedef struct
#ifdef __cplusplus
PR_END_EXTERN_C
#endif
#endif
#endif /* __APPS_INCLUDE_MODBUS_MBPROTO_H */

View File

@ -1,4 +1,6 @@
/*
/****************************************************************************
* apps/include/modbus/mbutils.h
*
* FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
* Copyright (c) 2006 Christian Walter <wolti@sil.at>
* All rights reserved.
@ -25,84 +27,84 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* File: $Id: mbutils.h,v 1.5 2006/12/07 22:10:34 wolti Exp $
*/
****************************************************************************/
#ifndef _MB_UTILS_H
#define _MB_UTILS_H
#ifndef __APPS_INCLUDE_MODBUS_MBUTILS_H
#define __APPS_INCLUDE_MODBUS_MBUTILS_H
#ifdef __cplusplus
PR_BEGIN_EXTERN_C
#endif
/*! \defgroup modbus_utils Utilities
*
* This module contains some utility functions which can be used by
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* This module contains some utility functions which can be used by
* the application. It includes some special functions for working with
* bitfields backed by a character array buffer.
*
*/
/*! \addtogroup modbus_utils
* @{
*/
/*! \brief Function to set bits in a byte buffer.
/* Function to set bits in a byte buffer.
*
* This function allows the efficient use of an array to implement bitfields.
* The array used for storing the bits must always be a multiple of two
* bytes. Up to eight bits can be set or cleared in one operation.
*
* \param ucByteBuf A buffer where the bit values are stored. Must be a
* Input Parameters:
* ucByteBuf A buffer where the bit values are stored. Must be a
* multiple of 2 bytes. No length checking is performed and if
* usBitOffset / 8 is greater than the size of the buffer memory contents
* is overwritten.
* \param usBitOffset The starting address of the bits to set. The first
* usBitOffset The starting address of the bits to set. The first
* bit has the offset 0.
* \param ucNBits Number of bits to modify. The value must always be smaller
* ucNBits Number of bits to modify. The value must always be smaller
* than 8.
* \param ucValues Thew new values for the bits. The value for the first bit
* starting at <code>usBitOffset</code> is the LSB of the value
* <code>ucValues</code>
* ucValues Thew new values for the bits. The value for the first bit
* starting at usBitOffset is the LSB of the value ucValues
*
* \code
* ucBits[2] = {0, 0};
*
* // Set bit 4 to 1 (read: set 1 bit starting at bit offset 4 to value 1)
*
* xMBUtilSetBits(ucBits, 4, 1, 1);
*
* // Set bit 7 to 1 and bit 8 to 0.
*
* xMBUtilSetBits(ucBits, 7, 2, 0x01);
*
* // Set bits 8 - 11 to 0x05 and bits 12 - 15 to 0x0A;
*
* xMBUtilSetBits(ucBits, 8, 8, 0x5A);
* \endcode
*/
void xMBUtilSetBits(uint8_t *ucByteBuf, uint16_t usBitOffset,
uint8_t ucNBits, uint8_t ucValues);
/*! \brief Function to read bits in a byte buffer.
/* Function to read bits in a byte buffer.
*
* This function is used to extract up bit values from an array. Up to eight
* bit values can be extracted in one step.
*
* \param ucByteBuf A buffer where the bit values are stored.
* \param usBitOffset The starting address of the bits to set. The first
* Input Parameters:
* ucByteBuf A buffer where the bit values are stored.
* usBitOffset The starting address of the bits to set. The first
* bit has the offset 0.
* \param ucNBits Number of bits to modify. The value must always be smaller
* ucNBits Number of bits to modify. The value must always be smaller
* than 8.
*
* \code
* uint8_t ucBits[2] = {0, 0};
* uint8_t ucResult;
*
* // Extract the bits 3 - 10.
*
* ucResult = xMBUtilGetBits(ucBits, 3, 8);
* \endcode
*/
uint8_t xMBUtilGetBits( uint8_t * ucByteBuf, uint16_t usBitOffset,
uint8_t ucNBits );
/*! @} */
uint8_t xMBUtilGetBits(uint8_t *ucByteBuf, uint16_t usBitOffset, uint8_t ucNBits);
#ifdef __cplusplus
PR_END_EXTERN_C
#endif
#endif
#endif /* __APPS_INCLUDE_MODBUS_MBUTILS_H */