Exmbus.Parser.Apl.DataRecord.CompactProfile (Exmbus v0.3.0)

View Source

This module provides functions for working with compact profiles.

Compact Profile is a way to encode multiple values into a single data record for efficient transfer, typically because there is an even spacing between the values (e.g. monthly data for last 12 months)

There are 3 types of compact profiles described in Annex F of EN 13757-3:2018.

  • "Compact Profile with register numbers"
  • "Compact Profile"
  • "Inverse Compact Profile"

The compact profile data layout is described as follows:

The first byte (spacing control byte, Tables E.6 and F.7) of this variable length record structure contains the data size of each individual element in the lower four bits (as in the lower nibble of the DIF definitions, but excluding variable length elements). The next higher two bits signal the time spacing units (00b = sec, 01b = min, 10b = hours and 11b = days). The highest two bits signal the increment mode of the profile (00b = absolute value (signed), 01, = positive (unsigned) increments (all differences ≥ 0), 10b = negative (unsigned) increments (all differences ≤ 0, 11b = signed difference, with: difference = younger value minus older value). All values of the profile are initially preset with the coding for "illegal", e.g. -128 for signed byte, 255 for unsigned byte, -32768 for signed word, etc. (refer toAnnex A, type B and C). Invalid values shall also be used in case of an overflow of an incremental value.

Compact Profiles are automatically expanded by default. This can be disabled with the option expand_compact_profiles: false in the options map.

Summary

Functions

Return true if the record is a compact profile record. false otherwise.

Given a compact profile record, and a list of records to search for base records, expand the compact profile record into a list of records. The returned list only contains the expanded reocrds, not the compact profile record itself, and not anything from the records in the second argument.

Expand a compact profile record into the given context. The compact profile record will be removed from the context's records, and replaced with the derived records from the compact profile.

Given a CompactProfileHeader and the profile data (as a binary), parse the values according to the header and return a list of parsed values.

Functions

compact_profile?(data_record)

Return true if the record is a compact profile record. false otherwise.

compact_profile_records(record, all_records)

@spec compact_profile_records(Exmbus.Parser.Apl.DataRecord.t(), [
  Exmbus.Parser.Apl.DataRecord.t()
]) ::
  {:ok, [Exmbus.Parser.Apl.DataRecord.t()]} | {:error, term()}

Given a compact profile record, and a list of records to search for base records, expand the compact profile record into a list of records. The returned list only contains the expanded reocrds, not the compact profile record itself, and not anything from the records in the second argument.

expand_compact_profile(record, ctx)

@spec expand_compact_profile(
  Exmbus.Parser.Apl.DataRecord.t(),
  Exmbus.Parser.Context.t()
) ::
  {:ok, Exmbus.Parser.Context.t()} | {:error, term()}

Expand a compact profile record into the given context. The compact profile record will be removed from the context's records, and replaced with the derived records from the compact profile.

parse_data(compact_profile_header, bin)

Given a CompactProfileHeader and the profile data (as a binary), parse the values according to the header and return a list of parsed values.