Processing a type change – Echelon LonTal Stack User Manual
Page 134
122
Developing a LonTalk Stack Device Application
This enumeration describes the type (signed short or floating-point, for example),
but does not provide information about structure or union fields. To support all
scalar types, test for a type_category value between
NVT_CAT_SIGNED_CHAR and NVT_UNSIGNED_LONG, plus
NVT_CAT_SIGNED_QUAD.
The type_length field provides the size of the type in bytes.
Multiple changeable-type network variables can share the SCPTnvType
configuration property. In this case, the application must process all network
variables from the property’s application set, because just as the SCTPnvType
configuration property applies to all of these network variables, so does the type
change request. The application should accept the type change only if all related
network variables can perform the required change.
If one or more type-inheriting configuration properties apply to changing
configuration network variables, these type-inheriting configuration NVs also
change their type at the same time. If this type-inheriting configuration NV is
shared among multiple network variables, all related network variables must
change to the new type. Sharing a type-inheriting configuration property among
both changeable and non-changeable network variables is not supported.
Processing a Type Change
After validating a type change request, the application performs the type change.
The type-dependent part of your application queries these details when required
and processes the network variable data accordingly.
Some type changes require additional processing, while others do not. For
example, if your application supports changing between different floating-point
types, perhaps no additional processing is required. But if your application
supports changing between different scalar types, it might require the use of
scaling factors to convert the raw network variable value to a scaled value. You
can use the three scaling factors defined in the SCPTnvType configuration
property (scaling_factor_a, scaling_factor_b, and scaling_factor_c) to
convert from raw data to scaled fixed-point data according to the following
formula:
(
)
(
)
c
raw
a
scaled
b
+
=
*
10
*
where raw is the value before scaling is applied, and a, b, and c are the values for
scaling_factor_a, scaling_factor_b, and scaling_factor_c.
To convert the scaled data back to a raw value for an output network variable,
use the following inverted scaling formula:
c
a
scaled
raw
b
−
⎟
⎠
⎞
⎜
⎝
⎛
=
10
*
For example, the SNVT_lev_cont type is an unsigned short value that
represents a continuous level from 0 to 100 percent, with a resolution of 0.5%.
The actual data values (the raw values) are in the variable range from 0 to 200.
The scaling factors for SNVT_lev_cont are defined as a=5, b= -1, c=0.
If the network variable is a member of an inheriting configuration property’s
application set that implements the property as a configuration network variable,