CANoe CAPL结构初始化

CANoe CAPL struct initialization

我在 Vectors CANoe CAPL 中声明和初始化 struct 时遇到问题。我已经知道来自 C/C++ 的结构,但 CAPL 中的声明似乎有点不同。

Vector 帮助功能并没有真正揭示。

我有多个 CAN ID(例如 0x61A)。每个 CAN ID 都是分配的不同数量的信号 ID(例如 0xDDF6)。我想从 CAN ID 中循环读取信号 ID,并计划将其组织成一个复杂的 struct

我已经尝试过不同类型的声明和初始化,但每次我都会遇到解析错误。

你能帮我解决我的问题吗? 不同于 struct?

的任何其他组织我的价值观的想法

谢谢和问候!

来自 CAPL 文档:

Structured types can be declared in CAPL in a similar way to C...

... they may only be used in CAPL programs with CANoe from version 7.0 Service Pack 3.

示例:

variables
{
  /* declarating a struct */
  struct MyData {
    int i;
    float f;
  };
}

on start
{
  /* defining a struct variable and initiliazing the elements */
  struct MyData data = {
    i = 42,
    f = 1.32
  };

  /* accessing the struct elements */
  write("i=%d, f=%f", data.i, data.f);
}

输出:

i=42, f=1.320000

我在 struct 访问方面存在缺陷。试图在变量声明例程中初始化 struct 参数,而不是在 on start 例程中。

我的多数据访问的工作代码现在是:

variables
{
  struct Veh_Database
  {
    dword ECU;
    dword ParamID[8][2];
  };
  struct Veh_Database ECU_Info[12];
}

on start
{
  ECU_Info[0].ECU = 0x1A;
  ECU_Info[0].ParamID[0][0] = 0xDD;     
  ECU_Info[0].ParamID[0][1] = 0xF6;
  /* ... */
  ECU_Info[1].ECU = 0x12;
  ECU_Info[1].ParamID[0][0] = 0xDE;
  ECU_Info[1].ParamID[0][1] = 0x9C;
  /* ... */
}

感谢您的帮助!

只是为了完整性:也可以在变量声明中初始化一个struct

variables
{
   struct myStruct
   {
      dword val;
      dword arr[8];
   };
   struct myStruct myInstance = {1, {1,2,3,4,5,6,7,8}};
}

(在 CANoe 10 上测试)