forked from espressif/esp-modbus
independent instance command handling using lists, fixes as per review and test
This commit is contained in:
1 parent
ddb731578c
commit
20b3dbaa82
42 files changed
+845
-542
No files matched your search
@@ -20,7 +20,7 @@
|
||||
#define MASTER_MAX_CIDS num_device_parameters
|
||||
|
||||
// Number of reading of parameters from slave
|
||||
#define MASTER_MAX_RETRY 30
|
||||
#define MASTER_MAX_RETRY (10)
|
||||
|
||||
// Timeout to update cid over Modbus
|
||||
#define UPDATE_CIDS_TIMEOUT_MS (500)
|
||||
@@ -56,7 +56,7 @@
|
||||
#define OPTS(min_val, max_val, step_val) { .opt1 = min_val, .opt2 = max_val, .opt3 = step_val }
|
||||
|
||||
#define EACH_ITEM(array, length) \
|
||||
(typeof(*(array)) *pitem = (array); (pitem < &((array)[length])); pitem++)
|
||||
(typeof(*(array)) *pitem = (array); (pitem < &((array)[length])); pitem++)
|
||||
|
||||
#define MB_CUST_DATA_LEN 100 // The length of custom command buffer
|
||||
|
||||
@@ -305,19 +305,6 @@ static void *master_get_param_data(const mb_parameter_descriptor_t *param_descri
|
||||
} \
|
||||
))
|
||||
|
||||
mb_exception_t my_custom_handler(void *, uint8_t *frame_ptr, uint16_t *plen)
|
||||
{
|
||||
MB_RETURN_ON_FALSE((frame_ptr && plen && *plen && *plen < (MB_CUST_DATA_LEN - 1)), MB_EX_CRITICAL, TAG,
|
||||
"incorrect custom frame buffer");
|
||||
ESP_LOGW(TAG, "Custom handler, Frame ptr: %p, len: %u", frame_ptr, *plen);
|
||||
// This error handler will be executed to handle the request for the registered custom command
|
||||
// Refer the handler functions in `esp-modbus/modbus/mb_objects/functions/mbfuncinput_master.c` for more information.
|
||||
// Parameters: pframe: is pointer to incoming frame buffer, plen: is pointer to length including the function code
|
||||
strncpy((char *)&my_custom_data[0], (char *)&frame_ptr[1], MB_CUST_DATA_LEN);
|
||||
ESP_LOG_BUFFER_HEXDUMP("CUSTOM_DATA", &my_custom_data[0], (*plen - 1), ESP_LOG_WARN);
|
||||
return MB_EX_NONE;
|
||||
}
|
||||
|
||||
// User operation function to read slave values and check alarm
|
||||
static void master_operation_func(void *arg)
|
||||
{
|
||||
@@ -336,12 +323,14 @@ static void master_operation_func(void *arg)
|
||||
};
|
||||
|
||||
// Send the request with custom command (vendor speciic)
|
||||
// This function supports sending of only even number of bytes
|
||||
// as instructed by req.reg_size (Modbus register = 2 bytes)
|
||||
err = mbc_master_send_request(master_handle, &req, pcustom_string);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE("CUSTOM_DATA", "Send custom request fail.");
|
||||
}
|
||||
|
||||
#if MB_FUNC_OTHER_REP_SLAVEID_ENABLED
|
||||
#if CONFIG_FMB_CONTROLLER_SLAVE_ID_SUPPORT
|
||||
// Command - 17 (0x11) Report Slave ID
|
||||
// The command contains vendor specific data and should be interpreted accordingly.
|
||||
// This version of command handler needs to define the maximum number
|
||||
@@ -349,12 +338,10 @@ static void master_operation_func(void *arg)
|
||||
// The returned slave info data will be stored into the `info_buf`.
|
||||
// Request fields: slave_addr - the UID of slave, reg_start - not used,
|
||||
// reg_size = max size of buffer (registers).
|
||||
req = {
|
||||
.slave_addr = MB_DEVICE_ADDR1, // slave UID to retrieve ID
|
||||
.command = 0x11, // the <Report Slave ID> command,
|
||||
.reg_start = 0, // must be zero,
|
||||
.reg_size = (CONFIG_FMB_CONTROLLER_SLAVE_ID_MAX_SIZE >> 1) // the expected length of buffer in registers
|
||||
};
|
||||
req.slave_addr = MB_DEVICE_ADDR1; // slave UID to retrieve ID
|
||||
req.command = 0x11; // the <Report Slave ID> command,
|
||||
req.reg_start = 0; // must be zero,
|
||||
req.reg_size = (CONFIG_FMB_CONTROLLER_SLAVE_ID_MAX_SIZE >> 1); // the expected length of buffer in registers
|
||||
|
||||
uint8_t info_buf[CONFIG_FMB_CONTROLLER_SLAVE_ID_MAX_SIZE] = {0}; // The buffer to save slave ID
|
||||
|
||||
@@ -498,6 +485,21 @@ static void master_operation_func(void *arg)
|
||||
ESP_ERROR_CHECK(mbc_master_delete(master_handle));
|
||||
}
|
||||
|
||||
// This is the custom function handler for the command.
|
||||
// The handler is executed from the context of modbus controller event task and should be as simple as possible.
|
||||
// Parameters: frame_ptr - the pointer to the incoming ADU frame from slave starting from function code,
|
||||
// plen - the pointer to length of the frame. After return from the handler the modbus object will
|
||||
// handle the end of transaction according to the exception returned.
|
||||
mb_exception_t my_custom_handler(void *inst, uint8_t *frame_ptr, uint16_t *plen)
|
||||
{
|
||||
MB_RETURN_ON_FALSE((frame_ptr && plen && *plen && *plen < (MB_CUST_DATA_LEN - 1)), MB_EX_ILLEGAL_DATA_VALUE, TAG,
|
||||
"incorrect custom frame buffer");
|
||||
ESP_LOGD(TAG, "Custom handler, Frame ptr: %p, len: %u", frame_ptr, *plen);
|
||||
strncpy((char *)&my_custom_data[0], (char *)&frame_ptr[1], MB_CUST_DATA_LEN);
|
||||
ESP_LOG_BUFFER_HEXDUMP("CUSTOM_DATA", &my_custom_data[0], (*plen - 1), ESP_LOG_WARN);
|
||||
return MB_EX_NONE;
|
||||
}
|
||||
|
||||
// Modbus master initialization
|
||||
static esp_err_t master_init(void)
|
||||
{
|
||||
@@ -523,15 +525,16 @@ static esp_err_t master_init(void)
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG,
|
||||
"mb controller initialization fail, returns(0x%x).", (int)err);
|
||||
|
||||
uint8_t override_command = 0x41;
|
||||
err = mbc_master_set_handler(master_handle, override_command, NULL);
|
||||
const uint8_t override_command = 0x41;
|
||||
// Delete the handler for specified command, if available
|
||||
err = mbc_delete_handler(master_handle, override_command);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK || err == ESP_ERR_INVALID_STATE), ESP_ERR_INVALID_STATE, TAG,
|
||||
"could not override handler, returned (0x%x).", (int)err);
|
||||
err = mbc_master_set_handler(master_handle, override_command, my_custom_handler);
|
||||
err = mbc_set_handler(master_handle, override_command, my_custom_handler);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG,
|
||||
"could not override handler, returned (0x%x).", (int)err);
|
||||
mb_fn_handler_fp phandler = NULL;
|
||||
err = mbc_master_get_handler(master_handle, override_command, &phandler);
|
||||
err = mbc_get_handler(master_handle, override_command, &phandler);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK && phandler == my_custom_handler), ESP_ERR_INVALID_STATE, TAG,
|
||||
"could not get handler for command %d, returned (0x%x).", (int)override_command, (int)err);
|
||||
|
||||
|
||||
@@ -145,20 +145,22 @@ static void setup_reg_data(void)
|
||||
input_reg_params.input_data7 = 4.78;
|
||||
}
|
||||
|
||||
// This is a simple custom function handler for the command.
|
||||
// The handler is executed from the context of modbus controller event task and should be as simple as possible.
|
||||
// Parameters: frame_ptr - the pointer to the incoming ADU request frame from master starting from function code,
|
||||
// plen - the pointer to length of the frame. The handler body can override the buffer and return the length of data.
|
||||
// After return from the handler the modbus object will handle the end of transaction according to the exception returned,
|
||||
// then builds the response frame and send it back to the master. If the whole transaction time including the response
|
||||
// latency exceeds the configured slave response time set in the master configuration the master will ignore the transaction.
|
||||
mb_exception_t my_custom_fc_handler(void *pinst, uint8_t *frame_ptr, uint16_t *plen)
|
||||
{
|
||||
char *str_append = ":Slave";
|
||||
MB_RETURN_ON_FALSE((frame_ptr && plen && *plen < (MB_CUST_DATA_MAX_LEN - strlen(str_append))), MB_EX_ILLEGAL_DATA_VALUE, TAG,
|
||||
"incorrect custom frame");
|
||||
//ESP_LOGW("CUSTOM_DATA", "Custom handler, frame ptr: %p, len: %u", frame_ptr, *plen);
|
||||
//ESP_LOG_BUFFER_HEXDUMP("CUSTOM_DATA", frame_ptr, *plen, ESP_LOG_WARN);
|
||||
// This command handler will be executed to check the request for the custom command
|
||||
// See the `esp-modbus/modbus/mb_objects/functions/functions/mbfuncinput.c` for more information
|
||||
// pframe is pointer to the buffer starting from function code, plen - is pointer to length of the data
|
||||
frame_ptr[*plen] = '\0';
|
||||
strcat((char *)&frame_ptr[1], str_append);
|
||||
*plen = (strlen(str_append) + *plen); // the length of (response + command)
|
||||
return MB_EX_NONE; // Set the exception code for slave appropriately
|
||||
return MB_EX_NONE; // Set the exception code for modbus object appropriately
|
||||
}
|
||||
|
||||
// An example application of Modbus slave. It is based on esp-modbus stack.
|
||||
@@ -190,15 +192,16 @@ void app_main(void)
|
||||
|
||||
ESP_ERROR_CHECK(mbc_slave_create_serial(&comm_config, &mbc_slave_handle)); // Initialization of Modbus controller
|
||||
|
||||
uint8_t custom_command = 0x41; // The custom command to be sent to slave
|
||||
esp_err_t err = mbc_slave_set_handler(mbc_slave_handle, custom_command, NULL);
|
||||
const uint8_t custom_command = 0x41; // The custom command to be sent to slave
|
||||
// Try to delete the handler for specified command.
|
||||
esp_err_t err = mbc_delete_handler(mbc_slave_handle, custom_command);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK || err == ESP_ERR_INVALID_STATE), ;, TAG,
|
||||
"could not reset handler, returned (0x%x).", (int)err);
|
||||
err = mbc_slave_set_handler(mbc_slave_handle, custom_command, my_custom_fc_handler);
|
||||
"could not delete handler, returned (0x%x).", (int)err);
|
||||
err = mbc_set_handler(mbc_slave_handle, custom_command, my_custom_fc_handler);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK), ;, TAG,
|
||||
"could not set or override handler, returned (0x%x).", (int)err);
|
||||
mb_fn_handler_fp phandler = NULL;
|
||||
err = mbc_slave_get_handler(mbc_slave_handle, custom_command, &phandler);
|
||||
err = mbc_get_handler(mbc_slave_handle, custom_command, &phandler);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK && phandler == my_custom_fc_handler), ;, TAG,
|
||||
"could not get handler for command %d, returned (0x%x).", (int)custom_command, (int)err);
|
||||
|
||||
|
||||
@@ -65,6 +65,9 @@
|
||||
// Options can be used as bit masks or parameter limits
|
||||
#define OPTS(min_val, max_val, step_val) { .opt1 = min_val, .opt2 = max_val, .opt3 = step_val }
|
||||
|
||||
#define EACH_ITEM(array, length) \
|
||||
(typeof(*(array)) *pitem = (array); (pitem < &((array)[length])); pitem++)
|
||||
|
||||
#define MB_ID_BYTE0(id) ((uint8_t)(id))
|
||||
#define MB_ID_BYTE1(id) ((uint8_t)(((uint16_t)(id) >> 8) & 0xFF))
|
||||
#define MB_ID_BYTE2(id) ((uint8_t)(((uint32_t)(id) >> 16) & 0xFF))
|
||||
@@ -80,9 +83,6 @@
|
||||
|
||||
#define MB_MDNS_INSTANCE(pref) pref"mb_master_tcp"
|
||||
|
||||
#define EACH_ITEM(array, length) \
|
||||
(typeof(*(array)) *pitem = (array); (pitem < &((array)[length])); pitem++)
|
||||
|
||||
#define MB_CUST_DATA_LEN 100 // The length of custom command buffer
|
||||
|
||||
static const char *TAG = "MASTER_TEST";
|
||||
@@ -675,16 +675,18 @@ static esp_err_t destroy_services(void)
|
||||
return err;
|
||||
}
|
||||
|
||||
mb_exception_t my_custom_fc_handler(void *pinst, uint8_t *frame_ptr, uint16_t *plen)
|
||||
// This is the custom function handler for the command.
|
||||
// The handler is executed from the context of modbus controller event task and should be as simple as possible.
|
||||
// Parameters: frame_ptr - the pointer to the incoming ADU frame from slave starting from function code,
|
||||
// plen - the pointer to length of the frame. After return from the handler the modbus object will
|
||||
// handle the end of transaction according to the exception returned.
|
||||
mb_exception_t my_custom_fc_handler(void *inst, uint8_t *frame_ptr, uint16_t *plen)
|
||||
{
|
||||
MB_RETURN_ON_FALSE((frame_ptr && plen && *plen && *plen < (MB_CUST_DATA_LEN - 1)), MB_EX_CRITICAL, TAG,
|
||||
MB_RETURN_ON_FALSE((frame_ptr && plen && *plen && *plen < (MB_CUST_DATA_LEN - 1)), MB_EX_ILLEGAL_DATA_VALUE, TAG,
|
||||
"incorrect custom frame buffer");
|
||||
ESP_LOGW(TAG, "Custom handler, Frame ptr: %p, len: %u", frame_ptr, *plen);
|
||||
// This error handler will be executed to handle the request for the registered custom command
|
||||
// Refer the handler functions in `esp-modbus/modbus/mb_objects/functions/mbfuncinput_master.c` for more information.
|
||||
// Parameters: pframe: is pointer to incoming frame buffer, plen: is pointer to length including the function code
|
||||
ESP_LOGI(TAG, "Custom handler, Frame ptr: %p, len: %u", frame_ptr, *plen);
|
||||
strncpy((char *)&my_custom_data[0], (char *)&frame_ptr[1], MB_CUST_DATA_LEN);
|
||||
ESP_LOG_BUFFER_HEXDUMP("CUSTOM_DATA", &my_custom_data[0], (*plen - 1), ESP_LOG_WARN);
|
||||
ESP_LOG_BUFFER_HEXDUMP("CUSTOM_DATA", &my_custom_data[0], (*plen - 1), ESP_LOG_INFO);
|
||||
return MB_EX_NONE;
|
||||
}
|
||||
|
||||
@@ -702,15 +704,15 @@ static esp_err_t master_init(mb_communication_info_t *pcomm_info)
|
||||
|
||||
// Add custom command handler
|
||||
uint8_t custom_command = 0x41;
|
||||
// Make sure the handler is undefined for the command
|
||||
err = mbc_master_set_handler(master_handle, custom_command, NULL);
|
||||
// Delete the handler for specified command, if available
|
||||
err = mbc_delete_handler(master_handle, custom_command);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK || err == ESP_ERR_INVALID_STATE), ESP_ERR_INVALID_STATE, TAG,
|
||||
"could not override handler, returned (0x%x).", (int)err);
|
||||
err = mbc_master_set_handler(master_handle, custom_command, my_custom_fc_handler);
|
||||
err = mbc_set_handler(master_handle, custom_command, my_custom_fc_handler);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG,
|
||||
"could not override handler, returned (0x%x).", (int)err);
|
||||
mb_fn_handler_fp phandler = NULL;
|
||||
err = mbc_master_get_handler(master_handle, custom_command, &phandler);
|
||||
err = mbc_get_handler(master_handle, custom_command, &phandler);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK && phandler == my_custom_fc_handler), ESP_ERR_INVALID_STATE, TAG,
|
||||
"could not get handler for command %d, returned (0x%x).", (int)custom_command, (int)err);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ CONFIG_FMB_MASTER_DELAY_MS_CONVERT=300
|
||||
CONFIG_FMB_TCP_UID_ENABLED=n
|
||||
CONFIG_FMB_TIMER_USE_ISR_DISPATCH_METHOD=y
|
||||
CONFIG_MB_SLAVE_IP_FROM_STDIN=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y # intentionally keep it here to change when needed
|
||||
CONFIG_FMB_EXT_TYPE_SUPPORT=y
|
||||
|
||||
CONFIG_EXAMPLE_CONNECT_IPV6=n
|
||||
|
||||
@@ -7,7 +7,7 @@ CONFIG_FMB_COMM_MODE_RTU_EN=n
|
||||
CONFIG_FMB_COMM_MODE_ASCII_EN=n
|
||||
CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND=3000
|
||||
CONFIG_FMB_MASTER_DELAY_MS_CONVERT=300
|
||||
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y # intentionally keep it here to change when needed
|
||||
CONFIG_FMB_TCP_UID_ENABLED=n
|
||||
CONFIG_MB_SLAVE_IP_FROM_STDIN=y
|
||||
CONFIG_EXAMPLE_CONNECT_IPV6=n
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
// FreeModbus Slave Example ESP32
|
||||
|
||||
#include <stdio.h>
|
||||
#include "esp_err.h"
|
||||
#include "sdkconfig.h"
|
||||
@@ -43,7 +41,7 @@
|
||||
#define MB_REG_HOLDING_START_AREA2_SIZE ((size_t)((HOLD_OFFSET(holding_area2_end) - HOLD_OFFSET(holding_u8_a)) << 1))
|
||||
|
||||
#define MB_PAR_INFO_GET_TOUT (10) // Timeout for get parameter info
|
||||
#define MB_CHAN_DATA_MAX_VAL (50)
|
||||
#define MB_CHAN_DATA_MAX_VAL (60)
|
||||
#define MB_CHAN_DATA_OFFSET (10.1f)
|
||||
|
||||
#define MB_READ_MASK (MB_EVENT_INPUT_REG_RD \
|
||||
@@ -267,27 +265,28 @@ static esp_err_t destroy_services(void)
|
||||
return err;
|
||||
}
|
||||
|
||||
// This custom command handler will be executed to check the request for the custom command
|
||||
// See the `esp-modbus/modbus/mb_objects/functions/mbfuncinput.c` for more information
|
||||
// pframe is pointer to the buffer starting from function code, plen - is pointer to length of the data
|
||||
// This is a simple custom function handler for the command.
|
||||
// The handler is executed from the context of modbus controller event task and should be as simple as possible.
|
||||
// Parameters: frame_ptr - the pointer to the incoming ADU request frame from master starting from function code,
|
||||
// plen - the pointer to length of the frame. The handler body can override the buffer and return the length of data.
|
||||
// After return from the handler the modbus object will handle the end of transaction according to the exception returned,
|
||||
// then builds the response frame and send it back to the master. If the whole transaction time including the response
|
||||
// latency exceeds the configured slave response time set in the master configuration the master will ignore the transaction.
|
||||
mb_exception_t my_custom_fc_handler(void *pinst, uint8_t *frame_ptr, uint16_t *plen)
|
||||
{
|
||||
char *str_append = ":Slave";
|
||||
MB_RETURN_ON_FALSE((frame_ptr && plen && *plen < (MB_CUST_DATA_MAX_LEN - strlen(str_append))),
|
||||
MB_EX_ILLEGAL_DATA_VALUE, TAG,
|
||||
MB_RETURN_ON_FALSE((frame_ptr && plen && *plen < (MB_CUST_DATA_MAX_LEN - strlen(str_append))), MB_EX_ILLEGAL_DATA_VALUE, TAG,
|
||||
"incorrect custom frame");
|
||||
ESP_LOGW("CUSTOM_DATA", "Custom handler, frame ptr: %p, len: %u", frame_ptr, *plen);
|
||||
ESP_LOG_BUFFER_HEXDUMP("CUSTOM_DATA", frame_ptr, *plen, ESP_LOG_WARN);
|
||||
frame_ptr[*plen] = '\0';
|
||||
strcat((char *)&frame_ptr[1], str_append);
|
||||
*plen = (strlen(str_append) + *plen); // the length of (response + command)
|
||||
return MB_EX_NONE; // Set the exception code for slave appropriately
|
||||
return MB_EX_NONE; // Set the exception code for modbus object appropriately
|
||||
}
|
||||
|
||||
// Modbus slave initialization
|
||||
static esp_err_t slave_init(mb_communication_info_t *pcomm_info)
|
||||
{
|
||||
mb_register_area_descriptor_t reg_area; // Modbus register area descriptor structure
|
||||
mb_register_area_descriptor_t reg_area = {0}; // Modbus register area descriptor structure
|
||||
|
||||
// Initialization of Modbus controller
|
||||
esp_err_t err = mbc_slave_create_tcp(pcomm_info, &slave_handle);
|
||||
@@ -296,14 +295,15 @@ static esp_err_t slave_init(mb_communication_info_t *pcomm_info)
|
||||
"mb controller create fail.");
|
||||
|
||||
uint8_t custom_command = 0x41;
|
||||
err = mbc_slave_set_handler(slave_handle, custom_command, NULL);
|
||||
// Delete the handler for specified command, if available.
|
||||
err = mbc_delete_handler(slave_handle, custom_command);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK || err == ESP_ERR_INVALID_STATE), ESP_ERR_INVALID_STATE, TAG,
|
||||
"could not reset handler, returned (0x%x).", (int)err);
|
||||
err = mbc_slave_set_handler(slave_handle, custom_command, my_custom_fc_handler);
|
||||
err = mbc_set_handler(slave_handle, custom_command, my_custom_fc_handler);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG,
|
||||
"could not set or override handler, returned (0x%x).", (int)err);
|
||||
mb_fn_handler_fp phandler = NULL;
|
||||
err = mbc_slave_get_handler(slave_handle, custom_command, &phandler);
|
||||
err = mbc_get_handler(slave_handle, custom_command, &phandler);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK && phandler == my_custom_fc_handler), ESP_ERR_INVALID_STATE, TAG,
|
||||
"could not get handler for command %d, returned (0x%x).", (int)custom_command, (int)err);
|
||||
|
||||
@@ -317,6 +317,7 @@ static esp_err_t slave_init(mb_communication_info_t *pcomm_info)
|
||||
reg_area.start_offset = MB_REG_HOLDING_START_AREA0; // Offset of register area in Modbus protocol
|
||||
reg_area.address = (void*)&holding_reg_params.holding_data0; // Set pointer to storage instance
|
||||
reg_area.size = (MB_REG_HOLDING_START_AREA1 - MB_REG_HOLDING_START_AREA0) << 1; // Set the size of register storage instance
|
||||
reg_area.access = MB_ACCESS_RW;
|
||||
err = mbc_slave_set_descriptor(slave_handle, reg_area);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE,
|
||||
TAG,
|
||||
@@ -327,6 +328,7 @@ static esp_err_t slave_init(mb_communication_info_t *pcomm_info)
|
||||
reg_area.start_offset = MB_REG_HOLDING_START_AREA1; // Offset of register area in Modbus protocol
|
||||
reg_area.address = (void*)&holding_reg_params.holding_data4; // Set pointer to storage instance
|
||||
reg_area.size = sizeof(float) << 2; // Set the size of register storage instance
|
||||
reg_area.access = MB_ACCESS_RW;
|
||||
err = mbc_slave_set_descriptor(slave_handle, reg_area);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE,
|
||||
TAG,
|
||||
@@ -339,6 +341,7 @@ static esp_err_t slave_init(mb_communication_info_t *pcomm_info)
|
||||
reg_area.start_offset = MB_REG_HOLDING_START_AREA2;
|
||||
reg_area.address = (void*)&holding_reg_params.holding_u8_a;
|
||||
reg_area.size = MB_REG_HOLDING_START_AREA2_SIZE;
|
||||
reg_area.access = MB_ACCESS_RW;
|
||||
err = mbc_slave_set_descriptor(slave_handle, reg_area);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE,
|
||||
TAG,
|
||||
@@ -351,6 +354,7 @@ static esp_err_t slave_init(mb_communication_info_t *pcomm_info)
|
||||
reg_area.start_offset = MB_REG_INPUT_START_AREA0;
|
||||
reg_area.address = (void*)&input_reg_params.input_data0;
|
||||
reg_area.size = sizeof(float) << 2;
|
||||
reg_area.access = MB_ACCESS_RW;
|
||||
err = mbc_slave_set_descriptor(slave_handle, reg_area);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE,
|
||||
TAG,
|
||||
@@ -360,6 +364,7 @@ static esp_err_t slave_init(mb_communication_info_t *pcomm_info)
|
||||
reg_area.start_offset = MB_REG_INPUT_START_AREA1;
|
||||
reg_area.address = (void*)&input_reg_params.input_data4;
|
||||
reg_area.size = sizeof(float) << 2;
|
||||
reg_area.access = MB_ACCESS_RW;
|
||||
err = mbc_slave_set_descriptor(slave_handle, reg_area);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE,
|
||||
TAG,
|
||||
@@ -371,6 +376,7 @@ static esp_err_t slave_init(mb_communication_info_t *pcomm_info)
|
||||
reg_area.start_offset = MB_REG_COILS_START;
|
||||
reg_area.address = (void*)&coil_reg_params;
|
||||
reg_area.size = sizeof(coil_reg_params);
|
||||
reg_area.access = MB_ACCESS_RW;
|
||||
err = mbc_slave_set_descriptor(slave_handle, reg_area);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE,
|
||||
TAG,
|
||||
@@ -382,6 +388,7 @@ static esp_err_t slave_init(mb_communication_info_t *pcomm_info)
|
||||
reg_area.start_offset = MB_REG_DISCRETE_INPUT_START;
|
||||
reg_area.address = (void*)&discrete_reg_params;
|
||||
reg_area.size = sizeof(discrete_reg_params);
|
||||
reg_area.access = MB_ACCESS_RW;
|
||||
err = mbc_slave_set_descriptor(slave_handle, reg_area);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE,
|
||||
TAG,
|
||||
|
||||
@@ -14,7 +14,7 @@ CONFIG_FMB_EXT_TYPE_SUPPORT=y
|
||||
CONFIG_FMB_TCP_UID_ENABLED=n
|
||||
CONFIG_FMB_TIMER_USE_ISR_DISPATCH_METHOD=y
|
||||
CONFIG_MB_SLAVE_ADDR=1
|
||||
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y # intentionally keep it here to change when needed!
|
||||
CONFIG_EXAMPLE_CONNECT_IPV6=n
|
||||
CONFIG_EXAMPLE_CONNECT_WIFI=n
|
||||
CONFIG_EXAMPLE_CONNECT_ETHERNET=y
|
||||
|
||||
@@ -8,7 +8,7 @@ CONFIG_FMB_COMM_MODE_ASCII_EN=n
|
||||
CONFIG_FMB_EXT_TYPE_SUPPORT=y
|
||||
CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND=3000
|
||||
CONFIG_FMB_MASTER_DELAY_MS_CONVERT=300
|
||||
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y # intentionally keep it here to change when needed!
|
||||
CONFIG_FMB_TCP_UID_ENABLED=n
|
||||
CONFIG_MB_SLAVE_ADDR=1
|
||||
CONFIG_EXAMPLE_CONNECT_IPV6=n
|
||||
|
||||
@@ -39,8 +39,7 @@ LOGGER_NAME = 'modbus_test'
|
||||
logger = logging.getLogger(LOGGER_NAME)
|
||||
|
||||
test_configs = [
|
||||
'wifi',
|
||||
# 'ethernet'
|
||||
'ethernet'
|
||||
]
|
||||
|
||||
@pytest.mark.esp32
|
||||
|
||||
Reference in new issue
Block a user