driftregion / iso14229

ISO 14229 (UDS) server and client for embedded systems
MIT License
227 stars 79 forks source link

Solved : Handling RX Data #4

Closed imecar-github closed 1 year ago

imecar-github commented 1 year ago

Hello. Thanks for the library.

I have a question about handling responses. Im currently sending uds data and it looks OK. But, How can I handle the response? I mean, How can I use the mockClientCANRxPoll function?

I modified mockClientSendCAN with HAL library for sending data. But I can not manage mockClientCANRxPoll.

Sorry for my bad English. Have a good day.

Edit1:

I tried something like this but It does not work

static enum Iso14229CANRxStatus mockClientCANRxPoll(uint32_t *arb_id, uint8_t *data, uint8_t *dlc) {

    HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &rxHeader, TxData);

    *arb_id = rxHeader.ExtId;
    *dlc = rxHeader.DLC;
    memmove(data,TxData,*dlc);

    return kCANRxNone;
}
driftregion commented 1 year ago

It looks like you're using ST's HAL: https://www.disca.upv.es/aperles/arm_cortex_m3/llibre/st/STM32F439xx_User_Manual/group__can__exported__functions__group3.html#gaf25698a35af7f78d01b036fcb80d81f3

HAL_CAN_GetRxMessage returns HAL_OK if there was a message otherwise HAL_ERROR.

Try this:

static enum Iso14229CANRxStatus mockClientCANRxPoll(uint32_t *arb_id, uint8_t *data, uint8_t *dlc) {
    if (HAL_OK == HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &rxHeader, TxData))  {
    *arb_id = rxHeader.ExtId;
    *dlc = rxHeader.DLC;
    memmove(data,TxData,*dlc);
        return kCANRxSome;
    }
    else {
        return kCANRxNone;    
    }
}
imecar-github commented 1 year ago

It looks like you're using ST's HAL: https://www.disca.upv.es/aperles/arm_cortex_m3/llibre/st/STM32F439xx_User_Manual/group__can__exported__functions__group3.html#gaf25698a35af7f78d01b036fcb80d81f3

HAL_CAN_GetRxMessage returns HAL_OK if there was a message otherwise HAL_ERROR.

Try this:

static enum Iso14229CANRxStatus mockClientCANRxPoll(uint32_t *arb_id, uint8_t *data, uint8_t *dlc) {
    if (HAL_OK == HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &rxHeader, TxData))  {
  *arb_id = rxHeader.ExtId;
  *dlc = rxHeader.DLC;
  memmove(data,TxData,*dlc);
        return kCANRxSome;
    }
    else {
        return kCANRxNone;    
    }
}

Yes I am using ST's HAL. Thanks for response.

But whenever I want to debug code, mockClientCANRxPoll function is not triggered.

Iso14229Client udsClient;
        struct Iso14229ClientConfig cfg = {
            .phys_send_id = 0x18DA66AA,
            .func_send_id = 0x18da55aa,
            .recv_id = 0x18DAAA66,
            .p2_ms = CLIENT_DEFAULT_P2_MS,
            .p2_star_ms = CLIENT_DEFAULT_P2_STAR_MS,
            .link = &g.clientLink,
            .link_receive_buffer = g.clientLinkRxBuf,
            .link_recv_buf_size = sizeof(g.clientLinkRxBuf),
            .link_send_buffer = g.clientLinkTxBuf,
            .link_send_buf_size = sizeof(g.clientLinkTxBuf),
            .userCANTransmit = mockClientSendCAN,
            .userGetms = mockUserGetms,
            .userCANRxPoll = mockClientCANRxPoll,
            .userDebug = mockClientLinkDbg,
            };

Here is my configuration.

driftregion commented 1 year ago

That configuration looks fine.

The callback function mockClientCANRxPoll will only be called when you call iso14229SequenceRunBlocking or the lower-level API Iso14229ClientPoll from your program.

You can try implementing a sequence like the one here:

https://github.com/driftregion/iso14229/blob/27cc02eda42e137063a20fdd141298873edf73d3/examples/client.c#L111-L124

imecar-github commented 1 year ago

I do not know how it is possible but,

In my

__weak void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
    CAN_RxHeaderTypeDef   RxHeader;
            uint8_t               RxData[8];
  /* Prevent unused argument(s) compilation warning */
             HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &RxHeader, RxData);
             if(RxData[1] == 80)
             {
                 int i = 1;
             }
  /* NOTE : This function Should not be modified, when the callback is needed,
            the HAL_CAN_RxFifo0MsgPendingCallback could be implemented in the
            user file
   */
}

Function, I can see the response message correctly, But,

static enum Iso14229CANRxStatus mockClientCANRxPoll(uint32_t *arb_id, uint8_t *data, uint8_t *dlc) {
    if (HAL_OK == HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &rxHeader, TxData))  {
    *arb_id = rxHeader.ExtId;
    *dlc = rxHeader.DLC;
    memmove(data,TxData,*dlc);
        return kCANRxSome;
    }
    else {
        return kCANRxNone;    
    }
}

In this function HAL_CAN_GetRxMessage function can not get anything from bus. Because of this, I can not run sequences.

driftregion commented 1 year ago

You can try either:

imecar-github commented 1 year ago

When I disable Interrupts, TX and RX functions triggered. Thanks.