-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/driftregion/iso14229 into c…
…ustomServiceHandler
- Loading branch information
Showing
10 changed files
with
285 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
Nick James Kirkby <iso14229dev@gmail.com> | ||
Mark Corbin <mcorbin@lunarenergy.com> | ||
Jens Fernández Mühlke <fernandezjens@gmail.com> | ||
Zhifa Lee <lzhifa@163.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "test/test.h" | ||
|
||
int main() { | ||
UDSClient_t client; | ||
{ | ||
ENV_CLIENT_INIT(client); | ||
|
||
EXPECT_OK(UDSSendRequestFileTransfer(&client, kAddFile, "/data/testfile.zip", 0x00, 3, 0x112233, 0x001122)); | ||
|
||
const uint8_t ADDFILE_REQUEST[] = {0x38, 0x01, 0x00, 0x12, 0x2F, 0x64, 0x61, 0x74, 0x61, 0x2F, 0x74, 0x65, | ||
0x73, 0x74, 0x66, 0x69, 0x6C, 0x65, 0x2E, 0x7A, 0x69, 0x70, 0x00, 0x03, | ||
0x11, 0x22, 0x33, 0x00, 0x11, 0x22}; | ||
TEST_MEMORY_EQUAL(client.send_buf, ADDFILE_REQUEST, sizeof(ADDFILE_REQUEST)); | ||
} | ||
{ | ||
ENV_CLIENT_INIT(client); | ||
|
||
EXPECT_OK(UDSSendRequestFileTransfer(&client, kDeleteFile, "/data/testfile.zip", 0x00, 0, 0, 0)); | ||
|
||
const uint8_t DELETEFILE_REQUEST[] = {0x38, 0x02, 0x00, 0x12, 0x2F, 0x64, 0x61, 0x74, 0x61, 0x2F, 0x74, 0x65, | ||
0x73, 0x74, 0x66, 0x69, 0x6C, 0x65, 0x2E, 0x7A, 0x69, 0x70}; | ||
TEST_MEMORY_EQUAL(client.send_buf, DELETEFILE_REQUEST, sizeof(DELETEFILE_REQUEST)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "test/test.h" | ||
|
||
uint8_t fn_addfile(UDSServer_t *srv, UDSServerEvent_t ev, const void *arg) { | ||
TEST_INT_EQUAL(ev, UDS_SRV_EVT_RequestFileTransfer); | ||
UDSRequestFileTransferArgs_t *r = (UDSRequestFileTransferArgs_t *)arg; | ||
TEST_INT_EQUAL(0x01, r->modeOfOperation); | ||
TEST_INT_EQUAL(18, r->filePathLen); | ||
TEST_MEMORY_EQUAL((void *)"/data/testfile.zip", r->filePath, r->filePathLen); | ||
TEST_INT_EQUAL(0x00, r->dataFormatIdentifier); | ||
TEST_INT_EQUAL(0x112233, r->fileSizeUnCompressed); | ||
TEST_INT_EQUAL(0x001122, r->fileSizeCompressed); | ||
r->maxNumberOfBlockLength = 0x0081; | ||
return kPositiveResponse; | ||
} | ||
|
||
uint8_t fn_delfile(UDSServer_t *srv, UDSServerEvent_t ev, const void *arg) { | ||
TEST_INT_EQUAL(ev, UDS_SRV_EVT_RequestFileTransfer); | ||
UDSRequestFileTransferArgs_t *r = (UDSRequestFileTransferArgs_t *)arg; | ||
TEST_INT_EQUAL(0x02, r->modeOfOperation); | ||
TEST_INT_EQUAL(18, r->filePathLen); | ||
TEST_MEMORY_EQUAL((void *)"/data/testfile.zip", r->filePath, r->filePathLen); | ||
return kPositiveResponse; | ||
} | ||
|
||
int main() { | ||
{ // case 0: No handler | ||
UDSTpHandle_t *mock_client = ENV_TpNew("client"); | ||
UDSServer_t srv; | ||
ENV_SERVER_INIT(srv); | ||
|
||
// when no handler function is installed, sending this request to the server | ||
uint8_t ADDFILE_REQUEST[] = {0x38, 0x01, 0x00, 0x12, 0x2F, 0x64, 0x61, 0x74, 0x61, 0x2F, 0x74, 0x65, | ||
0x73, 0x74, 0x66, 0x69, 0x6C, 0x65, 0x2E, 0x7A, 0x69, 0x70, 0x00, 0x03, | ||
0x11, 0x22, 0x33, 0x00, 0x11, 0x22}; | ||
UDSTpSend(mock_client, ADDFILE_REQUEST, sizeof(ADDFILE_REQUEST), NULL); | ||
|
||
// should return a kServiceNotSupported response | ||
uint8_t RESP[] = {0x7F, 0x38, 0x11}; | ||
EXPECT_IN_APPROX_MS(UDSTpGetRecvLen(mock_client) > 0, srv.p2_ms); | ||
TEST_MEMORY_EQUAL(UDSTpGetRecvBuf(mock_client, NULL), RESP, sizeof(RESP)); | ||
TPMockReset(); | ||
} | ||
|
||
{ // case 1: add file | ||
UDSTpHandle_t *mock_client = ENV_TpNew("client"); | ||
UDSServer_t srv; | ||
ENV_SERVER_INIT(srv); | ||
// when a handler is installed that implements UDS-1:2013 Table 435 | ||
srv.fn = fn_addfile; | ||
|
||
// sending this request to the server | ||
uint8_t ADDFILE_REQUEST[] = {0x38, 0x01, 0x00, 0x12, 0x2F, 0x64, 0x61, 0x74, 0x61, 0x2F, 0x74, 0x65, | ||
0x73, 0x74, 0x66, 0x69, 0x6C, 0x65, 0x2E, 0x7A, 0x69, 0x70, 0x00, 0x03, | ||
0x11, 0x22, 0x33, 0x00, 0x11, 0x22}; | ||
UDSTpSend(mock_client, ADDFILE_REQUEST, sizeof(ADDFILE_REQUEST), NULL); | ||
|
||
// should receive a positive response matching UDS-1:2013 Table 435 | ||
uint8_t RESP[] = {0x78, 0x01, 0x02, 0x00, 0x81}; | ||
EXPECT_IN_APPROX_MS(UDSTpGetRecvLen(mock_client) > 0, srv.p2_ms); | ||
TEST_MEMORY_EQUAL(UDSTpGetRecvBuf(mock_client, NULL), RESP, sizeof(RESP)); | ||
TPMockReset(); | ||
} | ||
{ // case 2: delete file | ||
UDSTpHandle_t *mock_client = ENV_TpNew("client"); | ||
UDSServer_t srv; | ||
ENV_SERVER_INIT(srv); | ||
// when a handler is installed that implements UDS-1:2013 Table 435 | ||
srv.fn = fn_delfile; | ||
|
||
// sending this request to the server | ||
const uint8_t DELETEFILE_REQUEST[] = {0x38, 0x02, 0x00, 0x12, 0x2F, 0x64, 0x61, 0x74, 0x61, 0x2F, 0x74, 0x65, | ||
0x73, 0x74, 0x66, 0x69, 0x6C, 0x65, 0x2E, 0x7A, 0x69, 0x70}; | ||
UDSTpSend(mock_client, DELETEFILE_REQUEST, sizeof(DELETEFILE_REQUEST), NULL); | ||
|
||
// should receive a positive response matching UDS-1:2013 Table 435 | ||
uint8_t RESP[] = {0x78, 0x02}; | ||
EXPECT_IN_APPROX_MS(UDSTpGetRecvLen(mock_client) > 0, srv.p2_ms); | ||
TEST_MEMORY_EQUAL(UDSTpGetRecvBuf(mock_client, NULL), RESP, sizeof(RESP)); | ||
TPMockReset(); | ||
} | ||
} |