devcoons / iso15765-canbus

Implementation of ISO15765-2 in C
MIT License
142 stars 61 forks source link

Bugs? #15

Closed Jason0926Ni closed 1 year ago

Jason0926Ni commented 1 year ago

The following code may be wrong.

  1. lib_iso15765.c // sequence issue / Increase the CF counter and check if the reception sequence is ok / ih->in.cf_cnt = ih->in.cf_cnt + 1 > 0x0F ? 1 : ih->in.cf_cnt + 1; => ih->in.cf_cnt = ih->in.cf_cnt + 1 > 0x0F ? 0 : ih->in.cf_cnt + 1;

  2. lib_iso15765.c // reach max counter issue / if we reach the max CF counter, then we send a FC frame / ... if (ih->in.cf_cnt % ih->config.bs) => if ((ih->in.cf_cnt % ih->config.bs) == 0)

devcoons commented 1 year ago

Thank you for taking time to check this project. Regarding the points you mentioned:

  1. According to ISO-15765-2 [section 6.5.4.2 at page 19 : The SN shall start with zero (0) for all segmented messages. The FF shall be assigned the value zero (0). It does not include an explicit SequenceNumber in the N_PCI field but shall be treated as the segment number zero (0). So, the first CF should be with SequenceNumber 1 (not 0)

  2. Yes, you are right!

Jason0926Ni commented 1 year ago

I think the SN is correct starting from 1, but when SN reaches 15, it should be 0.

According to ISO-15765-2 [section 9.6.4.3] SequenceNumber (SN) parameter definition Last rule:

https://en.wikipedia.org/wiki/ISO_15765-2 The sequence number starts at 1 and increments with each frame sent (1, 2,..., 15, 0, 1,...), with which lost or discarded frames can be detected. ... So the first set of CF(Consecutive frames) start from "1". There afterwards when it reaches "15", will be started from "0".

devcoons commented 1 year ago

Fixed! Thanks!