1 周期消息发送
无论是Simulation Setup中的仿真节点还是Test Setup中的Test Module所关联的CAPL脚本在做仿真或测试时都经常需要向总线模拟发送周期消息。
点击键盘按键 'a' 后向总线发送周期为20ms的can 消息msg:
variables
{
msTimer myTimer;
message 100 msg;
}
on key 'a' {
setTimer(myTimer,20);
}
on timer myTimer {
output(msg);
setTimer(myTimer,20);
}
2 应用报文REQUEST/RESPONSE测试
ECU通常都有很多请求/应答式的功能,比如BCM可以接收用户点击车窗、雨刮、遮阳帘等车身相关硬件的控制按钮向总线发出的开关请求(Request),然后由BCM向总线发出响应消息,并控制车窗、雨刮、遮阳帘等做出相应的反馈动作(Response)。
下面以测试BCM雨刮开关功能为例进行Request/Response测试。
DBC定义:

参考代码:
variables
{
message BCM_Request tBCM_Request;
message BCM_Response tBCM_Response;
int result = 0;
int waitTime = 1000;
}
void MainTest()
{
TestModuleTitle ("Test BCM Features");
TestModuleDescription ("Check all features in BCM.");
TestGroupBegin("BCM Wiper Feature", "Check the perfomance of Wiper");
Check_Wiper_Feature(0,0); //测试雨刮关闭功能
Check_Wiper_Feature(1,1); //测试雨刮开启功能
TestGroupEnd();
}
//Wiper Feature testcase
testcase Check_Wiper_Feature(int request, int response )
{
tBCM_Request.WiperRequest.phys = request;
output(tBCM_Request);
//测试请求发出去后1000ms内是否收到BCM的响应信号。
result = TestWaitForSignalMatch(BCM_Response::WiperResponse,response,waitTime);
passResult(result,request,response);
}
void passResult(long result,int request,int response)
{
switch(result){
case 1: TestStepPass("1.0","Test Pass - request : %d expect response : %d ",request,response);break;
case 0: TestStepFail("1.0","Timeout - request : %d expect response : %d ",request,response);break;
case -1: TestStepFail("1.0","General error - request : %d expect response : %d ",request,response);break;

本文详细介绍了CANoe中如何使用CAPL脚本进行周期消息发送、REQUEST/RESPONSE测试,以及检测报文发送周期的技巧,并展示了统一诊断测试(UDS)的示例。
最低0.47元/天 解锁文章
4350





