Search code examples
caplcanoe

Retrieving sysVar BusLoad for CAN channel adaptively


I am creating a program node for a test. The test requires knowledge of the bus load of the CAN channel being tested. The test is nearly fully autonomous except for retrieving the sysVar Busload for the respective channel. I want to make it so that I can retrieve the BusLoad value like this:

Proper way:

on message *{
      BusLoad = @_Statistics::CAN1::Busload;
}

What I want:

on message *{
      BusLoad = @_Statistics::this.msgChannel::Busload;
}

I am extremely new to CAPL so any help would be appreciated, I'm unsure if this is even possible.

Thank you! :)


Solution

  • You can access system variables by name.

    Try this (could not test this, I am currently away from my CANoe):

    on message * {
      char buffer[100], format[] = "CAN%d::Busload";
    
      snprintf(buffer, elcount(buffer), format, this.CAN);
      BusLoad = sysGetVariableInt("_Statistics", buffer);
    }
    

    sysGetVariableInt allows to specify the name of the system variable as string. With snprintf you can assemble the string using the channel number.