Обновление

This commit is contained in:
cfif 2026-01-23 15:49:16 +03:00
parent 00e0875547
commit b004a949e3
2 changed files with 65 additions and 25 deletions

View File

@ -22,20 +22,6 @@ bool ReceivedCan_func(void *arg, can_rx_message_type *canFrame) {
void ReceivedTP_func(void *arg, tCanTP_data *data) { void ReceivedTP_func(void *arg, tCanTP_data *data) {
tCanUds *env = arg; 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); osStatus_t status = osMessageQueuePut(env->queue, data, 0, 0U);
if (status != osOK) { if (status != osOK) {
@ -52,13 +38,35 @@ uint16_t setResponseError(tCanUds *env, eUdsServices service, eUdsResponseError
return 3; 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) { static uint16_t DiagnosticSessionControl_10(tCanUds *env) {
tUdsServiceCommand *com = (tUdsServiceCommand *) env->data.data; tUdsServiceCommand *com = (tUdsServiceCommand *) env->data.data;
if (com->service != 2) { if (com->service < 2) {
return setResponseError(env, UDS_DiagnosticSessionControl, UDS_error_incorrectMessageLengthOrInvalidFormat); 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) { 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); 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) { static uint16_t ECUReset_11(tCanUds *env) {
tUdsServiceCommand *com = (tUdsServiceCommand *) env->data.data; tUdsServiceCommand *com = (tUdsServiceCommand *) env->data.data;
if (env->data.len != 2) { if (env->data.len < 2) {
return setResponseError(env, UDS_ECUResetService, return setResponseError(env, UDS_ECUResetService,
UDS_error_incorrectMessageLengthOrInvalidFormat); UDS_error_incorrectMessageLengthOrInvalidFormat);
} }
@ -194,7 +202,7 @@ static uint16_t ECUReset_11(tCanUds *env) {
} }
env->dataResponse[0] = UDS_ECUResetService | 0b1000000;; 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; return 2;
} }
@ -209,7 +217,7 @@ static uint16_t ECUReset_11(tCanUds *env) {
static uint16_t UDS_ClearDiagnosticInformation_14(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, return setResponseError(env, UDS_ClearDiagnosticInformation,
UDS_error_incorrectMessageLengthOrInvalidFormat); UDS_error_incorrectMessageLengthOrInvalidFormat);
} }
@ -260,7 +268,7 @@ static uint16_t UDS_ReadDTCInformation_19(tCanUds *env) {
tUdsServiceCommand *com = (tUdsServiceCommand *) env->data.data; tUdsServiceCommand *com = (tUdsServiceCommand *) env->data.data;
if (env->data.len != 3) { if (env->data.len < 3) {
return setResponseError(env, UDS_ReadDTCInformation, UDS_error_incorrectMessageLengthOrInvalidFormat); 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) { 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; env->dataResponse[2] = 0xFF;
@ -291,7 +299,7 @@ static uint16_t UDS_ReadDTCInformation_19(tCanUds *env) {
if (com->sub_function == UDS_dtc_reportDTCByStatusMask) { 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; 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] = { const eUds_com uds_com[256] = {
{NULL, ""}, {NULL, ""},
@ -349,7 +384,7 @@ const eUds_com uds_com[256] = {
{NULL, ""}, {NULL, ""},
{NULL, ""}, {NULL, ""},
{NULL, ""}, {NULL, ""},
{NULL, ""}, {CommunicationControl_28, "CommunicationControl_28"},
{NULL, ""}, {NULL, ""},
{NULL, ""}, {NULL, ""},
{NULL, ""}, {NULL, ""},
@ -371,7 +406,7 @@ const eUds_com uds_com[256] = {
{NULL, ""}, {NULL, ""},
{NULL, ""}, {NULL, ""},
{NULL, ""}, {NULL, ""},
{NULL, ""}, {TesterPresent_3E, "TesterPresent_3E"},
{NULL, ""}, {NULL, ""},
{NULL, ""}, {NULL, ""},
{NULL, ""}, {NULL, ""},

View File

@ -33,7 +33,8 @@ typedef enum {
UDS_RoutineControl = 0x31, UDS_RoutineControl = 0x31,
UDS_ECUResetService = 0x11, UDS_ECUResetService = 0x11,
UDS_InputOutputControlByIdentifier = 0x2F, UDS_InputOutputControlByIdentifier = 0x2F,
UDS_SecurityAccess = 0x27 UDS_SecurityAccess = 0x27,
UDS_Communication_Control= 0x28
} eUdsServices; } eUdsServices;
typedef enum { typedef enum {
@ -67,6 +68,10 @@ typedef enum {
UDS_reset_softReset = 0x3 UDS_reset_softReset = 0x3
} eUdsReset; } eUdsReset;
typedef enum {
enableRxAndTx = 0x0,
enableRxAndDisableTx = 0x1
} eUdsCommunicationControl;
typedef struct { typedef struct {
eUdsServices service; eUdsServices service;