CAN/CANFD诊断:CDD诊断
CAN测试诊断方式
- output
- TP链接及相关API
- CDD文件及相关API(本文内容)
CDD配置
CDD Capl接口
发送
诊断功能寻址发送:long diagSendFunctional( diagRequest request)
诊断物理寻址发送:long diagSendRequest (diagRequest obj)
诊断发送判断:long TestWaitForDiagRequestSent (diagRequest request, dword timeout)
诊断请求数据获取:long diagGetPrimitiveData (diagRequest obj, byte* buffer, DWORD buffersize)
诊断响应抑制位设置:diagSetSuppressResp (diagRequest req, long flag)
诊断发送数据设置:long diagSetPrimitiveData (diagRequest obj, byte* buffer, DWORD buffersize)
接收
诊断响应抑制位获取:long diagGetSuppressResp (diagRequest req)
诊断响应数据长度获取:long diagGetRespPrimitiveSize( diagRequest request)
诊断响应判断:long TestWaitForDiagResponse (diagRequest request, dword timeout)
诊断响应数据按字节获取:long diagGetRespPrimitiveByte( diagRequest request, DWORD bytePos)
诊断响应数据获取:long diagGetPrimitiveData (diagResponse obj, byte* buffer, DWORD buffersize)
CDD常用功能
/// <GeneralFunction>
void hexToString(byte HexData[],dword DataLength,char HexDataString[])
{
int i;
char strByte[4];
strncpy(HexDataString,"",elcount(HexDataString));
for(i=0;i<DataLength;i++)
{
if(HexData[i] <= 0x0F)
strncat(HexDataString,"0",elcount(HexDataString));//小于0xF,前面补0
ltoa(HexData[i],strByte,16);//字节->字符
strncat(HexDataString,strByte,elcount(HexDataString));
strncat(HexDataString," ",elcount(HexDataString));//空格分隔符
}
}
long Flexray_Read_History(byte DiagIDType)
{//用于检查读取的DIDValue是否是合理的
int i,ret;
byte DIDTemp[2];
word DID;
//清空接收数组,接收标志
for(i=0;i<255;i++)
{
DID_Read[i] = 0;
}
strncpy(DID_Print,"",elcount(DID_Print));
//初始化参数
DiagInitialize(ReadDataByIdentifier_);
//确定SID
if(@Test::ECU_Index==1)//ACU
DID=0X46F1;
if(@Test::ECU_Index==2)//BBM
DID=0X46F1;
if(@Test::ECU_Index==3)//BGM
DID=0X46F1;
if(@Test::ECU_Index==4)//CDC
DID=0X46F1;
if(@Test::ECU_Index==5)//SRS
DID=0X46F1;
if(@Test::ECU_Index==6)//VDDM
DID=0X46F1;
//数据组包
DIDTemp[0]=(DID>>8) & 0xFF;
DIDTemp[1]=DID&0xFF;
diagSetParameterRaw(ReadDataByIdentifier_,"dataIdentifier",DIDTemp,2);
//将输入数据发送出去,诊断API函数读取接收数据,不对数据做任何处理
testStep("","发送诊断命令22_%x_%x读取历史缓存DID",DIDTemp[1],DIDTemp[0]);
diagSendData(ReadDataByIdentifier_,DiagIDType);
//判断响应
ret=diagGetLastResponseCode(ReadDataByIdentifier_);
if(ret!=-1)
{
testStepPass("","否定响应:历史缓存读取失败!");
return 0;
}
else
{
testStepPass("","肯定响应:历史缓存读取成功!");
}
//接收诊断数据并将DID依次存放到byte数组里面
DiagRxBufLength=diagGetRespPrimitiveSize(ReadDataByIdentifier_);//获取接收报文的长度
for(i=0;i<DiagRxBufLength;i++)
{
DID_Read[i]=DiagGetRespPrimitiveByte(ReadDataByIdentifier_,i);//获取接收报文的值
}
//打印数据
hexToString(DID_Read,DiagRxBufLength,DID_Print);
testStep("","ECU响应数据:%s",DID_Print);
return ret;
}
附:以太网直连配置(非VN板卡)
1、对应节点添加Vector提供的DHCP动态分配协议代码
2、option配置中使能基于channel
3、TCPIP STACK模块使能IPV4
4、配置CDD的ECU的IP地址与Tester的IP地址
5、配置DHCP携带的系统变量中的ECU的IP地址
6、关闭ECU以太网端口在网络适配器对应网口的IPV4协议
本文来自博客园,作者:{张一默},转载请注明原文链接:https://www.cnblogs.com/YiMo9929/p/16662683.html