- 🍅 我是蚂蚁小兵,专注于车载诊断领域,尤其擅长于对CANoe工具的使用
- 🍅 寻找组织 ,答疑解惑,摸鱼聊天,博客源码,点击加入👉【相亲相爱一家人】
- 🍅 玩转CANoe,博客目录大全,点击跳转👉
下面代码是源于Vector的LIN总线测试用例源码,我觉得不错,就单独摘出来分析给大家
C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 15.5.23\LIN\LINSlaveConformanceTest
- 新建一个LIN.cin文件,代码如下,这个函数
Util_SendHeader_ProveNoResponse
实现的功能是:发送LIN头,并判断DUT给出的什么响应,可以同时检测正常响应,错误帧响应等,这要比在on linTransmError,on linFrame * ,on linReceiveError中判断的方式要简便的多,
- 这个函数主要运用
testJoin..
系列函数将不同的事件同事监测,然后使用testWaitForAnyJoinedEvent
函数触发事件测量
/*@!Encoding:936*/
variables
{
long Util_MaxResultTimeout = 1000; // Timeout to wait for a message/event (in ms)
long Util_LinChannel = 1; // LIN application channel where IUT is connected
byte LinRawData[8];
}
/**************************************************************************************************
Description : This function transmits header with specified frame ID. Afterwards it proves that
IUT sends NO response.
Depending on the evaluation result a verdict is set!
------------------------------------------------------------------------------------------------
Parameter : frameId: Frame idenitifier to be transmitted
frameDescr: Frame description (optional)
------------------------------------------------------------------------------------------------
Return code : True on positive verdict, otherwise False
**************************************************************************************************/
long Util_SendHeader_ProveNoResponse(byte frameId, char frameDescr[])
{
long result;
long eventIndex;
testStep("", "Join event");
testJoinMessageEvent(frameId);
testJoinLinReceiveErrorEvent(frameId);
testJoinLinCSErrorEvent(frameId);
testJoinLinTransmErrorEvent(frameId);
testStep("", "Sending %s header (Id=0x%X)", frameDescr, frameId);
Util_SendHeader (frameId);
// ######## Verification ################
eventIndex = testWaitForAnyJoinedEvent(Util_MaxResultTimeout);
switch (eventIndex)
{
case 1: // valid frame
testStep("Verify", "IUT has responded");
break;
case 2: // receive error
testStep("Verify", "IUT receive error");
break;
case 3: // checksum error
testStep("Verify", "IUT checksum error");
break;
case 4: // transmission error
testStep("Verify", "IUT transmission error");
break;
default:
testStep("Verify", "Internal error! Unexpected event (return code %d) on waiting for response", eventIndex);
}
return eventIndex;
}
/**************************************************************************************************
Description : This function transmits LIN header
------------------------------------------------------------------------------------------------
Parameter : frameId: frame Id to be used
------------------------------------------------------------------------------------------------
Return code : None
**************************************************************************************************/
void Util_SendHeader (byte frameId)
{
linFrame 0x0 tst_Frame;
tst_Frame.MsgChannel = Util_LinChannel;
tst_Frame.ID = frameId;
tst_Frame.RTR=1;
output(tst_Frame);
}
- 新建一个LIN.can 测试模块文件,代码如下,这里通过
linInvertRespBit
函数分别注入校验和错误
,接收错误
,正常报文
来测试验证下函数。
/*@!Encoding:936*/
includes
{
#include "LIN_C.cin"
}
testcase TC_1()
{
long result;
testStep("","Set CheckSum Stop Bit Error");
linInvertRespBit(0x3c,8,7);
result = Util_SendHeader_ProveNoResponse(0x3c,"");
write("result = %d",result);
testStep("","Set data byte8 Stop bit Error.");
linInvertRespBit(0x0A,7,8);
result = Util_SendHeader_ProveNoResponse(0x0A,"");
write("result = %d",result);
testStep("","send normal frame");
result = Util_SendHeader_ProveNoResponse(0x0A,"");
write("result = %d",result);
}
void MainTest ()
{
TC_1();
}
-
测试结果如下图所示。
-
当然你也可以在
case 1
里面 添加如下代码 拿到正常响应报文的数据内容。
case 1: // valid frame
testStep("Verify", "IUT has responded");
if (testGetWaitEventMsgData(eventIndex, tst_Frame) != 0)
{
byte i;
for(i = 0;i< tst_Frame.dlc;i++)
LinRawData[i] = tst_Frame.byte(i);
}
- 🚩要有最朴素的生活,最遥远的梦想,即使明天天寒地冻,路遥马亡!
- 🚩如果这篇博客对你有帮助,请 “点赞” “评论”“收藏”一键三连 哦!码字不易,大家的支持就是我坚持下去的动力。