2

I'm having trouble with declaration and initialization of a struct in Vectors CANoe CAPL. I already know structs from C/C++ but it seems the declaration is a little different in CAPL.

The Vector help function isn't really revealing.

I have a number of CAN IDs (e.g. 0x61A). Every CAN ID is a different number of Signal IDs (e.g. 0xDDF6) assigned. I want to read out cyclic the Signal ID from the CAN IDs and plan to organize this in a convoluted struct.

I already tried out different types of declaration and initialization but every time I get a parse error.

Can you please give me a helping hand for my problem? Any other ideas to organize my values unlike a struct?

Thank you and regards!

StealthScream
  • 43
  • 1
  • 5

4 Answers4

4

From the CAPL documentation:

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.

Example:

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);
}

Output:

i=42, f=1.320000
sergej
  • 17,147
  • 6
  • 52
  • 89
2

I had a flaw in struct access. Tried to initialize the struct paramters right in the variable declaration routine, not in the on startroutine.

Working code for my multiple data access is now:

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;
  /* ... */
}

Thanks for your help!

StealthScream
  • 43
  • 1
  • 5
1

Just for completeness: It is also possible to initialize a struct in the variable declaration:

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

(tested on CANoe 10)

jan_v
  • 11
  • 2
0

CAPL allows initialization of variables structures at declaration also at Onstart procedure but we have to follow correct syntax. here is example code

      variables
        {
           struct mydata
           {

               int a;
               int b;
           } ak={5,3};
        }

       on start
     {
            write("Initial values are %d, %d",ak.a,ak.b);
            ak.a=10;
            ak.b=20;
            write("values after update are %d, %d", ak.a,ak.b);
     }


     find more details in following video

https://www.youtube.com/watch?v=hRfSqZBZVHA