CANoe 仿真

应用:

实际应用中遇到一些难以复现的case,需要将当时录取的数据重新注入至can线,以复现当时的工况,以便于相应控制器录取当时的内部变量。

步骤1:

使用CANoe自带工具Logging file Conversion将数据转为CSV格式。
CANoe 仿真_第1张图片
note:可以进行如下设置,根据自己需要进行选择。
CANoe 仿真_第2张图片
CANoe 仿真_第3张图片

步骤2

  1. 配置Capl test module “MyTestModule”.
    CANoe 仿真_第4张图片
  2. 设置按键“a”时仿真测试开始。
    CANoe 仿真_第5张图片
    3.相应代码
/*@!Encoding:1252*/
includes
{
  
}

variables
{
  // variables for the stimuli handling:
  dword StimEV1, StimEV2, StimSV1, StimSV2, StimSig1, StimSig2, StimSig3, StimSig4;
  // Creating a message that can be send via CAPL
  message frmSix myMsg = {DLC = 8};
  msTimer MyTimer;
}

on preStart
{
  // executed in the role of a developer
  ChkConfig_Init();
}

void MainTest ()
{
  // set the timer for cyclic sending of the message frmSix:
  setTimerCyclic(MyTimer,20);
  
  // Start the Test Case which in turn starts the stimuli:
  TC_Stimuli();
}

testcase TC_Stimuli()
{
  // Create Stimulus for System Variable cyclical - time column of CSV is NOT taken into account:
  StimSV1= StmCreate_CSV(sysvar::MyNameSpace::MySV1,sigOne, 200, "MyCSV.csv");
  // Create Stimulus for System Variable non-cyclical - time column of CSV is taken into account:
  StimSV2= StmCreate_CSV(sysvar::MyNameSpace::MySV2,sigOne, "MyCSV.csv");
  
  // Create Stimulus for Environment Variable cyclical - time column of CSV is NOT taken into account:
  StimEV1 = StmCreate_CSV(MyEnvVar1, sigTwo, 200, "MyCSV.csv");
  // Create Stimulus for Environment Variable non- cyclical - time column of CSV is taken into account:
  StimEV2= StmCreate_CSV(MyEnvVar2, sigTwo, "MyCSV.csv");
  
  // Create a Stimulus for a signal non- cyclical, signal send via CAPL:
  StimSig1 =StmCreate_CSV(myMsg,sigEleven, "MyCSV.csv");
  //Create a Stimulus for a signal non-cyclical, signal send via Interaction Layer:
  StimSig2 =StmCreate_CSV(sigThree, "MyCSV.csv");
  // Create a Stimulus for a signal cyclical, signal send via CAPL:
  StimSig3 =StmCreate_CSV(myMsg, sigTwelve,200,"MyCSV.csv");
  //Create a Stimulus for a signal cyclical, signal send via Interaction Layer:
  StimSig4 =StmCreate_CSV(sigTwo,200,"MyCSV.csv");
  
  //Start Stimuli:
  StmControl_Start(StimSV1);
  StmControl_Start(StimSV2);
  StmControl_Start(StimEV1);
  StmControl_Start(StimEV2);
  StmControl_Start(StimSig1);
  StmControl_Start(StimSig2);
  StmControl_Start(StimSig3);
  StmControl_Start(StimSig4);
  
  //testWaitForTimeout(10000);设置停止条件,可以自行进行设置。
  TestWaitForSignalOutsideRange(sigTwelve, 0, 300, 5000);
  // Stop Stimuli:
  StmControl_Stop(StimSV1);
  StmControl_Stop(StimSV2);
  StmControl_Stop(StimEV1);
  StmControl_Stop(StimEV2);
  StmControl_Stop(StimSig1);
  StmControl_Stop(StimSig2);
  StmControl_Stop(StimSig3);
  StmControl_Stop(StimSig4);
  
}

// send message via CAPL (cyclical):
on timer MyTimer
{
  output(myMsg);
}


on preStop
{
  // Destroy stimulus:
  StmControl_Destroy (StimSV1);
  StmControl_Destroy (StimSV2);
  StmControl_Destroy (StimEV1);
  StmControl_Destroy (StimEV2);
  StmControl_Destroy (StimSig1);
  StmControl_Destroy (StimSig2);
  StmControl_Destroy (StimSig3);
  StmControl_Destroy (StimSig4);
}

说明

  1. 可以以此为例根据自己项目往CAN线发送数据,计算MsgCounter and CRC value;
  2. CSV文件中的名称务必和程序中的一致。

你可能感兴趣的:(CANoe)