Open felixwrt opened 1 year ago
Status: this is still WIP. I don't like that PowerMeterTransmission
is generic over the value type, which could either be Vec<(ObisCode, Value)>
(allocating use case) or [Value; N]
(for the extractor use-case). Support for statically allocated vectors is also missing.
Using PowerMeterTransmission
's from_bytes_extract
is not possible from the SmlReader
. This needs work as well.
Here's a first version of a more high-level API.
Motivation
SML is a pretty flexible (some might say over-engineered) protocol. The parsers implemented in the
parser
module parse SML data in a way that all valid SML transmissions can be parsed* and all possible attributes are accessible.Real world data collected from power meters shows that they use SML in a certain way. For example, an SML file can consist of any number of SML messages, but all power meters send SML files containing exactly three messages: OpenResponse, GetListResponse, CloseResponse. There are also optional attributes in SML that aren't used by any power meter (e.g. signature fields).
This library's primary use case is to read data from power meters. The current API and data structures provided by the parser are very general, which makes them difficult to use in the context of power meters.
Approach
The idea with what I call the "application layer" is to provide an API that is designed for the power meter use case. This API will not expose attributes that aren't used by power meters and will assume a certain structure of the data (number and order of messages; obis codes for value descriptions etc.).
The "application layer" API should cover 95% of use cases. For everything else, it's still possible to use the parser layer directly. This exposes all data and allows handling more diverse data.
To me this approach (optimizing for the common use case while still allowing more flexibility when needed) looks promising.
Examples
The following block shows a debug output of the data structures created from a typical sml transmission when using the
parser
layer:Many fields aren't set, information is duplicated and typical users won't be interested in many of the provided values.
In comparison, this is what the debug output of the "application layer" data structure looks like:
The data structure is much more focused and still contains the most relevant information.
Extracting relevant data from the data structure is also much easier in the "application layer".
* Well, the subset of SML I found real world examples for.