@@ -773,22 +773,21 @@ static int response_exception(modbus_t *ctx,
773773 return rsp_length ;
774774}
775775
776- /* Send a response to the received request.
777- Analyses the request and constructs a response.
776+ /* Analyses the request and constructs a response.
778777
779- If an error occurs, this function construct the response
778+ If an error occurs, this function constructs the response
780779 accordingly.
781780*/
782- int modbus_reply (modbus_t * ctx ,
783- const uint8_t * req ,
784- int req_length ,
785- modbus_mapping_t * mb_mapping )
781+ int modbus_reply_construct (modbus_t * ctx ,
782+ const uint8_t * req ,
783+ int req_length ,
784+ modbus_mapping_t * mb_mapping ,
785+ uint8_t * rsp )
786786{
787787 unsigned int offset ;
788788 int slave ;
789789 int function ;
790790 uint16_t address ;
791- uint8_t rsp [MAX_MESSAGE_LENGTH ];
792791 int rsp_length = 0 ;
793792 sft_t sft ;
794793
@@ -1189,6 +1188,29 @@ int modbus_reply(modbus_t *ctx,
11891188 !(ctx -> quirks & MODBUS_QUIRK_REPLY_TO_BROADCAST )) {
11901189 return 0 ;
11911190 }
1191+ return rsp_length ;
1192+ }
1193+
1194+ int modbus_reply_send (modbus_t * ctx , uint8_t * rsp , int rsp_length )
1195+ {
1196+ return send_msg (ctx , rsp , rsp_length );
1197+ }
1198+
1199+ /* Send a response to the received request.
1200+ Analyses the request and constructs a response.
1201+
1202+ If an error occurs, this function construct the response
1203+ accordingly.
1204+ */
1205+ int modbus_reply (modbus_t * ctx ,
1206+ const uint8_t * req ,
1207+ int req_length ,
1208+ modbus_mapping_t * mb_mapping )
1209+ {
1210+ uint8_t rsp [MAX_MESSAGE_LENGTH ];
1211+ int rsp_length ;
1212+
1213+ rsp_length = modbus_reply_construct (ctx , req , req_length , mb_mapping , rsp );
11921214 return send_msg (ctx , rsp , rsp_length );
11931215}
11941216
0 commit comments