最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to dynamically switch ECU CAN message IDs in CAPL without hardcoding for each ECU? - Stack Overflow

programmeradmin2浏览0评论

I have a specific query related to UDS Testing in CAPL. Scenario

I have two different ECUs which are differentiated by the ECU number in the Extended CAN ID.

For a single ECU, there is no issue. I have defined the CAN messages like this:

message CAN1.0xXXXXX1x Diag_Resp;
message CAN1.0xXXXXX1x Diag_PhyReq;
message CAN1.0xXXXXX1x Diag_FuncReq;

I use on message events to receive the diagnostic responses for a diagnostic request in my framework. I want to reuse the same script for other ECUs without manually changing the message IDs. I need to scale this to 32 ECUs, where the same script can be reused dynamically.

I attempted to use a switch case with a global variable to control ECU switching, but it’s not working as expected. Main.can

variables
{
    byte Ecu_Selector = 0;
}

void mainTest()
{
    Ecu_Selector = 0x02; // Want to select ECU 2 for script 
    execution
}

/*UDS.cin*/

variables
{
    switch(Ecu_Selector)
    {
        case(0x02):
            message CAN1.0xXXXXX2x Diag_Req;
            message CAN1.0xXXXXX2x Diag_Resp;
            message CAN1.0xXXXXX2x Func_Diag_Req;
            break;

        default:
        case(0x01):
            message CAN1.0xXXXXX1x Diag_Req;
            message CAN1.0xXXXXX1x Diag_Resp;
            message CAN1.0xXXXXX1x Func_Diag_Req;
            break;
        }
}

I want to dynamically switch between different ECUs at runtime and send/receive messages accordingly, without having to hardcode message IDs for each ECU. Is there a better approach or design pattern for this scenario in CAPL? Can I avoid declaring message objects explicitly for each ECU and handle them more generically?

Working in the Vector CAPL environment. Using UDS diagnostic requests/responses (services 0x22, 0x2E, 0x10, etc.). The goal is to scale to 32 ECUs with different CAN IDs.

Thanks in advance for your help!

发布评论

评论列表(0)

  1. 暂无评论