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

@ -159,8 +159,8 @@ typedef enum
* - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
*/
eMBErrorCode eMBInit(eMBMode eMode, uint8_t ucSlaveAddress,
uint8_t ucPort, speed_t ulBaudRate, eMBParity eParity);
eMBErrorCode eMBInit(eMBMode eMode, uint8_t ucSlaveAddress,
uint8_t ucPort, speed_t ulBaudRate, eMBParity eParity);
/* Initialize the Modbus protocol stack for Modbus TCP.
*
@ -235,7 +235,7 @@ eMBErrorCode eMBDisable(void);
* returns eMBErrorCode::MB_EILLSTATE. Otherwise it returns
* eMBErrorCode::MB_ENOERR.
*/
eMBErrorCode eMBPoll(void);
eMBErrorCode eMBPoll(void);
/* Configure the slave id of the device.
*
@ -256,9 +256,9 @@ eMBErrorCode eMBPoll(void);
* is too small it returns eMBErrorCode::MB_ENORES. Otherwise
* it returns eMBErrorCode::MB_ENOERR.
*/
eMBErrorCode eMBSetSlaveID(uint8_t ucSlaveID, bool xIsRunning,
uint8_t const *pucAdditional,
uint16_t usAdditionalLen);
eMBErrorCode eMBSetSlaveID(uint8_t ucSlaveID, bool xIsRunning,
uint8_t const *pucAdditional,
uint16_t usAdditionalLen);
/* Registers a callback handler for a given function code.
*
@ -281,10 +281,8 @@ eMBErrorCode eMBSetSlaveID(uint8_t ucSlaveID, bool xIsRunning,
* case the values in config.h should be adjusted. If the argument was not
* valid it returns eMBErrorCode::MB_EINVAL.
*/
eMBErrorCode eMBRegisterCB(uint8_t ucFunctionCode,
pxMBFunctionHandler pxHandler);
/* ----------------------- Callback -----------------------------------------*/
eMBErrorCode eMBRegisterCB(uint8_t ucFunctionCode,
pxMBFunctionHandler pxHandler);
/* The protocol stack does not internally allocate any memory for the
* registers. This makes the protocol stack very small and also usable on
@ -326,8 +324,8 @@ eMBErrorCode eMBRegisterCB(uint8_t ucFunctionCode,
* - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
* a SLAVE DEVICE FAILURE exception is sent as a response.
*/
eMBErrorCode eMBRegInputCB(uint8_t * pucRegBuffer, uint16_t usAddress,
uint16_t usNRegs);
eMBErrorCode eMBRegInputCB(uint8_t * pucRegBuffer, uint16_t usAddress,
uint16_t usNRegs);
/* Callback function used if a Holding Register value is read or written by
* the protocol stack. The starting register address is given by \c usAddress
@ -361,8 +359,8 @@ eMBErrorCode eMBRegInputCB(uint8_t * pucRegBuffer, uint16_t usAddress,
* - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
* a SLAVE DEVICE FAILURE exception is sent as a response.
*/
eMBErrorCode eMBRegHoldingCB(uint8_t * pucRegBuffer, uint16_t usAddress,
uint16_t usNRegs, eMBRegisterMode eMode);
eMBErrorCode eMBRegHoldingCB(uint8_t * pucRegBuffer, uint16_t usAddress,
uint16_t usNRegs, eMBRegisterMode eMode);
/* Callback function used if a Coil Register value is read or written by the
* protocol stack. If you are going to use this function you might use the
@ -397,8 +395,8 @@ eMBErrorCode eMBRegHoldingCB(uint8_t * pucRegBuffer, uint16_t usAddress,
* - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
* a SLAVE DEVICE FAILURE exception is sent as a response.
*/
eMBErrorCode eMBRegCoilsCB(uint8_t * pucRegBuffer, uint16_t usAddress,
uint16_t usNCoils, eMBRegisterMode eMode);
eMBErrorCode eMBRegCoilsCB(uint8_t *pucRegBuffer, uint16_t usAddress,
uint16_t usNCoils, eMBRegisterMode eMode);
/* Callback function used if a Input Discrete Register value is read by
* the protocol stack.
@ -428,8 +426,8 @@ eMBErrorCode eMBRegCoilsCB(uint8_t * pucRegBuffer, uint16_t usAddress,
* - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
* a SLAVE DEVICE FAILURE exception is sent as a response.
*/
eMBErrorCode eMBRegDiscreteCB(uint8_t * pucRegBuffer, uint16_t usAddress,
uint16_t usNDiscrete);
eMBErrorCode eMBRegDiscreteCB(uint8_t *pucRegBuffer, uint16_t usAddress,
uint16_t usNDiscrete);
#ifdef __cplusplus
PR_END_EXTERN_C

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-------------------------------------*/
typedef void ( *pvMBFrameStart ) ( void );
/****************************************************************************
* Public Types
****************************************************************************/
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 );
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,56 +27,61 @@
* (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 );
eMBException eMBFuncReportSlaveID(uint8_t *pucFrame, uint16_t *usLen);
#endif
#ifdef CONFIG_MB_FUNC_READ_INPUT_ENABLED
eMBException eMBFuncReadInputRegister( uint8_t * pucFrame, uint16_t * usLen );
eMBException eMBFuncReadInputRegister(uint8_t *pucFrame, uint16_t *usLen);
#endif
#ifdef CONFIG_MB_FUNC_READ_HOLDING_ENABLED
eMBException eMBFuncReadHoldingRegister( uint8_t * pucFrame, uint16_t * usLen );
eMBException eMBFuncReadHoldingRegister(uint8_t *pucFrame, uint16_t *usLen);
#endif
#ifdef CONFIG_MB_FUNC_WRITE_HOLDING_ENABLED
eMBException eMBFuncWriteHoldingRegister( uint8_t * pucFrame, uint16_t * usLen );
eMBException eMBFuncWriteHoldingRegister(uint8_t *pucFrame, uint16_t *usLen);
#endif
#ifdef CONFIG_MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED
eMBException eMBFuncWriteMultipleHoldingRegister( uint8_t * pucFrame, uint16_t * usLen );
eMBException eMBFuncWriteMultipleHoldingRegister(uint8_t *pucFrame, uint16_t *usLen);
#endif
#ifdef CONFIG_MB_FUNC_READ_COILS_ENABLED
eMBException eMBFuncReadCoils( uint8_t * pucFrame, uint16_t * usLen );
eMBException eMBFuncReadCoils(uint8_t *pucFrame, uint16_t *usLen);
#endif
#ifdef CONFIG_MB_FUNC_WRITE_COIL_ENABLED
eMBException eMBFuncWriteCoil( uint8_t * pucFrame, uint16_t * usLen );
eMBException eMBFuncWriteCoil(uint8_t *pucFrame, uint16_t *usLen);
#endif
#ifdef CONFIG_MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED
eMBException eMBFuncWriteMultipleCoils( uint8_t * pucFrame, uint16_t * usLen );
eMBException eMBFuncWriteMultipleCoils(uint8_t *pucFrame, uint16_t *usLen);
#endif
#ifdef CONFIG_MB_FUNC_READ_DISCRETE_INPUTS_ENABLED
eMBException eMBFuncReadDiscreteInputs( uint8_t * pucFrame, uint16_t * usLen );
eMBException eMBFuncReadDiscreteInputs(uint8_t *pucFrame, uint16_t *usLen);
#endif
#ifdef CONFIG_MB_FUNC_READWRITE_HOLDING_ENABLED
eMBException eMBFuncReadWriteMultipleHoldingRegister( uint8_t * pucFrame, uint16_t * usLen );
eMBException eMBFuncReadWriteMultipleHoldingRegister(uint8_t *pucFrame, uint16_t *usLen);
#endif
#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,59 +27,67 @@
* (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. */
#define MB_FUNC_NONE ( 0 )
#define MB_FUNC_READ_COILS ( 1 )
#define MB_FUNC_READ_DISCRETE_INPUTS ( 2 )
#define MB_FUNC_WRITE_SINGLE_COIL ( 5 )
#define MB_FUNC_WRITE_MULTIPLE_COILS ( 15 )
#define MB_FUNC_READ_HOLDING_REGISTER ( 3 )
#define MB_FUNC_READ_INPUT_REGISTER ( 4 )
#define MB_FUNC_WRITE_REGISTER ( 6 )
#define MB_FUNC_WRITE_MULTIPLE_REGISTERS ( 16 )
#define MB_FUNC_READWRITE_MULTIPLE_REGISTERS ( 23 )
#define MB_FUNC_DIAG_READ_EXCEPTION ( 7 )
#define MB_FUNC_DIAG_DIAGNOSTIC ( 8 )
#define MB_FUNC_DIAG_GET_COM_EVENT_CNT ( 11 )
#define MB_FUNC_DIAG_GET_COM_EVENT_LOG ( 12 )
#define MB_FUNC_OTHER_REPORT_SLAVEID ( 17 )
#define MB_FUNC_ERROR ( 128 )
/* ----------------------- Type definitions ---------------------------------*/
typedef enum
/****************************************************************************
* 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)
#define MB_FUNC_WRITE_SINGLE_COIL (5)
#define MB_FUNC_WRITE_MULTIPLE_COILS (15)
#define MB_FUNC_READ_HOLDING_REGISTER (3)
#define MB_FUNC_READ_INPUT_REGISTER (4)
#define MB_FUNC_WRITE_REGISTER (6)
#define MB_FUNC_WRITE_MULTIPLE_REGISTERS (16)
#define MB_FUNC_READWRITE_MULTIPLE_REGISTERS (23)
#define MB_FUNC_DIAG_READ_EXCEPTION (7)
#define MB_FUNC_DIAG_DIAGNOSTIC (8)
#define MB_FUNC_DIAG_GET_COM_EVENT_CNT (11)
#define MB_FUNC_DIAG_GET_COM_EVENT_LOG (12)
#define MB_FUNC_OTHER_REPORT_SLAVEID (17)
#define MB_FUNC_ERROR (128)
/****************************************************************************
* Public Type Definitions
****************************************************************************/
typedef enum
{
MB_EX_NONE = 0x00,
MB_EX_ILLEGAL_FUNCTION = 0x01,
MB_EX_ILLEGAL_DATA_ADDRESS = 0x02,
MB_EX_ILLEGAL_DATA_VALUE = 0x03,
MB_EX_SLAVE_DEVICE_FAILURE = 0x04,
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_NONE = 0x00,
MB_EX_ILLEGAL_FUNCTION = 0x01,
MB_EX_ILLEGAL_DATA_ADDRESS = 0x02,
MB_EX_ILLEGAL_DATA_VALUE = 0x03,
MB_EX_SLAVE_DEVICE_FAILURE = 0x04,
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
} eMBException;
typedef eMBException( *pxMBFunctionHandler ) ( uint8_t * pucFrame, uint16_t * pusLength );
typedef eMBException(*pxMBFunctionHandler)(uint8_t *pucFrame, uint16_t *pusLength);
typedef struct
{
uint8_t ucFunctionCode;
pxMBFunctionHandler pxHandler;
uint8_t ucFunctionCode;
pxMBFunctionHandler pxHandler;
} xMBFunctionHandler;
#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
* 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
* bit has the offset 0.
* \param 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>
* 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.
* usBitOffset The starting address of the bits to set. The first
* bit has the offset 0.
* ucNBits Number of bits to modify. The value must always be smaller
* than 8.
* 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};
* 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 4 to 1 (read: set 1 bit starting at bit offset 4 to value 1)
*
* // Set bit 7 to 1 and bit 8 to 0.
* xMBUtilSetBits( ucBits, 7, 2, 0x01 );
* xMBUtilSetBits(ucBits, 4, 1, 1);
*
* // Set bits 8 - 11 to 0x05 and bits 12 - 15 to 0x0A;
* xMBUtilSetBits( ucBits, 8, 8, 0x5A);
* \endcode
* // 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);
*/
void xMBUtilSetBits( uint8_t * ucByteBuf, uint16_t usBitOffset,
uint8_t ucNBits, uint8_t ucValues );
/*! \brief Function to read bits in a byte buffer.
void xMBUtilSetBits(uint8_t *ucByteBuf, uint16_t usBitOffset,
uint8_t ucNBits, uint8_t ucValues);
/* 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
* bit has the offset 0.
* \param ucNBits Number of bits to modify. The value must always be smaller
* than 8.
* 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.
* ucNBits Number of bits to modify. The value must always be smaller
* than 8.
*
* \code
* uint8_t ucBits[2] = {0, 0};
* uint8_t ucResult;
* uint8_t ucBits[2] = {0, 0};
* uint8_t ucResult;
*
* // Extract the bits 3 - 10.
* ucResult = xMBUtilGetBits( ucBits, 3, 8 );
* \endcode
* // Extract the bits 3 - 10.
*
* ucResult = xMBUtilGetBits(ucBits, 3, 8);
*/
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 */