Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved : Handling RX Data #4

Closed
imecar-github opened this issue Nov 17, 2022 · 6 comments
Closed

Solved : Handling RX Data #4

imecar-github opened this issue Nov 17, 2022 · 6 comments

Comments

@imecar-github
Copy link

imecar-github commented Nov 17, 2022

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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:

iso14229/examples/client.c

Lines 111 to 124 in 27cc02e

static Iso14229ClientCallback callbacks[] = {
sendHardReset,
awaitPositiveResponse,
requestSomeData,
awaitPositiveResponse,
printTheData,
enterDiagnosticSession,
awaitResponse,
sendExitReset,
awaitPositiveResponse,
};

@imecar-github
Copy link
Author

imecar-github commented Nov 17, 2022

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
Copy link
Owner

You can try either:

@imecar-github
Copy link
Author

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

@imecar-github imecar-github changed the title Handling RX Data Solved : Handling RX Data Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants