From fed14c9c5b42366f0862fd462e80c93a07268665 Mon Sep 17 00:00:00 2001 From: Nicholas Hahn Date: Tue, 24 Mar 2026 21:00:27 -0300 Subject: [PATCH 1/2] Added function to get PD offset by address in control panel --- include/osdp.h | 14 ++++++++++++++ include/osdp.hpp | 5 +++++ src/osdp_cp.c | 16 ++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/include/osdp.h b/include/osdp.h index 6a087020..11a4d760 100644 --- a/include/osdp.h +++ b/include/osdp.h @@ -1176,6 +1176,20 @@ void osdp_cp_refresh(osdp_t *ctx); OSDP_EXPORT void osdp_cp_teardown(osdp_t *ctx); +/** + * @brief Get the PD offset (0-indexed) in the internal `osdp_pd_info_t *` + * list that is registered in the given address. + * + * @param ctx OSDP context + * @param address PD address of the device in `osdp_pd_info_t *` passed to + * osdp_cp_setup() + * + * @retval PD offset (0-indexed) on success + * @retval -1 on failure + */ +OSDP_EXPORT +int osdp_cp_get_pd_by_addr(osdp_t *ctx, int address); + /** * @brief Generic command enqueue API. * diff --git a/include/osdp.hpp b/include/osdp.hpp index 90d1196b..d4b4b67f 100644 --- a/include/osdp.hpp +++ b/include/osdp.hpp @@ -120,6 +120,11 @@ class OSDP_EXPORT ControlPanel : public Common { osdp_cp_set_command_completion_callback(_ctx, cb, arg); } + int get_pd_by_addr(int address) + { + return osdp_cp_get_pd_by_addr(_ctx, address); + } + int get_pd_id(int pd, struct osdp_pd_id *id) { return osdp_cp_get_pd_id(_ctx, pd, id); diff --git a/src/osdp_cp.c b/src/osdp_cp.c index e5883e57..32ebd856 100644 --- a/src/osdp_cp.c +++ b/src/osdp_cp.c @@ -1612,6 +1612,22 @@ void osdp_cp_teardown(osdp_t *ctx) #endif } +int osdp_cp_get_pd_by_addr(osdp_t *ctx, int address) +{ + input_check(ctx); + int i; + struct osdp_pd *pd; + + for (i = 0; i < NUM_PD(ctx); i++) { + pd = osdp_to_pd(ctx, i); + if (pd->address == address) { + return i; + } + } + + return -1; +} + void osdp_cp_refresh(osdp_t *ctx) { input_check(ctx); From bb29187519f3b3dc42825fd5dda51614701c0ebb Mon Sep 17 00:00:00 2001 From: Nicholas Hahn Date: Tue, 24 Mar 2026 21:19:18 -0300 Subject: [PATCH 2/2] Fixed format string mismatch in osdp_diag.c: %d used for size_t argument #283 --- src/osdp_diag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osdp_diag.c b/src/osdp_diag.c index b9477a2f..b524b5f4 100644 --- a/src/osdp_diag.c +++ b/src/osdp_diag.c @@ -52,7 +52,7 @@ void osdp_packet_capture_finish(struct osdp_pd *pd) LOG_ERR("Unable to stop capture (flush/close failed)"); return; } - LOG_INF("Captured %d packets", num_packets); + LOG_INF("Captured %zu packets", num_packets); } void osdp_capture_packet(struct osdp_pd *pd, uint8_t *buf, int len)