Echelon NodeBuilder FX/PL Examples User Manual

Page 34

Advertising
background image

26

Using the NodeBuilder FX/PL Example

else if ((TFblock_command)iCommand == FBC_WHEN_RESET)

HVACTempOld

=

0;

UpdateTemperature();
//

get

going:

setLockedOutBit(uFblockIndex, FALSE);
break;

10. Still in TempSensor.nc, add the following functions to the code:

#endif //_HAS_INPUT_NV_

int cmptime ( const SNVT_elapsed_tm * const a, const unsigned long b ) {

unsigned long ulA;

int

iResult;

// convert SNVT_elapsed_tm_a into a value of type(b).

ulA = a->millisecond;

ulA += (1000uL / HVAC_CORETICK)

* ( a->second + 60UL * (a->minute + 60ul

* (a->hour + 24ul * a->day)));


if (b > ulA) {

iResult

=

-1;

} else if (b < ulA) {

iResult

=

+1;

} else {

iResult

=

0;

}
return

iResult;

}

void PropagateTemp(const SNVT_temp_p Value) {

float_type fTemp, fResult;

// set the temp_p type nvo:

TempSensor::nvoHVACTemp = Value;

// convert to float.

// Get the float_type representation of the scaled

//temp_p value:

fl_from_slong(Value,

&fTemp);

// Get it right by correcting the fixed decimal point:

fl_div(&fTemp, &f100, &fResult);

// That's it!

TempSensor::nvoFloatTemp = fResult;

// restart the minsend/maxsend timers

HvacMinSendTimer = HvacMaxSendTimer = 0L;

}

void UpdateTemperature(void) {

// Get new value

SNVT_temp_p

NewValue;

NewValue = GizmoReadTemperature(FALSE, TRUE);

// Transmit if new value varies by more than nciMinDelta from

// old value:

if ((NewValue < (HVACTempOld - TempSensor::nvoHVACTemp::cpMinDelta))

|| (NewValue > (HVACTempOld

+

TempSensor::nvoHVACTemp::cpMinDelta)))

{

// Even so, only transmit if nciMinSendTimer allows:

if (cmptime((const SNVT_elapsed_tm * const)

&(TempSensor::cpMinSendTime), HvacMinSendTimer) <= 0 ) {

// min send time has expired, really send data now:

PropagateTemp(NewValue);

}

}

// In either case, make sure to keep record of the latest value:

HVACTempOld = NewValue;

}

Advertising