Skip to content

Commit

Permalink
libosdp: Add Packet scan skipped bytes instrumentation
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Feb 19, 2024
1 parent bc48117 commit 81207c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/osdp_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ struct osdp_pd {
uint8_t packet_buf[OSDP_PACKET_BUF_SIZE];
int packet_len;
int packet_buf_len;
uint32_t packet_scan_skip;

int cmd_id; /* Currently processing command ID */
int reply_id; /* Currently processing reply ID */
Expand Down
9 changes: 9 additions & 0 deletions src/osdp_phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ static int phy_check_header(struct osdp_pd *pd)
uint8_t cur_byte = 0, prev_byte = 0;
uint8_t *buf = pd->packet_buf;

/* Scan for packet start */
while (pd->packet_buf_len == 0) {
if (osdp_rb_pop(&pd->rx_rb, &cur_byte)) {
return OSDP_ERR_PKT_NO_DATA;
Expand All @@ -355,10 +356,13 @@ static int phy_check_header(struct osdp_pd *pd)
CLEAR_FLAG(pd, PD_FLAG_PKT_HAS_MARK);
}
break;
} else {
pd->packet_scan_skip++;
}
prev_byte = cur_byte;
}

/* Found start of a new packet; wait until we have atleast the header */
target_len = sizeof(struct osdp_packet_header);
len = osdp_rb_pop_buf(&pd->rx_rb, buf + pd->packet_buf_len,
target_len - pd->packet_buf_len);
Expand Down Expand Up @@ -514,6 +518,11 @@ int osdp_phy_check_packet(struct osdp_pd *pd)
return ret;
}
pd->packet_len = ret;
if (pd->packet_scan_skip) {
LOG_WRN("Packet scan skipped %u bytes before SoM",
pd->packet_scan_skip);
pd->packet_scan_skip = 0;
}
}

/* We have a valid header, collect one full packet */
Expand Down

0 comments on commit 81207c8

Please sign in to comment.