Lines Matching refs:adu
51 int modbus_raw_submit_rx(const int iface, const struct modbus_adu *adu) in modbus_raw_submit_rx() argument
67 ctx->rx_adu.trans_id = adu->trans_id; in modbus_raw_submit_rx()
68 ctx->rx_adu.proto_id = adu->proto_id; in modbus_raw_submit_rx()
69 ctx->rx_adu.length = adu->length; in modbus_raw_submit_rx()
70 ctx->rx_adu.unit_id = adu->unit_id; in modbus_raw_submit_rx()
71 ctx->rx_adu.fc = adu->fc; in modbus_raw_submit_rx()
72 memcpy(ctx->rx_adu.data, adu->data, in modbus_raw_submit_rx()
73 MIN(adu->length, sizeof(ctx->rx_adu.data))); in modbus_raw_submit_rx()
79 void modbus_raw_put_header(const struct modbus_adu *adu, uint8_t *header) in modbus_raw_put_header() argument
81 uint16_t length = MIN(adu->length, CONFIG_MODBUS_BUFFER_SIZE); in modbus_raw_put_header()
83 sys_put_be16(adu->trans_id, &header[0]); in modbus_raw_put_header()
84 sys_put_be16(adu->proto_id, &header[2]); in modbus_raw_put_header()
86 header[6] = adu->unit_id; in modbus_raw_put_header()
87 header[7] = adu->fc; in modbus_raw_put_header()
90 void modbus_raw_get_header(struct modbus_adu *adu, const uint8_t *header) in modbus_raw_get_header() argument
92 adu->trans_id = sys_get_be16(&header[0]); in modbus_raw_get_header()
93 adu->proto_id = sys_get_be16(&header[2]); in modbus_raw_get_header()
94 adu->length = MIN(sys_get_be16(&header[4]), CONFIG_MODBUS_BUFFER_SIZE); in modbus_raw_get_header()
95 adu->unit_id = header[6]; in modbus_raw_get_header()
96 adu->fc = header[7]; in modbus_raw_get_header()
98 if (adu->length >= MODBUS_ADU_LENGTH_DEVIATION) { in modbus_raw_get_header()
99 adu->length -= MODBUS_ADU_LENGTH_DEVIATION; in modbus_raw_get_header()
103 static void modbus_set_exception(struct modbus_adu *adu, in modbus_set_exception() argument
108 adu->fc |= excep_bit; in modbus_set_exception()
109 adu->data[0] = excep_code; in modbus_set_exception()
110 adu->length = 1; in modbus_set_exception()
113 void modbus_raw_set_server_failure(struct modbus_adu *adu) in modbus_raw_set_server_failure() argument
117 adu->fc |= excep_bit; in modbus_raw_set_server_failure()
118 adu->data[0] = MODBUS_EXC_SERVER_DEVICE_FAILURE; in modbus_raw_set_server_failure()
119 adu->length = 1; in modbus_raw_set_server_failure()
122 int modbus_raw_backend_txn(const int iface, struct modbus_adu *adu) in modbus_raw_backend_txn() argument
130 modbus_set_exception(adu, MODBUS_EXC_GW_PATH_UNAVAILABLE); in modbus_raw_backend_txn()
141 modbus_set_exception(adu, MODBUS_EXC_GW_PATH_UNAVAILABLE); in modbus_raw_backend_txn()
146 memcpy(&ctx->tx_adu, adu, sizeof(struct modbus_adu)); in modbus_raw_backend_txn()
155 uint16_t trans_id = adu->trans_id; in modbus_raw_backend_txn()
156 uint16_t proto_id = adu->proto_id; in modbus_raw_backend_txn()
158 memcpy(adu, &ctx->rx_adu, sizeof(struct modbus_adu)); in modbus_raw_backend_txn()
159 adu->trans_id = trans_id; in modbus_raw_backend_txn()
160 adu->proto_id = proto_id; in modbus_raw_backend_txn()
162 modbus_set_exception(adu, MODBUS_EXC_GW_TARGET_FAILED_TO_RESP); in modbus_raw_backend_txn()