Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

IAP/MQ Connections support type conversions between source and destination types to support connections between sources of one type and destinations of another. All sources and all destinations must themselves be assignment-compatible.

...

For example, this simple map transforms a value of standard type SNVT_switch to one of standard type SNVT_lev_percent:

{                                                                                                                                                                  
  "$": "$.value"
}

Key “$” addresses the entire value. Its value is “value”, which references a “value” property within the source datapoint value.  “$” addresses the entire source or destination item. A dotted notation addresses nested properties such as “top.left.x”.  

This is the identity map:

{                                                                                                                                                                  
  "$": "$"
}


Transformation objects support more complex operations such as type casts or transformation expressions. The following map produces a datapoint value of standard type SNVT_switchfrom a datapoint value of the standard scalar type SNVT_lev_percent:

{                                                                                                                                                                  
  value: "$",
  state: {
     transform: "$ ? 0 : 1"
  }
}

The first production assigns the entire source value, addressed as “$”, to the destination value property. The second production specifies a transformation with a ternary operator.  

...

The following map converts a value of type SNVT_switch into a simple string presentation:

{                                                                                                                                                                  
  "$": {
     transform: "$.value + ' ' + $.state"
  }
}

Transformations support all non-modifying Javascript operators (see developer.mozilla.org). Pre- and post-decrement and increment operators (++, --) have no effect.

...

The following numeric functions are available:

Function          Result                                   Description                                                                  
abs(v) v if v ≥ 0, else -vAbsolute of a value
min(v, w)v if v ≤ w, else wMinimum of two values
max(v, w)v if v ≥ w, else wMaximum of two values
sqrt(v)Square root of vSquare root function
pow(v, w)v to the power wPower function

...

Function          Result                                                                         Comment                                
length(s)Number of characters in s or 0 (zero) if none.
upper(s)The upper case version of s. s remains unchanged
lower(s)The lower case version of s.s remains unchanged
substr(s, i, l)The substring in s starting with zero-based index I and of length l characters.s remains unchanged
match(s, r )A Boolean result indicating whether s matched ECMAScript 6 regular expression r.Example:
match(“test”, “[a-z]{4}”)


The Constant Transformation Type

The $ object represents the source datapoint value.

This constant type map produces a SNVT_switch from a scalar SNVT_lev_percent input, where the destination “state” field is constant:

{                                                                                                                                                                  
  value: "$",
  state: {
     constant: "ST_ON"
  }
}

The constant value is copied into the destination verbatim.  The constant transformation is more efficient than an equivalent transform.

...

The enumeration type maps two different yet compatible enumerations:

{                                                                                                                                                                  
  value: "$",
  state: {
     enumeration: {
        source: "$", // the source enumeration value
        map: {
           1: -1,        // source 1 becomes destination -1,
           0: 0,        // source 0 remains 0 (the default),
          -1: 2         // source -1 becomes destination 2
      
  }  // map
     }   // enum
  }   // state
} // map

...

The source property of an enumeration transformation can also be evaluated as an expression. The following example maps the preset value into the preset name:

{                                                                                                                                                                  

         source: {
               
enumeration: {
                  source:
"$.value == 100 && $.state == 1 ? ‘ON’ :
                                 $.value == 50 && $.state == 1 ? ‘MID’ :
                                 $.value == 0 && $.state == 0 ? ‘OFF’ : ‘’"

                       map: {
                             
“ON”: ”ON”,  
                             
“MID”: “MID”,        
                             
“OFF”: “OFF
                       
} // map
                } // enum
            }
// source
}

...