Skip to content

Commit

Permalink
Modbus Master is missing many files and doesn't compile at all. I'm a…
Browse files Browse the repository at this point in the history
…ttaching diff with my implementation. More details in https://groups.yahoo.com/neo/groups/nuttx/conversations/topics/13734
  • Loading branch information
vylu authored and gregory-nutt committed Nov 3, 2016
1 parent 0b810c5 commit e3eacfe
Show file tree
Hide file tree
Showing 19 changed files with 1,736 additions and 68 deletions.
4 changes: 2 additions & 2 deletions include/modbus/mbport.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ typedef enum
EV_MASTER_EXECUTE = 1<<2, /* Execute function. */
EV_MASTER_FRAME_SENT = 1<<3, /* Frame sent. */
EV_MASTER_ERROR_PROCESS = 1<<4, /* Frame error process. */
EV_MASTER_PROCESS_SUCESS = 1<<5, /* Request process success. */
EV_MASTER_PROCESS_SUCCESS = 1<<5, /* Request process success. */
EV_MASTER_ERROR_RESPOND_TIMEOUT = 1<<6, /* Request respond timeout. */
EV_MASTER_ERROR_RECEIVE_DATA = 1<<7, /* Request receive data error. */
EV_MASTER_ERROR_EXECUTE_FUNCTION = 1<<8 /* Request execute function error. */
Expand Down Expand Up @@ -171,7 +171,7 @@ void vMBMasterErrorCBReceiveData(uint8_t ucDestAddress, const uint8_t *pucPDUDat
uint16_t ucPDULength);
void vMBMasterErrorCBExecuteFunction(uint8_t ucDestAddress, const uint8_t *pucPDUData,
uint16_t ucPDULength);
void vMBMasterCBRequestScuuess(void);
void vMBMasterCBRequestSuccess(void);

#ifdef CONFIG_MB_TCP_ENABLED
/* TCP port function */
Expand Down
136 changes: 114 additions & 22 deletions modbus/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@
#

menu "FreeModBus"

config MODBUS
bool "Modbus support via FreeModBus"
bool "Modbus support using FreeModbus"
default n

if MODBUS

config MB_FUNC_HANDLERS_MAX
int "Maximum number of Modbus functions"
default 16
---help---
Maximum number of Modbus functions codes the protocol stack should support.

The maximum number of supported Modbus functions must be greater than
the sum of all enabled functions in this file and custom function
handlers. If set to small adding more functions will fail.

config MODBUS_SLAVE
bool "Modbus slave support via FreeModBus"
default n

if MODBUS_SLAVE
config MB_ASCII_ENABLED
bool "Modbus ASCII support"
default y

config MB_ASCII_MASTER
bool "Modbus ASCII master"
default n
depends on MB_ASCII_ENABLED

config MB_RTU_ENABLED
bool "Modbus RTU support"
default y

config MB_RTU_MASTER
bool "Modbus RTU master"
default n
depends on MB_RTU_ENABLED

config MB_TCP_ENABLED
bool "Modbus TCP support"
default y
Expand Down Expand Up @@ -68,16 +72,6 @@ config MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS
transmitting the frame. If the master is to slow with enabling its
receiver then he will not receive the response correctly.

config MB_FUNC_HANDLERS_MAX
int "Maximum number of Modbus functions"
default 16
---help---
Maximum number of Modbus functions codes the protocol stack should support.

The maximum number of supported Modbus functions must be greater than
the sum of all enabled functions in this file and custom function
handlers. If set to small adding more functions will fail.

config MB_FUNC_OTHER_REP_SLAVEID_BUF
int "Size of Slave ID report buffer"
depends on MB_FUNC_OTHER_REP_SLAVEID_ENABLED
Expand Down Expand Up @@ -150,6 +144,32 @@ config MB_FUNC_READWRITE_HOLDING_ENABLED
---help---
If the Read/Write Multiple Registers function should be enabled.

endif # MODBUS_SLAVE

config MODBUS_MASTER
bool "Modbus Master support via FreeModBus"
default n

if MODBUS_MASTER

if 0
config MB_ASCII_MASTER
bool "Modbus ASCII master"
default n
endif

config MB_RTU_MASTER
bool "Modbus RTU master"
default n

config MB_PORT_HAS_CLOSE
bool "Platform close callbacks"
default n
---help---
A port which wants to get an callback must select
CONFIG_MB_HAS_CLOSE and provide vMBMasterPortClose() as
as pvMBMasterFrameCloseCur() (if CONFIG_MB_RTU_MASTER)

if MB_ASCII_MASTER || MB_RTU_MASTER

config MB_MASTER_TOTAL_SLAVE_NUM
Expand All @@ -159,6 +179,78 @@ config MB_MASTER_TOTAL_SLAVE_NUM
The total slaves in Modbus Master system. Default 16.
NOTE: The slave ID must be continuous from 1.

