Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Capl Message Can

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4
At a glance
Powered by AI
The document discusses declaring and accessing messages and data fields in CAPL code for automotive applications.

You can declare a message with the 'message' keyword followed by the message identifier or name and variable name.

You can access data fields like bytes, words, longs within a message using dot notation with the field name like msgName.byte(0).

---------------------------

Declaring Message with CAPL|


---------------------------

message <message identifier or name > <variable name>


//Should be defined in the database

exple : 1/ message EngineTemp eTemp ;


2/ message 0x100 eTemp ;

Without a database

message 0x100 eTemp = {DLC = 8} ;


or
message 0x100 eTemp ;
eTemp.DLC = 8 ;

on message * // for all messages


{
// print
write(�The message received is %c�, this.id);
}
on message CAN1.* // for all messages received on CAN channel 1
{
// print
write(�The message received on CAN channel 1 is %c�, this.id);
}
on message 0x100 // for messages with ID equal to 100 in hex only
{
// print
write(�The message with ID 0x100 is received.�);
}
on message CAN2.0x100 // for messages with ID equal to 0x100 from CAN channel 2
{
// print
write(�The message with ID 0x100 is received from CAN channel 2.�);
}

-----------------
Message Selectors|
-----------------

----
CAN |
----

message 0x100 msg = {dlc = 2, word(0) = 0x1234};

on key '1' {
write("sende via CAN 1");
msg.CAN = 1;
output(msg);
}
on key '2' {
write("sende via CAN 2");
msg.CAN = 2;
output(msg);
}
----
ID |
----

on message * {
if (this.ID == 0x600) {
write("message 0x600 received; triggering logging...");
trigger();
}
}

----
DIR |
----

on message 0x100 {
if (this.DIR == Rx) {
write("message 0x100 received");
}
if (this.DIR == Tx) {
write("message 0x100 sent");
}
}

----
RTR | Remote Transmission Request
----

// send remote frame


message 0x100 rmsg;
rmsg.RTR = 1;
output(rmsg);

----
TYPE| Combination of DIR and RTR for an efficient evaluation. (TYPE = (RTR << 8) |
DIR )
----

message 0x100 resp_msg = {dlc = 2, word(0) = 0x1234};

on message 0x100 {
if (this.TYPE == RXREMOTE) {
// remote frame 0x100 received
output(resp_msg);
}
}

----
DLC |
----

on message OneByteMessage {
if (this.DLC != 1) {
write("error: OneByteMessage has DLC != 1");
stop();
}
}
-----------------
Accessing Data |
-----------------

BYTE (8 bits), WORD (16 bits), LONG (32 bits), and DWORD (32 bits).

----------------------------------------------------------------------------
WORD_0 || WORD_1 || WORD_2 || WORD_3 |

----------------------------------------------------------------------------
Byte_0 || Byte_1 || Byte_2 || Byte_3 || Byte_4 || Byte_5 || Byte_6 || Byte_7|
-----------------------------------------------------------------------------
6E || 01 || FF || 51 || 7A || B5 || C9 || 23 |
-----------------------------------------------------------------------------

Messagename.BYTE(0) = 6E

Messagename.BYTE(5) = B5

Messagename.WORD(0) 0x16E

Messagename.WORD(3) 0x7A51

Messagename.LONG(0) 0x51FF016E

Messagename.LONG(2) 0xB57A51FF

Messagename.LONG(4) 0x23C9B57A

Messagename.LONG(6) Invalid

--------------------
message Transmission|
--------------------

message 0x100 msg1 = {dlc = 8}; // declare message to send


msg1.byte(0) = 0x12; // set the data field
msg1.long(1) = 0x90785634;
msg1.CarSpeed = 100; // assume CarSpeed occupies the last three bytes
msg1.CAN = 2;
output(msg1);

--------------------
message Reception |
--------------------

100 on message 100 the message ID 100 (decimal) is received


0x100 on message 0x100 the message ID 100 (hexadecimal) is received
4 or 8 on message 4,8 either message ID 4 or 8 (decimal) is
received
0x200-0x2FF on message 0x200-0x2FF any message ID 200 thru 2FF
(hexadecimal) is received

Engine on message Engine message named Engine defined in database is


received
any message on message * any message is received
any message
on CAN1 on message CAN1.* any message is received on CAN channel 1

on message ABSdata
{
if (this.DIR == RX)
{
write(�Message ID = %d is received from channel %d�, this.ID, this.CAN);
write(�The signal value of car speed is %d�, this.CarSpeed);
}
}

You might also like