- 🍅 我是蚂蚁小兵,专注于车载诊断领域,尤其擅长于对CANoe工具的使用
- 🍅 寻找组织 ,答疑解惑,摸鱼聊天,博客源码,点击加入👉【相亲相爱一家人】
- 🍅 玩转CANoe,博客目录大全,点击跳转👉
🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅- 🍅KB 编号:KB0021581
- 🍅发布日期:2025-02-04
- 🍅阅读量:857
- 🍅文章由AI自动生成,来源:https://support.vector.com/kb?id=kb_search&spa=1&query=KB0021581
🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅 🍅
目录
- 📙 CAPL 系统变量函数 数据类型 独立函数参数
- 问题
📙 CAPL 系统变量函数 数据类型 独立函数参数
问题
如何编写具有系统变量数据类型独立函数参数的 CAPL 函数?
本配置示例展示了如何实现系统变量参数独立于系统变量数据类型(稍后在函数内进行评估)的 CAPL 函数。目的是能够将具有不同数据类型的系统变量交给同一个函数。
Simulation Setup中的 CAPL node 显示了如何在函数内获取实际数据类型 (sysGetVariableSVtype(),sysIsVariableTypeSigned(), …),以及如何在函数内进一步处理(例如,转换为正确的数据类型并访问数值)。
开始测量时,函数会针对不同数据类型的系统变量进行调用。系统变量的数据类型、名称和值随后会被签入 “Write 窗口”,您可以对照 "数据窗口 "仔细检查其正确性。
/*@!Encoding:65001*/on start{// calling the function for System Variables with different data typesmyPrintSVvalueFcn(sysvar::myNamespace::my32BitSignedInt);myPrintSVvalueFcn(sysvar::myNamespace::my32BitUnsignedInt);myPrintSVvalueFcn(sysvar::myNamespace::my64BitSignedInt);myPrintSVvalueFcn(sysvar::myNamespace::my64BitUnsignedInt);myPrintSVvalueFcn(sysvar::myNamespace::myDataVar);myPrintSVvalueFcn(sysvar::myNamespace::myDoubleVar);myPrintSVvalueFcn(sysvar::myNamespace::myIntArray);myPrintSVvalueFcn(sysvar::myNamespace::myString);myPrintSVvalueFcn(sysvar::myNamespace::myDoubleArray);}// function definitionmyPrintSVvalueFcn(sysvar*mySV){longmySVtype;dword isSigned;charbuffer[1000];charbuffer2[6];dword myArrLength;inti;floatmyFloatArr[100];longmyIntArr[100];byte myByteBuffer[100];longcopiedBytes;sysvarint*myDummyInt;sysvarfloat*myDummyFloat;sysvarLongLong*myDummyLongLong;sysvarData*myDummyData;sysvarFloatArray*myDummyFloatArray;sysvarIntArray*myDummyIntArray;sysvarString*myDummyString;// get the data type of the SV parameter firstmySVtype=sysGetVariableSVType(mySV);// ...and evaluate itswitch(mySVtype){case0:write("SV type could not be read - Invalid!");break;case1:// 64Bit doublemyDummyFloat=(sysvarFloat*)mySV;write("64 Bit Double; SV name: %s; value: %.2f",mySV.name,@myDummyFloat);break;case2:// 32Bit integermyDummyInt=(sysvarint*)mySV;// here it is not clear yet if it is a signed or unsigned 32Bit integer, hence the following is necessarry to clarify thisisSigned=sysIsVariableTypeSigned(mySV);switch(isSigned){case1:write("32Bit signed Integer; SV name: %s; value: %d",mySV.name,@myDummyInt);break;default:write("32Bit unsigned Integer; SV name: %s; value: %u",mySV.name,@myDummyInt);break;}break;case3:// stringsnprintf(buffer,elcount(buffer),"");myDummyString=(sysvarstring*)mySV;sysGetVariableString(myDummyString,buffer,elcount(buffer));write("String; SV name: %s; value: %s",mySV.name,buffer);break;case4:// double arraysnprintf(buffer,elcount(buffer),"");myDummyFloatArray=(sysvarFloatArray*)mySV;myArrLength=sysGetVariableArrayLength(myDummyFloatArray);sysGetVariableFloatArray(myDummyFloatArray,myFloatArr,elcount(myFloatArr));for(i=0;i<myArrLength;i++){snprintf(buffer2,elcount(buffer2),"%.2f ",myFloatArr[i]);strncat(buffer,buffer2,elcount(buffer));}write("Double Array; SV name: %s; value: %s",mySV.name,buffer);break;case5:// Integer Arraysnprintf(buffer,elcount(buffer),"");myDummyIntArray=(sysvarIntArray*)mySV;myArrLength=sysGetVariableArrayLength(myDummyIntArray);sysGetVariableLongArray(myDummyIntArray,myIntArr,elcount(myIntArr));for(i=0;i<myArrLength;i++){snprintf(buffer2,elcount(buffer2),"0x%X ",myIntArr[i]);strncat(buffer,buffer2,elcount(buffer));}write("Integer Array; SV name: %s; value: %s",mySV.name,buffer);break;case6:// 64Bit IntegermyDummyLongLong=(sysvarLongLong*)mySV;// here it is not clear yet if it is a signed or unsigned 32Bit integer, hence the following is necessarry to clarify thisisSigned=sysIsVariableTypeSigned(mySV);switch(isSigned){case1:write("64Bit signed Integer; SV name: %s; value: %lld",mySV.name,sysGetVariableLongLong(myDummyLongLong));break;default:write("64Bit unsigned Integer; SV name: %s; value: %llu",mySV.name,sysGetVariableLongLong(myDummyLongLong));break;}break;case7:// datasnprintf(buffer,elcount(buffer),"");myDummyData=(sysvarData*)mySV;myArrLength=sysGetVariableArrayLength(myDummyData);sysGetVariableData(myDummyData,myByteBuffer,copiedBytes);for(i=0;i<copiedBytes;i++){snprintf(buffer2,elcount(buffer2),"0x%X ",myByteBuffer[i]);strncat(buffer,buffer2,elcount(buffer));}write("Data; SV name: %s; value: %s",mySV.name,buffer);break;}}
- 🚩要有最朴素的生活,最遥远的梦想,即使明天天寒地冻,路遥马亡!
- 🚩如果这篇博客对你有帮助,请“点赞” “评论”“收藏” 一键三连哦!
📎 本文 PDF 原文: KB0021581_CAPL_系统变量函数_数据类型_独立函数参数.pdf