A much requested enhancement to the ETS parameter mechanism is the possibility to further decouple user interface and download image by allowing calculated parameters. For example, timeouts are in most cases represented in the download image as base / factor pairs, often with rather odd bases. It would be nice if they were represented in the user interface in a natural way as explicit time. ParameterCalculations allow the application program designer to define formulas that are executed by ETS on demand to calculate the value of some parameters from the values of others.
For an application program, any number of ParameterCalculations can be defined. For each of them, there are two sets of parameters, called the “left” and the “right” set, and two calculation descriptions, called “RL-transformation” and “LR-transformation”. The task of the “RL-transformation” is to calculate all values in the “left” set from the values in the “right” set (and vice versa for the “LR-transformation”). Obviously, the two transformation should be (at least approximate) inverses of each other. It is important that the calculations do not fail or produce invalid values for the result parameters. Otherwise ETS would be unable to correctly calculate the parameter values which can result in undefined behavior of the device.
It is highly recommended to test the calculations in both directions with all relevant parameter value combinations. This can be done by the integrated Test functionality of the Parameter Calculation View, or out of manufacturer tool using a suitable development environment.
The calculations can be written in JavaScipt (recommended) or VBScript (deprecated).
There are two options where to specify the actual calculation
1."Inline": the transformations are directly entered in the ParameterCalculation element. This is supported for all ETS versions
2."Central" (available for ≥ ETS 5.6): the code is in the central Script element and the ParameterCalculation only specifies the method names. This allows easier code re-use and use of common helper methods.
Add parameter calculations
You can create a calculation with the following steps:
1.Perform the "Add New ParameterCalculation" command
3.Select the new calculation in the tree view; the right pane shows a detail view for the calculation
4.Assign the relevant parameters from the UI Parameters collection via Drag & Drop (with pressed Ctrl key!) to either the “left set” or the “right set” of the calculation side . A parameter can be part only of one calculation, and only in one of the two sets.
5.You should assign alias names to the ParameterRefs. This is necessary if the ParameterRef name is no valid identifier of the chosen scripting language. It also enables to re-use the same script for multiple calculations.
6.Specify the transformations:
a.With "Inline" option: type in the LRTransformation and RLTransformation scripts. You may insert the parameter names (or alias names) by dragging from the LParameters or RParameters lists.
b.With "Central" option: select the methods to be called. In addition, you can enter additional parameters to be passed to the methods in JSON format. This allows to use the same methods with different parameters.
7.Use the "Check" button to verify the correct syntax of the calculation script.
8.Use the "Test" button to enter test mode
At operation time (in the end user ETS) the calculations are triggered automatically when necessary. At any time either all values in the left set or all values in the right set (or both) are valid. The values in the invalid set can then be calculated automatically on demand.
Method signature for central Script
In the "central" option, the method must have the following signature:
function name(input, output, context)
Any return value of the function is ignored.
Example: Timer Representation as Base and Factor
Example: Use of context object