Echelon LonTal Stack User Manual
Page 131
LonTalk Stack Developer’s Guide
119
extern void myController(void);
void LonNvUpdateCompleted(unsigned index, const LonBool
success)
{
switch (index) {
case LonNvIndexNviAmpere: /* fall through */
case
LonNvIndexNviVolt:
myController();
break;
default:
/* handle other NV updates (if any) */
}
}
In your application source file:
#include "FtxlDev.h"
void myController(void) {
// nvoWatt = nviAmpere * nviVolt;
LON_SET_UNSIGNED_WORD(nvoWatt,
LON_GET_UNSIGNED_WORD(nviAmpere)
*
LON_GET_UNSIGNED_WORD(nviVolt));
if (LonPropagateNv(LonNvIndexNvoWatt) != LonApiNoError)
{
// handle propagation error here
...
}
}
This modification calls the myController() function defined in the example in
the previous section, Sending a Network Variable Update. Because network
variable types are defined as type LonWord, this example uses the
LON_GET_UNSIGNED_WORD macros to get the nviAmpere and nviVolt
network variable values, and LON_SET_UNSIGNED_WORD to set the value
for the nvoWatt network variable.
Example 2:
This example adds a configuration network variable to Example 1. A SCPTgain
configuration property is added to the device interface in the model file:
network input SNVT_amp
nviAmpere;
network input SNVT_volt
nviVolt;
network output SNVT_power
nvoWatt;
network input cp SCPTgain nciGain;
fblock UFPTpowerConverter {
nvoWatt
implements nvoPower;
nviAmpere implements nviCurrent;
nviVolt
implements nviVoltage;
} powerConverter fb_properties {
nciGain
};
You can enhance the myController() function to implement the new gain factor:
void myController(void)