User guide

Neuron C Programmer’s Guide 79
// returns the current length of the given NV (in bytes) or 0xFF to
// indicate that the initial type is still unchanged.
unsigned get_nv_length_override(unsigned uNvIndex) {
unsigned uResult;
uResult = 0xFF;
if (uNvIndex == fbSensor::nvoValue::global_index) {
// Return current length for our example NV, or return
// 0xFF to indicate the NV has the initial length:
if (nvTypeLastGood.type_category != NVT_CAT_INITIAL
&& nvTypeLastGood.type_category != NVT_CAT_NUL) {
// this is a distinct current length:
uResult = nvTypeLastGood.type_length;
}
}
return uResult;
}
// Triggered by some appropriate I/O event, timer, or network event,
// the application will need to process data for the changeable-type
// network variable. This example does not include an algorithm that
// performs numeric operations using the changeable-type data, but two
// conversion routines are shown that convert the current type of
// the changeable network variable into a float_type variable for
// internal use in such numeric operations, and vice versa.
void GetCurrent(float_type* const pFloat) {
// One union to hold all possible current types, plus the initial
// type of the changeable type NV
union {
unsigned long uLong;
signed long sLong;
SNVT_volt_f xInitial;
} nvLocal;
// bProcessABC: a flag to indicate whether the scaling factors
// A,B,C must be honored and used
boolean bProcessABC;
bProcessABC = FALSE;
nvLocal.xInitial = nvoVolt;
switch (nvoVolt::nvType.type_category) {
case NVT_CAT_SIGNED_LONG:
// Current type is signed long. Convert to float.
fl_from_slong(nvLocal.sLong,pFloat);
bProcessABC = TRUE;
break;
case NVT_CAT_UNSIGNED_LONG:
// Current type is unsigned long. Convert to float.
fl_from_ulong(nvLocal.uLong,pFloat);
bProcessABC = TRUE;
break;
case NVT_CAT_INITIAL:
// Fall through to float.
case NVT_CAT_FLOAT:
// Float is current. No conversion is required, just
// copy data into local variable.
*pFloat = nvLocal.xInitial;
break;
default:
// Unsupported type. The changeLength() handler should
// have recognized this and rejected the type earlier.
// Log this application error and set the device offline:
error_log(TYPE_ERROR);
go_offline();
} // switch
if (bProcessABC) {