这篇文章聊聊在工作中遇到的问题和分享一些好玩的函数
不允许直接int 变量 = 变量;
可以写成
int temp;
temp = x;
void swap(int x, int y) {
int temp = x;
x = y;
y = temp;
printf("在 swap 函数内:x = %d, y = %d\n", x, y);
}
halt();暂停模拟=断点
variables { message InspectMessage gMsgInspect; message BreakPointMessage gMsgBreakPoint; message BreakPointMessage2 gMsgBreakPoint2; msTimer tSignalUpdateBreakPoint; byte gBreakPointMsgByte0 ; byte gBreakPointMsgByte1 ; byte gBreakPointMsgByte2 ; byte gBreakPointMsgByte3 ; byte gBreakPointMsgByte4 ; byte gBreakPointMsgByte5 ; byte gBreakPointMsgByte6 ; byte gBreakPointMsgByte7 ; byte gInspectMsgByte0 ; byte gInspectMsgByte1 ; byte gInspectMsgByte2 ; byte gInspectMsgByte3 ; byte gInspectMsgByte4 ; byte gInspectMsgByte5 ; byte gInspectMsgByte6 ; byte gInspectMsgByte7 ; } on message InspectMessage { gMsgInspect = this; gInspectMsgByte0 = gMsgInspect.SigInspect0; gInspectMsgByte1 = gMsgInspect.SigInspect1; gInspectMsgByte2 = gMsgInspect.SigInspect2; gInspectMsgByte3 = gMsgInspect.SigInspect3; gInspectMsgByte4 = gMsgInspect.SigInspect4; gInspectMsgByte5 = gMsgInspect.SigInspect5; gInspectMsgByte6 = gMsgInspect.SigInspect6; gInspectMsgByte7 = gMsgInspect.SigInspect7; // Inspect() function will update // the variables in the debugger window if(@sysvar::Inspect::InspectOnOff) { inspect(); } } on start { @sysvar::Inspect::InspectOnOff = 0; @sysvar::BreakPoint::TimerBreakPoint = 0; @sysvar::BreakPoint::MessageBreakPointOnOff = 0; @sysvar::BreakPoint::SignalBreakPoint = 0; setTimer(tSignalUpdateBreakPoint,2000); } on message BreakPointMessage { int CAPLError; int SigPointValue; SigPointValue = this.SigBPoint0; if(@sysvar::BreakPoint::SetError) { if(SigPointValue == 0 && @sysvar::BreakPoint::SignalBreakPoint) { halt(); } CAPLError = (1.0/this.SigBPoint0); // Diff through 0 } } on timer tSignalUpdateBreakPoint { if(@sysvar::BreakPoint::TimerBreakPoint) { @sysvar::BreakPoint::TimerBreakPoint = 0; } setTimer(this,2000); } on message BreakPointMessage2 { gMsgBreakPoint2 = this; // halt() function will halt the simulation, if the // message comes into the on message handler if(@sysvar::BreakPoint::MessageBreakPointOnOff) { @sysvar::BreakPoint::MessageBreakPointOnOff = 0; halt(); } saveMessageBytes(); } void saveMessageBytes() { gBreakPointMsgByte0 = gMsgBreakPoint2.SigBPoint0; gBreakPointMsgByte1 = gMsgBreakPoint2.SigBPoint1; gBreakPointMsgByte2 = gMsgBreakPoint2.SigBPoint2; gBreakPointMsgByte3 = gMsgBreakPoint2.SigBPoint3; gBreakPointMsgByte4 = gMsgBreakPoint2.SigBPoint4; gBreakPointMsgByte5 = gMsgBreakPoint2.SigBPoint5; gBreakPointMsgByte6 = gMsgBreakPoint2.SigBPoint6; gBreakPointMsgByte7 = gMsgBreakPoint2.SigBPoint7; }stop():停止运行上位机
若字符串太长我们可以通过用两个“”“”,把字符串分成两行来写
// Phase 4: wait for 5min onoffsts should be 1 always if(testWaitForSignalOutsideRange(Msagonoffsts, 1, 1,5*1000*60)) { testStepFail("TRANS_TIMEOUT", "onoffsts should be 1 always for 5min," " but value: %d", $Msagonoffsts); return; }if (IsSimulated()) // don't activate tests when running in simulated mode { WriteLineEx(wrCAPLSink, wrError , "This demo cannot run in simulated mode!"); stop(); }linChangeSchedTable(dword tableIndex, dword slotIndex, dword onSlotIndex)实现调度表的调度(切换的调度表,切换的调度表的报文,上一个调度表终止调度的报文)
on start { //linStopScheduler(); linChangeSchedTable(2,2); } on key 'a' { linChangeSchedTable(2,2,4); }linRunSchedTableNTimes (1, 2, -2, -1);暂时只支持仿真模式,真实节点不确定是否可用
CAPL的函数里面定义的变量特性等同于C语言的静态变量
报错1:Start of measurement aborted:复制上位机后添加dbc出现此报错建议,重新新建一个工程环境
报错2:真实节点与仿真节点冲突会会报错
报错3:capl保存的canner报错原因:操作步骤不对
1.先生成
2.删除.can
3.重启上位机,不做任何操作
强制转义符
“%” -> “%%”
“>” 和“<”不能写在XML的引号内容内,尖括号在XML中有定义
Windows 路径中的反斜杠需用\\转义,或直接使用正斜杠/(CANoe 兼容)。setLogFileName("Logging 2","\\log\\NIO_TG1_TC1_1_{MeasurementStart}.blf");
变量类型
打印使用方法
Settimer获取信号值
只有在获取到报文的时候才会激活,所以定时器的起始位置很重要,定时周期必须小于调度周期,和报文间延时,建议10ms
StmCreate_CSV函数
testcase testcase_md(word mdtimeval) { byte i; //m1 // for(i = 1;i<=8;i++) // { // if(i >= 3) // { // $VehMd_l_LHZCU = i; // testWaitForTimeout(mdtimeval); // $VehMd_l_LHZCU = 0; // testWaitForTimeout(100); // } // // } dword stimId; //dbSignal StimSig; //Create stimulus for csv files and dbSignal stimId = StmCreate_CSV(sysvar::A,UsgMd_l_LHZCU, "stimulus.csv"); writeEx(-3,1,"st"); //Start the process of reading the stimulus from csv file StmControl_Start(stimId); testWaitForTimeout(5000); //Destroy the created stimulus StmControl_Destroy(stimId); }第一行时间不能是0.00
timer事件在test moudle的限制
CAPL 的 on timer 事件处理函数运行在 Timer Handler 上下文中 ,这个上下文:
1. ❌ 不能发送诊断请求(Diagnostic Request)
2. ❌ 不能执行 testWaitFor... 系列函数
3. ❌ 不能直接调用某些测试库函数
只能仿真调试进行局部变量 的查看