Skip to content

Commit 7fc8194

Browse files
committed
cp: Reset retry_count when PD responds
pd->phy_retry_count was not reset when the PD responds to a command from CP. This caused the retry_count to accumulate and push flaky PDs offline unnecessarily. Fixes: #230 Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
1 parent 847588f commit 7fc8194

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/osdp_cp.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,16 @@ static inline bool cp_phy_kick(struct osdp_pd *pd)
823823
return false;
824824
}
825825

826+
static void cp_phy_state_done(struct osdp_pd *pd)
827+
{
828+
/* called when we have a valid response from the PD */
829+
if (sc_is_active(pd)) {
830+
pd->sc_tstamp = osdp_millis_now();
831+
}
832+
pd->phy_retry_count = 0;
833+
pd->phy_state = OSDP_CP_PHY_STATE_DONE;
834+
}
835+
826836
static int cp_phy_state_update(struct osdp_pd *pd)
827837
{
828838
int rc, ret = OSDP_CP_ERR_CAN_YIELD;
@@ -858,18 +868,12 @@ static int cp_phy_state_update(struct osdp_pd *pd)
858868
rc = cp_process_reply(pd);
859869
if (rc == OSDP_CP_ERR_NONE) {
860870
pd->tstamp = osdp_millis_now();
861-
if (sc_is_active(pd)) {
862-
pd->sc_tstamp = osdp_millis_now();
863-
}
864-
pd->phy_state = OSDP_CP_PHY_STATE_DONE;
871+
cp_phy_state_done(pd);
865872
return OSDP_CP_ERR_NONE;
866873
}
867874
if (rc == OSDP_CP_ERR_UNKNOWN && pd->cmd_id == CMD_POLL &&
868875
ISSET_FLAG(pd, OSDP_FLAG_IGN_UNSOLICITED)) {
869-
if (sc_is_active(pd)) {
870-
pd->sc_tstamp = osdp_millis_now();
871-
}
872-
pd->phy_state = OSDP_CP_PHY_STATE_DONE;
876+
cp_phy_state_done(pd);
873877
return OSDP_CP_ERR_NONE;
874878
}
875879
if (rc == OSDP_CP_ERR_GENERIC || rc == OSDP_CP_ERR_UNKNOWN) {

0 commit comments

Comments
 (0)