config MB_MASTER_DELAY_MS_CONVERT
int "Convert Delay value"
default 200
---help---
When master sends a broadcast frame, it should allow slaves to process
current frame before sending new frame. New frame will be send only
after Convert Delay time duration.

config MB_MASTER_TIMEOUT_MS_RESPOND
int "Respond timeout value"
default 1000
---help---
When master sends frame, which is not broadcast, it should wait for
given time duration for slave response. If slave doesn't respond
during give time period, the master will process timeout
error and only then it will be able to send new frame.

config MB_MASTER_FUNC_READ_INPUT_ENABLED
bool "Read Input Registers function"
default y
---help---
If the Read Input Registers function should be enabled.

config MB_MASTER_FUNC_READ_HOLDING_ENABLED
bool "Read Holding Registers function"
default y
---help---
If the Read Holding Registers function should be enabled.

config MB_MASTER_FUNC_WRITE_HOLDING_ENABLED
bool "Write Single Register function"
default y
---help---
If the Write Single Register function should be enabled.

config MB_MASTER_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED
bool "Write Multiple registers function"
default y
---help---
If the Write Multiple registers function should be enabled.

config MB_MASTER_FUNC_READ_COILS_ENABLED
bool "Read Coils function"
default y
---help---
If the Read Coils function should be enabled.

config MB_MASTER_FUNC_WRITE_COIL_ENABLED
bool "Write Coils function"
default y
---help---
If the Write Coils function should be enabled.

config MB_MASTER_FUNC_WRITE_MULTIPLE_COILS_ENABLED
bool "Write Multiple Coils function"
default y
---help---
If the Write Multiple Coils function should be enabled.

config MB_MASTER_FUNC_READ_DISCRETE_INPUTS_ENABLED
bool "Read Discrete Inputs function"
default y
---help---
If the Read Discrete Inputs function should be enabled.

config MB_MASTER_FUNC_READWRITE_HOLDING_ENABLED
bool "Read/Write Multiple Registers function"
default y
---help---
If the Read/Write Multiple Registers function should be enabled.

endif # MB_ASCII_MASTER || MB_RTU_MASTER
endif # MODBUS_MASTER
endif # MODBUS
endmenu # FreeModBus
7 changes: 7 additions & 0 deletions modbus/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ CSRCS =

ifeq ($(CONFIG_MODBUS),y)

ifeq ($(CONFIG_MODBUS_SLAVE),y)
CSRCS += mb.c
endif

ifeq ($(CONFIG_MB_RTU_MASTER),y)
CSRCS += mb_m.c
endif

DEPPATH = --dep-path .
VPATH = .

Expand Down
8 changes: 4 additions & 4 deletions modbus/functions/mbfunccoils_m.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ eMBException prveMBError2Exception(eMBErrorCode eErrorCode);
* Public Functions
****************************************************************************/

#if defined(CONFIG_RTU_ASCII_MASTER) || defined(CONFIG_MB_ASCII_MASTER)
#if defined(CONFIG_MB_RTU_MASTER) || defined(CONFIG_MB_ASCII_MASTER)

/****************************************************************************
* Description:
Expand All @@ -100,7 +100,7 @@ eMBException prveMBError2Exception(eMBErrorCode eErrorCode);
*
****************************************************************************/

