From 30b33c9ede51090084f7cc82a5c01c397f606b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20=C3=96hrstr=C3=B6m?= Date: Wed, 28 Sep 2022 13:48:17 +0200 Subject: [PATCH] Make sure field matching is performed on the dv entries in an order where the offsets are increasing. --- simulations/simulation_broken.txt | 5 ++++- src/meters.cc | 17 +++++++++++++---- tests/test_broken.sh | 4 ++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/simulations/simulation_broken.txt b/simulations/simulation_broken.txt index ae3abc5..f50fd54 100644 --- a/simulations/simulation_broken.txt +++ b/simulations/simulation_broken.txt @@ -2,5 +2,8 @@ # Since the simulation will not remove the crcs unless they all check out, this will result in a broken telegram. telegram=|3444EE4D813929271608|811D|7A51000000|046D1912A62B036E000000|5170426CE1F1436E00000002FF2C00000259D6D0D4090265FC0902FD66A00044| - +# After offset 112 this telegram looks broken. Duplicate total energy entries and broken dif inside. telegram=|a944c5149564252200047a10009025a8431d8Bee683c2471d99f2B943e739f39aff1a257d056cBB97d6Ba1ce2a85c01455Bef04a0BB199582803174de070957378350c6419c5Bf499Bf8e089390B4aB4f610c0BB334ad2B810994Be18fcf0d8B12a3BBB3e8cBe90009df3d7cfc8B62d89923e1a0d207BBdd4B453491a00d3942fe1B8d0d03492ad8cce69c8968B157d6f25ad1a541aafB0787aae06d6c9Bf903f903fd0c05010002fd0B| + +# And this telegram as well. Duplicate total energy entries! No broken dif though. +telegram=|a944c5149564252200047a5d009025aa5d3614331a4e5c3316ae3f016Bea63B1999e17029355a4ae0f498f936e876c1ad9B4a973642c10c384f6f74c7de852f811ffB8acBB36245015726d1a75a6ad2d94ff8e19a093f6e4e010178B41e26468ca8d560B5c571ff8e047ec7d1f3a72B06B63cdcB2B86ff1df9f6de62831d19B109c13438e7851aB5890d540c06de90628B4e8388381B6e0fc96d36d577e462036203fd0c05010002fd0B| diff --git a/src/meters.cc b/src/meters.cc index ab48f05..12bbd96 100644 --- a/src/meters.cc +++ b/src/meters.cc @@ -1775,10 +1775,18 @@ void MeterCommonImplementation::processFieldExtractors(Telegram *t) { map found; - // Iterate through the data content (dv_entries) in the telegram. + vector sorted_entries; + for (auto &p : t->dv_entries) { - DVEntry *dve = &p.second.second; + sorted_entries.push_back(&p.second.second); + } + sort(sorted_entries.begin(), sorted_entries.end(), + [](const DVEntry* a, const DVEntry *b) -> bool { return a->offset < b->offset; }); + + // Iterate through the data content (dv_entries) in the telegram. + for (DVEntry *dve : sorted_entries) + { // We have telegram content, a dif-vif-value entry. // Now check for a field info that wants to handle this telegram content entry. for (FieldInfo &fi : field_infos_) @@ -1800,11 +1808,12 @@ void MeterCommonImplementation::processFieldExtractors(Telegram *t) else { // We have field that wants to handle this entry! - debug("(meters) using field info %s(%s)[%d] to extract %s\n", + debug("(meters) using field info %s(%s)[%d] to extract %s at offset %d\n", fi.vname().c_str(), toString(fi.xuantity()), fi.index(), - dve->dif_vif_key.str().c_str()); + dve->dif_vif_key.str().c_str(), + dve->offset); dve->addFieldInfo(&fi); fi.performExtraction(this, t, dve); diff --git a/tests/test_broken.sh b/tests/test_broken.sh index cff3015..ecf6c63 100755 --- a/tests/test_broken.sh +++ b/tests/test_broken.sh @@ -14,6 +14,10 @@ cat > $TEST/test_expected.txt <