0

I cannot find a comprehensive guide on how to build a Synthetic LIN Slave in a CANoe configuration, so I would like to create one here.

Scenario: an ECU acts as LIN master and communicates with n LIN slaves. The goal is to be able to add a synthetic slave to the CANoe simulation acting as a replacer for one of the physical slaves. Since there is no way to dynamically activate or de-activate a LIN node, our setup would be of n-1 physical slaves and 1 synthetic slave, plus the Master. Here, Master is under test, and, in particular, we want to assess its ability to react to certain slave responses, by mocking the slave and triggering whatever frame is needed. Let's assume there will be a GUI or something for that, it is not in scope for the question.

I am able to add a new Node to the simulation setup, assign it to the LIN network and, if active, it connects to the red line indicating the simulated bus. An LDF was created and added to the configuration and I know the linFrame ID the node should communicate.

The node is to be simulated via CAPL script. I am stuck on the transmission part:

on ???
{
    // This is my call: as LIN slave I should output something.
    output(myLinFrame);
}

Where should I add my logic to update and transmit the message?

The basic I tried was to key-bind it, but the output would be on the next associated slot of the LDF, plus it's key-bound.

on key 'A'
{
    // prepare new content...
    output(myLinFrame);
}

This question relates to an older question of mine regarding LIN censorship.

Final note: I have very limited slots for CANoe licenses to test whatever code I come up with, so I need to prepare and research in advance.

In this scenario, should I use linUpdateResponse()?

Daemon Painter
  • 3,208
  • 3
  • 29
  • 44
  • Not sure what you are asking. Do you want to know which event procedure you should be using (instead of on key) or do you want to know how to assemble and send a LIN frame? Or something else? – MSpiller Apr 24 '20 at 12:38
  • You hit the point precisely. How do I know that I should output my frame? and which method should I use to output it? `output` or `linUpdateFrame`? – Daemon Painter Apr 24 '20 at 14:11
  • 1
    I hope that still holds, it's been while since working with LIN... For slave nodes, there is not really a difference between `output` and `linUpdateResponse`. Both update the response that will be sent on the next request by the master. I think with `output` you are responsible to set the `RTR` selector. But the rest should be the same. Assemble a LIN frame with the necessary ID and either `output` or `linUpdateResponse` it. – MSpiller Apr 24 '20 at 15:17
  • What about when? Is there any event I can rely upon for knowing when my schedule is hit? For instance, is there anything telling me that, as a synth slave, I just sent my frame and I can assemble the next? I fear locking myself up linking it to `on myframe` – Daemon Painter Apr 24 '20 at 19:16
  • 1
    I think for the _when_ `on linFrame` would be the right place. This event handler is called when the _old_ frame is on the bus. In the event handler you use `linUpdateResponse` to update the response for the next time the frame is to be sent. – MSpiller Apr 27 '20 at 08:08
  • @M.Spiller thanks for your support, I'm feeling guilty not being able to credit you for it. I've got [this question](https://stackoverflow.com/q/61389656/2125110) regarding differences between linUpdateResponse and output, if you were so kind to post there, I'll be more than happy to credit your comment in full – Daemon Painter Apr 27 '20 at 12:44

1 Answers1

0

You should create on linFrame ... event handlers.

These event handlers will be called, once a frame has been put to the bus. Inside the event handler, you can use linUpdateResponse (or also output) to modify the frame which will be sent the next time, i.e. the call modifies does not send an immediate response but rather modifies the internal state of the slave so that a different frame is sent next time.

MSpiller
  • 3,500
  • 2
  • 12
  • 24