All right, I see there may be a misunderstanding in the way UDS session is working:
- Sessions are defined when a call to the corresponding service is made (UDS_SvcDiagnosticSessionControl), only after reading the response(s) from this service will the UDS API know that a specific session was set up (and may then start sending automatic tester present messages to the ECU(s) if it is a non-default session).
- If you switch from an unknown session (which is the case after the UDS initialization) or default diagnostic session to "an ECU programming" session then the current state of the session with that specific ECU will be updated. To disable automatic tester present messages, the corresponding code must be called after receiving the diagnostic session response from that ECU.
To sum up:
1. After UDS_Initialize, no session are defined so you cannot modify any.
2. After a call to the service UDS_SvcDiagnosticSessionControl and having received a valid response from an ECU, a session information is registered in the API.
3. If you want to disable the default tester present mechanism, you can only do it after processing that response. The processing is handled internally in our high level function like UDS_WaitForXXX, but if needed (for instance you do not use those functions) the corresponding function to call is UDS_ProcessResponse.
4. Keep in mind that if the service UDS_SvcDiagnosticSessionControl is called again, the received response will overwrite your customized session information.
You can assert my first statement by checking in your code the call to :
Code: Select all
result = UDS_GetValue(Channel, PUDS_PARAM_SESSION_INFO, &session, sizeof(TPUDSSessionInfo));
It returns a PUDS_ERROR_NOT_INITIALIZED.. which means that this session is not defined.
Here is a glimpse of how things should be handled:
Code: Select all
// keep your existing initialization process...
[...]
result = CAN_FilterMessages(PCAN_USBBUS1, 0x610, 0x6F1, PCAN_MESSAGE_STANDARD);
[...]
// At some point in your code, you must be changing session. For instance like so:
result = UDS_SvcDiagnosticSessionControl(Channel, &MsgUDS_WRITE, PUDS_SVC_PARAM_DSC_ECUPS);
if (result == PUDS_ERROR_OK)
result = UDS_WaitForService(Channel, &MsgUDS_READ[0], &MsgUDS_WRITE);
printf(" UDS_SvcDiagnosticSessionControl: %i\n", (int)result);
// Only then the API will send automatic TesterPrent messages !
// Check that in your CAN viewer by sleeping for 10s
Sleep(10000);
// Only then, you can specify to disable the mechanism
TPUDSSessionInfo session;
// You MUST specify the Protocol, SA, TA, etc. to retrieve the corresponding Network Address Information
session.NETADDRINFO.PROTOCOL = PUDS_PROTOCOL_ISO_15765_2_11B;
session.NETADDRINFO.SA = 0xFB;
session.NETADDRINFO.TA = 0x00;
session.NETADDRINFO.TA_TYPE = PUDS_ADDRESSING_PHYSICAL;
session.NETADDRINFO.RA = 0x00;
// You SHOULD ALSO check the result value of this function, if you get PUDS_ERROR_NOT_INITIALIZED, it means that the corresponding session information was not found.
result = UDS_GetValue(Channel, PUDS_PARAM_SESSION_INFO, &session, sizeof(TPUDSSessionInfo));
session.SESSION_TYPE = PUDS_SVC_PARAM_DSC_DS;
result = UDS_SetValue(Channel, PUDS_PARAM_SESSION_INFO, &session, sizeof(TPUDSSessionInfo));
// Check that the automatic TesterPresent is disabled, and no message is received
Sleep(10000);
// you can resume your code
WORD len = 0xFF;
int i = 0, j = 0;
for (i = 0; i < 0x606; i++)
{
[...]
}