Skip to content

Update parsing of plain text VIF - #229

Open
johvik wants to merge 1 commit into
rscada:masterfrom
johvik:second-pass
Open

Update parsing of plain text VIF#229
johvik wants to merge 1 commit into
rscada:masterfrom
johvik:second-pass

Conversation

@johvik

@johvik johvik commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

The plain text VIF is specified to be "given in the first byte" so it should be read from the data part.
I don't have a device using the specified way of doing it however I have an older ELV CMA10 which uses the immediate bytes (matches the way the code was written prior to this commit) so the parsing is updated to be done in two passes to work with both interpretations:

  1. As per the specification
  2. If variable length VIF is seen another attempt with the wrong placement is performed

@lategoodbye

Copy link
Copy Markdown
Collaborator

@johvik There is also no example in the test directory? Usually I prefer to have a test frame to "prove" features.

@johvik
johvik force-pushed the second-pass branch 2 times, most recently from 296863a to bc3fbdd Compare June 18, 2026 10:49
@johvik

johvik commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

I've added a test, what do you think @lategoodbye?

@lategoodbye

Copy link
Copy Markdown
Collaborator

I had some time to look deeper in the code and it doesn't look like a clean solution to me. Interestingly the mbus-protocol-aux seems to be able to parse the frame before. But there is a mismatch between unit/quantity in the xml files?

Just for understanding, this change is to handle M-Bus devices which doesn't follow the specification?

@johvik

johvik commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

I had some time to look deeper in the code and it doesn't look like a clean solution to me. Interestingly the mbus-protocol-aux seems to be able to parse the frame before. But there is a mismatch between unit/quantity in the xml files?

Just for understanding, this change is to handle M-Bus devices which doesn't follow the specification?

It is actually the other way around, this is to handle M-Bus devices which follows the specification. The second pass is to try to remain compatible with e.g. some ELV CMa10 which does it wrong. To be more specific the problem arise when plain-text VIF with extensions is used (0xFC).

Quoted from the specification:

the true VIF is represented by the following ASCII string with the length given in the first byte.

So for 0xFC it should be <0xFC> <VIFE(s)> <ascii length> <ascii text>. I've discussed this with a colleague who has the 13757-3:2013 specification and apparently they added a new appendix to showcase this.

For reference some ELV CMa10 devices seems to have this (wrong) order <0xFC> <ascii length> <ascii text> <VIFE(s)> which makes it a bit problematic since I guess we don't want to break existing usage.

About the xml output I haven't look too much into that code but it seems to be how the xml currently outputs it (%RH in test/test-frames/ELV-Elvaco-CMa10.norm.xml and test/test-frames/ELV-Elvaco-CMa10.xml have the same issue).

I agree this is not ideal and isn't guaranteed to always work either. I guess its possible to introduce a new API but then it will become harder for the users to know how to do things correctly.

The plain text VIF is specified to be "given in the first byte" so it
should be read after VIF extension(s).

The parsing is updated to be done in two passes to remain compatible
with the old code (and devices using the wrong placement):
1. As per the specification, after VIF extension(s)
2. If variable length VIF with extension(s) is seen another attempt
   with the wrong placement is performed for compatibility

I don't have a device using the specified way of doing it however I
have an (older) ELV CMA10 which uses the immediate bytes (matches the
way the code was written prior to this commit).

A handcrafted hex for the expected placement of the plain text VIF is
added.

In addition to this mbus_vib_unit_lookup() is patched so it prints the
custom_vif value when it has extensions instead of "Custom VIF". The
proper fix would be to also add support for the orthogonal VIF
extensions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants