// // Created by cfif on 20.01.2026. // #ifndef HVAC_M7_CANUDS_H #define HVAC_M7_CANUDS_H #include "CanSerialPortFrameTP.h" #include "DeviceStorage.h" #include "DiagnosticTask.h" #define CAN_US_QUEUE_SIZE 3 #define MAX_ATTEMPTS_DEFAULT 3 #define BLOCK_TIME_DEFAULT 60000 #define LEN_DEBUG_UDS_BUFF 128 // Время (логарифмическая шкала) // │ // ├── StMin (0.1-127 мс) ← Между КАДРАМИ // │ │ // ├── N_As, N_Bs (до 1000 мс) ← Транспортные таймауты // │ │ // ├── P2Server (до 50 мс) ← Между СООБЩЕНИЯМИ (UDS) // │ │ // ├── P2*Server (до 5000 мс) ← Ожидание при ResponsePending // │ │ // └── S3_Server (до 5000 мс) ← ТАЙМЕР ВСЕЙ СЕССИИ typedef enum { UDS_DiagnosticSessionControl = 0x10, UDS_ReadDTCInformation = 0x19, UDS_ClearDiagnosticInformation = 0x14, UDS_TesterPresent = 0x3E, UDS_ReadDataByIdentifier = 0x22, UDS_WriteDataByIdentifier = 0x2E, UDS_RoutineControl = 0x31, UDS_ECUResetService = 0x11, UDS_InputOutputControlByIdentifier = 0x2F, UDS_SecurityAccess = 0x27, UDS_Communication_Control = 0x28 } eUdsServices; typedef enum { UDS_error_incorrectMessageLengthOrInvalidFormat = 0x13, UDS_error_responseTooLong = 0x14, UDS_error_requestOutOfRange = 0x31, UDS_error_securityAccessDenied = 0x33, UDS_error_invalidKey= 0x35, UDS_error_sub_functionNotSupported = 0x12, UDS_error_conditionsNotCorrect = 0x22, UDS_error_requestSequenceError = 0x24, UDS_error_exceededNumberOfAttempts = 0x36, UDS_error_requiredTimeDelayNotExpired = 0x37 } eUdsResponseError; typedef enum { UDS_session_defaultSession = 0x1, UDS_session_programmingSession = 0x2, UDS_session_extendedDiagnosticSession = 0x3 } eUdsSession; typedef enum { UDS_io_returnControlToECU = 0x0, UDS_io_shortTermAdjustment = 0x3 } eUdsIO; typedef enum { UDS_dtc_reportNumberOfDTCByStatusMask = 0x1, UDS_dtc_reportDTCByStatusMask = 0x2 } eUdsDtc; typedef enum { UDS_reset_hardReset = 0x1, UDS_reset_softReset = 0x3 } eUdsReset; typedef enum { UDS_sub_enableRxAndTx = 0x0, UDS_sub_enableRxAndDisableTx = 0x1 } eUdsCommunicationControl; typedef enum { UDS_sub_requestSeed = 0x1, UDS_sub_sendKey = 0x2 } eUdsSecurityAccess; typedef enum { UDS_routine_StartRoutine = 1, UDS_routine_StopRoutine = 2, UDS_routine_RequestRoutineResults = 3 } eUdsRoutineControlType; typedef enum { UDS_routine_VIN_learn = 0x1300, UDS_routine_Deflector_learn = 0xCF00, UDS_routine_Compare_Checksum = 0x0202, UDS_routine_Check_Programming_Preconditions = 00203, UDS_routine_Erase_Memory = 0xFF00, UDS_routine_Check_Programming_Dependancies = 0xFF01 } eUdsRoutineModes; typedef enum { UDS_routine_RoutineStartStopSuccess = 0, UDS_routine_RoutineStartStopFailure = 0xff } eUdsRoutineStartStopRoutineResult; typedef enum { UDS_routine_RoutineStop = 0, UDS_routine_RoutineRun = 1, UDS_routine_RoutineFinishError = 2, UDS_routine_RoutineFinishSuccess = 3 } eUdsRequestRoutineResult; typedef struct { eUdsServices service; uint8_t sub_function; uint8_t *data; } tUdsServiceCommand; typedef struct { tCanSerialPortFrameTp canSerialPortFrameTp; tLoggerInterface *logger; tSerialPortFrameIO *CanIO; tDeviceStorage *deviceStorage; tDiagnostic *Diagnostic; tCanTP_Ext_data canTP_Ext_data; osMessageQueueId_t queue; tCanTP_data data; uint8_t dataResponse[1024]; uint8_t filterIdCount; uint32_t filterReqId[16]; uint32_t filterRespId[16]; uint8_t filterDirReq[16]; char hexString[LEN_DEBUG_UDS_BUFF]; eUdsSession currentSession; struct { bool requestSequenceRequestSeed; bool stateSecurityAccess; uint32_t counter_max_attempts_default; uint32_t time_counter_max_attempts_default; } SA; tStaticThreadBlock(512) T_can_Uds; } tCanUds; typedef uint16_t (*uds_func_ptr)(tCanUds *env); typedef struct { uds_func_ptr func; char *desc; } eUds_com; void CanUds_Init( tCanUds *env, tDiagnostic *Diagnostic, tSerialPortFrameIO *CanIO, tDeviceStorage *deviceStorage, tLoggerInterface *logger); void CanSerialPortCanUds_Start(tCanUds *env); #endif //HVAC_M7_CANUDS_H