SHIP:Property:variable:persistent

From Serious Documentation
Jump to: navigation, search

Node: variable

Property Data Type Description
persistent** Boolean Makes the variable persistent across reboots.

Variables can be marked persistent which means every time they are changed in a GUI, their value is written to a non-volatile registry on the SIM. When a GUI loads, SHIPEngine looks in the registry for all variables in the GUI marked as persistent and, if found, loads their values from the registry. If not found, the default value of the variable is used.

It is advised not to make frequently changed variables persistent as this adds significant overhead to each change in the variable -- an external FLASH device must be written on every change.

See the related properties context, varid, and varversion. In order to make a variable persistent, you must set these 3 related properties as well.

Here's how to make a variable persistent:

  • go into the property sheet for the variable in SHIPTide
  • turn the persistent property to true
  • set the context to 0x02...0xFD (your choice) - this is the name space for your application. This way you can have 2 different apps on the unit or more and each has its own set of persistent variables that do not conflict as long as they use different context IDs
  • assign the variable a unique varid (variable id) (e.g. 0x0001, 0x0002, ...) within your context
  • assign a variable version (varversion) to the variable (eg. 0x01) -- this is used if you ever need to upgrade a variable to a different version)

Now, whenever you change the variable it will write-thru automatically to the registry in serial flash. Whenever you boot, it will retrieve the value from serial flash.

Here's an example in the attached screen shot:

SHIP Persistent Variable Example

*The persistent property can only be set in SHIPTide.

Examples

The following example shows three global variables from a GUI, all defined directly under the display node d0, each with a different name and data type. Note how the context is the same across them (0x02. The varversion is all 0x01, which is the normal case.

What distinguishes them is the unique ID (varid) assigned to each within the context 0x02. The [context+varversion+varid] values form a unique 32-bit value that is the lookup key in the SIM's persistent storage registry, so it is critical that there is no overlapping combinations of [context+varversion+varid] in your GUI.

Name Type Value Context Version ID
d0.myStringVar1 String Hello 0x02 0x01 0x0001
d0.myByteVar1 Byte 12 0x02 0x01 0x0002
d0.myIntVar1 Integer -456 0x02 0x01 0x0003

The following example adds a fourth global variable, d0.myCrossGUIIntVar1 with a different context (0x80). Even though it has varid 0x0001 that does not conflict with d0.myStringVar1 because they are in a different context (i.e. namespace).

This is very useful if you have several different GUIs that may be installed on the hardware depending on the customer or machine. You can declare a set of common persistent variables that exist and are available across all your different GUIs in one context (e.g. the myCrossGUIIntVar1 below in context 0x80). Then you can assign a set of different specific GUI-locals contexts for each of your GUIs. For example, GUI#1 could have local GUI context variables in context 0x02 such as the three shown below, and then a different GUI#2 could use context 0x03 for its local specific persistent variables, and so on.

Name Type Value Context Version ID
d0.myStringVar1 String Hello 0x02 0x01 0x0001
d0.myByteVar1 Byte 12 0x02 0x01 0x0002
d0.myIntVar1 Integer -456 0x02 0x01 0x0003
d0.myCrossGUIIntVar1 Integer 7 0x80 0x01 0x0001