A Prescale is a simple multiplier / modulo-divide pair used by Accumulator objects to scale the raw pulse count coming from a physical meter into the engineering units that the present value property should report.
The multiplier is applied first, then the result is divided by the modulo_divide value (the remainder is discarded). This two-stage scaling allows devices to represent both fractional pulses (for example, a meter that produces one pulse per 0.1 kWh) and to handle situations where the display on the physical meter rolls over at a different point than the internal counter.
The structure exists because many real-world utility meters do not produce pulses that directly correspond to the desired engineering units. By exposing the scaling factors as readable and writable properties, BACnet makes it possible to commission or reconfigure pulse scaling without changing firmware.
Examples (Doc Test)
iex> scale = %Prescale{multiplier: 10, modulo_divide: 1000}
iex> scale.multiplier
10
Summary
Functions
Encodes a BACnet prescale into application tags encoding.
Parses a BACnet prescale from application tags encoding.
Validates whether the given prescale is in form valid.
Types
@type t() :: %BACnet.Protocol.Prescale{ modulo_divide: non_neg_integer(), multiplier: non_neg_integer() }
Represents the prescaling factors used by Accumulator objects.
Functions
@spec encode(t(), Keyword.t()) :: {:ok, BACnet.Protocol.ApplicationTags.encoding_list()} | {:error, term()}
Encodes a BACnet prescale into application tags encoding.
@spec parse(BACnet.Protocol.ApplicationTags.encoding_list()) :: {:ok, {t(), rest :: BACnet.Protocol.ApplicationTags.encoding_list()}} | {:error, term()}
Parses a BACnet prescale from application tags encoding.
Validates whether the given prescale is in form valid.
It only validates the struct is valid as per type specification.