@@ -183,8 +183,8 @@ static nmbs_error send(const nmbs_t* nmbs, uint16_t count) {
183183}
184184
185185
186- static void flush (nmbs_t * nmbs ) {
187- nmbs -> platform .read (nmbs -> msg .buf , sizeof (nmbs -> msg .buf ), 0 , nmbs -> platform .arg );
186+ static int32_t flush (nmbs_t * nmbs ) {
187+ return nmbs -> platform .read (nmbs -> msg .buf , sizeof (nmbs -> msg .buf ), 0 , nmbs -> platform .arg );
188188}
189189
190190
@@ -212,7 +212,7 @@ static void msg_state_req(nmbs_t* nmbs, uint8_t fc) {
212212 nmbs -> current_tid ++ ;
213213
214214 // Flush the remaining data on the line before sending the request
215- flush (nmbs );
215+ nmbs -> platform . flush (nmbs );
216216
217217 msg_state_reset (nmbs );
218218 nmbs -> msg .unit_id = nmbs -> dest_address_rtu ;
@@ -261,6 +261,7 @@ void nmbs_set_byte_timeout(nmbs_t* nmbs, int32_t timeout_ms) {
261261void nmbs_platform_conf_create (nmbs_platform_conf * platform_conf ) {
262262 memset (platform_conf , 0 , sizeof (nmbs_platform_conf ));
263263 platform_conf -> crc_calc = nmbs_crc_calc ;
264+ platform_conf -> flush = flush ;
264265 // Workaround for older user code not calling nmbs_platform_conf_create()
265266 platform_conf -> initialized = 0xFFFFDEBE ;
266267}
@@ -1881,7 +1882,7 @@ static nmbs_error handle_req_fc(nmbs_t* nmbs) {
18811882 break ;
18821883#endif
18831884 default :
1884- flush (nmbs );
1885+ nmbs -> platform . flush (nmbs );
18851886 if (!nmbs -> msg .ignored )
18861887 err = send_exception_msg (nmbs , NMBS_EXCEPTION_ILLEGAL_FUNCTION );
18871888 }
@@ -1941,7 +1942,7 @@ nmbs_error nmbs_server_poll(nmbs_t* nmbs) {
19411942 err = handle_req_fc (nmbs );
19421943 if (err != NMBS_ERROR_NONE ) {
19431944 if (err != NMBS_ERROR_TIMEOUT )
1944- flush (nmbs );
1945+ nmbs -> platform . flush (nmbs );
19451946
19461947 return err ;
19471948 }
0 commit comments