summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2015-09-18 14:04:47 +0200
committerMarc Kleine-Budde <mkl@pengutronix.de>2015-09-18 14:49:38 +0200
commite22a8d4e0d76817722500039451aac7e3c540c05 (patch)
tree6ed2d4390f1419164410692371b3ca1b7a089698
parent3adde88a642a7e3018ab53adf082d51cb326be94 (diff)
downloadcanutils-e22a8d4e0d76817722500039451aac7e3c540c05.tar.gz
cansequence: add internal 32 bit sequence counter
-rw-r--r--src/cansequence.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/cansequence.c b/src/cansequence.c
index d916576..197e9e8 100644
--- a/src/cansequence.c
+++ b/src/cansequence.c
@@ -89,8 +89,11 @@ static void do_receive()
};
const int dropmonitor_on = 1;
bool sequence_init = true;
- unsigned int seq_wrap = 0;
- uint8_t sequence = 0;
+ unsigned int sequence_wrap = 0;
+ uint32_t sequence_mask = 0xff;
+ uint32_t sequence_rx = 0;
+ uint32_t sequence_delta = 0;
+ uint32_t sequence = 0;
if (setsockopt(s, SOL_SOCKET, SO_RXQ_OVFL,
&dropmonitor_on, sizeof(dropmonitor_on)) < 0) {
@@ -116,15 +119,15 @@ static void do_receive()
exit(EXIT_FAILURE);
}
+ sequence_rx = frame.data[0];
+
if (sequence_init) {
sequence_init = false;
- sequence = frame.data[0];
+ sequence = sequence_rx;
}
- if (verbose > 1)
- printf("received frame. sequence number: %d\n", frame.data[0]);
-
- if (frame.data[0] != sequence) {
+ sequence_delta = (sequence_rx - sequence) & sequence_mask;
+ if (sequence_delta) {
struct cmsghdr *cmsg;
uint32_t overflows = 0;
@@ -140,17 +143,19 @@ static void do_receive()
}
fprintf(stderr, "[%d] received wrong sequence count. expected: %d, got: %d, socket overflows: %u\n",
- drop_count, sequence, frame.data[0], overflows);
+ drop_count, sequence & sequence_mask, sequence_rx, overflows);
if (drop_count == drop_until_quit)
exit(EXIT_FAILURE);
- sequence = frame.data[0];
+ sequence = sequence_rx;
+ } else if (verbose > 1) {
+ printf("sequence CNT: %6u, RX: %6u\n", sequence, sequence_rx);
}
sequence++;
- if (verbose && !sequence)
- printf("sequence wrap around (%d)\n", seq_wrap++);
+ if (verbose && !(sequence & sequence_mask))
+ printf("sequence wrap around (%d)\n", sequence_wrap++);
}
}