-1

I am new to CAPL Programming. How can I route the signals which belonged to one PDU of one CAN channel to another CAN Channel. Can anyone suggest me how to it?

Charanya G
  • 5
  • 1
  • 4
  • Hello, May I ask you to clarify some topic? I mean do you want to, let's say, mirror signal's value from PDU1 to another signal value PDU2? – Juhas Feb 25 '21 at 09:02
  • 1
    Its like re-routing. For example, a PDU contains 4 signals and its from CAN Channel 1. I wanted this particular PDU(all signals) to route to CAN channel 2. – Charanya G Feb 25 '21 at 11:29
  • How are you simulating the PDUs in the CAN channel 2? Are you using an Interaction Layer? Or are you just using CAPL to send all the PDUs and frames? – Shyam Mar 23 '21 at 11:28

2 Answers2

1

If I understood well, you are trying to do a gateway module in which you will receive a message from one channel and you will have to send the received message to another channel. please try this piece of code, might help you.

variables
{
   message 0x123 Chanl1 = 
   {
      ID = 0x111;
      DLC = 8,
      CAN = 1,
   };
   message 0x123 Chanl2 = 
   {
      ID = 0x111;
      DLC = 8,
      CAN = 2;
   };
} 
    
on message *
{
   if((this.ID == 0x111) && (this.CAN == 1)) // 0x111 is your channel1 id
   {
      chanl2.byte(0) = this.byte(0);
      chanl2.byte(1) = this.byte(1);
      chanl2.byte(7) = this.byte(7);
      chanl2.id = 0x111;
      output(chanl2);               
   }
}
Shyam
  • 649
  • 1
  • 5
  • 20
Arulkumar
  • 21
  • 7
-3

Declare system variables:

  • isPDUGoingToBeSent - value change will trigger an event on sysvar sysvar::isPDUGoingToBeSent

  • some_signal_sysvar

Write the received signal value to system variable, and trigger another event.

on PDU ReceivedPDU
{
    @sysvar::some_signal_sysvar = $ReceivedPDU::signal_name;
    @sysvar::isPDUGoingToBeSent = 1;
}

On triggered event check if sysvar has been set and send the PDU.

on sysvar sysvar::isPDUGoingToBeSent
{
    if(@this)
    {
        pdu PDU_FROM_DB mirrored_pdu;
        mirrored_pdu.some_signal = @sysvar::some_signal_sysvar;
        triggerPDU(mirrored_pdu);
    }
}
Juhas
  • 178
  • 2
  • 13
  • This solution will be a huge overhead if there are, say, 1000 signals in the database. If Interaction layer is used, best way is to use on pdu and then set the signals directly in the Interaction Layer variables. – Shyam Apr 09 '21 at 07:01
  • Hello, thanks for the answer. I assume that the owner has specified the number of PDU (`one particular`, assuming there are more that we don't want to pass to CAN2) and signals (`4`) in the comments under the question. IMHO it's still applicable, but I'm curious about other solutions. Please post the answer or edit mine, instead of resolving it in comments. Regards. – Juhas Apr 09 '21 at 10:25