159 lines
4.9 KiB
C
159 lines
4.9 KiB
C
//
|
||
// Created by cfif on 23.01.2026.
|
||
//
|
||
#include "DiagnosticTask.h"
|
||
#include "CmsisRtosThreadUtils.h"
|
||
#include "StatusData.h"
|
||
#include "StatusError.h"
|
||
#include "HVAC_model.h"
|
||
|
||
#define LOG_SIGN "DIAGNOSTIC"
|
||
#define LOGGER env->logger
|
||
|
||
void Diagnostic_Init(tDiagnostic *env, tLoggerInterface *logger) {
|
||
|
||
env->logger = logger;
|
||
|
||
env->access = osMutexNew(NULL);
|
||
|
||
// for (uint8_t i = 0; i < COUNT_DTC_CODE_ERROR; ++i) {
|
||
|
||
// Тест DTC не был выполнен в текущем цикле работы
|
||
// dtc_state_error[i] = UDS_dtc_mask_testNotCompletedThisOperationCycle;
|
||
// }
|
||
|
||
// InitThreadAtrStatic(&env->thread.attr, "Diagnostic", env->thread.controlBlock, env->thread.stack,
|
||
// osPriorityNormal);
|
||
}
|
||
|
||
uint32_t diagnostic_ClearDiagnosticInformation_14(tDiagnostic *env) {
|
||
|
||
if (osMutexAcquire(env->access, 5000) == osOK) {
|
||
|
||
// for (uint8_t i = 0; i < COUNT_DTC_CODE_ERROR; ++i) {
|
||
// Тест DTC не был выполнен с момента последней очистки
|
||
// dtc_state_error[i] |= UDS_dtc_mask_testNotCompletedSinceLastClear;
|
||
// dtc_state_FIX_error[i] |= UDS_dtc_mask_testNotCompletedSinceLastClear;
|
||
// }
|
||
|
||
osMutexRelease(env->access);
|
||
} else {
|
||
LoggerInfoStatic(LOGGER, LOG_SIGN, "Access error diagnostic_ClearDiagnosticInformation_14");
|
||
}
|
||
|
||
|
||
return 0;
|
||
}
|
||
|
||
uint32_t diagnostic_UDS_ReadDTCInformation_19_count(tDiagnostic *env, tDiagnosticDTC *diagnosticDTC) {
|
||
|
||
uint32_t countDTC = 0;
|
||
|
||
if (osMutexAcquire(env->access, 5000) == osOK) {
|
||
|
||
for (uint8_t i = 0; i < COUNT_DTC_CODE_ERROR; ++i) {
|
||
|
||
if (env->isNoBitsDTC) {
|
||
if (dtc_state_FIX_error[i] & (diagnosticDTC->mask)) {
|
||
++countDTC;
|
||
}
|
||
} else {
|
||
if (dtc_state_error[i] & (diagnosticDTC->mask)) {
|
||
++countDTC;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
osMutexRelease(env->access);
|
||
} else {
|
||
LoggerInfoStatic(LOGGER, LOG_SIGN, "Access error diagnostic_ClearDiagnosticInformation_14");
|
||
}
|
||
|
||
|
||
return countDTC;
|
||
}
|
||
|
||
uint32_t diagnostic_UDS_ReadDTCInformation_19_dtc(tDiagnostic *env, tDiagnosticDTC *diagnosticDTC) {
|
||
|
||
uint32_t size = 0;
|
||
|
||
if (osMutexAcquire(env->access, 5000) == osOK) {
|
||
|
||
for (uint8_t i = 0; i < COUNT_DTC_CODE_ERROR; ++i) {
|
||
|
||
if (env->isNoBitsDTC) {
|
||
if (dtc_state_FIX_error[i] & (diagnosticDTC->mask)) {
|
||
diagnosticDTC->dataResponse[size] = dtc_codes[i].DTCHighByte;
|
||
diagnosticDTC->dataResponse[size + 1] = dtc_codes[i].DTCMiddleByte;
|
||
diagnosticDTC->dataResponse[size + 2] = dtc_codes[i].DTCLowByte;
|
||
diagnosticDTC->dataResponse[size + 3] = dtc_state_error[i] & (diagnosticDTC->mask);
|
||
size += 4;
|
||
}
|
||
} else {
|
||
if (dtc_state_error[i] & (diagnosticDTC->mask)) {
|
||
diagnosticDTC->dataResponse[size] = dtc_codes[i].DTCHighByte;
|
||
diagnosticDTC->dataResponse[size + 1] = dtc_codes[i].DTCMiddleByte;
|
||
diagnosticDTC->dataResponse[size + 2] = dtc_codes[i].DTCLowByte;
|
||
diagnosticDTC->dataResponse[size + 3] = dtc_state_error[i] & (diagnosticDTC->mask);
|
||
size += 4;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
osMutexRelease(env->access);
|
||
} else {
|
||
LoggerInfoStatic(LOGGER, LOG_SIGN, "Access error diagnostic_UDS_ReadDTCInformation_19_dtc");
|
||
}
|
||
|
||
return size;
|
||
}
|
||
|
||
|
||
uint32_t diagnostic_UDS_ReadDTCSupportDTC_19_dtc(tDiagnostic *env, tDiagnosticDTC *diagnosticDTC) {
|
||
|
||
uint32_t size = 0;
|
||
|
||
if (osMutexAcquire(env->access, 5000) == osOK) {
|
||
|
||
for (uint8_t i = 0; i < COUNT_DTC_CODE_ERROR; ++i) {
|
||
|
||
diagnosticDTC->dataResponse[size] = dtc_codes[i].DTCHighByte;
|
||
diagnosticDTC->dataResponse[size + 1] = dtc_codes[i].DTCMiddleByte;
|
||
diagnosticDTC->dataResponse[size + 2] = dtc_codes[i].DTCLowByte;
|
||
diagnosticDTC->dataResponse[size + 3] = 0;
|
||
size += 4;
|
||
}
|
||
|
||
osMutexRelease(env->access);
|
||
} else {
|
||
LoggerInfoStatic(LOGGER, LOG_SIGN, "Access error diagnostic_UDS_ReadDTCSupportDTC_19_dtc");
|
||
}
|
||
|
||
return size;
|
||
}
|
||
|
||
|
||
void set_NoBitsDTC(tDiagnostic *env, bool noBitsDTC) {
|
||
if (osMutexAcquire(env->access, 5000) == osOK) {
|
||
|
||
env->isNoBitsDTC = noBitsDTC;
|
||
memcpy(dtc_state_FIX_error, dtc_state_error, sizeof(dtc_state_error));
|
||
|
||
osMutexRelease(env->access);
|
||
} else {
|
||
LoggerInfoStatic(LOGGER, LOG_SIGN, "Access error setBitsDTC");
|
||
}
|
||
}
|
||
|
||
void set_Dtc_state(tDiagnostic *env) {
|
||
if (osMutexAcquire(env->access, 1000) == osOK) {
|
||
memcpy(&dtc_state_error, &rtY.dtc_state_error_model, sizeof(dtc_state_error));
|
||
osMutexRelease(env->access);
|
||
} else {
|
||
LoggerErrorStatic(LOGGER, LOG_SIGN, "Access error set_Dtc_state_error");
|
||
}
|
||
}
|
||
|