1.5wuling_zhuanjietou/UDS/uds_dtc.h
2024-10-17 09:06:51 +08:00

172 lines
3.9 KiB
C

#ifndef __UDS_DTC_H__
#define __UDS_DTC_H__
// #include "config.h"
#include "uds_config.h"
#define DTC_FOREACH(func)\
/*00*/ func(0x911716,ECU_VOLTAGE_LOW) \
/*01*/ func(0x911717,ECU_VOLTAGE_HIGH) \
/*02*/ func(0xC07388,ECU_ENTER_BUSOFF) \
/*03*/ func(0xC0FE01,INPUT_OVERVOLTAGE) \
/*04*/ func(0xC0FE02,INPUT_UNDERVOLTAGE) \
/*05*/ func(0xC0FE03,OUTPUT_OVERVOLTAGE) \
/*06*/ func(0xC0FE04,OUTPUT_UNDERVOLTAGE) \
/*07*/ func(0xC0FE05,INPUT_OVERCURRENT) \
/*08*/ func(0xC0FE06,OUTPUT_OVERCURRENT) \
/*09*/ func(0xC0FE07,OVERTEMPERTURE)
#define GENERATE_DTC_ID(value,name) id##name ,
#define GENERATE_DTC_VALUE_ARRAY(value,name) value,
#define GENERATE_DTC_FAULT_FLAG(value,name) uint32_t f##name: 1;
#define GENERATE_DTC_TIMER_ARRAY(value,name) uint16_t u##name;
#define GENERATE_DTC_OPTION(value,name) uint32_t op##name: 1;
//DTC 请求子功能
#define DTC_ReportNumberOfDTCByStatusMask 0x01
#define DTC_ReportDTCByStatusMask 0x02
#define DTC_ReportDTCSnapshotRecordByDTCNumber 0x04
#define DTC_ReportDTCExtendedDataRecordByDTCNumber 0x06
#define DTC_ReportSupportedDTCs 0x0A
//DTCStatusMask/statusOfDtc 参数相关信息
#define DTC_STATUS_Test_Failed 0//测试失效
#define DTC_STATUS_Test_Failed_This_Monitoring_Cycle 1//本检测周期测试失效
#define DTC_STATUS_Pending_DTC 2//等待DTC
#define DTC_STATUS_Confirmed_DTC 3//确认DTC"
#define DTC_STATUS_Test_Not_Completed_Since_Last_Clear 4//上次清零后测试未完成
#define DTC_STATUS_Test_Failed_Since_Last_Clear 5//上次清零后测试失效
#define DTC_STATUS_Test_Not_Completed_This_Monitoring_Cycle 6//本检测周期测试未完成
#define DTC_STATUS_Warning_Indicator_Requested 7//警告指示位请求
#define DTC_STATUS_Support_Bit_Status ((1<<DTC_STATUS_Test_Failed) | (1<<DTC_STATUS_Confirmed_DTC))
//诊断初始化时间
#define DIAG_START_TIME 50 //500 MS
#define DIAG_START_INIT_TIME (150 - DIAG_START_TIME) //1500 MS
#pragma anon_unions
typedef enum _DTC_ID {
DTC_FOREACH(GENERATE_DTC_ID)
DTC_ID_NUM,
}DTC_ID;
typedef union _DTC_Fault_Flag{
uint32_t w;
struct
{
DTC_FOREACH(GENERATE_DTC_FAULT_FLAG)
}b;
}DTC_Fault_Flags;
typedef struct _DTC_Msg_Timer{
DTC_FOREACH(GENERATE_DTC_TIMER_ARRAY)
}DTC_Msg_Timers;
typedef union _DTC_Options{
uint32_t w;
struct
{
DTC_FOREACH(GENERATE_DTC_OPTION)
}b;
}DTC_Options;
typedef enum
{
ISO15031_6_DTCformat,
ISO14229_1_DTCformat,
SAE1939_73_DTCformat,
} DTC_FORMAT_IDENTIFIE;
typedef union
{
uint16_t map;
struct//小端端模式
{
uint8_t DTCcountLowByte;
uint8_t DTCcountHighByte;
//uint8_t DTCcountLowByte;
} b;
} DTC_COUNT;
typedef union
{
struct {
uint8_t PowerMode; //ECU供电模式 00h: OFF/Startup 01h: ACC, 02h: ON, 03h: CRANK+ON
uint8_t TolOdometerH; //总里程 高byte km 0-999999
uint8_t TolOdometerM; //总里程 中间byte
uint8_t TolOdometerL; //总里程 低byte
uint8_t DateSec; //日期 秒 0-59
uint8_t DateMin; //日期 分 0-59
uint8_t DateHour; //日期 时 0-23
uint8_t DateDay; //日期 日 1-31
uint8_t DateMonth; //日期 月 1-12
uint8_t DateYear; //日期 年 偏移2000
uint8_t VehSpeedH; //车速高byte km/h Phys =(Hex->Dec)*0.0625
uint8_t VehSpeedL; //车速低byte
uint8_t BatVolt; //蓄电池电压(最大25.4V) 精度.01V
uint8_t SOC;
};
uint8_t d8[14];
}DTC_SnapshotType;
typedef union
{
struct {
uint8_t FaultCounter;
uint8_t FaultCounterOfAge;
uint8_t FaultAgingCounter;
};
uint8_t d8[3];
}DTC_ExtendedType;
typedef struct
{
uint8_t status;
DTC_SnapshotType snapshot;
DTC_ExtendedType extended;
uint8_t crc16[2]; //校验
} DTC_RecordDataBufType;
typedef struct
{
DTC_RecordDataBufType recordData[DTC_ID_NUM];
}DTC_StatusType;
typedef union
{
struct {
uint8_t DTCLowByte;
uint8_t DTCMiddleByte;
uint8_t DTCHightByte;
uint8_t res;
};
uint32_t dtc;
}DTC_MaskRecordTpye;
typedef struct
{
uint8_t DTCReportSubFunction;
uint8_t DTCStatusMask;
DTC_MaskRecordTpye DTCMaskRecord;
uint8_t DTCRecordNumber;
DTC_FORMAT_IDENTIFIE DTCFormatIdentifie;
DTC_COUNT DTCcount;
DTC_StatusType DTCStatus;
} DTC_STRUCT;
#endif