Обновление
This commit is contained in:
parent
4699b95f7b
commit
70ee887cab
90
CanUds.c
90
CanUds.c
|
|
@ -117,7 +117,9 @@ void ReceivedTP_func(void *arg, tCanTP_data *data) {
|
|||
// LoggerFormatInfo(LOGGER, LOG_SIGN, "Add queue (UDS): %d", data[0])
|
||||
|
||||
if (status != osOK) {
|
||||
#if (LOG_UDS == 1)
|
||||
LoggerInfoStatic(LOGGER, LOG_SIGN, "Error addCommandQueue")
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -153,6 +155,8 @@ static uint16_t TesterPresent_3E(tCanUds *env) {
|
|||
testerPresent->ServiceId = UDS_TesterPresent | 0b1000000;
|
||||
testerPresent->zeroSubFunction = 0;
|
||||
|
||||
env->currentSessionTesterPresentTimeout = SystemGetMs() + timeout_session_S3_Server;
|
||||
|
||||
return 2;
|
||||
}
|
||||
// конец --------------------------- ПИНГ ---------------------------------------------------------
|
||||
|
|
@ -176,8 +180,11 @@ static uint16_t DiagnosticSessionControl_10(tCanUds *env) {
|
|||
}
|
||||
|
||||
if (env->currentSession != com->sub_function) {
|
||||
|
||||
env->currentSession = com->sub_function;
|
||||
|
||||
setDefaultSecurityAccess(env);
|
||||
statusData.Status_Active_Diagnostic_Session.Active_Diagnostic_Session = env->currentSession;
|
||||
}
|
||||
|
||||
tDiagnosticSessionsType *diagnosticSessionsType = (tDiagnosticSessionsType *) env->dataResponse;
|
||||
|
|
@ -507,6 +514,11 @@ static uint16_t CommunicationControl_28(tCanUds *env) {
|
|||
return setResponseError(env, UDS_Communication_Control, UDS_error_sub_functionNotSupported);
|
||||
}
|
||||
|
||||
if (com->sub_function == UDS_sub_enableRxAndTx) {
|
||||
set_CCU_Mute(env->canSpamTransmitter, false);
|
||||
} else {
|
||||
set_CCU_Mute(env->canSpamTransmitter, true);
|
||||
}
|
||||
|
||||
env->dataResponse[0] = UDS_Communication_Control | 0b1000000;
|
||||
env->dataResponse[1] = env->data.data[1] & 0b01111111; // sub-function
|
||||
|
|
@ -517,6 +529,42 @@ static uint16_t CommunicationControl_28(tCanUds *env) {
|
|||
// конец --------------------------- Молчание -------------------------------------------------------------
|
||||
// конец --------------------------- Молчание -------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// начало --------------------------- Запрет изменения DTC -------------------------------------------------------------
|
||||
// начало --------------------------- Запрет изменения DTC -------------------------------------------------------------
|
||||
// начало --------------------------- Запрет изменения DTC -------------------------------------------------------------
|
||||
|
||||
static uint16_t ControlDTCSetting_85(tCanUds *env) {
|
||||
|
||||
tUdsServiceCommand *com = (tUdsServiceCommand *) env->data.data;
|
||||
|
||||
if (env->data.len < 2) {
|
||||
return setResponseError(env, UDS_ControlDTCSetting,
|
||||
UDS_error_incorrectMessageLengthOrInvalidFormat);
|
||||
}
|
||||
|
||||
if ((com->sub_function != UDS_sub_dtc_on) &&
|
||||
(com->sub_function != UDS_sub_dtc_off)) {
|
||||
return setResponseError(env, UDS_ControlDTCSetting, UDS_error_sub_functionNotSupported);
|
||||
}
|
||||
|
||||
if (com->sub_function == UDS_sub_dtc_on) {
|
||||
setNoBitsDTC(env->Diagnostic, false);
|
||||
} else {
|
||||
setNoBitsDTC(env->Diagnostic, true);
|
||||
}
|
||||
|
||||
env->dataResponse[0] = UDS_ControlDTCSetting | 0b1000000;
|
||||
env->dataResponse[1] = env->data.data[1] & 0b01111111; // sub-function
|
||||
|
||||
return 2;
|
||||
}
|
||||
// конец --------------------------- Запрет изменения DTC -------------------------------------------------------------
|
||||
// конец --------------------------- Запрет изменения DTC -------------------------------------------------------------
|
||||
// конец --------------------------- Запрет изменения DTC -------------------------------------------------------------
|
||||
|
||||
|
||||
// начало --------------------------- Функции -------------------------------------------------------------
|
||||
// начало --------------------------- Функции -------------------------------------------------------------
|
||||
// начало --------------------------- Функции -------------------------------------------------------------
|
||||
|
|
@ -524,7 +572,7 @@ static uint16_t CommunicationControl_28(tCanUds *env) {
|
|||
static uint16_t vUDS_check_Programming_Preconditions(tCanUds *env, eUdsRoutineControlType udsRoutineControlType) {
|
||||
|
||||
eUdsRoutineStartStopRoutineResult udsStartStopRoutineResult = UDS_routine_RoutineStartStopSuccess;
|
||||
eUdsRequestRoutineResult udsRequestRoutineResult = UDS_routine_RoutineStop;
|
||||
eUdsRequestRoutineResult udsRequestRoutineResult = UDS_routine_RoutineFinishSuccess;
|
||||
|
||||
if ((udsRoutineControlType == UDS_routine_StartRoutine) || (udsRoutineControlType == UDS_routine_StopRoutine)) {
|
||||
env->dataResponse[4] = udsStartStopRoutineResult;
|
||||
|
|
@ -540,7 +588,7 @@ return 4 + 1;
|
|||
static uint16_t vUDS_routine_VIN_learn(tCanUds *env, eUdsRoutineControlType udsRoutineControlType) {
|
||||
|
||||
eUdsRoutineStartStopRoutineResult udsStartStopRoutineResult = UDS_routine_RoutineStartStopSuccess;
|
||||
eUdsRequestRoutineResult udsRequestRoutineResult = UDS_routine_RoutineStop;
|
||||
eUdsRequestRoutineResult udsRequestRoutineResult = UDS_routine_RoutineFinishSuccess;
|
||||
|
||||
if ((udsRoutineControlType == UDS_routine_StartRoutine) || (udsRoutineControlType == UDS_routine_StopRoutine)) {
|
||||
env->dataResponse[4] = udsStartStopRoutineResult;
|
||||
|
|
@ -557,7 +605,7 @@ static uint16_t vUDS_routine_VIN_learn(tCanUds *env, eUdsRoutineControlType udsR
|
|||
static uint16_t vUDS_routine_Compare_Checksum(tCanUds *env, eUdsRoutineControlType udsRoutineControlType) {
|
||||
|
||||
eUdsRoutineStartStopRoutineResult udsStartStopRoutineResult = UDS_routine_RoutineStartStopSuccess;
|
||||
eUdsRequestRoutineResult udsRequestRoutineResult = UDS_routine_RoutineStop;
|
||||
eUdsRequestRoutineResult udsRequestRoutineResult = UDS_routine_RoutineFinishSuccess;
|
||||
|
||||
if ((udsRoutineControlType == UDS_routine_StartRoutine) || (udsRoutineControlType == UDS_routine_StopRoutine)) {
|
||||
env->dataResponse[4] = udsStartStopRoutineResult;
|
||||
|
|
@ -573,7 +621,7 @@ static uint16_t vUDS_routine_Compare_Checksum(tCanUds *env, eUdsRoutineControlTy
|
|||
static uint16_t vUDS_routine_Erase_Memory(tCanUds *env, eUdsRoutineControlType udsRoutineControlType) {
|
||||
|
||||
eUdsRoutineStartStopRoutineResult udsStartStopRoutineResult = UDS_routine_RoutineStartStopSuccess;
|
||||
eUdsRequestRoutineResult udsRequestRoutineResult = UDS_routine_RoutineStop;
|
||||
eUdsRequestRoutineResult udsRequestRoutineResult = UDS_routine_RoutineFinishSuccess;
|
||||
|
||||
if ((udsRoutineControlType == UDS_routine_StartRoutine) || (udsRoutineControlType == UDS_routine_StopRoutine)) {
|
||||
env->dataResponse[4] = udsStartStopRoutineResult;
|
||||
|
|
@ -590,7 +638,7 @@ static uint16_t
|
|||
vUDS_routine_Check_Programming_Dependancies(tCanUds *env, eUdsRoutineControlType udsRoutineControlType) {
|
||||
|
||||
eUdsRoutineStartStopRoutineResult udsStartStopRoutineResult = UDS_routine_RoutineStartStopSuccess;
|
||||
eUdsRequestRoutineResult udsRequestRoutineResult = UDS_routine_RoutineStop;
|
||||
eUdsRequestRoutineResult udsRequestRoutineResult = UDS_routine_RoutineFinishSuccess;
|
||||
|
||||
if ((udsRoutineControlType == UDS_routine_StartRoutine) || (udsRoutineControlType == UDS_routine_StopRoutine)) {
|
||||
env->dataResponse[4] = udsStartStopRoutineResult;
|
||||
|
|
@ -606,7 +654,7 @@ vUDS_routine_Check_Programming_Dependancies(tCanUds *env, eUdsRoutineControlType
|
|||
static uint16_t vUDS_routine_eComp_Initialize(tCanUds *env, eUdsRoutineControlType udsRoutineControlType) {
|
||||
|
||||
eUdsRoutineStartStopRoutineResult udsStartStopRoutineResult = UDS_routine_RoutineStartStopSuccess;
|
||||
eUdsRequestRoutineResult udsRequestRoutineResult = UDS_routine_RoutineStop;
|
||||
eUdsRequestRoutineResult udsRequestRoutineResult = UDS_routine_RoutineFinishSuccess;
|
||||
|
||||
if ((udsRoutineControlType == UDS_routine_StartRoutine) || (udsRoutineControlType == UDS_routine_StopRoutine)) {
|
||||
env->dataResponse[4] = udsStartStopRoutineResult;
|
||||
|
|
@ -899,7 +947,7 @@ const eUds_com uds_com[256] = {
|
|||
{NULL, ""},
|
||||
{NULL, ""},
|
||||
{NULL, ""},
|
||||
{NULL, ""},
|
||||
{ControlDTCSetting_85, "ControlDTCSetting_85"},
|
||||
{NULL, ""},
|
||||
{NULL, ""},
|
||||
{NULL, ""},
|
||||
|
|
@ -1030,22 +1078,39 @@ void CanUds(tCanUds *env) {
|
|||
for (;;) {
|
||||
osStatus_t status = osMessageQueueGet(env->queue, &env->data, 0, 1000);
|
||||
|
||||
// Контроль TesterPresent
|
||||
if ((env->currentSessionTesterPresentTimeout > 0) &&
|
||||
(env->currentSessionTesterPresentTimeout < SystemGetMs())) {
|
||||
env->currentSessionTesterPresentTimeout = 0;
|
||||
|
||||
#if (LOG_UDS == 1)
|
||||
LoggerFormatInfo(LOGGER, LOG_SIGN, "Resetting the session to default: %d", UDS_session_defaultSession)
|
||||
#endif
|
||||
setDefaultSecurityAccess(env);
|
||||
set_CCU_Mute(env->canSpamTransmitter, false);
|
||||
setNoBitsDTC(env->Diagnostic, false);
|
||||
env->currentSession = UDS_session_defaultSession;
|
||||
statusData.Status_Active_Diagnostic_Session.Active_Diagnostic_Session = env->currentSession;
|
||||
|
||||
}
|
||||
|
||||
if (status == osOK) {
|
||||
|
||||
uint8_t com = env->data.data[0];
|
||||
|
||||
if (uds_com[com].func != NULL) {
|
||||
|
||||
#if (LOG_UDS == 1)
|
||||
sendLogCanUdsHex(env, env->data.data, env->data.len);
|
||||
LoggerFormatInfo(LOGGER, LOG_SIGN, "> %s [%d] %s", uds_com[com].desc, env->data.len, env->hexString)
|
||||
|
||||
#endif
|
||||
uint8_t response_size = uds_com[com].func(env);
|
||||
|
||||
if (response_size) {
|
||||
|
||||
#if (LOG_UDS == 1)
|
||||
sendLogCanUdsHex(env, env->dataResponse, response_size);
|
||||
LoggerFormatInfo(LOGGER, LOG_SIGN, "< %s [%d] %s", uds_com[com].desc, response_size, env->hexString)
|
||||
|
||||
#endif
|
||||
CanSerialPortFrameTpTransmit(&env->canSerialPortFrameTp, env->dataResponse,
|
||||
response_size, PROTOCOL_CAN_ADR_UDS, WAIT_FRAME_WRITE);
|
||||
}
|
||||
|
|
@ -1073,6 +1138,7 @@ void CanUds_Init(
|
|||
tDiagnostic *Diagnostic,
|
||||
tSerialPortFrameIO *CanIO,
|
||||
tDeviceStorage *deviceStorage,
|
||||
tCanSpamTransmitter *canSpamTransmitter,
|
||||
tLoggerInterface *logger) {
|
||||
|
||||
env->logger = logger;
|
||||
|
|
@ -1080,9 +1146,11 @@ void CanUds_Init(
|
|||
env->deviceStorage = deviceStorage;
|
||||
env->Diagnostic = Diagnostic;
|
||||
env->filterIdCount = 2;
|
||||
|
||||
env->canSpamTransmitter = canSpamTransmitter;
|
||||
env->queue = osMessageQueueNew(CAN_US_QUEUE_SIZE, sizeof(tCanTP_data), NULL);
|
||||
|
||||
setDefaultStatus();
|
||||
|
||||
env->filterReqId[0] = Diag_To_CCU_CANID;
|
||||
env->filterReqId[1] = Diag_Functional_CANID;
|
||||
env->filterReqId[2] = 0;
|
||||
|
|
|
|||
18
CanUds.h
18
CanUds.h
|
|
@ -8,12 +8,18 @@
|
|||
#include "CanSerialPortFrameTP.h"
|
||||
#include "DeviceStorage.h"
|
||||
#include "DiagnosticTask.h"
|
||||
#include "CanSpamTransmitter.h"
|
||||
|
||||
#define LOG_UDS 1
|
||||
|
||||
#define CAN_US_QUEUE_SIZE 3
|
||||
|
||||
#define MAX_ATTEMPTS_DEFAULT 3
|
||||
#define BLOCK_TIME_DEFAULT 60000
|
||||
|
||||
#define timeout_session_S3_Server 5000
|
||||
|
||||
|
||||
#define LEN_DEBUG_UDS_BUFF 128
|
||||
|
||||
// Время (логарифмическая шкала)
|
||||
|
|
@ -39,7 +45,8 @@ typedef enum {
|
|||
UDS_ECUResetService = 0x11,
|
||||
UDS_InputOutputControlByIdentifier = 0x2F,
|
||||
UDS_SecurityAccess = 0x27,
|
||||
UDS_Communication_Control = 0x28
|
||||
UDS_Communication_Control = 0x28,
|
||||
UDS_ControlDTCSetting = 0x85
|
||||
} eUdsServices;
|
||||
|
||||
typedef enum {
|
||||
|
|
@ -82,6 +89,11 @@ typedef enum {
|
|||
UDS_sub_enableRxAndDisableTx = 0x1
|
||||
} eUdsCommunicationControl;
|
||||
|
||||
typedef enum {
|
||||
UDS_sub_dtc_on = 0x1,
|
||||
UDS_sub_dtc_off = 0x2
|
||||
} eUdsControlDTCSetting;
|
||||
|
||||
typedef enum {
|
||||
UDS_sub_requestSeed = 0x1,
|
||||
UDS_sub_sendKey = 0x2
|
||||
|
|
@ -141,6 +153,9 @@ typedef struct {
|
|||
char hexString[LEN_DEBUG_UDS_BUFF];
|
||||
|
||||
eUdsSession currentSession;
|
||||
uint32_t currentSessionTesterPresentTimeout;
|
||||
|
||||
tCanSpamTransmitter *canSpamTransmitter;
|
||||
|
||||
struct {
|
||||
bool requestSequenceRequestSeed;
|
||||
|
|
@ -164,6 +179,7 @@ void CanUds_Init(
|
|||
tDiagnostic *Diagnostic,
|
||||
tSerialPortFrameIO *CanIO,
|
||||
tDeviceStorage *deviceStorage,
|
||||
tCanSpamTransmitter *canSpamTransmitter,
|
||||
tLoggerInterface *logger);
|
||||
|
||||
void CanSerialPortCanUds_Start(tCanUds *env);
|
||||
|
|
|
|||
Loading…
Reference in New Issue