Sending Basic Packet with Flow Control
Posted: 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?


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;
}