From b004a949e31435eafce473f19fd8ed0a24ed70c1 Mon Sep 17 00:00:00 2001 From: cfif Date: Fri, 23 Jan 2026 15:49:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CanUds.c | 83 ++++++++++++++++++++++++++++++++++++++++---------------- CanUds.h | 7 ++++- 2 files changed, 65 insertions(+), 25 deletions(-) diff --git a/CanUds.c b/CanUds.c index fc2abf9..ff4a7c9 100644 --- a/CanUds.c +++ b/CanUds.c @@ -22,20 +22,6 @@ bool ReceivedCan_func(void *arg, can_rx_message_type *canFrame) { void ReceivedTP_func(void *arg, tCanTP_data *data) { tCanUds *env = arg; - tUdsServiceCommand *com = (tUdsServiceCommand *) data; - - if (com->service == UDS_TesterPresent) { - - tTesterPresent testerPresent; - testerPresent.ServiceId = data->data[0] | 0b1000000; - testerPresent.zeroSubFunction = data->data[1] & 0b1111111; - - CanSerialPortFrameTpTransmit(&env->canSerialPortFrameTp, (uint8_t *) &testerPresent, - sizeof(tTesterPresent), PROTOCOL_CAN_ADR_UDS, WAIT_FRAME_WRITE); - - return; - } - osStatus_t status = osMessageQueuePut(env->queue, data, 0, 0U); if (status != osOK) { @@ -52,13 +38,35 @@ uint16_t setResponseError(tCanUds *env, eUdsServices service, eUdsResponseError return 3; } +// начало --------------------------- ПИНГ --------------------------------------------------------- +// начало --------------------------- ПИНГ --------------------------------------------------------- +// начало --------------------------- ПИНГ --------------------------------------------------------- + +static uint16_t TesterPresent_3E(tCanUds *env) { + + tUdsServiceCommand *com = (tUdsServiceCommand *) env->data.data; + + if (com->service < 2) { + return setResponseError(env, UDS_TesterPresent, UDS_error_incorrectMessageLengthOrInvalidFormat); + } + + tTesterPresent testerPresent; + testerPresent.ServiceId = UDS_TesterPresent | 0b1000000; + testerPresent.zeroSubFunction = 0; + + return 2; +} +// конец --------------------------- ПИНГ --------------------------------------------------------- +// конец --------------------------- ПИНГ --------------------------------------------------------- +// конец --------------------------- ПИНГ --------------------------------------------------------- + // начало ----------------------------- Сессия ------------------------------------------------------------- // начало ----------------------------- Сессия ------------------------------------------------------------- // начало ----------------------------- Сессия ------------------------------------------------------------- static uint16_t DiagnosticSessionControl_10(tCanUds *env) { tUdsServiceCommand *com = (tUdsServiceCommand *) env->data.data; - if (com->service != 2) { + if (com->service < 2) { return setResponseError(env, UDS_DiagnosticSessionControl, UDS_error_incorrectMessageLengthOrInvalidFormat); } @@ -92,7 +100,7 @@ static uint16_t DiagnosticSessionControl_10(tCanUds *env) { // начало --------------------------- Чтение --------------------------------------------------------- static uint16_t ReadDataByIdentifier_22(tCanUds *env) { - if (env->data.len != 3) { + if (env->data.len < 3) { return setResponseError(env, UDS_ReadDataByIdentifier, UDS_error_incorrectMessageLengthOrInvalidFormat); } @@ -183,7 +191,7 @@ static uint16_t InputOutputControlByIdentifier_2F(tCanUds *env) { static uint16_t ECUReset_11(tCanUds *env) { tUdsServiceCommand *com = (tUdsServiceCommand *) env->data.data; - if (env->data.len != 2) { + if (env->data.len < 2) { return setResponseError(env, UDS_ECUResetService, UDS_error_incorrectMessageLengthOrInvalidFormat); } @@ -194,7 +202,7 @@ static uint16_t ECUReset_11(tCanUds *env) { } env->dataResponse[0] = UDS_ECUResetService | 0b1000000;; - env->dataResponse[1] = env->data.data[1]; + env->dataResponse[1] = env->data.data[1] & 0b01111111; // sub-function return 2; } @@ -209,7 +217,7 @@ static uint16_t ECUReset_11(tCanUds *env) { static uint16_t UDS_ClearDiagnosticInformation_14(tCanUds *env) { - if (env->data.len != 4) { + if (env->data.len < 4) { return setResponseError(env, UDS_ClearDiagnosticInformation, UDS_error_incorrectMessageLengthOrInvalidFormat); } @@ -260,7 +268,7 @@ static uint16_t UDS_ReadDTCInformation_19(tCanUds *env) { tUdsServiceCommand *com = (tUdsServiceCommand *) env->data.data; - if (env->data.len != 3) { + if (env->data.len < 3) { return setResponseError(env, UDS_ReadDTCInformation, UDS_error_incorrectMessageLengthOrInvalidFormat); } @@ -275,7 +283,7 @@ static uint16_t UDS_ReadDTCInformation_19(tCanUds *env) { if (com->sub_function == UDS_dtc_reportNumberOfDTCByStatusMask) { - env->dataResponse[1] = env->data.data[1]; + env->dataResponse[1] = env->data.data[1] & 0b01111111; // sub-function // доступные биты статусов env->dataResponse[2] = 0xFF; @@ -291,7 +299,7 @@ static uint16_t UDS_ReadDTCInformation_19(tCanUds *env) { if (com->sub_function == UDS_dtc_reportDTCByStatusMask) { - env->dataResponse[1] = env->data.data[1]; + env->dataResponse[1] = env->data.data[1] & 0b01111111; // sub-function // доступные биты статусов env->dataResponse[2] = 0xFF; @@ -307,6 +315,33 @@ static uint16_t UDS_ReadDTCInformation_19(tCanUds *env) { // конец --------------------------- Чтение ошибок --------------------------------------------------------- // конец --------------------------- Чтение ошибок --------------------------------------------------------- +// начало --------------------------- Молчание ------------------------------------------------------------- +// начало --------------------------- Молчание ------------------------------------------------------------- +// начало --------------------------- Молчание ------------------------------------------------------------- + +static uint16_t CommunicationControl_28(tCanUds *env) { + + tUdsServiceCommand *com = (tUdsServiceCommand *) env->data.data; + + if (env->data.len < 3) { + return setResponseError(env, UDS_Communication_Control, + UDS_error_incorrectMessageLengthOrInvalidFormat); + } + + if ((com->sub_function != enableRxAndTx) && + (com->sub_function != enableRxAndDisableTx)) { + return setResponseError(env, UDS_Communication_Control, UDS_error_sub_functionNotSupported); + } + + + env->dataResponse[0] = UDS_Communication_Control | 0b1000000; + env->dataResponse[1] = env->data.data[1] & 0b01111111; // sub-function + + return 2; +} +// конец --------------------------- Молчание ------------------------------------------------------------- +// конец --------------------------- Молчание ------------------------------------------------------------- +// конец --------------------------- Молчание ------------------------------------------------------------- const eUds_com uds_com[256] = { {NULL, ""}, @@ -349,7 +384,7 @@ const eUds_com uds_com[256] = { {NULL, ""}, {NULL, ""}, {NULL, ""}, - {NULL, ""}, + {CommunicationControl_28, "CommunicationControl_28"}, {NULL, ""}, {NULL, ""}, {NULL, ""}, @@ -371,7 +406,7 @@ const eUds_com uds_com[256] = { {NULL, ""}, {NULL, ""}, {NULL, ""}, - {NULL, ""}, + {TesterPresent_3E, "TesterPresent_3E"}, {NULL, ""}, {NULL, ""}, {NULL, ""}, diff --git a/CanUds.h b/CanUds.h index 7d00bb1..544f4e9 100644 --- a/CanUds.h +++ b/CanUds.h @@ -33,7 +33,8 @@ typedef enum { UDS_RoutineControl = 0x31, UDS_ECUResetService = 0x11, UDS_InputOutputControlByIdentifier = 0x2F, - UDS_SecurityAccess = 0x27 + UDS_SecurityAccess = 0x27, + UDS_Communication_Control= 0x28 } eUdsServices; typedef enum { @@ -67,6 +68,10 @@ typedef enum { UDS_reset_softReset = 0x3 } eUdsReset; +typedef enum { + enableRxAndTx = 0x0, + enableRxAndDisableTx = 0x1 +} eUdsCommunicationControl; typedef struct { eUdsServices service;