From 3af71302d399990380ee516ff364261fbd682b36 Mon Sep 17 00:00:00 2001 From: Nicholas Hahn Date: Thu, 28 Nov 2024 08:56:59 -0300 Subject: [PATCH] Solved most revision topics raised --- include/osdp.h | 26 +++++++++++++------------- src/osdp_cp.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/include/osdp.h b/include/osdp.h index 3ccf102..3df218e 100644 --- a/include/osdp.h +++ b/include/osdp.h @@ -1014,6 +1014,19 @@ int osdp_pd_flush_events(osdp_t *ctx); OSDP_EXPORT osdp_t *osdp_cp_setup(int num_pd, const osdp_pd_info_t *info); +/** + * @brief Adds more PD devices in the CP control list. + * + * @param num_pd Number of PDs connected to this CP. The `osdp_pd_info_t *` is + * treated as an array of length num_pd. + * @param info Pointer to info struct populated by application. + * + * @retval 0 on success + * @retval -1 on failure + */ +OSDP_EXPORT +int osdp_cp_add_pd(osdp_t *ctx, int num_pd, const osdp_pd_info_t *info); + /** * @brief Periodic refresh method. Must be called by the application at least * once every 50ms to meet OSDP timing requirements. @@ -1049,19 +1062,6 @@ void osdp_cp_teardown(osdp_t *ctx); OSDP_EXPORT int osdp_cp_send_command(osdp_t *ctx, int pd, const struct osdp_cmd *cmd); -/** - * @brief Adds more PD devices in the CP control list. - * - * @param num_pd Number of PDs connected to this CP. The `osdp_pd_info_t *` is - * treated as an array of length num_pd. - * @param info Pointer to info struct populated by application. - * - * @retval 0 on success - * @retval -1 on failure - */ -OSDP_EXPORT -int osdp_cp_add_pd(osdp_t *ctx, int num_pd, const osdp_pd_info_t *info); - /** * @brief Deletes all commands queued for a give PD * diff --git a/src/osdp_cp.c b/src/osdp_cp.c index ee5169c..816b5e7 100644 --- a/src/osdp_cp.c +++ b/src/osdp_cp.c @@ -1404,7 +1404,7 @@ static int cp_add_pd(struct osdp *ctx, int new_num_pd, ctx->pd = new_pd_array; ctx->_num_pd = old_num_pd + new_num_pd; - bzero(&ctx->pd[old_num_pd], sizeof(struct osdp_pd) * new_num_pd); + memset(&ctx->pd[old_num_pd], 0, sizeof(struct osdp_pd) * new_num_pd); for (i = 0; i < new_num_pd; i++) { info = new_info_list + i; @@ -1473,6 +1473,13 @@ static struct osdp *__cp_setup(int num_pd, const osdp_pd_info_t *info_list) goto error; } + if (cp_detect_connection_topology(ctx)) { + LOG_PRINT("Failed to detect connection topology"); + goto error; + } + + SET_CURRENT_PD(ctx, 0); + LOG_PRINT("CP Setup complete; LibOSDP-%s %s NumPDs:%d Channels:%d", osdp_get_version(), osdp_get_source_info(), num_pd, ctx->num_channels); @@ -1496,10 +1503,26 @@ osdp_t *osdp_cp_setup(int num_pd, const osdp_pd_info_t *info_list) int osdp_cp_add_pd(osdp_t *ctx, int num_pd, const osdp_pd_info_t *info) { - assert(ctx); + input_check(ctx); assert(info); - return cp_add_pd(ctx, num_pd, info); + if(cp_add_pd(ctx, num_pd, info)) { + LOG_PRINT("Failed to add PDs"); + return -1; + } + + if (cp_detect_connection_topology(ctx)) { + LOG_PRINT("Failed to detect connection topology"); + return -1; + } + + SET_CURRENT_PD(ctx, 0); + + LOG_PRINT("PD Added successfully. NumPDs:%d Channels:%d", + ((struct osdp *)ctx)->_num_pd, + ((struct osdp *)ctx)->num_channels); + + return 0; } void osdp_cp_teardown(osdp_t *ctx)