Table Tutorial

This tutorial covers the basics of defining a table. This tutorial focuses on case tables, but the process for creating interpolation tables is fairly similar.

The scenario

Suppose you have an enumeration that represents various error levels in your system. Errors have different levels of severity, and different actions need to occur based upon the current severity level. The error levels you have in the system are as follow:

  • Trace
  • Info
  • Warn
  • Error
  • Fatal

Here, Trace is the least severe and Fatal is the most severe. Your enumeration for these errors might look like this:

../_images/CertSAFE-Modeler-Verifier-2015-05-15-17.46.40.png

With these enumeration values, you’ll want to do greater-than and less-than comparisons to perform different error handling logic. CertSAFE does not allow you to do that on enumerations directly, so you will have to convert the enumerations to a data type that will allow this. You might decide that you would like to cast them to UInt8 to perform the comparisons, as UInt8 allows greater than and less than comparisons, uses less space than any of the other types that allow comparison, and having signed values really doesn’t make sense for the comparisons you will be doing.

To perform the cast you will need to instruct CertSAFE how to convert an Error Level to a UInt8 value, and the easiest way to do that in CertSAFE is to create a case table. Before you begin this tutorial, please make sure you have an enumeration similar to the one shown above.

Creating a new case table

To create a new case table, open up the project you want the case table to be in. Then, go to the menu and choose File ‣ New ‣ New Case Table. This will open up the case table editor, showing the I/Os tab.

Thinking a bit, you know you will want the table to take in an enumeration of type Error Level and output to type UInt8. To add a new input to the case table, locate the Inputs table in the upper left of the case table editor. Next to the table, there are two buttons, Add and Remove. Click the Add button. This will create a new input in the table, initially called “Input” with the data type set to Int32. After you click the Add button, your table should look like this:

../_images/CertSAFE-Modeler-Verifier-2015-05-15-17.14.14.png

Double-clicking on the name “Input” will allow you to rename it. Give it a more meaningful name, like “Error”. Double-clicking on the Int32 will produce a drop down box that will allow you to change the type. Since you want to be casting from the Error Level enumeration to UInt8, you will want to set the input’s type to the “Error Level” enumeration. When you finish editing the input, it should look like this:

../_images/CertSAFE-Modeler-Verifier-2015-05-15-17.16.28.png

Now that you have the input defined, you will want to define what the output is. To do so, look at the bottom table in the Case Table editor labeled Outputs. Next to it is an Add and Remove button. Click the Add button to add a new output. By default, it will call the output “Output” and set its data type to Int32. As with inputs, double-clicking the output’s name will allow you to rename it, while double-clicking on the data type will produce a drop down menu to select its data type. Rename the output to “Error Value” and change its data type to be UInt8. When you are finished, the editor should look like this:

../_images/CertSAFE-Modeler-Verifier-2015-05-15-17.17.22.png

Now, for a case table to work, you will need to define each possible value the input can be. This is done through the upper right table in the Case Table Editor, labeled “Keys for selected input”. Next to that table is an empty text field, an Add button, an Add default button, and a Remove button. To add a possible value to an input, first select the input in the “Inputs” table. Once selected, there are two ways to add values for that input: either type in a value in the empty text field, or drag and drop values from from a text source directly into the table.

Open up the “Error Level” enumeration and select all the values in that enumeration, then drag the values from the enumeration editor into the table for selected input values. Once you are done, the selected input values table should be populated, and the editor should look like this:

../_images/CertSAFE-Modeler-Verifier-2015-05-15-17.43.36.png

If you look over the available values for the selected inputs, you will notice a default value. In case tables, each input starts out with a default value that is used when the input receives a value that is not one of the ones explicitly listed. If all values for a given input are provided and the default value exists, CertSAFE will generate a warning on the table file stating that the default value is unreachable. If you have not exhaustively listed all possible values for a given input and you have removed the default value, CertSAFE will generate an error saying that the cases are non-exhaustive. Since you have exhaustively listed every value for the enumeration type, you can safely delete the default value. The default value can be removed by selecting it and clicking the Remove button.

Once you are finished, switch to the Values tab. Your case table editor should look like this:

../_images/CertSAFE-Modeler-Verifier-2015-05-15-17.44.20.png

On this tab, the blue cells specify input values, and the white cells specify corresponding output values. Looking over the possible error states the system can be in, notice that Trace is the least significant, and Fatal is the most significant. So, you would want to give the smallest value to the least significant error. In the white cell next to Trace, double-click to edit it, and then enter the value 0. In Info put in 1, Warn 2, Error 3, and Fatal 4. When you are finished, it should look like this:

../_images/CertSAFE-Modeler-Verifier-2015-05-15-17.45.29.png

The table maps the values of the white cells to the values of the blue cells, so that when the table receives an input value that corresponds to a value in a blue cell it will output the value in the white cell.

Once you finish entering the values into the white cells, save your table. You now have a working case table. This table can be used in a diagram like any other custom component.