Skip to content

Commit 46e45ba

Browse files
authored
Merge pull request #292 from brivolabs/issue-282
Better calculate the transmit timeout for packets
2 parents 0d229b5 + 810d33d commit 46e45ba

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/osdp_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ struct osdp_pd {
418418
tick_t tstamp; /* Last POLL command issued time in ticks */
419419
tick_t sc_tstamp; /* Last received secure reply time in ticks */
420420
tick_t phy_tstamp; /* Time in ticks since command was sent */
421+
tick_t resp_expected; /* Time in ticks when the response is expected */
421422
uint32_t request; /* Event loop requests */
422423

423424
uint16_t peer_rx_size; /* Receive buffer size of the peer PD/CP */

src/osdp_cp.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,10 @@ static void cp_phy_state_wait(struct osdp_pd *pd, uint32_t wait_ms)
795795
pd->phy_state = OSDP_CP_PHY_STATE_WAIT;
796796
}
797797

798+
static int cp_calculate_transmit_time(struct osdp_pd* pd){
799+
return (pd->packet_buf_len * 10000U + pd->baud_rate - 1) / pd->baud_rate;
800+
}
801+
798802
static int cp_phy_state_update(struct osdp_pd *pd)
799803
{
800804
int rc, ret = OSDP_CP_ERR_DEFER;
@@ -830,6 +834,7 @@ static int cp_phy_state_update(struct osdp_pd *pd)
830834
pd->reply_id = REPLY_INVALID;
831835
pd->phy_state = OSDP_CP_PHY_STATE_REPLY_WAIT;
832836
pd->phy_tstamp = osdp_millis_now();
837+
pd->resp_expected = pd->phy_tstamp + OSDP_RESP_TOUT_MS + cp_calculate_transmit_time(pd);
833838
break;
834839
case OSDP_CP_PHY_STATE_REPLY_WAIT:
835840
rc = cp_process_reply(pd);
@@ -856,7 +861,7 @@ static int cp_phy_state_update(struct osdp_pd *pd)
856861
cp_phy_state_wait(pd, OSDP_CMD_RETRY_WAIT_MS);
857862
return OSDP_CP_ERR_DEFER;
858863
}
859-
if (osdp_millis_since(pd->phy_tstamp) > OSDP_RESP_TOUT_MS) {
864+
if (osdp_millis_since(pd->phy_tstamp) > pd->resp_expected) {
860865
if (pd->phy_retry_count < OSDP_CMD_MAX_RETRIES) {
861866
pd->phy_retry_count += 1;
862867
LOG_WRN("No response in 200ms; probing (%d)",

0 commit comments

Comments
 (0)