Skip to content

Commit

Permalink
add some pre-checks
Browse files Browse the repository at this point in the history
  • Loading branch information
devcoons committed Nov 19, 2024
1 parent 5ee9233 commit 5792298
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
40 changes: 37 additions & 3 deletions src/lib_iso15765.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,14 +953,18 @@ n_rslt iso15765_init(iso15765_t* instance)
memset(&instance->out, 0, sizeof(n_iostream_t));
memset(&instance->fl_pdu, 0, sizeof(n_pdu_t));
/* init the incoming canbus frame queue(buffer) */
iqueue_init(&instance->inqueue,
if (iqueue_init(&instance->inqueue,
I15765_QUEUE_ELMS,
sizeof(canbus_frame_t),
instance->inq_buf);
instance->inq_buf) != I_OK)
{
return N_INV;
}

ISO_15675_UNUSED(sgn_chg_cfm);

return N_OK;
instance->init_sts = N_OK;
return instance->init_sts;
}

/*
Expand All @@ -970,6 +974,16 @@ n_rslt iso15765_init(iso15765_t* instance)
*/
n_rslt iso15765_enqueue(iso15765_t* instance, canbus_frame_t* frame)
{
if (instance == NULL)
{
return N_NULL;
}

if (instance->init_sts != N_OK)
{
return N_ERROR;
}

return iqueue_enqueue(&instance->inqueue, frame) == I_OK
? N_OK : N_BUFFER_OVFLW;
}
Expand All @@ -981,6 +995,16 @@ n_rslt iso15765_enqueue(iso15765_t* instance, canbus_frame_t* frame)
*/
n_rslt iso15765_send(iso15765_t* instance, n_req_t* frame)
{
if (instance == NULL)
{
return N_NULL;
}

if (instance->init_sts != N_OK)
{
return N_ERROR;
}

/* Make sure that there is no transmission in progress */
if (instance->out.sts != N_S_IDLE)
{
Expand Down Expand Up @@ -1009,6 +1033,16 @@ n_rslt iso15765_send(iso15765_t* instance, n_req_t* frame)
*/
n_rslt iso15765_process(iso15765_t* instance)
{
if (instance == NULL)
{
return N_NULL;
}

if (instance->init_sts != N_OK)
{
return N_ERROR;
}

/* First check if a timeout is occured. Only for the inbound stream */
n_rslt rslt = process_timeouts(instance);
canbus_frame_t frame;
Expand Down
1 change: 1 addition & 0 deletions src/lib_iso15765.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ typedef struct ALIGNMENT

typedef struct ALIGNMENT
{
n_rslt init_sts; /* Instance is initialized correctly */
addr_md addr_md; /* Selected address mode of the TP */
cbus_id_type fr_id_type; /* CANBus frame Id Type */
n_iostream_t in; /* Incoming data stream (reception) */
Expand Down

0 comments on commit 5792298

Please sign in to comment.