modbus: fix ASCII frame reception and add test for ASCII mode
Fix ASCII frame reception and add test for ASCII mode. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
parent
b0518d6100
commit
a9690e0862
6 changed files with 43 additions and 3 deletions
|
@ -134,7 +134,7 @@ static int mb_rx_ascii_frame(struct mb_rtu_context *ctx)
|
|||
return -EMSGSIZE;
|
||||
}
|
||||
|
||||
if (rx_size > MODBUS_ASCII_MIN_MSG_SIZE) {
|
||||
if (rx_size < MODBUS_ASCII_MIN_MSG_SIZE) {
|
||||
LOG_WRN("Frame length error");
|
||||
return -EMSGSIZE;
|
||||
}
|
||||
|
@ -169,8 +169,6 @@ static int mb_rx_ascii_frame(struct mb_rtu_context *ctx)
|
|||
ctx->rx_frame.length++;
|
||||
}
|
||||
|
||||
/* Subtract the Address and function code */
|
||||
ctx->rx_frame.length -= 2;
|
||||
/* Extract the message's LRC */
|
||||
hex2bin(pmsg, 2, &frame_lrc, 1);
|
||||
ctx->rx_frame.crc = frame_lrc;
|
||||
|
|
|
@ -6,5 +6,6 @@ CONFIG_ZTEST=y
|
|||
CONFIG_SERIAL=y
|
||||
CONFIG_UART_INTERRUPT_DRIVEN=y
|
||||
CONFIG_UART_LINE_CTRL=n
|
||||
CONFIG_MODBUS_RTU_ASCII_MODE=y
|
||||
|
||||
CONFIG_MODBUS_RTU=y
|
||||
|
|
|
@ -35,6 +35,15 @@ void test_main(void)
|
|||
ztest_unit_test(test_rtu_holding_reg),
|
||||
ztest_unit_test(test_rtu_diagnostic),
|
||||
ztest_unit_test(test_client_rtu_disable),
|
||||
ztest_unit_test(test_server_rtu_disable),
|
||||
ztest_unit_test(test_server_rtu_setup_ascii),
|
||||
ztest_unit_test(test_client_rtu_setup_ascii),
|
||||
ztest_unit_test(test_rtu_coil_wr_rd),
|
||||
ztest_unit_test(test_rtu_di_rd),
|
||||
ztest_unit_test(test_rtu_input_reg),
|
||||
ztest_unit_test(test_rtu_holding_reg),
|
||||
ztest_unit_test(test_rtu_diagnostic),
|
||||
ztest_unit_test(test_client_rtu_disable),
|
||||
ztest_unit_test(test_server_rtu_disable)
|
||||
);
|
||||
ztest_run_test_suite(modbus_client_test);
|
||||
|
|
|
@ -33,11 +33,13 @@
|
|||
void test_server_rtu_setup_low_none(void);
|
||||
void test_server_rtu_setup_low_odd(void);
|
||||
void test_server_rtu_setup_high_even(void);
|
||||
void test_server_rtu_setup_ascii(void);
|
||||
void test_server_rtu_disable(void);
|
||||
|
||||
void test_client_rtu_setup_low_none(void);
|
||||
void test_client_rtu_setup_low_odd(void);
|
||||
void test_client_rtu_setup_high_even(void);
|
||||
void test_client_rtu_setup_ascii(void);
|
||||
void test_rtu_coil_wr_rd(void);
|
||||
void test_rtu_di_rd(void);
|
||||
void test_rtu_input_reg(void);
|
||||
|
|
|
@ -226,6 +226,16 @@ void test_client_rtu_setup_high_even(void)
|
|||
zassert_equal(err, 0, "Failed to configure RTU client");
|
||||
}
|
||||
|
||||
void test_client_rtu_setup_ascii(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = mb_rtu_cfg_client(iface, MB_TEST_BAUDRATE_HIGH,
|
||||
UART_CFG_PARITY_EVEN,
|
||||
MB_TEST_RESPONSE_TO, true);
|
||||
zassert_equal(err, 0, "Failed to configure RTU client");
|
||||
}
|
||||
|
||||
void test_client_rtu_disable(void)
|
||||
{
|
||||
int err;
|
||||
|
@ -251,6 +261,11 @@ void test_client_rtu_setup_high_even(void)
|
|||
ztest_test_skip();
|
||||
}
|
||||
|
||||
void test_client_rtu_setup_ascii(void)
|
||||
{
|
||||
ztest_test_skip();
|
||||
}
|
||||
|
||||
void test_rtu_coil_wr_rd(void)
|
||||
{
|
||||
ztest_test_skip();
|
||||
|
|
|
@ -209,6 +209,21 @@ void test_server_rtu_setup_high_even(void)
|
|||
}
|
||||
}
|
||||
|
||||
void test_server_rtu_setup_ascii(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (IS_ENABLED(CONFIG_MODBUS_RTU_SERVER)) {
|
||||
err = mb_rtu_cfg_server(MB_TEST_IFACE_SERVER, MB_TEST_NODE_ADDR,
|
||||
MB_TEST_BAUDRATE_HIGH,
|
||||
UART_CFG_PARITY_EVEN,
|
||||
&mbs_cbs, true);
|
||||
zassert_equal(err, 0, "Failed to configure RTU server");
|
||||
} else {
|
||||
ztest_test_skip();
|
||||
}
|
||||
}
|
||||
|
||||
void test_server_rtu_disable(void)
|
||||
{
|
||||
int err;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue