Sending Basic Packet with Flow Control

A free API for the transfer of data packages according to ISO-TP (ISO 15765-2)
Locked
Just4242
Posts: 6
Joined: Tue 3. Nov 2020, 00:13

Sending Basic Packet with Flow Control

Post by Just4242 » Wed 4. Nov 2020, 23:01

I am trying to modify the example 02_client_ISO15765-2_normal_addressing to send a string of 8 bytes or longer. So I have the MSG to "PEAK1234" and the MSG_SIZE to 8. I also added a call to CANTP_SetValue_2016 to set the timing. On the bus I can see the data below and the first packet looks ok, I "think" my flow control is correct, but I dont the second packet of the transmission. I am getting OK returned from all of my calls. What am I doing wrong?
Image

Code: Select all

#define MSG "PEAK1234"
#define MSG_SIZE 8
[attachment=0]Capture1.PNG[/attachment]
/// <summary>Entry point of the program, start a small CAN ISO TP read/write example</summary>
/// <returns>By convention, return success.</returns>
int main()
{
	// Local variables
	cantp_status res;
	char buffer[500];
	uint32_t STmin;
	cantp_msg tx_msg;
	cantp_mapping mapping;
	cantp_handle client_handle;
	HANDLE receive_event;
	// Initialize structs 
	client_handle = PCANTP_HANDLE_USBBUS1; // TODO: modify the value according to your available PCAN devices.
	memset(&tx_msg, 0, sizeof(cantp_msg));
	memset(&mapping, 0, sizeof(cantp_mapping));

	// Print version informations
	CANTP_GetValue_2016(PCANTP_HANDLE_NONEBUS, PCANTP_PARAMETER_API_VERSION, buffer, 500);
	printf("PCAN-ISO-TP API Version: %s\n", buffer);

	// Initialize channels: CAN2.0 - 125Kbit/s
	res = CANTP_Initialize_2016(client_handle, PCANTP_BAUDRATE_125K, (cantp_hwtype)0, 0, 0);
	printf("Initialize: %s\n", STATUS_OK_KO(res));

	// Change STmin value to 600us
	STmin = STMIN_600US;
	res = CANTP_SetValue_2016(client_handle, PCANTP_PARAMETER_SEPARATION_TIME, &STmin, sizeof(STmin));
	printf("Set STMIN = 600us: %s\n", STATUS_OK_KO(res));

	// Allocate tx message
	res = CANTP_MsgDataAlloc_2016(&tx_msg, PCANTP_MSGTYPE_ISOTP);
	printf("Allocate tx message: %s\n", STATUS_OK_KO(res));

	// Create a simple physical mapping: 
	//    - Source 0xF1 (client), target 0x01 (server), CAN id 0xA1, CAN ID flow control 0xA2
	//    - Diagnostic message in a classic format
	mapping.can_id = 0xA1;
	mapping.can_id_flow_ctrl = 0xA2;
	mapping.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
	mapping.netaddrinfo.extension_addr = 0x00;
	mapping.netaddrinfo.format = PCANTP_ISOTP_FORMAT_NORMAL;
	mapping.netaddrinfo.msgtype = PCANTP_ISOTP_MSGTYPE_DIAGNOSTIC;
	//mapping.netaddrinfo.msgtype = PCANTP_ISOTP_MSGTYPE_FLAG_INDICATION_TX;
	mapping.netaddrinfo.source_addr = 0xF1;
	mapping.netaddrinfo.target_addr = 0x01;
	mapping.netaddrinfo.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;

	// Add mapping on channels
	res = CANTP_AddMapping_2016(client_handle, &mapping);
	printf("Add a simple mapping: %s\n", STATUS_OK_KO(res));
	
	// Change STmin value to 600us
	STmin = STMIN_600US;
	res = CANTP_SetValue_2016(client_handle, PCANTP_PARAMETER_SEPARATION_TIME, &STmin, sizeof(STmin));
	printf("Set STMIN = 600us on channel %s: %s\n", "USB1", STATUS_OK_KO(res));

	// Initialize Tx message containing "PEAK1234"
	res = CANTP_MsgDataInit_2016(&tx_msg, mapping.can_id, mapping.can_msgtype, MSG_SIZE, MSG, &mapping.netaddrinfo);
	printf("Initialize tx message: %s\n", STATUS_OK_KO(res));
	receive_event = NULL;

	// Write "PEAK" message
	res = CANTP_Write_2016(client_handle, &tx_msg);
	printf("Write \"PEAK\" message: %s\n", STATUS_OK_KO(PCANTP_STATUS_OK));
	// Get receive event if any
	
	res = CANTP_GetValue_2016(client_handle, PCANTP_PARAMETER_RECEIVE_EVENT, &receive_event, sizeof(receive_event));
	printf("Get receive event on XX: %s\n",  STATUS_OK_KO(res));

	// Free messages space
	res = CANTP_MsgDataFree_2016(&tx_msg);
	printf("Free tx message: %s\n", STATUS_OK_KO(res));

	// Uninitialize transmitter and receiver
	res = CANTP_Uninitialize_2016(client_handle);
	printf("Uninitialize: %s\n", STATUS_OK_KO(res));

	// Exit
	system("PAUSE");
	return EXIT_SUCCESS;
}

Attachments
Capture1.PNG
Capture1.PNG (18.97 KiB) Viewed 321 times

K.Wagner
Software Development
Software Development
Posts: 767
Joined: Wed 22. Sep 2010, 13:36

Re: Sending Basic Packet with Flow Control

Post by K.Wagner » Thu 5. Nov 2020, 10:51

Hello,

please note that the sample 02_cleint_ISO15765-2_normal_addressing is intended to demonstrate how to send non-segmented data using normal addressing. By sending 8 bytes the data must be segmented in more CAN frames and additional procedure must be done. Note following things:
  • In the example number 2, only one mapping is needed (just to send). For reading, a reverse mapping has to be additional included
  • In the example number 2, sending only one CAN frame is OK, so the app doesn't wait for completion indication (loopback messages) and terminates. When sending segmented data you need to wait for completion (check for instance the function wait_and_read_msg within the example 06_isotp_segmented_read_write)
You can modify the example number 02 to send segmented data by:
  1. Defining and including an additional reverse mapping:

    Code: Select all

    ...
    	// Reverse mapping for reception
    	//
    	cantp_mapping reverse_mapping;
    	
    	reverse_mapping = mapping;
    	reverse_mapping.can_id = 0xA2;
    	reverse_mapping.can_id_flow_ctrl = 0xA1;
    	reverse_mapping.netaddrinfo.source_addr = 0x01;
    	reverse_mapping.netaddrinfo.target_addr = 0xf1;
    	
    	res = CANTP_AddMapping_2016(client_handle, &reverse_mapping);
    	printf("Add a simple mapping from A2->A1: %s\n", STATUS_OK_KO(res));	
    
  2. And then wait for Completion. In order to keep this simple you can just include a Sleep statement after calling CANTP_Write_2016

    Code: Select all

    	// Write "PEAK" message
    	res = CANTP_Write_2016(client_handle, &tx_msg);
    	Sleep(100);
    
Now the sample should work for sending "PEAK1234".
Best regards,
Keneth

K.Wagner
Software Development
Software Development
Posts: 767
Joined: Wed 22. Sep 2010, 13:36

Re: Sending Basic Packet with Flow Control

Post by K.Wagner » Thu 5. Nov 2020, 11:05

Hello,

For completeness, you find attached a modified "client_ISO15765-2_normal_addressing.cpp" handling segmentation correctly.
Attachments
client_ISO15765-2_normal_addressing.cpp
single and segmented sending
(4.9 KiB) Downloaded 24 times
Best regards,
Keneth

Just4242
Posts: 6
Joined: Tue 3. Nov 2020, 00:13

Re: Sending Basic Packet with Flow Control

Post by Just4242 » Tue 10. Nov 2020, 00:39

Thank you very much. I was able to get my first messages to go through with these changes.

K.Wagner
Software Development
Software Development
Posts: 767
Joined: Wed 22. Sep 2010, 13:36

Re: Sending Basic Packet with Flow Control

Post by K.Wagner » Tue 10. Nov 2020, 07:49

You're welcome. Closed.
Best regards,
Keneth

Locked