1 | /////////////////////////////////////////////////////////////
|
2 | // ReadEcuIdentification: IdCode //
|
3 | // expected positive response with defined IdCode //
|
4 | /////////////////////////////////////////////////////////////
|
5 | testcase Testcase_ReadEcuIdentification_IdCode()
|
6 | {
|
7 | DiagRequest KLineTester.IDCode req;
|
8 | DiagResponse KLineTester.IDCode resp;
|
9 | char buffer[100];
|
10 | long ret, ret2, ret3, ret4, ret5;
|
11 | byte idCode[62];
|
12 | byte counter;
|
13 | char step[5] = "1.0";
|
14 |
|
15 | testStep(0, step, "Read Ecu Identification: IdCode"); // Write the current teststep to the testreport
|
16 |
|
17 | diagGetObjectName(req, buffer, elCount(buffer)); // Get the name of the diagnostic object
|
18 | DiagSendRequest(req);
|
19 | ret = testWaitForDiagRequestSent(req, 2000); // Wait until the request has been completely sent
|
20 |
|
21 | if(ret==1) // Request sent
|
22 | {
|
23 | TestReportWriteDiagObject(req); // Write the request-Object to the testreport
|
24 | write("Request has been successfully sent");
|
25 | ret2=TestWaitForDiagResponse(req, 5000); // Wait for a response, here for 5000ms. Note: This is no P2 timeout!
|
26 |
|
27 | if(ret2==1) // Response received
|
28 | {
|
29 | ret3=DiagGetLastResponse(req,resp); // Get the receveived response
|
30 | if(ret3>=0)
|
31 | {
|
32 | if(diagIsPositiveResponse(resp)) // Is it a positive response?
|
33 | {
|
34 | DiagGetParameterRaw(resp, "IdCode", idCode, elCount(idCode)); // Retrieve the serial number from the response in raw format
|
35 | write("Current IdCode is:");
|
36 | for(counter=0; counter<elCount(idCode); counter++)
|
37 | {
|
38 | write(" 0x%02X", idCode[counter]);
|
39 | }
|
40 | TestReportWriteDiagObject(resp); // Write the response-Object to the testreport
|
41 | ret5 = memcmp(REI_ID_CODE, idCode, elCount(idCode)); // compare received IdCode with the expected IdCode
|
42 | if(ret5 == 0) // received IdCode and expected IdCode are same
|
43 | {
|
44 | testStepPass(0, step, "IdCode has been successfully read"); // teststep accomplished
|
45 | }
|
46 | else
|
47 | {
|
48 | testStepFail(0, step, "The received IdCode does not match with the expected IdCode"); // teststep failed
|
49 | }
|
50 | }
|
51 | else // It is a negative Response
|
52 | {
|
53 | ret4=diagGetResponseCode(resp);
|
54 | write("Negative Response, NRC: 0x%02X",(byte)ret4);
|
55 | TestReportWriteDiagObject(resp); // Write the response-Object to the testreport
|
56 | testStepFail(0, step, "Negative Response. NRC: 0x%02X",(byte)ret4); // teststep failed
|
57 | }
|
58 | }
|
59 | else
|
60 | {
|
61 | write("Could not retrieve response");
|
62 | testStepFail(0, step, "Could not retrieve response");
|
63 | }
|
64 | }
|
65 |
|
66 | if(ret2==0) // Timeout. No response received
|
67 | {
|
68 | write("Timeout specified in TestWaitForDiagResponse expired");
|
69 | testStepFail(0, step, "Timeout specified in TestWaitForDiagResponse expired");
|
70 | }
|
71 | if(ret2<0) // Error e.g. transport protocol level
|
72 | {
|
73 | if(ret2==-92) // This is the error code for P2 or P2* timeouts
|
74 | {
|
75 | write("TP level error %d, probably P2 or P2* timeout", ret2);
|
76 | testStepFail(0, step, "TP level error %d, probably P2 or P2* timeout", ret2);
|
77 | }
|
78 | else
|
79 | {
|
80 | write("Error %d in the diagnostic or transport layer", ret2);
|
81 | testStepFail(0, step, "Error %d in the diagnostic or transport layer", ret2);
|
82 | }
|
83 | }
|
84 | }
|
85 | else
|
86 | {
|
87 | if(ret==0)
|
88 | {
|
89 | write("Timeout expired while trying to send request %s", buffer);
|
90 | testStepFail(0, step, "Timeout expired while trying to send request %s", buffer);
|
91 | }
|
92 | if(ret<0)
|
93 | {
|
94 | write("Internal error %d occured while trying to send request %s", ret, buffer);
|
95 | testStepFail(0, step, "Internal error %d occured while trying to send request %s", ret, buffer);
|
96 | }
|
97 | }
|
98 | }
|