Skip to content

Commit 810d33d

Browse files
author
Robert Middleton
committed
Better calculate the transmit timeout for packets
Some packets(such as firmware upgrade packets) can be so large that they will cause a timeout on libosdp, especially at slower baud rates. Add in a way to calculate how long the packet transmission should take in order to have an acceptable timeout. See: #282
1 parent 5810411 commit 810d33d

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
@@ -417,6 +417,7 @@ struct osdp_pd {
417417
tick_t tstamp; /* Last POLL command issued time in ticks */
418418
tick_t sc_tstamp; /* Last received secure reply time in ticks */
419419
tick_t phy_tstamp; /* Time in ticks since command was sent */
420+
tick_t resp_expected; /* Time in ticks when the response is expected */
420421
uint32_t request; /* Event loop requests */
421422

422423
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;
@@ -825,6 +829,7 @@ static int cp_phy_state_update(struct osdp_pd *pd)
825829
pd->reply_id = REPLY_INVALID;
826830
pd->phy_state = OSDP_CP_PHY_STATE_REPLY_WAIT;
827831
pd->phy_tstamp = osdp_millis_now();
832+
pd->resp_expected = pd->phy_tstamp + OSDP_RESP_TOUT_MS + cp_calculate_transmit_time(pd);
828833
break;
829834
case OSDP_CP_PHY_STATE_REPLY_WAIT:
830835
rc = cp_process_reply(pd);
@@ -851,7 +856,7 @@ static int cp_phy_state_update(struct osdp_pd *pd)
851856
cp_phy_state_wait(pd, OSDP_CMD_RETRY_WAIT_MS);
852857
return OSDP_CP_ERR_DEFER;
853858
}
854-
if (osdp_millis_since(pd->phy_tstamp) > OSDP_RESP_TOUT_MS) {
859+
if (osdp_millis_since(pd->phy_tstamp) > pd->resp_expected) {
855860
if (pd->phy_retry_count < OSDP_CMD_MAX_RETRIES) {
856861
pd->phy_retry_count += 1;
857862
LOG_WRN("No response in 200ms; probing (%d)",

0 commit comments

Comments
 (0)