Vector-常用CAN工具 - CANoe入门到精通_04

        前面已经介绍了Network Node节点的创建和配置,我想大家如果仔细研究下这块基本没什么问题,但是针对相应的CAPL编程该如何去做呢?今天这篇文章就是我们专门介绍在Network Node节点中常用的一些操作函数和使用技巧。

五、 Network Node相关CAPL编程

1、on message

        on message作为一个功能异常强大的CAPL专有的的姑且叫它函数吧,它伴随很多人从初入测试行业到熟练与开发battle三小时不会累,可想而知的强大。首先我们来介绍它的第一种用法。

on message 0x101
{
  this.BRS = 
  this.FDF =
  this.TYPE = 
  this.dlc = 
  this.byte(0) = 
    .
    .
    .
  this.byte(n) =    
}

        从上面我们能看到使用起来是相当的简单,而且Vector CAPL Browser自带联想功能,是你能够快捷、方便的进行编程,在on message 0x101中,其中on message你可以把它当成一个函数,0x101作为一个触发开关,一旦总线上出现0x101报文,就会进入到{}的内部(并且实时更新),就会执行内部的CAPL代码,我们可以在里面编写任意我们需要的功能。这里大家会注意到有一个特殊的单词this那他是什么意思呢?

        this在这里其实相当于一个message类型,这样说的话大家应该就很好理解,它就是总线上实时的一个message,内部包含了大量的信息,这里我就不再一一列举,在上面的代码中我列举了几个常用的参数,基本能够满足我们大部分时候的使用,实际这些参数都可以在CAN报文中找到,大家如果有兴趣也可以学习一下CAN报文的结构,是跟这里一一对应。下面我也列举一下。

       

 

 这里顺便再提下Rx和Tx:

Rx

Message was received (DIR == Rx)

Tx

Message was transmitted (DIR == Tx)

TXREQUEST

Transmission request was set for message (DIR == TXREQUEST)

下面我们说另外一种用法,就是将CAN1的报文全部转发到CAN2上,源码如下:(简单归类为通道识别,只要是某一CAN通道就会触发)

//The gateway should transmit all messages between Bus 1 and Bus 2 in both directions:
on message CAN1.*
{
   message CAN2.* msg;
   if(this.dir != rx) return; //important!
   msg = this;
 output(msg);
}

on message CAN2.*
{
   message CAN1.* msg;
   if(this.dir != rx) return; //important!
   msg = this;
 output(msg);
}

第三种使用方法就是任意触发:

//将所有接收到得报文发送出去
on message * 
{
   output(this);
};

        上面基本囊括了on message的大部分使用场景,至于内部填充和想要做什么大家可以自由发挥想象,实现你能想到的所有功能吧。

2、数据类型介绍

Scalar Data Types

  • Integers in form of
    byte (unsigned, 1 Byte)
    word (unsigned, 2 Byte)
    dword (unsigned, 4 Byte)
    int (signed, 2 Byte)
    long (signed, 4 Byte)
    int64(signed, 8 Byte)
    qword(unsigned, 8 Byte)
  • Individual character
    char (1 Byte)
  • Floating point numbers
    float (8 Byte)
    double (8 Byte)

常见变量定义之struct:

//struct 常见定义
//one
struct Data {
int type;
long l;
char name[50];
};

//two
struct Point
  {
    int x;
    int y;
  };
  struct Point myPoint;

struct { int first; int second; } pair;

//three
variables
{
  struct { int first; int second; } pair;
}

on start
{
  pair.first = 1;
  pair.second = 2;
}

//four
struct Point
  {
    int x;
    int y;
  };
  struct Point myPoint;
  struct Point allPoints[50];

常见变量定义之enum:

//Enumeration types are defined in CAPL in exactly the same way as in C:

enum Colors { Red, Green, Blue };

//
enum State { State_Off = -1, State_On = 1 };


//If necessary, an enumeration type is implicitly converted to an integer type

int i; enum State state;
state = State_Off;
i = state + 1;   // i == 0

//Enumeration types can be used especially in switch-case-statement:

switch (state) {
  case State_On: write("On"); break;
  case State_Off: write("Off"); break;
  default: write("Undefined"); break;
}

/*For a conversion from an integer type to an enumeration type or between two different enumeration types a cast is necessary:*/

enum State state; enum Colors color;
state = (enum State) 1;       // state == State_On
color = (enum Color) state;   // color == Green




        数组类型的我们就不在这里介绍了,都是跟C语言一样的,如果有需要度娘随便一搜都是一大把,我就不在这卖弄了。

这一块太多了,如果后续催更的人比较多的话,我就继续写吧!!!

  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

车载网络测试

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值