From a5ba6b79f1f24ed71d4fd7e9e206cf0e446977c2 Mon Sep 17 00:00:00 2001 From: Benjamin Vedder Date: Mon, 19 Sep 2022 23:17:04 +0200 Subject: [PATCH] Added app data handler to c-if and check function pointer --- comm/commands.c | 9 +++++++-- comm/commands.h | 2 +- lispBM/c_libs/vesc_c_if.h | 3 +++ lispBM/lispif_c_lib.c | 3 +++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/comm/commands.c b/comm/commands.c index 1061461f..caa2c842 100644 --- a/comm/commands.c +++ b/comm/commands.c @@ -1723,8 +1723,13 @@ disp_pos_mode commands_get_disp_pos_mode(void) { return display_position_mode; } -void commands_set_app_data_handler(void(*func)(unsigned char *data, unsigned int len)) { - appdata_func = func; +bool commands_set_app_data_handler(void(*func)(unsigned char *data, unsigned int len)) { + if (utils_is_func_valid(func)) { + appdata_func = func; + return true; + } + + return false; } void commands_set_hw_data_handler(void(*func)(unsigned char *data, unsigned int len)) { diff --git a/comm/commands.h b/comm/commands.h index af5dbb41..b0241650 100644 --- a/comm/commands.h +++ b/comm/commands.h @@ -37,7 +37,7 @@ void commands_send_rotor_pos(float rotor_pos); void commands_send_experiment_samples(float *samples, int len); void commands_fwd_can_frame(int len, unsigned char *data, uint32_t id, bool is_extended); disp_pos_mode commands_get_disp_pos_mode(void); -void commands_set_app_data_handler(void(*func)(unsigned char *data, unsigned int len)); +bool commands_set_app_data_handler(void(*func)(unsigned char *data, unsigned int len)); void commands_set_hw_data_handler(void(*func)(unsigned char *data, unsigned int len)); void commands_send_app_data(unsigned char *data, unsigned int len); void commands_send_hw_data(unsigned char *data, unsigned int len); diff --git a/lispBM/c_libs/vesc_c_if.h b/lispBM/c_libs/vesc_c_if.h index dc6cb06e..e980e21d 100755 --- a/lispBM/c_libs/vesc_c_if.h +++ b/lispBM/c_libs/vesc_c_if.h @@ -389,6 +389,9 @@ typedef struct { // Settings (TODO: Add more types and also setters) float (*get_cfg_float)(CFG_PARAM p); + + // Add handler for received app data + bool (*set_app_data_handler)(void(*func)(unsigned char *data, unsigned int len)); } vesc_c_if; typedef struct { diff --git a/lispBM/lispif_c_lib.c b/lispBM/lispif_c_lib.c index b827439a..257c5dbd 100644 --- a/lispBM/lispif_c_lib.c +++ b/lispBM/lispif_c_lib.c @@ -608,6 +608,9 @@ lbm_value ext_load_native_lib(lbm_value *args, lbm_uint argn) { // Settings cif.cif.get_cfg_float = lib_get_cfg_float; + // Add handler for received app data + cif.cif.set_app_data_handler = commands_set_app_data_handler; + lib_init_done = true; }