diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2023-12-04 14:00:47 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2023-12-07 17:52:06 -0500 |
commit | 62bf52bfcf1aab6d97236c3945320d790774ad92 (patch) | |
tree | 08ac3e221b8e9ffe963943e1cb1fa575b034a05a /klippy | |
parent | 99d7af87fd7cd74b9a6eab355eb71327ed3b8256 (diff) | |
download | kutter-62bf52bfcf1aab6d97236c3945320d790774ad92.tar.gz kutter-62bf52bfcf1aab6d97236c3945320d790774ad92.tar.xz kutter-62bf52bfcf1aab6d97236c3945320d790774ad92.zip |
serialqueue: Simplify sequence number upconversion
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy')
-rw-r--r-- | klippy/chelper/serialqueue.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/klippy/chelper/serialqueue.c b/klippy/chelper/serialqueue.c index e6810933..c207495c 100644 --- a/klippy/chelper/serialqueue.c +++ b/klippy/chelper/serialqueue.c @@ -222,12 +222,11 @@ handle_message(struct serialqueue *sq, double eventtime, int len) pthread_mutex_lock(&sq->lock); // Calculate receive sequence number - uint64_t rseq = ((sq->receive_seq & ~MESSAGE_SEQ_MASK) - | (sq->input_buf[MESSAGE_POS_SEQ] & MESSAGE_SEQ_MASK)); + uint32_t rseq_delta = ((sq->input_buf[MESSAGE_POS_SEQ] - sq->receive_seq) + & MESSAGE_SEQ_MASK); + uint64_t rseq = sq->receive_seq + rseq_delta; if (rseq != sq->receive_seq) { // New sequence number - if (rseq < sq->receive_seq) - rseq += MESSAGE_SEQ_MASK+1; if (rseq > sq->send_seq && sq->receive_seq != 1) { // An ack for a message not sent? Out of order message? sq->bytes_invalid += len; |