Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/osdp_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ struct osdp_pd {
tick_t tstamp; /* Last POLL command issued time in ticks */
tick_t sc_tstamp; /* Last received secure reply time in ticks */
tick_t phy_tstamp; /* Time in ticks since command was sent */
tick_t resp_expected; /* Time in ticks when the response is expected */
uint32_t request; /* Event loop requests */

uint16_t peer_rx_size; /* Receive buffer size of the peer PD/CP */
Expand Down
7 changes: 6 additions & 1 deletion src/osdp_cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,10 @@ static void cp_phy_state_wait(struct osdp_pd *pd, uint32_t wait_ms)
pd->phy_state = OSDP_CP_PHY_STATE_WAIT;
}

static int cp_calculate_transmit_time(struct osdp_pd* pd){
return (pd->packet_buf_len * 10000U + pd->baud_rate - 1) / pd->baud_rate;
}

static int cp_phy_state_update(struct osdp_pd *pd)
{
int rc, ret = OSDP_CP_ERR_DEFER;
Expand Down Expand Up @@ -825,6 +829,7 @@ static int cp_phy_state_update(struct osdp_pd *pd)
pd->reply_id = REPLY_INVALID;
pd->phy_state = OSDP_CP_PHY_STATE_REPLY_WAIT;
pd->phy_tstamp = osdp_millis_now();
pd->resp_expected = pd->phy_tstamp + OSDP_RESP_TOUT_MS + cp_calculate_transmit_time(pd);
break;
case OSDP_CP_PHY_STATE_REPLY_WAIT:
rc = cp_process_reply(pd);
Expand All @@ -851,7 +856,7 @@ static int cp_phy_state_update(struct osdp_pd *pd)
cp_phy_state_wait(pd, OSDP_CMD_RETRY_WAIT_MS);
return OSDP_CP_ERR_DEFER;
}
if (osdp_millis_since(pd->phy_tstamp) > OSDP_RESP_TOUT_MS) {
if (osdp_millis_since(pd->phy_tstamp) > pd->resp_expected) {
if (pd->phy_retry_count < OSDP_CMD_MAX_RETRIES) {
pd->phy_retry_count += 1;
LOG_WRN("No response in 200ms; probing (%d)",
Expand Down
Loading