Skip to content

Commit

Permalink
[fx] SN reset only on new transmission
Browse files Browse the repository at this point in the history
  • Loading branch information
devcoons committed Dec 5, 2024
1 parent 0b11aa8 commit bb79ed3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion exm/ISO15765Development.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static iso15765_t handler1 = {
.clbs.get_ms = getms,
.clbs.indn = indn1,
.config.stmin = 0x3,
.config.bs = 0x0f,
.config.bs = 0x2a,
.config.n_bs = 100,
.config.n_cr = 3
};
Expand Down
13 changes: 9 additions & 4 deletions src/lib_iso15765.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,12 +716,13 @@ static n_rslt process_in_cf(iso15765_t* ih)

/* Increase the CF counter and check if the reception sequence is ok */
ih->in.cf_cnt = ih->in.cf_cnt + 1 > 0xFF ? 0 : ih->in.cf_cnt + 1;
if ((ih->in.cf_cnt & 0x0f) != ih->in.pdu.n_pci.sn)
ih->in.sn_glb = (ih->in.sn_glb + 1) & 0x0F;
if (ih->in.sn_glb != ih->in.pdu.n_pci.sn)
{
rslt = N_INV_SEQ_NUM;
goto in_cf_error;
}

/* As long as everything is ok the we copy the frame data to the inbound
* stream buffer. Afterwards check if the message size is completed and
* signal the user and afterwards reset the inboud stream */
Expand Down Expand Up @@ -909,8 +910,9 @@ static n_rslt iso15765_process_out(iso15765_t* ih)

/* Increase the sequence number of the frame and the CF counter of the stream
* and then pack the PDU to a CANBus frame */
ih->out.pdu.n_pci.sn = ih->out.cf_cnt & 0x0F;

ih->out.pdu.n_pci.sn = ih->out.sn_glb;
ih->out.sn_glb = (ih->out.sn_glb + 1) & 0x0F;

if (ih->out.fr_fmt == CBUS_FR_FRM_STD)
{
uint8_t max_payload = (ih->addr_md & 0x01) == 0 ? 7 : 6;
Expand Down Expand Up @@ -1125,6 +1127,9 @@ n_rslt iso15765_send(iso15765_t* instance, n_req_t* frame)
instance->out.msg_sz = frame->msg_sz;
memmove(instance->out.msg, frame->msg, frame->msg_sz);
memmove(&instance->out.pdu.n_ai, &frame->n_ai, sizeof(n_ai_t));
instance->out.sn_glb = 1;
instance->out.cf_cnt = 0;
instance->out.wf_cnt = 0;
instance->out.sts = N_S_TX_BUSY;

return N_OK;
Expand Down
1 change: 1 addition & 0 deletions src/lib_iso15765.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ typedef struct ALIGNMENT
n_pdu_t pdu; /* Keep information about the in/out frame in a PDU format */
uint8_t cf_cnt; /* Current block sequence number (ConsecutiveFrame) */
uint8_t wf_cnt; /* Current received wait flow control frames */
uint8_t sn_glb; /* Current Sequence Number of the transmittion */
uint8_t cfg_wf; /* Max supported Wait Flow Control frames */
uint8_t stmin; /* Frames transmission rate */
uint8_t cfg_bs; /* Max. supported block sequence (ConsecutiveFrame) */
Expand Down

0 comments on commit bb79ed3

Please sign in to comment.