Part 1: t Script Roadblock Resolutions: Implementing a Program Flow using Hooks

10/04/2017 by 2448Judson Brundage

If you are familiar with t scripts, you know that they are based on “hooks”. Hooks are like interrupts. The runtime engine waits for these hooks, then executes the code that is inside its code block. For example, let’s say you need to respond to a CAN message with an ID of 0x200. The t script code would look something like:

On CanMessage 0x200{
  replyFunc();
}

When we receive a CAN message with an ID of 0x200, our t script will raise replyFunc() to, say, send a CAN response message, then it will leave the code block when complete. However, each time we receive a message from ID 0x200 we start at the same point. This can make executing a sequence of events challenging.

By implementing a switch/case statement with a global incrementor, we can enter the hook and reference the incrementor, just as you would use a bookmark. We will execute some process, and increment to bookmark before we leave. See the code example below:

On CanMessage 0x200{
  switch(bookmark){
    case 0:
      replyFuncStepOne();
      bookmark++;
      break;
    case 1:
      replyFuncStepTwo();
      bookmark++;
      break;
    case 2:
      replyFuncStepThree();
      bookmark++;
      break;
  }
}

So Kvasers’ t script hooks handle an event and the bookmark switch/case approach creates a sequence of events. Reflashing is a perfect example of such a sequence of events. We leverage this simple, yet effective technique to follow the Unified Diagnostic Services (UDS)-prescribed sequence of events to build reflashing tools (I wrote an article about that here, check it out!) and CAN Calibration Protocol (CCP) calibration tools.

If you’d like a template t script of this strategy outlined above, you can download it here. If you’d like Exclusive Origin to design a t script to turn a Memorator into a handheld reflashing or recalibration tool, please contact us!

This is one of a series of posts by Judson on using t-script to its fullest.

Part 2: t Script Roadblock Resolutions: 3 t script Resources You Can’t Do Without (Plus a bonus tip!)

Exclusive Origin – Judson Brundage

Judson Brundage

As owner of Exclusive Origin, based in Florida, USA, Judson Brundage provides test and diagnostics hardware and software to the automotive industry. With an in-depth knowledge of CAN and automotive HLPs, he’s a highly-respected problem solver to the automotive development community.

Exclusive Origin

Exclusive Origin, LLC is driven to constructing intuitive software to fit an individual’s needs without complicating the user experience.