diff --git a/nanomodbus.c b/nanomodbus.c index 42cb2ed..6d3ddd7 100644 --- a/nanomodbus.c +++ b/nanomodbus.c @@ -1575,6 +1575,11 @@ nmbs_error nmbs_server_poll(nmbs_t* nmbs) { return NMBS_ERROR_NONE; } + +void nmbs_set_callbacks_arg(nmbs_t* nmbs, void* arg) +{ + nmbs->callbacks.arg = arg; +} #endif diff --git a/nanomodbus.h b/nanomodbus.h index b6eb79d..00331dd 100644 --- a/nanomodbus.h +++ b/nanomodbus.h @@ -195,7 +195,7 @@ typedef struct nmbs_callbacks { #endif #endif - char _nonempty; // Struct may become empty, which is undefined behavior + void* arg; // User data, will be passed to functions above } nmbs_callbacks; @@ -272,6 +272,12 @@ nmbs_error nmbs_server_create(nmbs_t* nmbs, uint8_t address_rtu, const nmbs_plat * @return NMBS_ERROR_NONE if successful, other errors otherwise. */ nmbs_error nmbs_server_poll(nmbs_t* nmbs); + +/** Set the pointer to user data argument passed to server request callbacks. + * @param nmbs pointer to the nmbs_t instance + * @param arg user data argument + */ +void nmbs_set_callbacks_arg(nmbs_t* nmbs, void* arg); #endif #ifndef NMBS_CLIENT_DISABLED