@@ -89,6 +89,13 @@ mb_err_enum_t mbs_get_handler_count(mb_base_t *inst, uint16_t *count)
8989 return MB_ENOERR ;
9090}
9191
92+ uint8_t mbs_get_request_unit_id (mb_base_t * inst )
93+ {
94+ MB_RETURN_ON_FALSE (inst , MB_TCP_PSEUDO_ADDRESS , TAG , "slave instance invalid." );
95+ mbs_object_t * mbs_obj = MB_GET_OBJ_CTX (inst , mbs_object_t , base );
96+ return mbs_obj ? mbs_obj -> rcv_addr : MB_TCP_PSEUDO_ADDRESS ;
97+ }
98+
9299static mb_exception_t mbs_check_invoke_handler (mb_base_t * inst , uint8_t func_code , uint8_t * buf , uint16_t * len )
93100{
94101 mbs_object_t * mbs_obj = MB_GET_OBJ_CTX (inst , mbs_object_t , base );
@@ -201,7 +208,7 @@ mb_err_enum_t mbs_rtu_create(mb_serial_opts_t *ser_opts, void **in_out_obj)
201208 TAG , "name alloc fail, err: %d" , (int )res );
202209 transp_obj = (mb_trans_base_t * )mbs_obj ;
203210 ret = mbs_rtu_transp_create (ser_opts , (void * * )& transp_obj );
204- MB_GOTO_ON_FALSE ((transp_obj && (ret == MB_ENOERR )), MB_EILLSTATE , error ,
211+ MB_GOTO_ON_FALSE ((transp_obj && (ret == MB_ENOERR )), MB_EILLSTATE , error ,
205212 TAG , "transport creation, err: %d" , (int )ret );
206213 ret = mbs_register_default_handlers (& mbs_obj -> base );
207214 MB_GOTO_ON_FALSE ((ret == MB_ENOERR ), MB_EILLSTATE , error ,
@@ -215,7 +222,7 @@ mb_err_enum_t mbs_rtu_create(mb_serial_opts_t *ser_opts, void **in_out_obj)
215222 * in_out_obj = (void * )& (mbs_obj -> base );
216223 ESP_LOGD (TAG , "created object %s" , mbs_obj -> base .descr .parent_name );
217224 return MB_ENOERR ;
218-
225+
219226error :
220227 if (transp_obj ) {
221228 mbs_rtu_transp_delete (transp_obj );
@@ -260,7 +267,7 @@ mb_err_enum_t mbs_ascii_create(mb_serial_opts_t *ser_opts, void **in_out_obj)
260267 TAG , "name alloc fail, err: %d" , (int )res );
261268 transp_obj = (mb_trans_base_t * )mbs_obj ;
262269 ret = mbs_ascii_transp_create (ser_opts , (void * * )& transp_obj );
263- MB_GOTO_ON_FALSE ((transp_obj && (ret == MB_ENOERR )), MB_EILLSTATE , error ,
270+ MB_GOTO_ON_FALSE ((transp_obj && (ret == MB_ENOERR )), MB_EILLSTATE , error ,
264271 TAG , "transport creation, err: %d" , (int )ret );
265272 ret = mbs_register_default_handlers (& mbs_obj -> base );
266273 MB_GOTO_ON_FALSE ((ret == MB_ENOERR ), MB_EILLSTATE , error ,
@@ -274,7 +281,7 @@ mb_err_enum_t mbs_ascii_create(mb_serial_opts_t *ser_opts, void **in_out_obj)
274281 * in_out_obj = (void * )& (mbs_obj -> base );
275282 ESP_LOGD (TAG , "created object %s" , mbs_obj -> base .descr .parent_name );
276283 return MB_ENOERR ;
277-
284+
278285error :
279286 if (transp_obj ) {
280287 mbs_ascii_transp_delete (transp_obj );
@@ -320,7 +327,7 @@ mb_err_enum_t mbs_tcp_create(mb_tcp_opts_t *tcp_opts, void **in_out_obj)
320327 TAG , "name alloc fail, err: %d" , (int )res );
321328 transp_obj = (mb_trans_base_t * )mbs_obj ;
322329 ret = mbs_tcp_transp_create (tcp_opts , (void * * )& transp_obj );
323- MB_GOTO_ON_FALSE ((transp_obj && (ret == MB_ENOERR )), MB_EILLSTATE , error ,
330+ MB_GOTO_ON_FALSE ((transp_obj && (ret == MB_ENOERR )), MB_EILLSTATE , error ,
324331 TAG , "transport creation, err: %d" , (int )ret );
325332 ret = mbs_register_default_handlers (& mbs_obj -> base );
326333 MB_GOTO_ON_FALSE ((ret == MB_ENOERR ), MB_EILLSTATE , error ,
@@ -334,7 +341,7 @@ mb_err_enum_t mbs_tcp_create(mb_tcp_opts_t *tcp_opts, void **in_out_obj)
334341 * in_out_obj = (void * )& (mbs_obj -> base );
335342 ESP_LOGD (TAG , "created object %s" , mbs_obj -> base .descr .parent_name );
336343 return MB_ENOERR ;
337-
344+
338345error :
339346 if (transp_obj ) {
340347 mbs_tcp_transp_delete (transp_obj );
@@ -469,7 +476,7 @@ mb_err_enum_t mbs_poll(mb_base_t *inst)
469476 ESP_LOGD (TAG , MB_OBJ_FMT ":EV_READY" , MB_OBJ_PARENT (inst ));
470477 mb_port_event_res_release (MB_OBJ (inst -> port_obj ));
471478 break ;
472-
479+
473480 case EV_FRAME_RECEIVED :
474481 ESP_LOGD (TAG , MB_OBJ_FMT ":EV_FRAME_RECEIVED" , MB_OBJ_PARENT (inst ));
475482 mbs_obj -> length = event .length ;
0 commit comments