modbus: keep transaction and protocol IDs in gateway mode

Serial line interface does not use transaction and protocol
IDs. Continue to use memcpy() for the whole frame as it is safer
and more efficient but temporarily store transaction and protocol
IDs, and write it back if the transfer was successful.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
Johann Fischer 2022-01-08 12:34:58 +01:00 committed by Maureen Helm
commit 767a87b1b6

View file

@ -147,7 +147,17 @@ int modbus_raw_backend_txn(const int iface, struct modbus_adu *adu)
err = modbus_tx_wait_rx_adu(ctx);
if (err == 0) {
/*
* Serial line does not use transaction and protocol IDs.
* Temporarily store transaction and protocol IDs, and write it
* back if the transfer was successful.
*/
uint16_t trans_id = adu->trans_id;
uint16_t proto_id = adu->proto_id;
memcpy(adu, &ctx->rx_adu, sizeof(struct modbus_adu));
adu->trans_id = trans_id;
adu->proto_id = proto_id;
} else {
modbus_set_exception(adu, MODBUS_EXC_GW_TARGET_FAILED_TO_RESP);
}