-
Notifications
You must be signed in to change notification settings - Fork 70
Closed
Description
Checklist
- Checked the issue tracker for similar issues to ensure this is not a duplicate
- Read the documentation to confirm the issue is not addressed there and your configuration is set correctly
- Tested with the latest version to ensure the issue hasn't been fixed
How often does this bug occurs?
always
Expected behavior
I except macros that are named the same to behave the same.
In serial_master.c
#define HOLD_OFFSET(field) ((uint16_t)(offsetof(holding_reg_params_t, field) + 1))
In serial_slave.c
#define HOLD_OFFSET(field) ((uint16_t)(offsetof(holding_reg_params_t, field) >> 1))
Actual behavior (suspected bug)
I am trying to understand why the Master and Slave use slightly different initialization macros. I cannot get my Master to consistently communicate the same message to the Slave due to this weird nuance.
Error logs or terminal output
typedef struct __attribute__((packed)) {
uint16_t command;
uint16_t file_name[MAX_FILE_NAME_STRING_LEN];
uint16_t ack;
} holding_reg_params_t;
typedef struct __attribute__((packed)) {
uint16_t status;
uint16_t data_ready;
uint16_t buffer_size;
uint16_t chunk_size;
uint16_t buffer[KB_TO_BYTES(CONFIG_OFFLOAD_BUFFER_SIZE) / sizeof(uint16_t)];
} input_reg_params_t;
In master:
ESP_LOGI(TAG, "Start: %zu, size: %zu, offset: %zu", TEST_HOLD_REG_START(command), TEST_HOLD_REG_SIZE(command), HOLD_OFFSET(command));
ESP_LOGI(TAG, "Start: %zu, size: %zu, offset: %zu", TEST_HOLD_REG_START(file_name), TEST_HOLD_REG_SIZE(file_name), HOLD_OFFSET(file_name));
ESP_LOGI(TAG, "Start: %zu, size: %zu, offset: %zu", TEST_HOLD_REG_START(ack), TEST_HOLD_REG_SIZE(ack), HOLD_OFFSET(ack));
ESP_LOGI(TAG, "Start: %zu, size: %zu, offset: %zu", TEST_INPUT_REG_START(status), TEST_INPUT_REG_SIZE(status), INPUT_OFFSET(status));
ESP_LOGI(TAG, "Start: %zu, size: %zu, offset: %zu", TEST_INPUT_REG_START(data_ready), TEST_INPUT_REG_SIZE(data_ready), INPUT_OFFSET(data_ready));
ESP_LOGI(TAG, "Start: %zu, size: %zu, offset: %zu", TEST_INPUT_REG_START(buffer_size), TEST_INPUT_REG_SIZE(buffer_size), INPUT_OFFSET(buffer_size));
ESP_LOGI(TAG, "Start: %zu, size: %zu, offset: %zu", TEST_INPUT_REG_START(chunk_size), TEST_INPUT_REG_SIZE(chunk_size), INPUT_OFFSET(chunk_size));
ESP_LOGI(TAG, "Start: %zu, size: %zu, offset: %zu", TEST_INPUT_REG_START(buffer), TEST_INPUT_REG_SIZE(buffer), INPUT_OFFSET(buffer));
Outputs:
I (491) MASTER_TEST: Start: 0, size: 1, offset: 1
I (491) MASTER_TEST: Start: 1, size: 13, offset: 3
I (491) MASTER_TEST: Start: 14, size: 1, offset: 29
I (501) MASTER_TEST: Start: 0, size: 1, offset: 1
I (501) MASTER_TEST: Start: 1, size: 1, offset: 3
I (511) MASTER_TEST: Start: 2, size: 1, offset: 5
I (511) MASTER_TEST: Start: 3, size: 1, offset: 7
In slave:
ESP_LOGW(F_TAG, "start: %zu, size: %zu, offset: %zu", HOLDING_REG_START_ADDRESS, sizeof(holding_reg_params.command), HOLDING_REG_OFFSET(command));
ESP_LOGW(F_TAG, "start: %zu, size: %zu, offset: %zu", HOLDING_REG_START_ADDRESS, sizeof(holding_reg_params.file_name), HOLDING_REG_OFFSET(file_name));
ESP_LOGW(F_TAG, "start: %zu, size: %zu, offset: %zu", HOLDING_REG_START_ADDRESS, sizeof(holding_reg_params.ack), HOLDING_REG_OFFSET(ack));
ESP_LOGW(F_TAG, "start: %zu, size: %zu, offset: %zu", INPUT_REG_START_ADDRESS, sizeof(input_reg_params.status), INPUT_REG_OFFSET(status));
ESP_LOGW(F_TAG, "start: %zu, size: %zu, offset: %zu", INPUT_REG_START_ADDRESS, sizeof(input_reg_params.data_ready), INPUT_REG_OFFSET(data_ready));
ESP_LOGW(F_TAG, "start: %zu, size: %zu, offset: %zu", INPUT_REG_START_ADDRESS, sizeof(input_reg_params.buffer_size), INPUT_REG_OFFSET(buffer_size));
ESP_LOGW(F_TAG, "start: %zu, size: %zu, offset: %zu", INPUT_REG_START_ADDRESS, sizeof(input_reg_params.chunk_size), INPUT_REG_OFFSET(chunk_size));
ESP_LOGW(F_TAG, "start: %zu, size: %zu, offset: %zu", INPUT_REG_START_ADDRESS, sizeof(input_reg_params.buffer), INPUT_REG_OFFSET(buffer));
Outputs:
W (1926) MODBUS-TASK: start: 0, size: 2, offset: 0
W (1936) MODBUS-TASK: start: 0, size: 26, offset: 1
W (1946) MODBUS-TASK: start: 0, size: 2, offset: 14
W (1966) MODBUS-TASK: start: 0, size: 2, offset: 0
W (1976) MODBUS-TASK: start: 0, size: 2, offset: 1
W (1986) MODBUS-TASK: start: 0, size: 2, offset: 2
W (1996) MODBUS-TASK: start: 0, size: 2, offset: 3
W (2006) MODBUS-TASK: start: 0, size: 8192, offset: 4Steps to reproduce the behavior
- Review the serial examples in the esp-modbus repo
Project release version
Latest
System architecture
Intel/AMD 64-bit (modern PC, older Mac)
Operating system
Linux
Operating system version
Ubuntu 24.04
Shell
Bash
Additional context
No response
Metadata
Metadata
Assignees
Labels
No labels