#ifdef CONFIG_MB_FUNC_READ_COILS_ENABLED
#ifdef CONFIG_MB_MASTER_FUNC_READ_COILS_ENABLED
eMBMasterReqErrCode eMBMasterReqReadCoils(uint8_t ucSndAddr,
uint16_t usCoilAddr,
uint16_t usNCoils,
Expand Down Expand Up @@ -230,7 +230,7 @@ eMBException eMBMasterFuncReadCoils(uint8_t *pucFrame, uint16_t *usLen)
*
****************************************************************************/

#ifdef CONFIG_MB_FUNC_WRITE_COIL_ENABLED
#ifdef CONFIG_MB_MASTER_FUNC_WRITE_COIL_ENABLED
eMBMasterReqErrCode eMBMasterReqWriteCoil(uint8_t ucSndAddr,
uint16_t usCoilAddr,
uint16_t usCoilData,
Expand Down Expand Up @@ -342,7 +342,7 @@ eMBException eMBMasterFuncWriteCoil(uint8_t *pucFrame, uint16_t *usLen)
*
****************************************************************************/

#ifdef CONFIG_MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED
#ifdef CONFIG_MB_MASTER_FUNC_WRITE_MULTIPLE_COILS_ENABLED
eMBMasterReqErrCode eMBMasterReqWriteMultipleCoils(uint8_t ucSndAddr,
uint16_t usCoilAddr,
uint16_t usNCoils,
Expand Down
4 changes: 2 additions & 2 deletions modbus/functions/mbfuncdisc_m.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ eMBException prveMBError2Exception(eMBErrorCode eErrorCode);
* Public Functions
****************************************************************************/

#if defined(CONFIG_RTU_ASCII_MASTER) || defined(CONFIG_MB_ASCII_MASTER)
#if defined(CONFIG_MB_RTU_MASTER) || defined(CONFIG_MB_ASCII_MASTER)

/****************************************************************************
* Description:
Expand All @@ -82,7 +82,7 @@ eMBException prveMBError2Exception(eMBErrorCode eErrorCode);
*
****************************************************************************/

#ifdef CONFIG_MB_FUNC_READ_DISCRETE_INPUTS_ENABLED
#ifdef CONFIG_MB_MASTER_FUNC_READ_DISCRETE_INPUTS_ENABLED
eMBMasterReqErrCode eMBMasterReqReadDiscreteInputs(uint8_t ucSndAddr,
uint16_t usDiscreteAddr,
uint16_t usNDiscreteIn,
Expand Down
10 changes: 5 additions & 5 deletions modbus/functions/mbfuncholding_m.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ eMBException prveMBError2Exception(eMBErrorCode eErrorCode);
* Public Functions
****************************************************************************/

#if defined(CONFIG_RTU_ASCII_MASTER) || defined(CONFIG_MB_ASCII_MASTER)
#if defined(CONFIG_MB_RTU_MASTER) || defined(CONFIG_MB_ASCII_MASTER)

/****************************************************************************
* Description:
Expand All @@ -111,7 +111,7 @@ eMBException prveMBError2Exception(eMBErrorCode eErrorCode);
*
****************************************************************************/

#ifdef CONFIG_MB_FUNC_WRITE_HOLDING_ENABLED
#ifdef CONFIG_MB_MASTER_FUNC_WRITE_HOLDING_ENABLED
eMBMasterReqErrCode eMBMasterReqWriteHoldingRegister(uint8_t ucSndAddr,
uint16_t usRegAddr,
uint16_t usRegData,
Expand Down Expand Up @@ -195,7 +195,7 @@ eMBException eMBMasterFuncWriteHoldingRegister(uint8_t *pucFrame,
*
****************************************************************************/

#ifdef CONFIG_MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED
#ifdef CONFIG_MB_MASTER_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED
eMBMasterReqErrCode
eMBMasterReqWriteMultipleHoldingRegister(uint8_t ucSndAddr,
uint16_t usRegAddr,
Expand Down Expand Up @@ -313,7 +313,7 @@ eMBException eMBMasterFuncWriteMultipleHoldingRegister(uint8_t *pucFrame,
*
****************************************************************************/

#ifdef CONFIG_MB_FUNC_READ_HOLDING_ENABLED
#ifdef CONFIG_MB_MASTER_FUNC_READ_HOLDING_ENABLED
eMBMasterReqErrCode eMBMasterReqReadHoldingRegister(uint8_t ucSndAddr,
uint16_t usRegAddr,
uint16_t usNRegs,
Expand Down Expand Up @@ -429,7 +429,7 @@ eMBException eMBMasterFuncReadHoldingRegister(uint8_t *pucFrame,
*
****************************************************************************/

#ifdef CONFIG_MB_FUNC_READWRITE_HOLDING_ENABLED
#ifdef CONFIG_MB_MASTER_FUNC_READWRITE_HOLDING_ENABLED
eMBMasterReqErrCode
eMBMasterReqReadWriteMultipleHoldingRegister(uint8_t ucSndAddr,
uint16_t usReadRegAddr,
Expand Down
4 changes: 2 additions & 2 deletions modbus/functions/mbfuncinput_m.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ eMBException prveMBError2Exception(eMBErrorCode eErrorCode);
* Public Functions
****************************************************************************/

#if defined(CONFIG_RTU_ASCII_MASTER) || defined(CONFIG_MB_ASCII_MASTER)
#if defined(CONFIG_MB_RTU_MASTER) || defined(CONFIG_MB_ASCII_MASTER)

/****************************************************************************
* Description:
Expand All @@ -84,7 +84,7 @@ eMBException prveMBError2Exception(eMBErrorCode eErrorCode);
*
****************************************************************************/

#if defined(CONFIG_MB_FUNC_READ_INPUT_ENABLED)
#if defined(CONFIG_MB_MASTER_FUNC_READ_INPUT_ENABLED)
eMBMasterReqErrCode eMBMasterReqReadInputRegister(uint8_t ucSndAddr,
uint16_t usRegAddr,
uint16_t usNRegs,
Expand Down
Loading

0 comments on commit e3eacfe

Please sign in to comment.