简体   繁体   English

通过 CAPL 发送消息

[英]Send message via CAPL

I am sending a CAN message from a database,我正在从数据库发送 CAN 消息,

variables
{
  message PNHV_Energy msg;
}

output (msg);

This message has 5 signals此消息有 5 个信号

signal A: 1 bit - startbit is 28
signal B: 3 bit - startbit is 29
signal C: 16bit - startbit is 48
signal D: 8 bit - startbit is 32
signal E: 8 bit - startbit is 40

How do I construct this and send it?我如何构建并发送它? The problem I face is in signal A and signal B, which are packed in one byte at location A: 1bit-28.我面临的问题是信号 A 和信号 B,它们在位置 A:1bit-28 处被打包成一个字节。 signal B: 3bit-29 to 30.信号 B:3bit-29 到 30。

what value for byte 3 should be set in?应该为字节 3 设置什么值?

msg.byte(3)= ?

It uses a little-endian format.它使用小端格式。

Variables of type message are classes in CAPL. message类型的变量是 CAPL 中的类。 If drawed from a valid CAN database, they come pre-packed with all the signals associated with them.如果从有效的 CAN 数据库中提取,它们会预先打包所有与它们相关的信号。 Let us see an example让我们看一个例子

Variables
{
    message PHNV_Energy msg;
}

on start {
    /* at the beginning of measurement, set the signals */
    msg.A = 0x00;
    msg.B = 0x00;
    msg.C = 0x00;
    ...
}

on message * {
    /* every time a message is received by our CAPL program node */
    output(message);
}

This is a much easier way to set your message, compared to your solution: you no longer need to worry about this与您的解决方案相比,这是一种更简单的设置消息的方法:您不再需要担心这个

The problem i face is in signal A and signal B, which are packed in one byte at location signal A: 1bit-28.我面临的问题是信号 A 和信号 B,它们在位置信号 A:1bit-28 处打包成一个字节。 signal B: 3bit-29 to 30.信号 B:3bit-29 到 30。

Found an answer for the question,找到了问题的答案,

Variables
{
    message PNHV_Energy msg; //Message to be sent from database
}

send_message()
{
    msg.byte(0)=0x0;  //0x00
    msg.byte(1)=0x0;  //0x00
    msg.byte(2)=0x0;  //0x00
    msg.byte(3)=0x20; //bit29-31: signal 1, bit 28: signal 2
    msg.byte(4)=0xFF; //FF to be sent at byte4: signal 3
    msg.byte(5)=0xFF; //bit 40 to bit 47: signal 4
    msg.byte(6)=0x10; //bit 48-51:0 bit52-55:1: signal 5
    msg.byte(7)=0x27; //bit 56-59:7 bit60-63:2: signal 5

    output (msg); // output Message
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM