Added function to unregister previously registered reply function

This commit is contained in:
Benjamin Vedder 2022-11-17 11:21:45 +01:00
parent cf6723ba25
commit 40e9e29075
4 changed files with 22 additions and 0 deletions

View File

@ -165,6 +165,21 @@ void commands_send_packet_last_blocking(unsigned char *data, unsigned int len) {
}
}
void commands_unregister_reply_func(void(*reply_func)(unsigned char *data, unsigned int len)) {
if (send_func == reply_func) {
send_func = NULL;
}
if (send_func_blocking == reply_func) {
send_func_blocking = NULL;
}
if (send_func_nrf == reply_func) {
send_func_nrf = NULL;
}
if (send_func_can_fwd == reply_func) {
send_func_can_fwd = NULL;
}
}
/**
* Process a received buffer with commands and data.
*

View File

@ -29,6 +29,7 @@ void commands_send_packet(unsigned char *data, unsigned int len);
void commands_send_packet_can_last(unsigned char *data, unsigned int len);
void commands_send_packet_nrf(unsigned char *data, unsigned int len);
void commands_send_packet_last_blocking(unsigned char *data, unsigned int len);
void commands_unregister_reply_func(void(*reply_func)(unsigned char *data, unsigned int len));
void commands_process_packet(unsigned char *data, unsigned int len,
void(*reply_func)(unsigned char *data, unsigned int len));
int commands_printf(const char* format, ...);

View File

@ -495,6 +495,9 @@ typedef struct {
// System lock (with counting)
void (*sys_lock)(void);
void (*sys_unlock)(void);
// Unregister pointers to previously used reply function
void (*commands_unregister_reply_func)(void(*reply_func)(unsigned char *data, unsigned int len));
} vesc_c_if;
typedef struct {

View File

@ -780,6 +780,9 @@ lbm_value ext_load_native_lib(lbm_value *args, lbm_uint argn) {
cif.cif.sys_lock = utils_sys_lock_cnt;
cif.cif.sys_unlock = utils_sys_unlock_cnt;
// Unregister pointers to previously used reply function
cif.cif.commands_unregister_reply_func = commands_unregister_reply_func;
lib_init_done = true;
}