Skip to content

Commit

Permalink
Solved most revision topics raised
Browse files Browse the repository at this point in the history
  • Loading branch information
hahnnicholas committed Nov 28, 2024
1 parent 1d2868e commit 3af7130
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
26 changes: 13 additions & 13 deletions include/osdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
*
Expand Down
29 changes: 26 additions & 3 deletions src/osdp_cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down

0 comments on commit 3af7130

Please sign in to comment.