Обновление
This commit is contained in:
parent
d23bfa381e
commit
c9dbf3793f
62
CanUds.c
62
CanUds.c
|
|
@ -63,6 +63,46 @@ static void PrintfDebug(uint8_t *data, uint8_t dlc) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Проверка валидности BCD
|
||||||
|
static bool is_valid_bcd(uint8_t value) {
|
||||||
|
return ((value & 0x0F) <= 9) && ((value >> 4) <= 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка года
|
||||||
|
static bool is_valid_year(uint8_t year) {
|
||||||
|
return is_valid_bcd(year); // 0x00-0x99
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка месяца
|
||||||
|
static bool is_valid_month(uint8_t month) {
|
||||||
|
if (!is_valid_bcd(month)) return false;
|
||||||
|
uint8_t m = ((month >> 4) * 10) + (month & 0x0F);
|
||||||
|
return (m >= 1 && m <= 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка дня (с учетом месяца и года)
|
||||||
|
static bool is_valid_day(uint8_t year, uint8_t month, uint8_t day) {
|
||||||
|
if (!is_valid_bcd(day)) return false;
|
||||||
|
|
||||||
|
uint8_t y = ((year >> 4) * 10) + (year & 0x0F);
|
||||||
|
uint8_t m = ((month >> 4) * 10) + (month & 0x0F);
|
||||||
|
uint8_t d = ((day >> 4) * 10) + (day & 0x0F);
|
||||||
|
|
||||||
|
if (d < 1) return false;
|
||||||
|
|
||||||
|
// Дни в месяцах
|
||||||
|
uint8_t days_in_month[] = {31, 28, 31, 30, 31, 30,
|
||||||
|
31, 31, 30, 31, 30, 31};
|
||||||
|
|
||||||
|
// Проверка на високосный год
|
||||||
|
if (m == 2) {
|
||||||
|
bool is_leap = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
|
||||||
|
return d <= (is_leap ? 29 : 28);
|
||||||
|
}
|
||||||
|
|
||||||
|
return d <= days_in_month[m - 1];
|
||||||
|
}
|
||||||
|
|
||||||
static bool isSecurityAccessDenied(tCanUds *env, tPermissionSession isPermissionSession) {
|
static bool isSecurityAccessDenied(tCanUds *env, tPermissionSession isPermissionSession) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
|
|
@ -375,6 +415,17 @@ static uint16_t WriteDataByIdentifier_2E(tCanUds *env) {
|
||||||
env->dataResponse[0] = UDS_WriteDataByIdentifier | 0b1000000;
|
env->dataResponse[0] = UDS_WriteDataByIdentifier | 0b1000000;
|
||||||
env->dataResponse[1] = dataIdentifier_hi;
|
env->dataResponse[1] = dataIdentifier_hi;
|
||||||
env->dataResponse[2] = dataIdentifier_lo;
|
env->dataResponse[2] = dataIdentifier_lo;
|
||||||
|
|
||||||
|
// CCU_Configuration
|
||||||
|
if (dataIdentifier_lo == 0) {
|
||||||
|
tStatus_CCU_Configuration *CCU_Configuration = (tStatus_CCU_Configuration *) &env->data.data[4];
|
||||||
|
if ((CCU_Configuration->AromaConfiguration > 1) || (CCU_Configuration->AlgorithmConfiguration > 1) ||
|
||||||
|
(CCU_Configuration->RearHVACConfiguration > 1)) {
|
||||||
|
return setResponseError(env, UDS_WriteDataByIdentifier,
|
||||||
|
UDS_error_requestOutOfRange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(uds_WriteDataByIdentifier_2E_com_CF[dataIdentifier_lo].data, &env->data.data[3], size);
|
memcpy(uds_WriteDataByIdentifier_2E_com_CF[dataIdentifier_lo].data, &env->data.data[3], size);
|
||||||
|
|
||||||
SaveToStorageFromStatusData(env->deviceStorage, &statusData.ecu);
|
SaveToStorageFromStatusData(env->deviceStorage, &statusData.ecu);
|
||||||
|
|
@ -407,6 +458,17 @@ static uint16_t WriteDataByIdentifier_2E(tCanUds *env) {
|
||||||
env->dataResponse[0] = UDS_WriteDataByIdentifier | 0b1000000;
|
env->dataResponse[0] = UDS_WriteDataByIdentifier | 0b1000000;
|
||||||
env->dataResponse[1] = dataIdentifier_hi;
|
env->dataResponse[1] = dataIdentifier_hi;
|
||||||
env->dataResponse[2] = dataIdentifier_lo;
|
env->dataResponse[2] = dataIdentifier_lo;
|
||||||
|
|
||||||
|
|
||||||
|
// Tester_Fingerprint
|
||||||
|
if (dataIdentifier_lo == 0x5A) {
|
||||||
|
tFingerprint *fingerprint = (tFingerprint *) &env->data.data[4];
|
||||||
|
if (is_valid_day(fingerprint->year, fingerprint->month, fingerprint->day) == false) {
|
||||||
|
return setResponseError(env, UDS_WriteDataByIdentifier,
|
||||||
|
UDS_error_requestOutOfRange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(uds_WriteDataByIdentifier_2E_com_F1[dataIdentifier_lo].data, &env->data.data[3], size);
|
memcpy(uds_WriteDataByIdentifier_2E_com_F1[dataIdentifier_lo].data, &env->data.data[3], size);
|
||||||
|
|
||||||
SaveToStorageFromStatusData(env->deviceStorage, &statusData.ecu);
|
SaveToStorageFromStatusData(env->deviceStorage, &statusData.ecu);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue